summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordzwdz2021-08-27 19:23:10 +0200
committerdzwdz2021-08-27 19:23:10 +0200
commitaa3ce9383da78a83b64160d5c64ecd077d0b36ef (patch)
tree2d1f54e001289713ef71adfa50a7788e4c0fa194
parent0876ffb05e6973601ef1e930f1ed8d939666132a (diff)
basic vfs_mount_resolve tests
-rw-r--r--src/kernel/tests/vfs.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/kernel/tests/vfs.c b/src/kernel/tests/vfs.c
index bc95541..cfbf86b 100644
--- a/src/kernel/tests/vfs.c
+++ b/src/kernel/tests/vfs.c
@@ -1,5 +1,7 @@
+#include <kernel/mem.h>
#include <kernel/tests/base.h>
#include <kernel/util.h>
+#include <kernel/vfs/mount.h>
#include <kernel/vfs/path.h>
TEST(path_simplify) {
@@ -57,6 +59,41 @@ TEST(path_simplify) {
#undef TEST_WRAPPER
}
+TEST(vfs_mount_resolve) {
+ struct vfs_mount *mount = NULL;
+
+#define ADD_MOUNT(path) do { \
+ struct vfs_mount *mount2 = kmalloc(sizeof(struct vfs_mount)); \
+ mount2->prefix = path; \
+ mount2->prefix_len = sizeof(path) - 1; \
+ mount2->prev = mount; \
+ mount = mount2; \
+ } while (0)
+
+ ADD_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
+}
+
void tests_vfs(void) {
TEST_RUN(path_simplify);
+ TEST_RUN(vfs_mount_resolve);
}