public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH] syscalls/fsmount: add coverage for fsmount01.c
@ 2024-08-30  7:11 YouZhi Zhao
  2024-11-29 16:19 ` Cyril Hrubis
  0 siblings, 1 reply; 2+ messages in thread
From: YouZhi Zhao @ 2024-08-30  7:11 UTC (permalink / raw)
  To: ltp

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(-)

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 = {
--
2.43.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [LTP] [PATCH] syscalls/fsmount: add coverage for fsmount01.c
  2024-08-30  7:11 [LTP] [PATCH] syscalls/fsmount: add coverage for fsmount01.c YouZhi Zhao
@ 2024-11-29 16:19 ` Cyril Hrubis
  0 siblings, 0 replies; 2+ messages in thread
From: Cyril Hrubis @ 2024-11-29 16:19 UTC (permalink / raw)
  To: YouZhi Zhao; +Cc: ltp

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

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-11-29 16:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-30  7:11 [LTP] [PATCH] syscalls/fsmount: add coverage for fsmount01.c YouZhi Zhao
2024-11-29 16:19 ` Cyril Hrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox