[LTP] [PATCH] syscalls/fsmount: add coverage for fsmount01.c
Cyril Hrubis
chrubis@suse.cz
Fri Nov 29 17:19:44 CET 2024
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.
--
Cyril Hrubis
chrubis@suse.cz
More information about the ltp
mailing list