1 | // SPDX-License-Identifier: GPL-3.0-or-later |
2 | |
3 | #include "mos/filesystem/dentry.h" |
4 | #include "mos/filesystem/vfs.h" |
5 | #include "test_engine_impl.h" |
6 | |
7 | static void stat_receiver(int depth, const dentry_t *dentry, bool mountroot, void *data) |
8 | { |
9 | MOS_UNUSED(data); |
10 | pr_info2("%*s%s: %zu%s" , depth * 4, "" , dentry_name(dentry), dentry->refcount, mountroot ? " (mountroot)" : "" ); |
11 | } |
12 | |
13 | MOS_TEST_DECL_PTEST(vfs_mount_test, "Mount %s in %s, with rootfs: %d" , const char *fs, const char *mountpoint, bool rootfs) |
14 | { |
15 | long ok = false; |
16 | |
17 | if (rootfs) |
18 | { |
19 | ok = vfs_mount(device: "none" , path: "/" , fs: "tmpfs" , options: "" ); |
20 | MOS_TEST_ASSERT(ok == 0, "failed to mount tmpfs on /" ); |
21 | } |
22 | |
23 | ok = vfs_mkdir(path: mountpoint); |
24 | MOS_TEST_ASSERT((ok == 0) == rootfs, "creating %s should %sbe successful" , mountpoint, rootfs ? "" : "not" ); |
25 | dentry_dump_refstat(dentry: root_dentry, receiver: stat_receiver, NULL); |
26 | |
27 | ok = vfs_mount(device: "none" , path: mountpoint, fs, options: "" ); |
28 | MOS_TEST_ASSERT((ok == 0) == rootfs, "mounting %s on %s should %sbe successful" , fs, mountpoint, rootfs ? "" : "not" ); |
29 | dentry_dump_refstat(dentry: root_dentry, receiver: stat_receiver, NULL); |
30 | |
31 | ok = vfs_unmount(path: mountpoint); |
32 | MOS_TEST_ASSERT((ok == 0) == rootfs, "unmounting /tmp should %sbe successful" , rootfs ? "" : "not" ); |
33 | dentry_dump_refstat(dentry: root_dentry, receiver: stat_receiver, NULL); |
34 | |
35 | ok = vfs_rmdir(path: mountpoint); |
36 | MOS_TEST_ASSERT((ok == 0) == rootfs, "removing %s should %sbe successful" , mountpoint, rootfs ? "" : "not" ); |
37 | dentry_dump_refstat(dentry: root_dentry, receiver: stat_receiver, NULL); |
38 | |
39 | if (rootfs) |
40 | { |
41 | ok = vfs_unmount(path: "/" ); |
42 | MOS_TEST_ASSERT(ok == 0, "failed to unmount rootfs" ); |
43 | } |
44 | } |
45 | |
46 | MOS_TEST_PTEST_INSTANCE(vfs_mount_test, "tmpfs" , "/tmp" , false); |
47 | MOS_TEST_PTEST_INSTANCE(vfs_mount_test, "tmpfs" , "/tmp" , true); |
48 | |