Skip to contentSkip to conversation

syscalls/utimensat: Migrate to new test framework

PATCH New Viresh Kumar 2 participants 3 messages Aug 7, 2020 – Aug 10, 2020

lore
Share & tools
lore
#0 lore raw

PATCH v9 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).

---
V9:
- Rearranged the code a bit
- Dropped some useless TEST() calls
- Use the syscall from variant structure

 runtest/syscalls                                   |   2 +-
 testcases/kernel/syscalls/utimensat/Makefile       |   4 -
 testcases/kernel/syscalls/utimensat/utimensat01.c  | 455 +++++++++---------
 .../kernel/syscalls/utimensat/utimensat_tests.sh   | 517 ---------------------
 4 files changed, 213 insertions(+), 765 deletions(-)
 delete mode 100755 testcases/kernel/syscalls/utimensat/utimensat_tests.sh
runtest/syscalls +1 -1
index ecd0d0c92322..3c2f5f6c0b37 100644
@@ -1607,7 +1607,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 +212 -243

494 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 v9 2/2 syscalls/utimensat: Add support for time64 tests

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

---
 testcases/kernel/syscalls/utimensat/utimensat01.c | 74 +++++++++++++++++++----
 1 file changed, 63 insertions(+), 11 deletions(-)
testcases/kernel/syscalls/utimensat/utimensat01.c +63 -11
index 617565e52676..d5b9954505a2 100644
@@ -99,13 +99,67 @@ struct test_case {
 };
 
 static inline int sys_utimensat(int dirfd, const char *pathname,
-			const struct __kernel_old_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);
 }
@@ -146,11 +200,11 @@ static void change_attr(struct test_case *tc, int fd, int set)
 
 static void reset_time(char *pathname, int dfd, int flags, int i)
 {
-	struct __kernel_old_timespec ts[2];
+	struct test_variants *tv = &variants[tst_variant];
 	struct stat sb;
 
-	memset(ts, 0, sizeof(ts));
-	sys_utimensat(dfd, pathname, ts, flags);
+	memset(&ts, 0, sizeof(ts));
+	tv->utimensat(dfd, pathname, &ts, flags);
 
 	TEST(stat(pathname, &sb));
 	if (TST_RET) {
@@ -163,8 +217,8 @@ static void reset_time(char *pathname, int dfd, int flags, int i)
 
 static void run(unsigned int i)
 {
+	struct test_variants *tv = &variants[tst_variant];
 	struct test_case *tc = &tcase[i];
-	struct __kernel_old_timespec ts[2];
 	int dfd = AT_FDCWD, fd = 0, atime_change, mtime_change;
 	struct mytime *mytime = tc->mytime;
 	char *pathname = NULL;
@@ -187,16 +241,13 @@ static void run(unsigned int i)
 	}
 
 	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;
 	} else if (tc->exp_err == EFAULT) {
 		tsp = 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);
 
@@ -245,6 +296,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 v9 1/2 syscalls/utimensat: Migrate to new test framework

In reply to Viresh Kumar

Hi!
Pushed with a minor change, thanks.

I have moved the errno update to the setup with:

testcases/kernel/syscalls/utimensat/utimensat01.c +11 -8
index 617565e52..7e4fb9f25 100644
@@ -104,12 +104,6 @@ static inline int sys_utimensat(int dirfd, const char *pathname,
 	return tst_syscall(__NR_utimensat, dirfd, pathname, times, flags);
 }
 
-static void setup(void)
-{
-	bad_addr = tst_get_bad_addr(NULL);
-	SAFE_MKDIR(TEST_DIR, 0700);
-}
-
 static void update_error(struct test_case *tc)
 {
 	if (tc->exp_err != -1)
@@ -171,8 +165,6 @@ static void run(unsigned int i)
 	void *tsp = NULL;
 	struct stat sb;
 
-	update_error(tc);
-
 	if (tc->dirfd != AT_FDCWD)
 		dfd = SAFE_OPEN(TEST_DIR, tc->oflags);
 
@@ -242,6 +234,17 @@ close:
 		SAFE_CLOSE(fd);
 }
 
+static void setup(void)
+{
+	size_t i;
+
+	bad_addr = tst_get_bad_addr(NULL);
+	SAFE_MKDIR(TEST_DIR, 0700);
+
+	for (i = 0; i < ARRAY_SIZE(tcase); i++)
+		update_error(&tcase[i]);
+}
+
 static struct tst_test test = {
 	.test = run,
 	.tcnt = ARRAY_SIZE(tcase),
Signature · 2 lines
Cyril Hrubis
[email protected]