Message ID | 027453D6AD3FFC61+20240830071101.754457-1-zhaoyouzhi@uniontech.com |
---|---|
State | Changes Requested |
Headers | show |
Series | syscalls/fsmount: add coverage for fsmount01.c | expand |
Hi! > +static void verify_mount_readonly(void) > +{ > + int fd; > + > + fd = open(TEST_FILE, O_WRONLY | O_CREAT, 0644); > + if (fd == -1) { > + if (errno == EROFS) { > + tst_res(TPASS, "MOUNT_ATTR_RDONLY verified: Cannot create file, filesystem is read-only."); > + } else { > + tst_res(TFAIL | TTERRNO, "Failed to create file for unknown reason."); > + } > + } else { > + tst_res(TFAIL, "MOUNT_ATTR_RDONLY verification failed: File created on supposed read-only filesystem."); > + close(fd); > + unlink(TEST_FILE); > + } This could be just single TST_EXP_FAIL(). > +} > + > static void run(unsigned int n) > { > struct tcase *tc = &tcases[n]; > @@ -81,10 +100,14 @@ static void run(unsigned int n) > return; > } > > - if (tst_is_mounted_at_tmpdir(MNTPOINT)) { > - SAFE_UMOUNT(MNTPOINT); > - tst_res(TPASS, "%s: fsmount() passed", tc->name); > - } > + if (tst_is_mounted_at_tmpdir(MNTPOINT)) { > + if (tc->attrs & MOUNT_ATTR_RDONLY) { > + verify_mount_readonly(); > + } else { > + tst_res(TPASS, "%s: fsmount() passed", tc->name); > + } > + SAFE_UMOUNT(MNTPOINT); > + } Instead of this hackery we can add a pointer to a verify function to the struct tcase and execute the function if it was set. Then we can possibly implement the verify function for more flags. E.g. expect that mknod() fails on FS mounted with NODEV.
diff --git a/testcases/kernel/syscalls/fsmount/fsmount01.c b/testcases/kernel/syscalls/fsmount/fsmount01.c index 5f755863f..8bf4a5a0a 100644 --- a/testcases/kernel/syscalls/fsmount/fsmount01.c +++ b/testcases/kernel/syscalls/fsmount/fsmount01.c @@ -10,6 +10,7 @@ #include "lapi/fsmount.h" #define MNTPOINT "mntpoint" +#define TEST_FILE MNTPOINT "/testfile" #define TCASE_ENTRY(_flags, _attrs) {.name = "Flag " #_flags ", Attr " #_attrs, .flags = _flags, .attrs = _attrs} @@ -36,6 +37,24 @@ static struct tcase { TCASE_ENTRY(FSMOUNT_CLOEXEC, MOUNT_ATTR_NODIRATIME), }; +static void verify_mount_readonly(void) +{ + int fd; + + fd = open(TEST_FILE, O_WRONLY | O_CREAT, 0644); + if (fd == -1) { + if (errno == EROFS) { + tst_res(TPASS, "MOUNT_ATTR_RDONLY verified: Cannot create file, filesystem is read-only."); + } else { + tst_res(TFAIL | TTERRNO, "Failed to create file for unknown reason."); + } + } else { + tst_res(TFAIL, "MOUNT_ATTR_RDONLY verification failed: File created on supposed read-only filesystem."); + close(fd); + unlink(TEST_FILE); + } +} + static void run(unsigned int n) { struct tcase *tc = &tcases[n]; @@ -81,10 +100,14 @@ static void run(unsigned int n) return; } - if (tst_is_mounted_at_tmpdir(MNTPOINT)) { - SAFE_UMOUNT(MNTPOINT); - tst_res(TPASS, "%s: fsmount() passed", tc->name); - } + if (tst_is_mounted_at_tmpdir(MNTPOINT)) { + if (tc->attrs & MOUNT_ATTR_RDONLY) { + verify_mount_readonly(); + } else { + tst_res(TPASS, "%s: fsmount() passed", tc->name); + } + SAFE_UMOUNT(MNTPOINT); + } } static struct tst_test test = {
Can I create a file and write a file verification after adding the setting for MOUNT_STTR_RDONLY Signed-off-by: Youzhi Zhao <zhaoyouzhi@uniontech.com> --- testcases/kernel/syscalls/fsmount/fsmount01.c | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) -- 2.43.0