diff --git a/Userspace/apps/test/libc_test/assert/assert.c b/Userspace/apps/test/libc_test/assert/assert.c index b45aee69..eaa5f2db 100644 --- a/Userspace/apps/test/libc_test/assert/assert.c +++ b/Userspace/apps/test/libc_test/assert/assert.c @@ -16,3 +16,9 @@ */ #include + +int test_assert(void) +{ + assert(1 == 1); + return 0; +} diff --git a/Userspace/apps/test/libc_test/dirent/alphasort.c b/Userspace/apps/test/libc_test/dirent/alphasort.c index dc794ee6..04dd7a20 100644 --- a/Userspace/apps/test/libc_test/dirent/alphasort.c +++ b/Userspace/apps/test/libc_test/dirent/alphasort.c @@ -16,3 +16,5 @@ */ #include + +int test_alphasort(void) { return 2; } diff --git a/Userspace/apps/test/libc_test/dirent/closedir.c b/Userspace/apps/test/libc_test/dirent/closedir.c index dc794ee6..3b1a238c 100644 --- a/Userspace/apps/test/libc_test/dirent/closedir.c +++ b/Userspace/apps/test/libc_test/dirent/closedir.c @@ -16,3 +16,5 @@ */ #include + +int test_closedir(void) { return 2; } diff --git a/Userspace/apps/test/libc_test/dirent/dirfd.c b/Userspace/apps/test/libc_test/dirent/dirfd.c index dc794ee6..5a6b4ad4 100644 --- a/Userspace/apps/test/libc_test/dirent/dirfd.c +++ b/Userspace/apps/test/libc_test/dirent/dirfd.c @@ -16,3 +16,5 @@ */ #include + +int test_dirfd(void) { return 2; } diff --git a/Userspace/apps/test/libc_test/dirent/fdopendir.c b/Userspace/apps/test/libc_test/dirent/fdopendir.c index dc794ee6..0ef67c91 100644 --- a/Userspace/apps/test/libc_test/dirent/fdopendir.c +++ b/Userspace/apps/test/libc_test/dirent/fdopendir.c @@ -16,3 +16,5 @@ */ #include + +int test_fdopendir(void) { return 2; } diff --git a/Userspace/apps/test/libc_test/dirent/opendir.c b/Userspace/apps/test/libc_test/dirent/opendir.c index dc794ee6..dfbd1126 100644 --- a/Userspace/apps/test/libc_test/dirent/opendir.c +++ b/Userspace/apps/test/libc_test/dirent/opendir.c @@ -16,3 +16,5 @@ */ #include + +int test_opendir() { return 2; } diff --git a/Userspace/apps/test/libc_test/dirent/posix_getdents.c b/Userspace/apps/test/libc_test/dirent/posix_getdents.c index dc794ee6..4db30bd7 100644 --- a/Userspace/apps/test/libc_test/dirent/posix_getdents.c +++ b/Userspace/apps/test/libc_test/dirent/posix_getdents.c @@ -16,3 +16,5 @@ */ #include + +int test_posix_getdents() { return 2; } diff --git a/Userspace/apps/test/libc_test/dirent/readdir.c b/Userspace/apps/test/libc_test/dirent/readdir.c index dc794ee6..68d84b85 100644 --- a/Userspace/apps/test/libc_test/dirent/readdir.c +++ b/Userspace/apps/test/libc_test/dirent/readdir.c @@ -16,3 +16,5 @@ */ #include + +int test_readdir() { return 2; } diff --git a/Userspace/apps/test/libc_test/dirent/readdir_r.c b/Userspace/apps/test/libc_test/dirent/readdir_r.c index dc794ee6..3e35ff9e 100644 --- a/Userspace/apps/test/libc_test/dirent/readdir_r.c +++ b/Userspace/apps/test/libc_test/dirent/readdir_r.c @@ -16,3 +16,5 @@ */ #include + +int test_readdir_r() { return 2; } diff --git a/Userspace/apps/test/libc_test/dirent/rewinddir.c b/Userspace/apps/test/libc_test/dirent/rewinddir.c index dc794ee6..4ea710e8 100644 --- a/Userspace/apps/test/libc_test/dirent/rewinddir.c +++ b/Userspace/apps/test/libc_test/dirent/rewinddir.c @@ -16,3 +16,5 @@ */ #include + +int test_rewinddir() { return 2; } diff --git a/Userspace/apps/test/libc_test/dirent/scandir.c b/Userspace/apps/test/libc_test/dirent/scandir.c index dc794ee6..b646d459 100644 --- a/Userspace/apps/test/libc_test/dirent/scandir.c +++ b/Userspace/apps/test/libc_test/dirent/scandir.c @@ -16,3 +16,5 @@ */ #include + +int test_scandir() { return 2; } diff --git a/Userspace/apps/test/libc_test/dirent/seekdir.c b/Userspace/apps/test/libc_test/dirent/seekdir.c index dc794ee6..2f665b5a 100644 --- a/Userspace/apps/test/libc_test/dirent/seekdir.c +++ b/Userspace/apps/test/libc_test/dirent/seekdir.c @@ -16,3 +16,5 @@ */ #include + +int test_seekdir() { return 2; } diff --git a/Userspace/apps/test/libc_test/dirent/telldir.c b/Userspace/apps/test/libc_test/dirent/telldir.c index dc794ee6..4c9202d3 100644 --- a/Userspace/apps/test/libc_test/dirent/telldir.c +++ b/Userspace/apps/test/libc_test/dirent/telldir.c @@ -16,3 +16,5 @@ */ #include + +int test_telldir() { return 2; } diff --git a/Userspace/apps/test/libc_test/errno/__errno_location.c b/Userspace/apps/test/libc_test/errno/__errno_location.c index 46aa93b8..b76f8ecc 100644 --- a/Userspace/apps/test/libc_test/errno/__errno_location.c +++ b/Userspace/apps/test/libc_test/errno/__errno_location.c @@ -16,3 +16,11 @@ */ #include + +int test___errno_location(void) +{ + (*__errno_location()) = ENOENT; + if ((*__errno_location()) != ENOENT) + return 1; + return 0; +} diff --git a/Userspace/apps/test/libc_test/errno/strerror.c b/Userspace/apps/test/libc_test/errno/strerror.c index 46aa93b8..81ce89dc 100644 --- a/Userspace/apps/test/libc_test/errno/strerror.c +++ b/Userspace/apps/test/libc_test/errno/strerror.c @@ -16,3 +16,11 @@ */ #include + +int test_strerror(void) +{ + char *enosys = strerror(ENOSYS); + if (enosys == ((void *)0)) + return -1; + return 0; +} diff --git a/Userspace/apps/test/libc_test/fcntl/creat.c b/Userspace/apps/test/libc_test/fcntl/creat.c index fdaa111c..5c539d13 100644 --- a/Userspace/apps/test/libc_test/fcntl/creat.c +++ b/Userspace/apps/test/libc_test/fcntl/creat.c @@ -16,3 +16,5 @@ */ #include + +int test_creat() { return 2; } diff --git a/Userspace/apps/test/libc_test/fcntl/fcntl.c b/Userspace/apps/test/libc_test/fcntl/fcntl.c index fdaa111c..b9ba70b2 100644 --- a/Userspace/apps/test/libc_test/fcntl/fcntl.c +++ b/Userspace/apps/test/libc_test/fcntl/fcntl.c @@ -16,3 +16,5 @@ */ #include + +int test_fcntl() { return 2; } diff --git a/Userspace/apps/test/libc_test/fcntl/open.c b/Userspace/apps/test/libc_test/fcntl/open.c index fdaa111c..eef9929c 100644 --- a/Userspace/apps/test/libc_test/fcntl/open.c +++ b/Userspace/apps/test/libc_test/fcntl/open.c @@ -16,3 +16,5 @@ */ #include + +int test_open() { return 2; } diff --git a/Userspace/apps/test/libc_test/fcntl/openat.c b/Userspace/apps/test/libc_test/fcntl/openat.c index fdaa111c..c1eaf7e2 100644 --- a/Userspace/apps/test/libc_test/fcntl/openat.c +++ b/Userspace/apps/test/libc_test/fcntl/openat.c @@ -16,3 +16,5 @@ */ #include + +int test_openat() { return 2; } diff --git a/Userspace/apps/test/libc_test/fcntl/posix_fadvise.c b/Userspace/apps/test/libc_test/fcntl/posix_fadvise.c index fdaa111c..d4d47820 100644 --- a/Userspace/apps/test/libc_test/fcntl/posix_fadvise.c +++ b/Userspace/apps/test/libc_test/fcntl/posix_fadvise.c @@ -16,3 +16,5 @@ */ #include + +int test_posix_fadvise() { return 2; } diff --git a/Userspace/apps/test/libc_test/fcntl/posix_fallocate.c b/Userspace/apps/test/libc_test/fcntl/posix_fallocate.c index fdaa111c..b773a276 100644 --- a/Userspace/apps/test/libc_test/fcntl/posix_fallocate.c +++ b/Userspace/apps/test/libc_test/fcntl/posix_fallocate.c @@ -16,3 +16,5 @@ */ #include + +int test_posix_fallocate() { return 2; } diff --git a/Userspace/apps/test/libc_test/main.c b/Userspace/apps/test/libc_test/main.c index e17e8d2e..f8b1bd2c 100644 --- a/Userspace/apps/test/libc_test/main.c +++ b/Userspace/apps/test/libc_test/main.c @@ -15,7 +15,92 @@ along with Fennix Userspace. If not, see . */ -int main(int argc, char *argv[]) +#include +#include + +__attribute__((noreturn)) __attribute__((no_stack_protector)) void __stack_chk_fail(void) +{ + _exit(0xbeef); +} + +int sample_test_pass() { return 0; } + +int sample_test_fail() +{ + return 1; +} + +#define TEST(func) \ + do \ + { \ + printf("Testing \033[1;30m%s\033[0m...", #func); \ + fflush(stdout); \ + int func(void); /* Declare the function */ \ + int result = func(); \ + if (result == 0) \ + printf("\033[0;32m PASS (%d)\033[0m\n", result); \ + else \ + { \ + printf("\033[0;31m FAIL (%d)\033[0m\n", result); \ + failed_tests[failed_count++] = #func; \ + } \ + fflush(stdout); \ + total_tests++; \ + } while (0) + +int main(int, char *[]) +{ + printf("--- Fennix C Library Test Suite ---\n"); + printf("Required functions: printf, fflush & _exit\n"); + printf("-------------------------------------------\n"); + + char *failed_tests[100]; + int failed_count = 0; + int total_tests = 0; + + printf("--- assert.h ---\n"); + TEST(test_assert); + + printf("--- dirent.h ---\n"); + TEST(test_alphasort); + TEST(test_closedir); + TEST(test_dirfd); + TEST(test_fdopendir); + TEST(test_opendir); + TEST(test_posix_getdents); + TEST(test_readdir_r); + TEST(test_readdir); + TEST(test_rewinddir); + TEST(test_scandir); + TEST(test_seekdir); + TEST(test_telldir); + + printf("--- errno.h ---\n"); + TEST(test___errno_location); + TEST(test_strerror); + + printf("--- fnctl.h ---\n"); + TEST(test_creat); + TEST(test_fcntl); + TEST(test_open); + TEST(test_openat); + TEST(test_posix_fadvise); + TEST(test_posix_fallocate); + + // TEST(); + + printf("-------------------------------------------\n"); + printf("Total tests: \033[1;34m%d\033[0m\n", total_tests); + printf("Failed tests: \033[1;31m%d\033[0m\n", failed_count); + if (failed_count > 0) + { + printf("Failed test functions:\n"); + for (int i = 0; i < failed_count; i++) + printf(" - \033[1;31m%s\033[0m\n", failed_tests[i]); + } + printf("Failure rate: \033[1;34m%.2f%%\033[0m\n", (failed_count / (float)total_tests) * 100); + return 0; +}