diff options
-rw-r--r-- | src/kernel/main.c | 4 | ||||
-rw-r--r-- | src/kernel/tests/base.h | 21 | ||||
-rw-r--r-- | src/kernel/tests/main.c | 14 | ||||
-rw-r--r-- | src/kernel/tests/tests.h | 4 | ||||
-rw-r--r-- | src/kernel/tests/vfs.c | 49 | ||||
-rw-r--r-- | src/user/app/tests/kernel/path.c | 41 |
6 files changed, 41 insertions, 92 deletions
diff --git a/src/kernel/main.c b/src/kernel/main.c index 75d9a29..03ff177 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -2,14 +2,10 @@ #include <kernel/main.h> #include <kernel/mem/alloc.h> #include <kernel/proc.h> -#include <kernel/tests/tests.h> #include <kernel/util.h> #include <stdint.h> void kmain(struct kmain_info info) { - kprintf("tests...\n"); - tests_all(); - kprintf("loading init...\n"); process_seed(&info); diff --git a/src/kernel/tests/base.h b/src/kernel/tests/base.h deleted file mode 100644 index ec314c5..0000000 --- a/src/kernel/tests/base.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once -#include <kernel/arch/generic.h> -#include <kernel/util.h> -#include <stdbool.h> - -extern bool _did_tests_fail; - -// tests MUST be used -#pragma GCC diagnostic error "-Wunused-function" - -#define TEST(name) \ - static void __test_##name(void) - -#define TEST_RUN(name) \ - __test_##name(); - -#define TEST_COND(cond) \ - if (!(cond)) { \ - _did_tests_fail = true; \ - kprintf("test failed at " __FILE__ ":" NUM2STR(__LINE__) " "); \ - } diff --git a/src/kernel/tests/main.c b/src/kernel/tests/main.c deleted file mode 100644 index 8a6921a..0000000 --- a/src/kernel/tests/main.c +++ /dev/null @@ -1,14 +0,0 @@ -#include <kernel/panic.h> -#include <kernel/tests/base.h> -#include <kernel/tests/tests.h> - -bool _did_tests_fail; - -void tests_all(void) { - _did_tests_fail = false; - - tests_vfs(); - - if (_did_tests_fail) - panic_invalid_state(); -} diff --git a/src/kernel/tests/tests.h b/src/kernel/tests/tests.h deleted file mode 100644 index 0f8693a..0000000 --- a/src/kernel/tests/tests.h +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once - -void tests_all(void); -void tests_vfs(void); diff --git a/src/kernel/tests/vfs.c b/src/kernel/tests/vfs.c deleted file mode 100644 index 9f7c6da..0000000 --- a/src/kernel/tests/vfs.c +++ /dev/null @@ -1,49 +0,0 @@ -#include <kernel/mem/alloc.h> -#include <kernel/tests/base.h> -#include <kernel/tests/tests.h> -#include <kernel/vfs/mount.h> -#include <shared/mem.h> - -TEST(vfs_mount_resolve) { - struct vfs_mount *mount = NULL; - -#define ADD_MOUNT(path) do { \ - struct vfs_mount *mount2 = kmalloc(sizeof *mount2); \ - mount2->prefix = path; \ - mount2->prefix_len = sizeof(path) - 1; \ - mount2->prev = mount; \ - mount = mount2; \ - } while (0) - - ADD_MOUNT(""); // root mount - ADD_MOUNT("/dir/shadowed"); - ADD_MOUNT("/dir"); - -#undef ADD_MOUNT - -#define TEST_WRAPPER(path, expected) do { \ - struct vfs_mount *mount2 = vfs_mount_resolve(mount, path, sizeof(path) - 1); \ - TEST_COND((mount2->prefix_len == sizeof(expected) - 1) \ - && (0 == memcmp(mount2->prefix, expected, mount2->prefix_len))); \ - } while (0) - - TEST_WRAPPER("/", ""); - TEST_WRAPPER("/test", ""); - TEST_WRAPPER("/dir", "/dir"); - TEST_WRAPPER("/dirry", ""); - TEST_WRAPPER("/dir/", "/dir"); - TEST_WRAPPER("/dir/shadowed", "/dir"); - TEST_WRAPPER("/dir/shadowed/", "/dir"); - -#undef TEST_WRAPPER - - while (mount != NULL) { - struct vfs_mount *tmp = mount; - mount = mount->prev; - kfree(tmp); - } -} - -void tests_vfs(void) { - TEST_RUN(vfs_mount_resolve); -} diff --git a/src/user/app/tests/kernel/path.c b/src/user/app/tests/kernel/path.c index bc87881..e25154d 100644 --- a/src/user/app/tests/kernel/path.c +++ b/src/user/app/tests/kernel/path.c @@ -1,6 +1,7 @@ #include "../tests.h" #include <camellia/path.h> #include <string.h> +#include <user/lib/fs/misc.h> static void test_path_simplify(void) { const char *testcases[][2] = { @@ -61,6 +62,46 @@ static void test_path_simplify(void) { } } +static void mount_resolve_drv(const char *path) { + if (fork2_n_mount(path)) return; + + struct fs_wait_response res; + while (!_syscall_fs_wait(NULL, 0, &res)) { + // TODO does the first argument of _syscall_fs_respond need to be non-const? + _syscall_fs_respond((void*)path, strlen(path), 0); + } + exit(1); +} + +static void test_mount_resolve(void) { + const char *testcases[][2] = { + {"/", "/"}, + {"/test", "/"}, + {"/dir", "/dir"}, + {"/dir/..", "/"}, + {"/dir/../dir", "/dir"}, + {"/dirry", "/"}, + {"/dir/", "/dir"}, + {"/dir/shadowed", "/dir"}, + {"/dir/shadowed/", "/dir"}, + }; + mount_resolve_drv("/"); + mount_resolve_drv("/dir/shadowed"); + mount_resolve_drv("/dir"); + + char buf[16]; + for (size_t i = 0; i < sizeof(testcases) / sizeof(testcases[0]); i++) { + const char *input = testcases[i][0]; + const char *expected = testcases[i][1]; + handle_t h = _syscall_open(input, strlen(input), 0); + test(h >= 0); + int len = _syscall_read(h, buf, sizeof buf, 0); + test(len == (int)strlen(expected) && !memcmp(expected, buf, len)); + _syscall_close(h); + } +} + void r_k_path(void) { run_test(test_path_simplify); + run_test(test_mount_resolve); } |