Skip to contentSkip to conversation

mount/mount03.c: Test feature MS_NOATIME of mount(2)

PATCH Superseded DAN LI 2 participants 2 messages Jul 1, 2013

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

DAN LI

author
#0 lore raw

PATCH 1/1 mount/mount03.c: Test feature MS_NOATIME of mount(2)

Additional test for features MS_NOATIME.

---
 testcases/kernel/syscalls/mount/mount03.c | 47 +++++++++++++++++++++++++++++--
 1 file changed, 45 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/mount/mount03.c +45 -2
index b1aa71f..370b880 100644
@@ -20,7 +20,7 @@
  *
  *    TEST TITLE	: Test for checking mount(2) flags
  *
- *    TEST CASE TOTAL	: 6
+ *    TEST CASE TOTAL	: 7
  *
  *    AUTHOR		: Nirmala Devi Dhanasekar <[email protected]>
  *
@@ -35,6 +35,7 @@
  *	4) MS_SYNCHRONOUS - writes are synced at once.
  *	5) MS_REMOUNT - alter flags of a mounted FS.
  *	6) MS_NOSUID - ignore suid and sgid bits.
+ *	7) MS_NOATIME - do not update access times.
  *
  *	Setup:
  *	  Setup signal handling.
@@ -83,7 +84,7 @@ static int test_rwflag(int, int);
 static int setup_uid(void);
 
 char *TCID = "mount03";
-int TST_TOTAL = 6;
+int TST_TOTAL = 7;
 
 #define DEFAULT_FSTYPE	"ext2"
 #define TEMP_FILE	"temp_file"
@@ -115,6 +116,7 @@ long rwflags[] = {
 	MS_SYNCHRONOUS,
 	MS_RDONLY,
 	MS_NOSUID,
+	MS_NOATIME,
 };
 
 static option_t options[] = {
@@ -208,6 +210,8 @@ int test_rwflag(int i, int cnt)
 {
 	int ret, fd, pid, status;
 	char nobody_uid[] = "nobody";
+	time_t atime;
+	struct stat file_stat;
 	struct passwd *ltpuser;
 
 	switch (i) {
@@ -370,6 +374,45 @@ int test_rwflag(int i, int cnt)
 					return 1;
 			}
 		}
+	case 6:
+		/* Validate MS_NOATIME flag of mount call */
+
+		snprintf(file, PATH_MAX, "%satime", path_name);
+		fd = open(file, O_CREAT | O_RDWR, S_IRWXU);
+		if (fd == -1) {
+			tst_resm(TWARN | TERRNO, "opening %s failed", file);
+			return 1;
+		}
+
+		if (write(fd, "TEST_MS_NOATIME", 15) != 15) {
+			tst_resm(TWARN | TERRNO, "write %s failed", file);
+			return 1;
+		}
+
+		if (fstat(fd, &file_stat) == -1) {
+			tst_resm(TWARN | TERRNO, "stat %s failed #1", file);
+			return 1;
+		}
+
+		atime = file_stat.st_atime;
+
+		if (read(fd, NULL, 20) == -1) {
+			tst_resm(TWARN | TERRNO, "read %s failed", file);
+			return 1;
+		}
+
+		if (fstat(fd, &file_stat) == -1) {
+			tst_resm(TWARN | TERRNO, "stat %s failed #2", file);
+			return 1;
+		}
+
+		close(fd);
+
+		if (file_stat.st_atime != atime) {
+			tst_resm(TWARN, "access time is updated");
+			return 1;
+		}
+		return 0;
 	}
 	return 0;
 }
Signature · 12 lines
1.8.1

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#1 lore raw

Hi!

Quoted 12 lines
testcases/kernel/syscalls/mount/mount03.c +12 -0
+	case 6:
+		/* Validate MS_NOATIME flag of mount call */
+
+		snprintf(file, PATH_MAX, "%satime", path_name);
+		fd = open(file, O_CREAT | O_RDWR, S_IRWXU);
+		if (fd == -1) {
+			tst_resm(TWARN | TERRNO, "opening %s failed", file);
+			return 1;
+		}
+
+		if (write(fd, "TEST_MS_NOATIME", 15) != 15) {
+			tst_resm(TWARN | TERRNO, "write %s failed", file);

testcases/kernel/syscalls/mount/mount03.c int test_rwflag(int i, int cnt) · line 398

Quoted 10 lines
testcases/kernel/syscalls/mount/mount03.c +10 -0
+			return 1;
+		}
+
+		if (fstat(fd, &file_stat) == -1) {
+			tst_resm(TWARN | TERRNO, "stat %s failed #1", file);
+			return 1;
+		}
+
+		atime = file_stat.st_atime;
+

The time_t, if I'm not mistaken, has resolution in seconds, so you need to sleep a second here before you call the read() bellow to be sure timestamp is different at the time you try to read.

Moreover the whole testcase should better be cleaned up (it doesn't use the tst_require_root() and does some strange/unnecessary things in the temp dir).

Signature · 13 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list