Skip to contentSkip to conversation

syscalls/utimensat: Migrate to new test framework

PATCH Superseded Viresh Kumar 2 participants 6 messages Aug 5, 2020 – Aug 7, 2020

v8 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

PATCH v8 1/2 syscalls/utimensat: Migrate to new test framework

This gets rid of the test script and updates the utimensat01.c file to handle most of the tests covered earlier (apart from testing the same for files owned by root, as the test is run as root right now).

---
V8:
- Added verification of atime and mtime
- Moved Makefile and syscalls changes here from 2/2
- No double indirection of mtime required
- Add directory in setup instead of run().
- update_error() can't be moved to setup() as that is dependent on each testcase.

 runtest/syscalls                                   |   2 +-
 testcases/kernel/syscalls/utimensat/Makefile       |   4 -
 testcases/kernel/syscalls/utimensat/utimensat01.c  | 449 +++++++++---------
 .../kernel/syscalls/utimensat/utimensat_tests.sh   | 517 ---------------------
 4 files changed, 208 insertions(+), 764 deletions(-)
 delete mode 100755 testcases/kernel/syscalls/utimensat/utimensat_tests.sh
runtest/syscalls +1 -1
index a0f67e85c363..3c6e78a4c6d0 100644
@@ -1606,7 +1606,7 @@ utime06 utime06
 utimes01 utimes01
 
 # Introduced from Kernel 2.6.22 onwards
-utimensat01 utimensat_tests.sh
+utimensat01 utimensat01
 
 vfork01 vfork01
 vfork02 vfork02
testcases/kernel/syscalls/utimensat/Makefile +0 -4
index 69cab8dbc057..044619fb8724 100644
@@ -5,8 +5,4 @@ top_srcdir		?= ../../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
 
-vpath %.c $(srcdir):$(top_srcdir)/lib
-
-INSTALL_TARGETS		:= utimensat_tests.sh
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/utimensat/utimensat01.c +207 -242

489 lines not on this page · raw message

testcases/kernel/syscalls/utimensat/utimensat_tests.sh deleted +0 -517

517 lines not on this page · raw message

Signature · 1 line
2.14.1
#1 lore raw

PATCH v8 2/2 syscalls/utimensat: Add support for time64 tests

This adds support for time64 tests to the existing utimensat() syscall tests.

---
V8: Resolved rebase conflicts

 testcases/kernel/syscalls/utimensat/utimensat01.c | 71 +++++++++++++++++++----
 1 file changed, 61 insertions(+), 10 deletions(-)
testcases/kernel/syscalls/utimensat/utimensat01.c +61 -10
index 6e14e1f150db..fbdc6a1ce1ed 100644
@@ -16,8 +16,7 @@
 #include <string.h>
 #include <sys/stat.h>
 #include "lapi/fs.h"
-#include "tst_test.h"
-#include "lapi/syscalls.h"
+#include "tst_timer.h"
 
 #define UTIME_NOW	((1l << 30) - 1l)
 #define UTIME_OMIT	((1l << 30) - 2l)
@@ -100,13 +99,67 @@ struct test_case {
 };
 
 static inline int sys_utimensat(int dirfd, const char *pathname,
-				const struct timespec times[2], int flags)
+				void *times, int flags)
 {
 	return tst_syscall(__NR_utimensat, dirfd, pathname, times, flags);
 }
 
+static inline int sys_utimensat_time64(int dirfd, const char *pathname,
+				       void *times, int flags)
+{
+	return tst_syscall(__NR_utimensat_time64, dirfd, pathname, times, flags);
+}
+
+static struct test_variants {
+	int (*utimensat)(int dirfd, const char *pathname, void *times,
+			 int flags);
+	enum tst_ts_type type;
+	char *desc;
+} variants[] = {
+#if (__NR_utimensat != __LTP__NR_INVALID_SYSCALL)
+	{ .utimensat = sys_utimensat, .type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with old kernel spec"},
+#endif
+
+#if (__NR_utimensat_time64 != __LTP__NR_INVALID_SYSCALL)
+	{ .utimensat = sys_utimensat_time64, .type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec"},
+#endif
+};
+
+union tst_multi {
+	struct timespec libc_ts[2];
+	struct __kernel_old_timespec kern_old_ts[2];
+	struct __kernel_timespec kern_ts[2];
+} ts;
+
+static void tst_multi_set_time(enum tst_ts_type type, struct mytime *mytime)
+{
+	switch (type) {
+	case TST_LIBC_TIMESPEC:
+		ts.libc_ts[0].tv_sec = mytime->access_tv_sec;
+		ts.libc_ts[0].tv_nsec = mytime->access_tv_nsec;
+		ts.libc_ts[1].tv_sec = mytime->mod_tv_sec;
+		ts.libc_ts[1].tv_nsec = mytime->mod_tv_nsec;
+		break;
+	case TST_KERN_OLD_TIMESPEC:
+		ts.kern_old_ts[0].tv_sec = mytime->access_tv_sec;
+		ts.kern_old_ts[0].tv_nsec = mytime->access_tv_nsec;
+		ts.kern_old_ts[1].tv_sec = mytime->mod_tv_sec;
+		ts.kern_old_ts[1].tv_nsec = mytime->mod_tv_nsec;
+		break;
+	case TST_KERN_TIMESPEC:
+		ts.kern_ts[0].tv_sec = mytime->access_tv_sec;
+		ts.kern_ts[0].tv_nsec = mytime->access_tv_nsec;
+		ts.kern_ts[1].tv_sec = mytime->mod_tv_sec;
+		ts.kern_ts[1].tv_nsec = mytime->mod_tv_nsec;
+		break;
+	default:
+		tst_brk(TBROK, "Invalid type: %d", type);
+	}
+}
+
 static void setup(void)
 {
+	tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
 	bad_addr = tst_get_bad_addr(NULL);
 	SAFE_MKDIR(TEST_DIR, 0700);
 }
@@ -165,8 +218,8 @@ static void reset_time(char *pathname, int dfd, int flags)
 
 static void run(unsigned int i)
 {
+	struct test_variants *tv = &variants[tst_variant];
 	struct test_case *tc = &tcase[i];
-	struct timespec ts[2];
 	void *tsp = NULL;
 	char *pathname = NULL;
 	int dfd = AT_FDCWD, fd = 0, atime_change, mtime_change;
@@ -179,11 +232,8 @@ static void run(unsigned int i)
 		dfd = SAFE_OPEN(TEST_DIR, tc->oflags);
 
 	if (mytime) {
-		ts[0].tv_sec = mytime->access_tv_sec;
-		ts[0].tv_nsec = mytime->access_tv_nsec;
-		ts[1].tv_sec = mytime->mod_tv_sec;
-		ts[1].tv_nsec = mytime->mod_tv_nsec;
-		tsp = ts;
+		tst_multi_set_time(tv->type, mytime);
+		tsp = &ts.libc_ts;
 	} else if (tc->exp_err == EFAULT) {
 		tsp = bad_addr;
 	}
@@ -198,7 +248,7 @@ static void run(unsigned int i)
 		pathname = bad_addr;
 	}
 
-	TEST(sys_utimensat(dfd, pathname, tsp, tc->flags));
+	TEST(tv->utimensat(dfd, pathname, tsp, tc->flags));
 	if (tc->pathname)
 		change_attr(tc, fd, 0);
 
@@ -241,6 +291,7 @@ static void run(unsigned int i)
 static struct tst_test test = {
 	.test = run,
 	.tcnt = ARRAY_SIZE(tcase),
+	.test_variants = ARRAY_SIZE(variants),
 	.setup = setup,
 	.needs_root = 1,
 	.needs_tmpdir = 1,
Signature · 1 line
2.14.1
#2 lore raw

PATCH v8 1/2 syscalls/utimensat: Migrate to new test framework

In reply to Viresh Kumar

Hi!

Quoted 11 lines
testcases/kernel/syscalls/utimensat/utimensat01.c +4 -6
+static void reset_time(char *pathname, int dfd, int flags)
+{
+	struct timespec ts[2];
+	struct stat sb;
 
-		ts[1].tv_sec = atoi(argv[optind + 3]);
-		if (argv[optind + 4][0] == 'n') {
-			ts[1].tv_nsec = UTIME_NOW;
-		} else if (argv[optind + 4][0] == 'o') {
-			ts[1].tv_nsec = UTIME_OMIT;
-		} else {

testcases/kernel/syscalls/utimensat/utimensat01.c line 159

Quoted 10 lines
testcases/kernel/syscalls/utimensat/utimensat01.c +6 -3
-			ts[1].tv_nsec = atoi(argv[optind + 4]);
-		}
+	ts[0].tv_sec = 0;
+	ts[0].tv_nsec = 0;
+	ts[1].tv_sec = 0;
+	ts[1].tv_nsec = 0;
 
-		tsp = ts;
+	TEST(sys_utimensat(dfd, pathname, ts, flags));
+	TEST(stat(pathname, &sb));

Wrapping the calls to TEST() macro here is useless.

Also we do pass libc timespec to a syscall that is supposed to take the old kernel type, right?

I guess that the options are:

* Use the glibc function here instead

* Change the type in the follow up patch

Quoted 5 lines
testcases/kernel/syscalls/utimensat/utimensat01.c +4 -0
+	if (sb.st_atime || sb.st_mtime) {
+		tst_res(TFAIL, "Failed to reset access and modification time (%lu: %lu)",
+			sb.st_atime, sb.st_mtime);
 	}
+}
Signature · 2 lines
Cyril Hrubis
[email protected]
#3 lore raw

PATCH v8 1/2 syscalls/utimensat: Migrate to new test framework

Quoted 19 lines · Cyril Hrubis

Hi!

Quoted 18 lines
testcases/kernel/syscalls/utimensat/utimensat01.c +8 -8
+static void reset_time(char *pathname, int dfd, int flags)
+{
+	struct timespec ts[2];
+	struct stat sb;
 
-		ts[1].tv_sec = atoi(argv[optind + 3]);
-		if (argv[optind + 4][0] == 'n') {
-			ts[1].tv_nsec = UTIME_NOW;
-		} else if (argv[optind + 4][0] == 'o') {
-			ts[1].tv_nsec = UTIME_OMIT;
-		} else {
-			ts[1].tv_nsec = atoi(argv[optind + 4]);
-		}
+	ts[0].tv_sec = 0;
+	ts[0].tv_nsec = 0;
+	ts[1].tv_sec = 0;
+	ts[1].tv_nsec = 0;
Quoted 5 lines

testcases/kernel/syscalls/utimensat/utimensat01.c line 159

Quoted 3 lines
testcases/kernel/syscalls/utimensat/utimensat01.c +2 -1
-		tsp = ts;
+	TEST(sys_utimensat(dfd, pathname, ts, flags));
+	TEST(stat(pathname, &sb));

Wrapping the calls to TEST() macro here is useless.

The TEST() thing always look like the SAFE_() macros to me somehow and so did this mistake.

Quoted 8 lines

Also we do pass libc timespec to a syscall that is supposed to take the old kernel type, right?

I guess that the options are:

* Use the glibc function here instead

* Change the type in the follow up patch

This is already properly fixed in 2/2.

Signature · 1 line
viresh
#4 lore raw

PATCH v8 1/2 syscalls/utimensat: Migrate to new test framework

Hi!

Quoted 10 lines
Quoted 8 lines

Also we do pass libc timespec to a syscall that is supposed to take the old kernel type, right?

I guess that the options are:

* Use the glibc function here instead

* Change the type in the follow up patch

This is already properly fixed in 2/2.

Maybe I'm blind but I do not see anything that would touch the reset_time() function in 2/2.

Signature · 2 lines
Cyril Hrubis
[email protected]
#5 lore raw

PATCH v8 1/2 syscalls/utimensat: Migrate to new test framework

Quoted 6 lines · Cyril Hrubis

Hi!

Quoted 5 lines
Quoted 5 lines

Also we do pass libc timespec to a syscall that is supposed to take the old kernel type, right?

I guess that the options are:

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

* Use the glibc function here instead

* Change the type in the follow up patch

This is already properly fixed in 2/2.

Maybe I'm blind but I do not see anything that would touch the reset_time() function in 2/2.

I mistakenly thought about the one used in the run() call. Sent V9 now.

Signature · 1 line
viresh