Skip to contentSkip to conversation

Syscalls: Add support for time64 variants

PATCH Superseded Viresh Kumar 4 participants 37 messages May 8, 2020 – May 12, 2020

v2 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v2 cover Syscalls: Add support for time64 variants

Hi Cyril/Petr,

This replaces all my pending patches that I have sent earlier and not applied yet. I am sending them all together (along with few new patches) to avoid any rebase conflicts as reported by Petr.

I have also fixed the GPL licensing thing that Petr asked for at several files in this V2. Otherwise no difference in the patches.

With this I have completed the time64 support for all the syscalls tests.

Viresh Kumar (17):
syscalls/timer_gettime: Add support for time64 tests syscalls/timer_settime: Add support for time64 tests syscalls/timerfd: Add support for time64 tests syscalls/sched_rr_get_interval: Add support for time64 tests syscalls/futex: Merge futex_wait_bitset tests syscalls/futex: Add support for time64 tests syscalls/io_pgetevents: Add support for time64 tests syscalls/sigwaitinfo: Migrate to new test framework syscalls/rt_sigtimedwait: Add support for time64 tests syscalls/mq_timed{send|receive}: Add support for time64 tests syscalls/recvmmsg: Add support for time64 tests syscalls/ppoll: Add support for time64 tests syscalls/select6: Add support for time64 tests syscalls/semop: Migrate to new test framework syscalls/semtimedop: Add support for semtimedop and its time64 version syscalls/utimensat: Migrate to new test framework syscalls/utimensat: Add support for time64 tests

 include/lapi/io_pgetevents.h                  |  15 +-
 include/tst_timer.h                           | 191 +++++++
 runtest/syscalls                              |   1 -
 testcases/kernel/syscalls/futex/.gitignore    |   1 -
 testcases/kernel/syscalls/futex/Makefile      |   1 -
 .../syscalls/futex/futex_cmp_requeue01.c      |  35 +-
 .../syscalls/futex/futex_cmp_requeue02.c      |  25 +-
 testcases/kernel/syscalls/futex/futex_utils.h |  52 +-
 .../kernel/syscalls/futex/futex_wait01.c      |  83 +--
 .../kernel/syscalls/futex/futex_wait02.c      | 104 ++--
 .../kernel/syscalls/futex/futex_wait03.c      |  91 +--
 .../kernel/syscalls/futex/futex_wait04.c      |  85 +--
 .../kernel/syscalls/futex/futex_wait05.c      |   2 +-
 .../kernel/syscalls/futex/futex_wait_bitset.h |  75 ---
 .../syscalls/futex/futex_wait_bitset01.c      | 103 +++-
 .../syscalls/futex/futex_wait_bitset02.c      |  18 -
 .../kernel/syscalls/futex/futex_wake01.c      |  71 ++-
 .../kernel/syscalls/futex/futex_wake02.c      |  99 ++--
 .../kernel/syscalls/futex/futex_wake03.c      | 111 ++--
 .../kernel/syscalls/futex/futex_wake04.c      | 150 ++---
 testcases/kernel/syscalls/futex/futextest.h   | 111 ++--
 .../syscalls/io_pgetevents/io_pgetevents01.c  |  41 +-
 .../syscalls/io_pgetevents/io_pgetevents02.c  |  59 +-
 testcases/kernel/syscalls/ipc/semop/Makefile  |   2 +-
 testcases/kernel/syscalls/ipc/semop/semop.h   |  52 ++
 testcases/kernel/syscalls/ipc/semop/semop01.c | 145 +++--
 testcases/kernel/syscalls/ipc/semop/semop02.c | 153 +++---
 testcases/kernel/syscalls/ipc/semop/semop03.c | 160 ++----
 testcases/kernel/syscalls/ipc/semop/semop04.c | 173 +++---
 testcases/kernel/syscalls/ipc/semop/semop05.c | 309 +++++------
 .../mq_timedreceive/mq_timedreceive01.c       |  97 +++-
 .../syscalls/mq_timedsend/mq_timedsend01.c    | 101 ++--
 testcases/kernel/syscalls/ppoll/ppoll01.c     |  76 ++-
 .../sched_rr_get_interval01.c                 | 131 ++---
 .../sched_rr_get_interval02.c                 | 137 ++---
 .../sched_rr_get_interval03.c                 | 151 +++--
 testcases/kernel/syscalls/select/select_var.h |  27 +-
 .../kernel/syscalls/sendmmsg/sendmmsg01.c     |  45 +-
 .../kernel/syscalls/sendmmsg/sendmmsg_var.h   |  55 +-
 .../syscalls/sigwaitinfo/sigwaitinfo01.c      | 317 ++++++-----
 .../syscalls/timer_gettime/timer_gettime01.c  | 135 ++---
 .../syscalls/timer_settime/timer_settime01.c  |  51 +-
 .../syscalls/timer_settime/timer_settime02.c  |  65 ++-
 testcases/kernel/syscalls/timerfd/timerfd01.c |  58 +-
 testcases/kernel/syscalls/timerfd/timerfd04.c |  56 +-
 .../syscalls/timerfd/timerfd_gettime01.c      | 138 +++--
 .../syscalls/timerfd/timerfd_settime01.c      | 139 +++--
 .../syscalls/timerfd/timerfd_settime02.c      |  33 +-
 testcases/kernel/syscalls/utils/mq_timed.h    |  42 +-
 .../kernel/syscalls/utimensat/utimensat01.c   | 469 ++++++++--------
 .../syscalls/utimensat/utimensat_tests.sh     | 517 ------------------
 51 files changed, 2657 insertions(+), 2701 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/futex/futex_wait_bitset.h
 delete mode 100644 testcases/kernel/syscalls/futex/futex_wait_bitset02.c
 create mode 100644 testcases/kernel/syscalls/ipc/semop/semop.h
 delete mode 100755 testcases/kernel/syscalls/utimensat/utimensat_tests.sh
Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
#1 lore raw

PATCH v2 1/17 syscalls/timer_gettime: Add support for time64 tests

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

---
 include/tst_timer.h                           |  40 ++++++
 .../syscalls/timer_gettime/timer_gettime01.c  | 135 ++++++++----------
 2 files changed, 100 insertions(+), 75 deletions(-)
include/tst_timer.h +40 -0
index 256e1d71e1bc..601f934da670 100644
@@ -15,6 +15,7 @@
 #include <sys/time.h>
 #include <time.h>
 #include "tst_test.h"
+#include "lapi/common_timers.h"
 #include "lapi/syscalls.h"
 
 /*
@@ -112,6 +113,11 @@ struct __kernel_timespec {
 	__kernel_time64_t       tv_sec;                 /* seconds */
 	long long               tv_nsec;                /* nanoseconds */
 };
+
+struct __kernel_itimerspec {
+	struct __kernel_timespec it_interval;    /* timer period */
+	struct __kernel_timespec it_value;       /* timer expiration */
+};
 #endif
 
 enum tst_ts_type {
@@ -129,6 +135,14 @@ struct tst_ts {
 	} ts;
 };
 
+struct tst_its {
+	enum tst_ts_type type;
+	union {
+		struct itimerspec libc_its;
+		struct __kernel_itimerspec kern_its;
+	} ts;
+};
+
 static inline void *tst_ts_get(struct tst_ts *t)
 {
 	if (!t)
@@ -147,6 +161,22 @@ static inline void *tst_ts_get(struct tst_ts *t)
 	}
 }
 
+static inline void *tst_its_get(struct tst_its *t)
+{
+	if (!t)
+		return NULL;
+
+	switch (t->type) {
+	case TST_LIBC_TIMESPEC:
+		return &t->ts.libc_its;
+	case TST_KERN_TIMESPEC:
+		return &t->ts.kern_its;
+	default:
+		tst_brk(TBROK, "Invalid type: %d", t->type);
+		return NULL;
+	}
+}
+
 static inline int libc_clock_getres(clockid_t clk_id, void *ts)
 {
 	return clock_getres(clk_id, ts);
@@ -212,6 +242,16 @@ static inline int sys_clock_nanosleep64(clockid_t clk_id, int flags,
 			   request, remain);
 }
 
+static inline int sys_timer_gettime(kernel_timer_t timerid, void *its)
+{
+	return tst_syscall(__NR_timer_gettime, timerid, its);
+}
+
+static inline int sys_timer_gettime64(kernel_timer_t timerid, void *its)
+{
+	return tst_syscall(__NR_timer_gettime64, timerid, its);
+}
+
 /*
  * Returns tst_ts seconds.
  */
testcases/kernel/syscalls/timer_gettime/timer_gettime01.c +60 -75

155 lines not on this page · raw message

Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
#2 lore raw

PATCH v2 1/17 syscalls/timer_gettime: Add support for time64 tests

testcases/kernel/syscalls/timer_gettime/timer_gettime01.c line 24

Quoted 7 lines · Viresh Kumar
testcases/kernel/syscalls/timer_gettime/timer_gettime01.c +6 -0
+#if defined(TST_ABI32)
+       { .func = sys_timer_gettime, .type = TST_LIBC_TIMESPEC, .desc = "syscall with libc spec"},
+#endif
 
+#if defined(TST_ABI64)
+       { .func = sys_timer_gettime, .type = TST_KERN_TIMESPEC, .desc = "syscall with kernel spec64"},
+#endif

I think these are both invalid: timer_gettime() does not take a libc timespec or a __kernel_timespec but takes a __kernel_old_timespec. You should only use the libc data structure with the libc timer_gettime, and the __kernel_timespec
with the kernel's timer_gettime64().

Arnd

#3 lore raw

PATCH v2 2/17 syscalls/timer_settime: Add support for time64 tests

In reply to Viresh Kumar

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

---
 include/tst_timer.h                           | 34 ++++++++++
 .../syscalls/timer_settime/timer_settime01.c  | 51 +++++++++++----
 .../syscalls/timer_settime/timer_settime02.c  | 65 ++++++++++++++-----
 3 files changed, 122 insertions(+), 28 deletions(-)
include/tst_timer.h +34 -0
index 601f934da670..94d03cecdabe 100644
@@ -252,6 +252,40 @@ static inline int sys_timer_gettime64(kernel_timer_t timerid, void *its)
 	return tst_syscall(__NR_timer_gettime64, timerid, its);
 }
 
+static inline int sys_timer_settime(kernel_timer_t timerid, int flags,
+				    void *its, void *old_its)
+{
+	return tst_syscall(__NR_timer_settime, timerid, flags, its, old_its);
+}
+
+static inline int sys_timer_settime64(kernel_timer_t timerid, int flags,
+				      void *its, void *old_its)
+{
+	return tst_syscall(__NR_timer_settime64, timerid, flags, its, old_its);
+}
+
+static inline void tst_its_set_time(struct tst_its *its, long long value_sec,
+				long long value_nsec, long long interval_sec,
+				long long interval_nsec)
+{
+	switch (its->type) {
+	case TST_LIBC_TIMESPEC:
+		its->ts.libc_its.it_value.tv_sec = value_sec;
+		its->ts.libc_its.it_value.tv_nsec = value_nsec;
+		its->ts.libc_its.it_interval.tv_sec = interval_sec;
+		its->ts.libc_its.it_interval.tv_nsec = interval_nsec;
+	break;
+	case TST_KERN_TIMESPEC:
+		its->ts.kern_its.it_value.tv_sec = value_sec;
+		its->ts.kern_its.it_value.tv_nsec = value_nsec;
+		its->ts.kern_its.it_interval.tv_sec = interval_sec;
+		its->ts.kern_its.it_interval.tv_nsec = interval_nsec;
+	break;
+	default:
+		tst_brk(TBROK, "Invalid type: %d", its->type);
+	}
+}
+
 /*
  * Returns tst_ts seconds.
  */
testcases/kernel/syscalls/timer_settime/timer_settime01.c +39 -12

97 lines not on this page · raw message

testcases/kernel/syscalls/timer_settime/timer_settime02.c +49 -16

99 lines not on this page · raw message

Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
#4 lore raw

PATCH v2 3/17 syscalls/timerfd: Add support for time64 tests

In reply to Viresh Kumar

This adds support for time64 tests to the existing timerfd_gettime() and timerfd_settime() syscall tests.

---
 include/tst_timer.h                           |  48 ++++++
 testcases/kernel/syscalls/timerfd/timerfd01.c |  58 ++++++--
 testcases/kernel/syscalls/timerfd/timerfd04.c |  56 ++++++-
 .../syscalls/timerfd/timerfd_gettime01.c      | 138 ++++++++---------
 .../syscalls/timerfd/timerfd_settime01.c      | 139 +++++++++---------
 .../syscalls/timerfd/timerfd_settime02.c      |  33 ++++-
 6 files changed, 303 insertions(+), 169 deletions(-)
include/tst_timer.h +48 -0
index 94d03cecdabe..a728d78d7def 100644
@@ -264,6 +264,54 @@ static inline int sys_timer_settime64(kernel_timer_t timerid, int flags,
 	return tst_syscall(__NR_timer_settime64, timerid, flags, its, old_its);
 }
 
+static inline int sys_timerfd_gettime(int fd, void *its)
+{
+	return tst_syscall(__NR_timerfd_gettime, fd, its);
+}
+
+static inline int sys_timerfd_gettime64(int fd, void *its)
+{
+	return tst_syscall(__NR_timerfd_gettime64, fd, its);
+}
+
+static inline int sys_timerfd_settime(int fd, int flags, void *its,
+				      void *old_its)
+{
+	return tst_syscall(__NR_timerfd_settime, fd, flags, its, old_its);
+}
+
+static inline int sys_timerfd_settime64(int fd, int flags, void *its,
+				      void *old_its)
+{
+	return tst_syscall(__NR_timerfd_settime64, fd, flags, its, old_its);
+}
+
+static inline long long tst_its_get_val_sec(struct tst_its its)
+{
+	switch (its.type) {
+	case TST_LIBC_TIMESPEC:
+		return its.ts.libc_its.it_value.tv_sec;
+	case TST_KERN_TIMESPEC:
+		return its.ts.kern_its.it_value.tv_sec;
+	default:
+		tst_brk(TBROK, "Invalid type: %d", its.type);
+		return -1;
+	}
+}
+
+static inline long long tst_its_get_val_nsec(struct tst_its its)
+{
+	switch (its.type) {
+	case TST_LIBC_TIMESPEC:
+		return its.ts.libc_its.it_value.tv_nsec;
+	case TST_KERN_TIMESPEC:
+		return its.ts.kern_its.it_value.tv_nsec;
+	default:
+		tst_brk(TBROK, "Invalid type: %d", its.type);
+		return -1;
+	}
+}
+
 static inline void tst_its_set_time(struct tst_its *its, long long value_sec,
 				long long value_nsec, long long interval_sec,
 				long long interval_nsec)
testcases/kernel/syscalls/timerfd/timerfd01.c +46 -12

108 lines not on this page · raw message

testcases/kernel/syscalls/timerfd/timerfd04.c +48 -8

97 lines not on this page · raw message

testcases/kernel/syscalls/timerfd/timerfd_gettime01.c +64 -74

183 lines not on this page · raw message

testcases/kernel/syscalls/timerfd/timerfd_settime01.c +67 -72

186 lines not on this page · raw message

testcases/kernel/syscalls/timerfd/timerfd_settime02.c +30 -3
index 0565802f4288..b6444a6db7ba 100644
@@ -15,8 +15,9 @@
  *  timerfd: Protect the might cancel mechanism proper
  */
 #include <unistd.h>
+#include "tst_timer.h"
+#include "lapi/abisize.h"
 #include "tst_safe_timerfd.h"
-#include "tst_test.h"
 #include "tst_fuzzy_sync.h"
 #include "tst_taint.h"
 
@@ -27,11 +28,34 @@
 #endif
 
 static int fd = -1;
-static struct itimerspec its;
+static struct tst_its its;
 static struct tst_fzsync_pair fzsync_pair;
 
+static struct test_variants {
+	int (*tfd_settime)(int fd, int flags, void *new_value, void *old_value);
+	enum tst_ts_type type;
+	char *desc;
+} variants[] = {
+#if defined(TST_ABI32)
+	{ .tfd_settime = sys_timerfd_settime, .type = TST_LIBC_TIMESPEC, .desc = "syscall with libc spec"},
+#endif
+
+#if defined(TST_ABI64)
+	{ .tfd_settime = sys_timerfd_settime, .type = TST_KERN_TIMESPEC, .desc = "syscall with kernel spec64"},
+#endif
+
+#if (__NR_timerfd_settime64 != __LTP__NR_INVALID_SYSCALL)
+	{ .tfd_settime = sys_timerfd_settime64, .type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec64"},
+#endif
+};
+
 static void setup(void)
 {
+	struct test_variants *tv = &variants[tst_variant];
+
+	tst_res(TINFO, "Testing variant: %s", tv->desc);
+	its.type = tv->type;
+
 	tst_taint_init(TST_TAINT_W | TST_TAINT_D);
 	fd = SAFE_TIMERFD_CREATE(CLOCK_REALTIME, 0);
 
@@ -48,7 +72,9 @@ static void cleanup(void)
 
 static int punch_clock(int flags)
 {
-	return timerfd_settime(fd, flags, &its, NULL);
+	return variants[tst_variant].tfd_settime(fd, flags, tst_its_get(&its),
+						 NULL);
+
 }
 
 static void *thread_run(void *arg)
@@ -91,6 +117,7 @@ static void run(void)
 
 static struct tst_test test = {
 	.test_all = run,
+	.test_variants = ARRAY_SIZE(variants),
 	.setup = setup,
 	.cleanup = cleanup,
 	.min_kver = "2.6.25",
Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
#5 lore raw

PATCH v2 4/17 syscalls/sched_rr_get_interval: Add support for time64 tests

In reply to Viresh Kumar

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

---
 include/tst_timer.h                           |  16 ++
 .../sched_rr_get_interval01.c                 | 131 +++++++--------
 .../sched_rr_get_interval02.c                 | 137 +++++++---------
 .../sched_rr_get_interval03.c                 | 151 ++++++++----------
 4 files changed, 198 insertions(+), 237 deletions(-)
include/tst_timer.h +16 -0
index a728d78d7def..a726298b407d 100644
@@ -12,6 +12,7 @@
 #ifndef TST_TIMER
 #define TST_TIMER
 
+#include <sched.h>
 #include <sys/time.h>
 #include <time.h>
 #include "tst_test.h"
@@ -242,6 +243,21 @@ static inline int sys_clock_nanosleep64(clockid_t clk_id, int flags,
 			   request, remain);
 }
 
+static inline int libc_sched_rr_get_interval(pid_t pid, void *ts)
+{
+	return sched_rr_get_interval(pid, ts);
+}
+
+static inline int sys_sched_rr_get_interval(pid_t pid, void *ts)
+{
+	return tst_syscall(__NR_sched_rr_get_interval, pid, ts);
+}
+
+static inline int sys_sched_rr_get_interval64(pid_t pid, void *ts)
+{
+	return tst_syscall(__NR_sched_rr_get_interval_time64, pid, ts);
+}
+
 static inline int sys_timer_gettime(kernel_timer_t timerid, void *its)
 {
 	return tst_syscall(__NR_timer_gettime, timerid, its);
testcases/kernel/syscalls/sched_rr_get_interval/sched_rr_get_interval01.c +55 -76

156 lines not on this page · raw message

testcases/kernel/syscalls/sched_rr_get_interval/sched_rr_get_interval02.c +58 -79

162 lines not on this page · raw message

testcases/kernel/syscalls/sched_rr_get_interval/sched_rr_get_interval03.c +69 -82

193 lines not on this page · raw message

Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
#6 lore raw

PATCH v2 5/17 syscalls/futex: Merge futex_wait_bitset tests

In reply to Viresh Kumar

We can handle them easily in a single test, lets do it.

---
 runtest/syscalls                              |  1 -
 testcases/kernel/syscalls/futex/.gitignore    |  1 -
 testcases/kernel/syscalls/futex/Makefile      |  1 -
 .../kernel/syscalls/futex/futex_wait_bitset.h | 75 -------------------
 .../syscalls/futex/futex_wait_bitset01.c      | 73 +++++++++++++++++-
 .../syscalls/futex/futex_wait_bitset02.c      | 18 -----
 6 files changed, 71 insertions(+), 98 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/futex/futex_wait_bitset.h
 delete mode 100644 testcases/kernel/syscalls/futex/futex_wait_bitset02.c
runtest/syscalls +0 -1
index edd3e8de7861..4a19075cd131 100644
@@ -1664,7 +1664,6 @@ futex_wake02 futex_wake02
 futex_wake03 futex_wake03
 futex_wake04 futex_wake04
 futex_wait_bitset01 futex_wait_bitset01
-futex_wait_bitset02 futex_wait_bitset02
 
 memfd_create01 memfd_create01
 memfd_create02 memfd_create02
testcases/kernel/syscalls/futex/.gitignore +0 -1
index 68bc2028e1b2..54cd02b0223f 100644
@@ -6,7 +6,6 @@
 /futex_wait04
 /futex_wait05
 /futex_wait_bitset01
-/futex_wait_bitset02
 /futex_wake01
 /futex_wake02
 /futex_wake03
testcases/kernel/syscalls/futex/Makefile +0 -1
index 8dd239301e63..c88af7c9643b 100644
@@ -12,7 +12,6 @@ futex_wake02: CFLAGS+=-pthread
 futex_wake04: CFLAGS+=-pthread
 futex_wait05: LDLIBS+=-lrt
 futex_wait_bitset01: LDLIBS+=-lrt
-futex_wait_bitset02: LDLIBS+=-lrt
 
 include $(top_srcdir)/include/mk/testcases.mk
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/futex/futex_wait_bitset.h deleted +0 -75

75 lines not on this page · raw message

testcases/kernel/syscalls/futex/futex_wait_bitset01.c +71 -2

78 lines not on this page · raw message

testcases/kernel/syscalls/futex/futex_wait_bitset02.c deleted +0 -18
deleted file mode 100644
index 4d532fc07775..000000000000
@@ -1,18 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-/*
- * Copyright (C) 2015 Cyril Hrubis <[email protected]>
- *
- * 1. Block on a bitset futex and wait for timeout, the difference between
- *    normal futex and bitset futex is that that the later have absolute timeout.
- * 2. Check that the futex waited for expected time.
- */
-
-#include <errno.h>
-
-#include "tst_test.h"
-#include "tst_timer.h"
-#include "futextest.h"
-
-#define USE_CLOCK CLOCK_REALTIME
-
-#include "futex_wait_bitset.h"
Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
#7 lore raw

PATCH v2 6/17 syscalls/futex: Add support for time64 tests

In reply to Viresh Kumar

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

---
 include/tst_timer.h                           |  12 ++
 .../syscalls/futex/futex_cmp_requeue01.c      |  35 +++-
 .../syscalls/futex/futex_cmp_requeue02.c      |  25 ++-
 testcases/kernel/syscalls/futex/futex_utils.h |  52 ++++--
 .../kernel/syscalls/futex/futex_wait01.c      |  83 +++++-----
 .../kernel/syscalls/futex/futex_wait02.c      | 104 ++++++------
 .../kernel/syscalls/futex/futex_wait03.c      |  91 +++++------
 .../kernel/syscalls/futex/futex_wait04.c      |  85 +++++-----
 .../kernel/syscalls/futex/futex_wait05.c      |   2 +-
 .../syscalls/futex/futex_wait_bitset01.c      |  50 ++++--
 .../kernel/syscalls/futex/futex_wake01.c      |  71 ++++-----
 .../kernel/syscalls/futex/futex_wake02.c      |  99 ++++++------
 .../kernel/syscalls/futex/futex_wake03.c      | 111 +++++++------
 .../kernel/syscalls/futex/futex_wake04.c      | 150 +++++++++---------
 testcases/kernel/syscalls/futex/futextest.h   | 111 ++++++++-----
 15 files changed, 609 insertions(+), 472 deletions(-)
include/tst_timer.h +12 -0
index a726298b407d..b4280042c77f 100644
@@ -243,6 +243,18 @@ static inline int sys_clock_nanosleep64(clockid_t clk_id, int flags,
 			   request, remain);
 }
 
+static inline int sys_futex(int *uaddr, int futex_op, int val, void *to,
+			    int *uaddr2, int val3)
+{
+	return tst_syscall(__NR_futex, uaddr, futex_op, val, to, uaddr2, val3);
+}
+
+static inline int sys_futex_time64(int *uaddr, int futex_op, int val, void *to,
+				   int *uaddr2, int val3)
+{
+	return tst_syscall(__NR_futex_time64, uaddr, futex_op, val, to, uaddr2, val3);
+}
+
 static inline int libc_sched_rr_get_interval(pid_t pid, void *ts)
 {
 	return sched_rr_get_interval(pid, ts);
testcases/kernel/syscalls/futex/futex_cmp_requeue01.c +29 -6
index c50fade9f969..bc9d2a6bee37 100644
@@ -18,6 +18,7 @@
 #include "tst_timer_test.h"
 #include "tst_test.h"
 #include "futextest.h"
+#include "lapi/abisize.h"
 
 struct shared_data {
 	futex_t futexes[2];
@@ -42,14 +43,33 @@ static struct tcase {
 	{1000, 300, 500},
 };
 
+static struct test_variants {
+	enum futex_fn_type fntype;
+	enum tst_ts_type tstype;
+	char *desc;
+} variants[] = {
+#if defined(TST_ABI32)
+	{ .fntype = FUTEX_FN_FUTEX, .tstype = TST_KERN_OLD_TIMESPEC, .desc = "syscall with kernel spec32"},
+#endif
+
+#if defined(TST_ABI64)
+	{ .fntype = FUTEX_FN_FUTEX, .tstype = TST_KERN_TIMESPEC, .desc = "syscall with kernel spec64"},
+#endif
+
+#if (__NR_futex_time64 != __LTP__NR_INVALID_SYSCALL)
+	{ .fntype = FUTEX_FN_FUTEX64, .tstype = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec64"},
+#endif
+};
+
 static void do_child(void)
 {
+	struct test_variants *tv = &variants[tst_variant];
+	struct tst_ts usec = tst_ts_from_ms(tv->tstype, max_sleep_ms);
 	int slept_for_ms = 0;
-	struct timespec usec = tst_timespec_from_ms(max_sleep_ms);
 	int pid = getpid();
 	int ret = 0;
 
-	if (futex_wait(&sd->futexes[0], sd->futexes[0], &usec, 0) == -1) {
+	if (futex_wait(tv->fntype, &sd->futexes[0], sd->futexes[0], &usec, 0) == -1) {
 		if (errno == EAGAIN) {
 			/* spurious wakeup or signal */
 			tst_atomic_inc(&sd->spurious);
@@ -72,6 +92,7 @@ static void do_child(void)
 
 static void verify_futex_cmp_requeue(unsigned int n)
 {
+	struct test_variants *tv = &variants[tst_variant];
 	int num_requeues = 0, num_waits = 0, num_total = 0;
 	int i, status, spurious, woken_up;
 	struct tcase *tc = &tcases[n];
@@ -104,8 +125,8 @@ static void verify_futex_cmp_requeue(unsigned int n)
 	 * specifies an upper limit on the number of waiters that are requeued.
 	 * Returns the total number of waiters that were woken up or requeued.
 	 */
-	TEST(futex_cmp_requeue(&sd->futexes[0], sd->futexes[0], &sd->futexes[1],
-		tc->set_wakes, tc->set_requeues, 0));
+	TEST(futex_cmp_requeue(tv->fntype, &sd->futexes[0], sd->futexes[0],
+			&sd->futexes[1], tc->set_wakes, tc->set_requeues, 0));
 
 	/* Fail if more than requested wakes + requeues were returned */
 	if (TST_RET > exp_ret) {
@@ -115,8 +136,8 @@ static void verify_futex_cmp_requeue(unsigned int n)
 		tst_res(TINFO, "futex_cmp_requeue() returned %ld", TST_RET);
 	}
 
-	num_requeues = futex_wake(&sd->futexes[1], tc->num_waiters, 0);
-	num_waits = futex_wake(&sd->futexes[0], tc->num_waiters, 0);
+	num_requeues = futex_wake(tv->fntype, &sd->futexes[1], tc->num_waiters, 0);
+	num_waits = futex_wake(tv->fntype, &sd->futexes[0], tc->num_waiters, 0);
 
 	tst_atomic_store(1, &sd->test_done);
 	for (i = 0; i < tc->num_waiters; i++) {
@@ -178,6 +199,7 @@ static void verify_futex_cmp_requeue(unsigned int n)
 
 static void setup(void)
 {
+	tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
 	max_sleep_ms = tst_multiply_timeout(5000);
 
 	sd = SAFE_MMAP(NULL, sizeof(*sd), PROT_READ | PROT_WRITE,
@@ -198,5 +220,6 @@ static struct tst_test test = {
 	.cleanup = cleanup,
 	.tcnt = ARRAY_SIZE(tcases),
 	.test = verify_futex_cmp_requeue,
+	.test_variants = ARRAY_SIZE(variants),
 	.forks_child = 1,
 };
testcases/kernel/syscalls/futex/futex_cmp_requeue02.c +23 -2
index 228d8cff6ea0..5559b72a3a45 100644
@@ -18,6 +18,7 @@
 
 #include "tst_test.h"
 #include "futextest.h"
+#include "lapi/abisize.h"
 
 static futex_t *futexes;
 
@@ -32,12 +33,30 @@ static struct tcase {
 	{1, 1, FUTEX_INITIALIZER + 1, EAGAIN},
 };
 
+static struct test_variants {
+	enum futex_fn_type fntype;
+	char *desc;
+} variants[] = {
+#if defined(TST_ABI32)
+	{ .fntype = FUTEX_FN_FUTEX, .desc = "syscall with kernel spec32"},
+#endif
+
+#if defined(TST_ABI64)
+	{ .fntype = FUTEX_FN_FUTEX, .desc = "syscall with kernel spec64"},
+#endif
+
+#if (__NR_futex_time64 != __LTP__NR_INVALID_SYSCALL)
+	{ .fntype = FUTEX_FN_FUTEX64, .desc = "syscall time64 with kernel spec64"},
+#endif
+};
+
 static void verify_futex_cmp_requeue(unsigned int n)
 {
+	struct test_variants *tv = &variants[tst_variant];
 	struct tcase *tc = &tcases[n];
 
-	TEST(futex_cmp_requeue(&futexes[0], tc->exp_val, &futexes[1],
-	     tc->set_wakes, tc->set_requeues, 0));
+	TEST(futex_cmp_requeue(tv->fntype, &futexes[0], tc->exp_val,
+			&futexes[1], tc->set_wakes, tc->set_requeues, 0));
 	if (TST_RET != -1) {
 		tst_res(TFAIL, "futex_cmp_requeue() succeeded unexpectedly");
 		return;
@@ -55,6 +74,7 @@ static void verify_futex_cmp_requeue(unsigned int n)
 
 static void setup(void)
 {
+	tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
 	futexes = SAFE_MMAP(NULL, sizeof(futex_t) * 2, PROT_READ | PROT_WRITE,
 			    MAP_ANONYMOUS | MAP_SHARED, -1, 0);
 
@@ -73,6 +93,7 @@ static struct tst_test test = {
 	.cleanup = cleanup,
 	.test = verify_futex_cmp_requeue,
 	.tcnt = ARRAY_SIZE(tcases),
+	.test_variants = ARRAY_SIZE(variants),
 	.tags = (const struct tst_tag[]) {
 		{"CVE", "2018-6927"},
 		{"linux-git", "fbe0e839d1e2"},
testcases/kernel/syscalls/futex/futex_utils.h +42 -10

86 lines not on this page · raw message

testcases/kernel/syscalls/futex/futex_wait01.c +43 -40

124 lines not on this page · raw message

testcases/kernel/syscalls/futex/futex_wait02.c +47 -57

152 lines not on this page · raw message

testcases/kernel/syscalls/futex/futex_wait03.c +46 -45

133 lines not on this page · raw message

testcases/kernel/syscalls/futex/futex_wait04.c +44 -41

109 lines not on this page · raw message

testcases/kernel/syscalls/futex/futex_wait05.c +1 -1
index 2573ae177d5b..8fad5d858716 100644
@@ -19,7 +19,7 @@ int sample_fn(int clk_id, long long usec)
 	futex_t futex = FUTEX_INITIALIZER;
 
 	tst_timer_start(clk_id);
-	TEST(futex_wait(&futex, futex, &to, 0));
+	TEST(syscall(SYS_futex, &futex, FUTEX_WAIT, futex, &to, NULL, 0));
 	tst_timer_stop();
 	tst_timer_sample();
 
testcases/kernel/syscalls/futex/futex_wait_bitset01.c +40 -10

97 lines not on this page · raw message

testcases/kernel/syscalls/futex/futex_wake01.c +34 -37

98 lines not on this page · raw message

testcases/kernel/syscalls/futex/futex_wake02.c +49 -50

177 lines not on this page · raw message

testcases/kernel/syscalls/futex/futex_wake03.c +54 -57

173 lines not on this page · raw message

testcases/kernel/syscalls/futex/futex_wake04.c +76 -74

257 lines not on this page · raw message

testcases/kernel/syscalls/futex/futextest.h +69 -42

214 lines not on this page · raw message

Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
#8 lore raw

PATCH v2 6/17 syscalls/futex: Add support for time64 tests

Quoted 74 lines · Viresh Kumar

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

---
 include/tst_timer.h                           |  12 ++
 .../syscalls/futex/futex_cmp_requeue01.c      |  35 +++-
 .../syscalls/futex/futex_cmp_requeue02.c      |  25 ++-
 testcases/kernel/syscalls/futex/futex_utils.h |  52 ++++--
 .../kernel/syscalls/futex/futex_wait01.c      |  83 +++++-----
 .../kernel/syscalls/futex/futex_wait02.c      | 104 ++++++------
 .../kernel/syscalls/futex/futex_wait03.c      |  91 +++++------
 .../kernel/syscalls/futex/futex_wait04.c      |  85 +++++-----
 .../kernel/syscalls/futex/futex_wait05.c      |   2 +-
 .../syscalls/futex/futex_wait_bitset01.c      |  50 ++++--
 .../kernel/syscalls/futex/futex_wake01.c      |  71 ++++-----
 .../kernel/syscalls/futex/futex_wake02.c      |  99 ++++++------
 .../kernel/syscalls/futex/futex_wake03.c      | 111 +++++++------
 .../kernel/syscalls/futex/futex_wake04.c      | 150 +++++++++---------
 testcases/kernel/syscalls/futex/futextest.h   | 111 ++++++++-----
 15 files changed, 609 insertions(+), 472 deletions(-)
include/tst_timer.h +10 -0
index a726298b407d..b4280042c77f 100644
@@ -243,6 +243,18 @@ static inline int sys_clock_nanosleep64(clockid_t
 clk_id, int flags,
                           request, remain);
 }
 
+static inline int sys_futex(int *uaddr, int futex_op, int val, void *to,
+                           int *uaddr2, int val3)
+{
+       return tst_syscall(__NR_futex, uaddr, futex_op, val, to, uaddr2,
 val3);
+}
+
+static inline int sys_futex_time64(int *uaddr, int futex_op, int val,
 void *to,
+                                  int *uaddr2, int val3)
+{
+       return tst_syscall(__NR_futex_time64, uaddr, futex_op, val, to,

uaddr2, val3);

include/tst_timer.h +2 -0
+}
+
 static inline int libc_sched_rr_get_interval(pid_t pid, void *ts)
 {
        return sched_rr_get_interval(pid, ts);
testcases/kernel/syscalls/futex/futex_cmp_requeue01.c +8 -0
index c50fade9f969..bc9d2a6bee37 100644
@@ -18,6 +18,7 @@
 #include "tst_timer_test.h"
 #include "tst_test.h"
 #include "futextest.h"
+#include "lapi/abisize.h"
 
 struct shared_data {
        futex_t futexes[2];
@@ -42,14 +43,33 @@ static struct tcase {
        {1000, 300, 500},
 };
 
+static struct test_variants {
+       enum futex_fn_type fntype;
+       enum tst_ts_type tstype;
+       char *desc;
+} variants[] = {
+#if defined(TST_ABI32)
+       { .fntype = FUTEX_FN_FUTEX, .tstype = TST_KERN_OLD_TIMESPEC, .desc

testcases/kernel/syscalls/futex/futex_cmp_requeue01.c static struct tcase { · line 62

Quoted 10 lines
testcases/kernel/syscalls/futex/futex_cmp_requeue01.c +7 -0
 = "syscall with kernel spec32"},
+#endif
+
+#if defined(TST_ABI64)
+       { .fntype = FUTEX_FN_FUTEX, .tstype = TST_KERN_TIMESPEC, .desc =
 "syscall with kernel spec64"},
+#endif
+
+#if (__NR_futex_time64 != __LTP__NR_INVALID_SYSCALL)
 

This might not safe to use it directly if only check __NR_futex_time64 being defined. i.e Test it on the platform without achieving the system syscall(but
define __NR_futex_time64), the test children exit with TCONF will cause kind of issues.

RHEL-8.2(ppc64le) failed as:
--------------------------------------

tag=futex_cmp_requeue01 stime=1588947939 cmdline="futex_cmp_requeue01"
contacts=""
analysis=exit
<<<test_output>>>
tst_test.c:1246: INFO: Timeout per run is 0h 05m 00s futex_cmp_requeue01.c:202: INFO: Testing variant: syscall with kernel spec64 futex_cmp_requeue01.c:114: INFO: Test 0: waiters: 10, wakes: 3, requeues: 7 futex_cmp_requeue01.c:136: INFO: futex_cmp_requeue() returned 10 futex_cmp_requeue01.c:152: INFO: children woken, futex0: 0, futex1: 7, spurious wakeups: 0
futex_cmp_requeue01.c:197: PASS: futex_cmp_requeue() futex_cmp_requeue01.c:114: INFO: Test 1: waiters: 10, wakes: 0, requeues: 10 futex_cmp_requeue01.c:136: INFO: futex_cmp_requeue() returned 10 futex_cmp_requeue01.c:152: INFO: children woken, futex0: 0, futex1:
10, spurious wakeups: 0
futex_cmp_requeue01.c:197: PASS: futex_cmp_requeue() futex_cmp_requeue01.c:114: INFO: Test 2: waiters: 10, wakes: 2, requeues: 6
...
futex_cmp_requeue01.c:152: INFO: children woken, futex0: 200, futex1:
500, spurious wakeups: 0
futex_cmp_requeue01.c:197: PASS: futex_cmp_requeue() tst_test.c:1246: INFO: Timeout per run is 0h 05m 00s futex_cmp_requeue01.c:202: INFO: Testing variant: syscall time64 with kernel spec64
../../../../include/tst_timer.h:256: CONF: syscall(422) __NR_futex_time64 not supported
...
../../../../include/tst_timer.h:256: CONF: syscall(422) __NR_futex_time64 not supported ../../../../include/tst_timer.h:256: CONF: syscall(422) __NR_futex_time64 not supported
Test timeouted, sending SIGKILL!
tst_test.c:1286: INFO: If you are running on slow machine, try exporting LTP_TIMEOUT_MUL > 1
tst_test.c:1287: BROK: Test killed! (timeout?)

cmdline="futex_wake02"
contacts=""
analysis=exit
<<<test_output>>>
tst_test.c:1246: INFO: Timeout per run is 0h 05m 00s futex_wake02.c:155: INFO: Testing variant: syscall with kernel spec64 futex_wake02.c:105: PASS: futex_wake() woken up 1 threads futex_wake02.c:105: PASS: futex_wake() woken up 2 threads futex_wake02.c:105: PASS: futex_wake() woken up 3 threads futex_wake02.c:105: PASS: futex_wake() woken up 4 threads futex_wake02.c:105: PASS: futex_wake() woken up 5 threads futex_wake02.c:105: PASS: futex_wake() woken up 6 threads futex_wake02.c:105: PASS: futex_wake() woken up 7 threads futex_wake02.c:105: PASS: futex_wake() woken up 8 threads futex_wake02.c:105: PASS: futex_wake() woken up 9 threads futex_wake02.c:105: PASS: futex_wake() woken up 10 threads futex_wake02.c:118: PASS: futex_wake() woken up 0 threads tst_test.c:1246: INFO: Timeout per run is 0h 05m 00s futex_wake02.c:155: INFO: Testing variant: syscall time64 with kernel spec64 ../../../../include/tst_timer.h:256: CONF: syscall(422) __NR_futex_time64 not supported ../../../../include/tst_timer.h:256: CONF: syscall(422) __NR_futex_time64 not supported
tst_test.c:1063: BROK: Test haven't reported results!

futex_wake03.c:111: INFO: Testing variant: syscall with kernel spec64 futex_wake03.c:71: PASS: futex_wake() woken up 1 childs futex_wake03.c:71: PASS: futex_wake() woken up 2 childs futex_wake03.c:71: PASS: futex_wake() woken up 3 childs futex_wake03.c:71: PASS: futex_wake() woken up 4 childs futex_wake03.c:71: PASS: futex_wake() woken up 5 childs futex_wake03.c:71: PASS: futex_wake() woken up 6 childs futex_wake03.c:71: PASS: futex_wake() woken up 7 childs futex_wake03.c:71: PASS: futex_wake() woken up 8 childs futex_wake03.c:71: PASS: futex_wake() woken up 9 childs futex_wake03.c:71: PASS: futex_wake() woken up 10 childs futex_wake03.c:105: PASS: futex_wake() woken up 0 children tst_test.c:1246: INFO: Timeout per run is 0h 05m 00s futex_wake03.c:111: INFO: Testing variant: syscall time64 with kernel spec64 ../../../../include/tst_timer.h:256: CONF: syscall(422) __NR_futex_time64 not supported ../../../../include/tst_timer.h:256: CONF: syscall(422) __NR_futex_time64 not supported ../../../../include/tst_timer.h:256: CONF: syscall(422) __NR_futex_time64 not supported... ../../../../include/tst_timer.h:256: CONF: syscall(422) __NR_futex_time64 not supported ../../../../include/tst_timer.h:256: CONF: syscall(422) __NR_futex_time64 not supported
Test timeouted, sending SIGKILL!
tst_test.c:1286: INFO: If you are running on slow machine, try exporting LTP_TIMEOUT_MUL > 1
tst_test.c:1287: BROK: Test killed! (timeout?)

cmdline="futex_wake04"
contacts=""
analysis=exit
<<<test_output>>>
tst_test.c:1246: INFO: Timeout per run is 0h 05m 00s futex_wake04.c:69: INFO: Testing variant: syscall with kernel spec64 futex_wake04.c:142: INFO: Hugepagesize 16777216 futex_wake04.c:127: PASS: Hi hydra, thread2 awake! tst_test.c:1246: INFO: Timeout per run is 0h 05m 00s futex_wake04.c:69: INFO: Testing variant: syscall time64 with kernel spec64 futex_wake04.c:142: INFO: Hugepagesize 16777216 ../../../../include/tst_timer.h:256: CONF: syscall(422) __NR_futex_time64 not supported ../../../../include/tst_timer.h:256: CONF: syscall(422) __NR_futex_time64 not supported
futex_wake04.c:129: FAIL: Bug: wait_thread2 did not wake after 30 secs.: SUCCESS (0)

Signature · 5 lines
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20200509/a0d436a4/attachment-0001.htm>
#9 lore raw

PATCH v2 6/17 syscalls/futex: Add support for time64 tests

Quoted 5 lines · Li Wang

This might not safe to use it directly if only check __NR_futex_time64 being defined. i.e Test it on the platform without achieving the system syscall(but
define __NR_futex_time64), the test children exit with TCONF will cause kind of issues.

I will add this to the patch then, I am wondering if I need to add this to all tests now ? Cyril ?

testcases/kernel/syscalls/futex/futex_cmp_requeue01.c +5 -1
index efde3410f564..537641766357 100644
@@ -194,7 +194,11 @@ static void verify_futex_cmp_requeue(unsigned int n)
 
 static void setup(void)
 {
-	tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
+	struct test_variants *tv = &variants[tst_variant];
+
+	tst_res(TINFO, "Testing variant: %s", tv->desc);
+	futex_supported_by_kernel(tv->fntype);
+
 	max_sleep_ms = tst_multiply_timeout(5000);
 
 	sd = SAFE_MMAP(NULL, sizeof(*sd), PROT_READ | PROT_WRITE,
testcases/kernel/syscalls/futex/futex_cmp_requeue02.c +5 -1
index e1af5ddab509..dd8fafb3ee38 100644
@@ -69,7 +69,11 @@ static void verify_futex_cmp_requeue(unsigned int n)
 
 static void setup(void)
 {
-	tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
+	struct test_variants *tv = &variants[tst_variant];
+
+	tst_res(TINFO, "Testing variant: %s", tv->desc);
+	futex_supported_by_kernel(tv->fntype);
+
 	futexes = SAFE_MMAP(NULL, sizeof(futex_t) * 2, PROT_READ | PROT_WRITE,
 			    MAP_ANONYMOUS | MAP_SHARED, -1, 0);
 
testcases/kernel/syscalls/futex/futex_wait01.c +4 -1
index 41b21a71f2c6..e884e696ef55 100644
@@ -74,7 +74,10 @@ static void run(unsigned int n)
 
 static void setup(void)
 {
-	tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
+	struct test_variants *tv = &variants[tst_variant];
+
+	tst_res(TINFO, "Testing variant: %s", tv->desc);
+	futex_supported_by_kernel(tv->fntype);
 }
 
 static struct tst_test test = {
testcases/kernel/syscalls/futex/futex_wait02.c +4 -1
index 7b19115073dd..34b78357f6e6 100644
@@ -74,7 +74,10 @@ static void run(void)
 
 static void setup(void)
 {
-	tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
+	struct test_variants *tv = &variants[tst_variant];
+
+	tst_res(TINFO, "Testing variant: %s", tv->desc);
+	futex_supported_by_kernel(tv->fntype);
 
 	futex = SAFE_MMAP(NULL, sizeof(*futex), PROT_READ | PROT_WRITE,
 			  MAP_ANONYMOUS | MAP_SHARED, -1, 0);
testcases/kernel/syscalls/futex/futex_wait03.c +4 -1
index 83601479adc0..e436b238a165 100644
@@ -73,7 +73,10 @@ static void run(void)
 
 static void setup(void)
 {
-	tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
+	struct test_variants *tv = &variants[tst_variant];
+
+	tst_res(TINFO, "Testing variant: %s", tv->desc);
+	futex_supported_by_kernel(tv->fntype);
 }
 
 static struct tst_test test = {
testcases/kernel/syscalls/futex/futex_wait04.c +4 -1
index ba6988a20e98..8de3c90b08d3 100644
@@ -53,7 +53,10 @@ static void run(void)
 
 static void setup(void)
 {
-	tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
+	struct test_variants *tv = &variants[tst_variant];
+
+	tst_res(TINFO, "Testing variant: %s", tv->desc);
+	futex_supported_by_kernel(tv->fntype);
 }
 
 static struct tst_test test = {
testcases/kernel/syscalls/futex/futex_wait_bitset01.c +4 -1
index 9f2f4025d4a4..a871af992572 100644
@@ -102,7 +102,10 @@ static void run(unsigned int n)
 
 static void setup(void)
 {
-	tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
+	struct test_variants *tv = &variants[tst_variant];
+
+	tst_res(TINFO, "Testing variant: %s", tv->desc);
+	futex_supported_by_kernel(tv->fntype);
 }
 
 static struct tst_test test = {
testcases/kernel/syscalls/futex/futex_wake01.c +4 -1
index 21cf158daac7..2dbe8cc2f3aa 100644
@@ -58,7 +58,10 @@ static void run(unsigned int n)
 
 static void setup(void)
 {
-	tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
+	struct test_variants *tv = &variants[tst_variant];
+
+	tst_res(TINFO, "Testing variant: %s", tv->desc);
+	futex_supported_by_kernel(tv->fntype);
 }
 
 static struct tst_test test = {
testcases/kernel/syscalls/futex/futex_wake02.c +4 -1
index cd535163a6e9..3491839872ac 100644
@@ -147,7 +147,10 @@ static void run(void)
 
 static void setup(void)
 {
-	tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
+	struct test_variants *tv = &variants[tst_variant];
+
+	tst_res(TINFO, "Testing variant: %s", tv->desc);
+	futex_supported_by_kernel(tv->fntype);
 }
 
 static struct tst_test test = {
testcases/kernel/syscalls/futex/futex_wake03.c +4 -1
index b059cf6fa272..29e586c40132 100644
@@ -103,7 +103,10 @@ static void run(void)
 
 static void setup(void)
 {
-	tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
+	struct test_variants *tv = &variants[tst_variant];
+
+	tst_res(TINFO, "Testing variant: %s", tv->desc);
+	futex_supported_by_kernel(tv->fntype);
 
 	futex = SAFE_MMAP(NULL, sizeof(*futex), PROT_READ | PROT_WRITE,
 			  MAP_ANONYMOUS | MAP_SHARED, -1, 0);
testcases/kernel/syscalls/futex/futex_wake04.c +1 -0
index 2f58efc1eb2a..edbb9c644c57 100644
@@ -62,6 +62,7 @@ static void setup(void)
 	struct test_variants *tv = &variants[tst_variant];
 
 	tst_res(TINFO, "Testing variant: %s", tv->desc);
+	futex_supported_by_kernel(tv->fntype);
 
 	to.type = tv->tstype;
 	tst_ts_set_sec(&to, 30);
testcases/kernel/syscalls/futex/futextest.h +11 -0
index a9dcbbedd249..816f2f1f4689 100644
@@ -88,6 +88,17 @@ enum futex_fn_type {
 	FUTEX_FN_FUTEX64,
 };
 
+static inline void futex_supported_by_kernel(enum futex_fn_type fntype)
+{
+	if (fntype != FUTEX_FN_FUTEX64)
+		return;
+
+	/* Check if the syscall is backported on an older kernel */
+	TEST(sys_futex_time64(NULL, 0, 0, NULL, NULL, 0));
+	if (TST_RET == -1 && TST_ERR == ENOSYS)
+		tst_brk(TCONF, "Test not supported on kernel");
+}
+
 /**
  * futex_syscall() - futex syscall wrapper
  * @fntype:	Futex function type
Signature · 1 line
viresh
#10 lore raw

PATCH v2 7/17 syscalls/io_pgetevents: Add support for time64 tests

In reply to Viresh Kumar

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

While at it, also pass mode to SAFE_OPEN() to avoid any errors when the tests are run for multiple variants together.

Also get rid of an extra copy of local fd variable, which is incorrect.

---
 include/lapi/io_pgetevents.h                  | 15 +++--
 .../syscalls/io_pgetevents/io_pgetevents01.c  | 41 ++++++++++++-
 .../syscalls/io_pgetevents/io_pgetevents02.c  | 59 +++++++++++++++----
 3 files changed, 97 insertions(+), 18 deletions(-)
include/lapi/io_pgetevents.h +10 -5
index 3c9d5b2d7618..5bb9a60c352a 100644
@@ -16,15 +16,20 @@
 #ifdef HAVE_LIBAIO
 #include <libaio.h>
 
-#ifndef HAVE_IO_PGETEVENTS
-int io_pgetevents(io_context_t ctx, long min_nr, long max_nr,
-		 struct io_event *events, struct timespec *timeout,
-		 sigset_t *sigmask)
+static inline int sys_io_pgetevents(io_context_t ctx, long min_nr, long max_nr,
+		struct io_event *events, void *timeout, sigset_t *sigmask)
 {
 	return tst_syscall(__NR_io_pgetevents, ctx, min_nr, max_nr, events,
 			   timeout, sigmask);
 }
-#endif /* HAVE_IO_PGETEVENTS */
+
+static inline int sys_io_pgetevents_time64(io_context_t ctx, long min_nr, long max_nr,
+		struct io_event *events, void *timeout, sigset_t *sigmask)
+{
+	return tst_syscall(__NR_io_pgetevents_time64, ctx, min_nr, max_nr,
+			   events, timeout, sigmask);
+}
+
 #endif /* HAVE_LIBAIO */
 
 #endif /* IO_PGETEVENTS_H */
testcases/kernel/syscalls/io_pgetevents/io_pgetevents01.c +38 -3

81 lines not on this page · raw message

testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c +49 -10

107 lines not on this page · raw message

Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
#11 lore raw

PATCH v2 8/17 syscalls/sigwaitinfo: Migrate to new test framework

In reply to Viresh Kumar

This migrates the sigwaitinfo tests to use the new test framework.

---
 .../syscalls/sigwaitinfo/sigwaitinfo01.c      | 209 +++++++-----------
 1 file changed, 84 insertions(+), 125 deletions(-)
testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c +84 -125
index 6a30c27f6f2f..1b976a271d28 100644
@@ -1,93 +1,58 @@
-/*
- * Copyright (c) Jiri Palecek<[email protected]>, 2009
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-#include "test.h"
+// SPDX-License-Identifier: GPL-2.0-or-later
+/* Copyright (c) Jiri Palecek<[email protected]>, 2009 */
+
+#include "tst_test.h"
 #include <errno.h>
+#include <stdlib.h>
 #include <signal.h>
-#include "../utils/include_j_h.h"
-#include "../utils/common_j_h.c"
 #include <limits.h>
 #include "lapi/syscalls.h"
+#include "tst_sig_proc.h"
 
 #define SUCCEED_OR_DIE(syscall, message, ...)				 \
 	(errno = 0,							 \
 		({int ret=syscall(__VA_ARGS__);				 \
 			if (ret==-1)					 \
-				tst_brkm(TBROK|TERRNO, cleanup, message);\
+				tst_brk(TBROK|TERRNO, message);\
 			ret;}))
 
-/* Report success iff TEST_RETURN and TEST_ERRNO are equal to
+/* Report success iff TST_RET and TST_ERR are equal to
 	 exp_return and exp_errno, resp., and cond is true. If cond is not
 	 true, report condition_errmsg
 */
-static void report_success_cond(const char *func, const char *file, int line,
+static void report_success_cond(const char *func, int line,
 				long exp_return, int exp_errno, int condition,
 				char *condition_errmsg)
 {
-	if (exp_return == TEST_RETURN
-	    && (exp_return != -1 || exp_errno == TEST_ERRNO))
+	if (exp_return == TST_RET
+	    && (exp_return != -1 || exp_errno == TST_ERR))
 		if (condition)
-			tst_resm(TPASS, "Test passed");
+			tst_res(TPASS, "%s (%d): Test passed", func, line);
 		else
-			tst_resm(TFAIL, "%s (%s: %d): %s", func, file, line,
+			tst_res(TFAIL, "%s (%d): %s", func, line,
 				 condition_errmsg);
-	else if (TEST_RETURN != -1)
-		tst_resm(TFAIL,
-			 "%s (%s: %d): Unexpected return value; expected %ld, got %ld",
-			 func, file, line, exp_return, TEST_RETURN);
+	else if (TST_RET != -1)
+		tst_res(TFAIL,
+			 "%s (%d): Unexpected return value; expected %ld, got %ld",
+			 func, line, exp_return, TST_RET);
 	else
-		tst_resm(TFAIL | TTERRNO, "%s (%s: %d): Unexpected failure",
-			 func, file, line);
+		tst_res(TFAIL | TTERRNO, "%s (%d): Unexpected failure",
+			 func, line);
 }
 
 #define REPORT_SUCCESS_COND(exp_return, exp_errno, condition, condition_errmsg)	\
-	report_success_cond(__FUNCTION__, __FILE__, __LINE__, exp_return, exp_errno, condition, condition_errmsg);
+	report_success_cond(__FUNCTION__, __LINE__, exp_return, exp_errno, condition, condition_errmsg);
 
-/* Report success iff TEST_RETURN and TEST_ERRNO are equal to
+/* Report success iff TST_RET and TST_ERR are equal to
 	 exp_return and exp_errno, resp.
 */
 #define REPORT_SUCCESS(exp_return, exp_errno)					\
 	REPORT_SUCCESS_COND(exp_return, exp_errno, 1, "");
 
-static void cleanup(void);
-
 static void empty_handler(int sig)
 {
 }
 
-static void setup(void)
-{
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-	signal(SIGUSR1, empty_handler);
-	signal(SIGALRM, empty_handler);
-	signal(SIGUSR2, SIG_IGN);
-
-	TEST_PAUSE;
-}
-
-static void cleanup(void)
-{
-}
-
 typedef int (*swi_func) (const sigset_t * set, siginfo_t * info,
 			 struct timespec * timeout);
 typedef void (*test_func) (swi_func, int);
@@ -110,7 +75,6 @@ static int my_sigwait(const sigset_t * set, siginfo_t * info,
 static int my_sigwaitinfo(const sigset_t * set, siginfo_t * info,
 			  struct timespec *timeout)
 {
-
 	return sigwaitinfo(set, info);
 }
 #endif
@@ -119,7 +83,6 @@ static int my_sigwaitinfo(const sigset_t * set, siginfo_t * info,
 static int my_sigtimedwait(const sigset_t * set, siginfo_t * info,
 			   struct timespec *timeout)
 {
-
 	return sigtimedwait(set, info, timeout);
 }
 #endif
@@ -129,7 +92,7 @@ static int my_rt_sigtimedwait(const sigset_t * set, siginfo_t * info,
 			      struct timespec *timeout)
 {
 	/* _NSIG is always the right number of bits of signal map for all arches */
-	return ltp_syscall(__NR_rt_sigtimedwait, set, info, timeout, _NSIG/8);
+	return tst_syscall(__NR_rt_sigtimedwait, set, info, timeout, _NSIG/8);
 }
 #endif
 
@@ -141,12 +104,13 @@ void test_empty_set(swi_func sigwaitinfo, int signo)
 
 	SUCCEED_OR_DIE(sigemptyset, "sigemptyset failed", &sigs);
 	/* Run a child that will wake us up */
-	child = create_sig_proc(100000, signo, UINT_MAX);
+	child = create_sig_proc(signo, INT_MAX, 100000);
 
 	TEST(sigwaitinfo(&sigs, &si, NULL));
 	REPORT_SUCCESS(-1, EINTR);
 
-	kill(child, SIGTERM);
+	SAFE_KILL(child, SIGTERM);
+	SAFE_WAIT(NULL);
 }
 
 void test_timeout(swi_func sigwaitinfo, int signo)
@@ -159,12 +123,13 @@ void test_timeout(swi_func sigwaitinfo, int signo)
 	SUCCEED_OR_DIE(sigemptyset, "sigemptyset failed", &sigs);
 
 	/* Run a child that will wake us up */
-	child = create_sig_proc(100000, signo, UINT_MAX);
+	child = create_sig_proc(signo, INT_MAX, 100000);
 
 	TEST(sigwaitinfo(&sigs, &si, &ts));
 	REPORT_SUCCESS(-1, EAGAIN);
 
-	kill(child, SIGTERM);
+	SAFE_KILL(child, SIGTERM);
+	SAFE_WAIT(NULL);
 }
 
 /* Note: sigwait-ing for a signal that is not blocked is unspecified
@@ -180,14 +145,15 @@ void test_unmasked_matching(swi_func sigwaitinfo, int signo)
 	SUCCEED_OR_DIE(sigaddset, "sigaddset failed", &sigs, signo);
 
 	/* Run a child that will wake us up */
-	child = create_sig_proc(100000, signo, UINT_MAX);
+	child = create_sig_proc(signo, INT_MAX, 100000);
 
 	TEST(sigwaitinfo(&sigs, &si, NULL));
 	REPORT_SUCCESS_COND(signo, 0, si.si_pid == child
 			    && si.si_code == SI_USER
 			    && si.si_signo == signo, "Struct siginfo mismatch");
 
-	kill(child, SIGTERM);
+	SAFE_KILL(child, SIGTERM);
+	SAFE_WAIT(NULL);
 }
 
 void test_unmasked_matching_noinfo(swi_func sigwaitinfo, int signo)
@@ -198,12 +164,13 @@ void test_unmasked_matching_noinfo(swi_func sigwaitinfo, int signo)
 	SUCCEED_OR_DIE(sigemptyset, "sigemptyset failed", &sigs);
 	SUCCEED_OR_DIE(sigaddset, "sigaddset failed", &sigs, signo);
 	/* Run a child that will wake us up */
-	child = create_sig_proc(100000, signo, UINT_MAX);
+	child = create_sig_proc(signo, INT_MAX, 100000);
 
 	TEST(sigwaitinfo(&sigs, NULL, NULL));
 	REPORT_SUCCESS(signo, 0);
 
-	kill(child, SIGTERM);
+	SAFE_KILL(child, SIGTERM);
+	SAFE_WAIT(NULL);
 }
 
 void test_masked_matching(swi_func sigwaitinfo, int signo)
@@ -224,7 +191,7 @@ void test_masked_matching(swi_func sigwaitinfo, int signo)
 	SUCCEED_OR_DIE(sigdelset, "sigaddset failed", &sigs, SIGCHLD);
 
 	/* Run a child that will wake us up */
-	child = create_sig_proc(0, signo, 1);
+	child = create_sig_proc(signo, 1, 0);
 
 	TEST(sigwaitinfo(&sigs, &si, NULL));
 	REPORT_SUCCESS_COND(signo, 0, si.si_pid == child
@@ -234,13 +201,14 @@ void test_masked_matching(swi_func sigwaitinfo, int signo)
 	SUCCEED_OR_DIE(sigprocmask, "restoring original signal mask failed",
 		       SIG_SETMASK, &oldmask, &oldmask);
 
-	tst_count--;
-
 	if (sigismember(&oldmask, signo))
-		tst_resm(TPASS, "sigwaitinfo restored the original mask");
+		tst_res(TPASS, "sigwaitinfo restored the original mask");
 	else
-		tst_resm(TFAIL,
+		tst_res(TFAIL,
 			 "sigwaitinfo failed to restore the original mask");
+
+	SAFE_KILL(child, SIGTERM);
+	SAFE_WAIT(NULL);
 }
 
 void test_masked_matching_rt(swi_func sigwaitinfo, int signo)
@@ -265,12 +233,12 @@ void test_masked_matching_rt(swi_func sigwaitinfo, int signo)
 	SUCCEED_OR_DIE(sigdelset, "sigdelset failed", &sigs, SIGCHLD);
 
 	/* Run a child that will wake us up */
-	child[0] = create_sig_proc(0, signo, 1);
-	child[1] = create_sig_proc(0, signo + 1, 1);
+	child[0] = create_sig_proc(signo, 1, 0);
+	child[1] = create_sig_proc(signo + 1, 1, 0);
 
 	/* Ensure that the signals have been sent */
-	waitpid(child[0], &status, 0);
-	waitpid(child[1], &status, 0);
+	SAFE_WAITPID(child[0], &status, 0);
+	SAFE_WAITPID(child[1], &status, 0);
 
 	TEST(sigwaitinfo(&sigs, &si, NULL));
 	REPORT_SUCCESS_COND(signo, 0, si.si_pid == child[0]
@@ -278,7 +246,6 @@ void test_masked_matching_rt(swi_func sigwaitinfo, int signo)
 			    && si.si_signo == signo, "Struct siginfo mismatch");
 
 	/* eat the other signal */
-	tst_count--;
 	TEST(sigwaitinfo(&sigs, &si, NULL));
 	REPORT_SUCCESS_COND(signo + 1, 0, si.si_pid == child[1]
 			    && si.si_code == SI_USER
@@ -288,12 +255,10 @@ void test_masked_matching_rt(swi_func sigwaitinfo, int signo)
 	SUCCEED_OR_DIE(sigprocmask, "restoring original signal mask failed",
 		       SIG_SETMASK, &oldmask, &oldmask);
 
-	tst_count--;
-
 	if (sigismember(&oldmask, signo))
-		tst_resm(TPASS, "sigwaitinfo restored the original mask");
+		tst_res(TPASS, "sigwaitinfo restored the original mask");
 	else
-		tst_resm(TFAIL,
+		tst_res(TFAIL,
 			 "sigwaitinfo failed to restore the original mask");
 }
 
@@ -314,7 +279,7 @@ void test_masked_matching_noinfo(swi_func sigwaitinfo, int signo)
 	SUCCEED_OR_DIE(sigdelset, "sigaddset failed", &sigs, SIGCHLD);
 
 	/* Run a child that will wake us up */
-	child = create_sig_proc(0, signo, 1);
+	child = create_sig_proc(signo, 1, 0);
 
 	TEST(sigwaitinfo(&sigs, NULL, NULL));
 	REPORT_SUCCESS(signo, 0);
@@ -322,14 +287,14 @@ void test_masked_matching_noinfo(swi_func sigwaitinfo, int signo)
 	SUCCEED_OR_DIE(sigprocmask, "restoring original signal mask failed",
 		       SIG_SETMASK, &oldmask, &oldmask);
 
-	tst_count--;
-
 	if (sigismember(&oldmask, signo))
-		tst_resm(TPASS, "sigwaitinfo restored the original mask");
+		tst_res(TPASS, "sigwaitinfo restored the original mask");
 	else
-		tst_resm(TFAIL,
+		tst_res(TFAIL,
 			 "sigwaitinfo failed to restore the original mask");
 
+	SAFE_KILL(child, SIGTERM);
+	SAFE_WAIT(NULL);
 }
 
 void test_bad_address(swi_func sigwaitinfo, int signo)
@@ -349,7 +314,7 @@ void test_bad_address(swi_func sigwaitinfo, int signo)
 	SUCCEED_OR_DIE(sigdelset, "sigaddset failed", &sigs, SIGCHLD);
 
 	/* Run a child that will wake us up */
-	child = create_sig_proc(0, signo, 1);
+	child = create_sig_proc(signo, 1, 0);
 
 	TEST(sigwaitinfo(&sigs, (void *)1, NULL));
 	REPORT_SUCCESS(-1, EFAULT);
@@ -357,7 +322,8 @@ void test_bad_address(swi_func sigwaitinfo, int signo)
 	SUCCEED_OR_DIE(sigprocmask, "sigprocmask failed", SIG_SETMASK, &oldmask,
 		       &oldmask);
 
-	kill(child, SIGTERM);
+	SAFE_KILL(child, SIGTERM);
+	SAFE_WAIT(NULL);
 }
 
 void test_bad_address2(swi_func sigwaitinfo, int signo)
@@ -367,7 +333,7 @@ void test_bad_address2(swi_func sigwaitinfo, int signo)
 
 	switch (pid = fork()) {
 	case -1:
-		tst_brkm(TBROK | TERRNO, NULL, "fork() failed");
+		tst_brk(TBROK | TERRNO, "fork() failed");
 	case 0:
 		signal(SIGSEGV, SIG_DFL);
 
@@ -377,31 +343,31 @@ void test_bad_address2(swi_func sigwaitinfo, int signo)
 		 */
 		TEST(sigwaitinfo((void *)1, NULL, NULL));
 
-		if (TEST_RETURN == -1 && TEST_ERRNO == EFAULT)
+		if (TST_RET == -1 && TST_ERR == EFAULT)
 			_exit(0);
 
-		tst_resm(TINFO | TTERRNO, "swi_func returned: %ld",
-			TEST_RETURN);
+		tst_res(TINFO | TTERRNO, "swi_func returned: %ld",
+			TST_RET);
 		_exit(1);
 		break;
 	default:
 		break;
 	}
 
-	SUCCEED_OR_DIE(waitpid, "waitpid failed", pid, &status, 0);
+	SAFE_WAITPID(pid, &status, 0);
 
 	if ((WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV)
 		|| (WIFEXITED(status) && WEXITSTATUS(status) == 0)) {
-		tst_resm(TPASS, "Test passed");
+		tst_res(TPASS, "Test passed");
 		return;
 	}
 
 	if (WIFEXITED(status)) {
-		tst_resm(TFAIL, "Unrecognised child exit code: %d",
+		tst_res(TFAIL, "Unrecognised child exit code: %d",
 			WEXITSTATUS(status));
 	}
 	if (WIFSIGNALED(status)) {
-		tst_resm(TFAIL, "Unrecognised child termsig: %d",
+		tst_res(TFAIL, "Unrecognised child termsig: %d",
 			WTERMSIG(status));
 	}
 }
@@ -474,38 +440,31 @@ struct test_desc {
 #endif
 };
 
-#if defined TEST_SIGWAITINFO
-const char *TCID = "sigwaitinfo01";
-#elif defined TEST_RT_SIGTIMEDWAIT
-const char *TCID = "rt_sigtimedwait01";
-#elif defined TEST_SIGTIMEDWAIT
-const char *TCID = "sigtimedwait01";
-#elif defined TEST_SIGWAIT
-const char *TCID = "sigwait01";
-#endif
-
-int TST_TOTAL = ARRAY_SIZE(tests);
-
-int main(int argc, char **argv)
+static void run(unsigned int i)
 {
-	unsigned i;
-	int lc;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
+	struct test_desc *tc = &tests[i];
 
-	setup();
+	tc->tf(tc->swi, tc->signo);
+}
 
-	for (lc = 0; TEST_LOOPING(lc); ++lc) {
-		tst_count = 0;
+static void setup(void)
+{
+	signal(SIGUSR1, empty_handler);
+	signal(SIGALRM, empty_handler);
+	signal(SIGUSR2, SIG_IGN);
 
-		for (i = 0; i < ARRAY_SIZE(tests); i++) {
-			alarm(10);	/* arrange a 10 second timeout */
-			tst_resm(TINFO, "%p, %d", tests[i].swi, tests[i].signo);
-			tests[i].tf(tests[i].swi, tests[i].signo);
-		}
-		alarm(0);
-	}
+	alarm(10);	/* arrange a 10 second timeout */
+}
 
-	cleanup();
-	tst_exit();
+static void cleanup(void)
+{
+	alarm(0);
 }
+
+static struct tst_test test = {
+	.test= run,
+	.tcnt = ARRAY_SIZE(tests),
+	.setup = setup,
+	.cleanup = cleanup,
+	.forks_child = 1,
+};
Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
#12 lore raw

PATCH v2 9/17 syscalls/rt_sigtimedwait: Add support for time64 tests

In reply to Viresh Kumar

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

---
 .../syscalls/sigwaitinfo/sigwaitinfo01.c      | 118 +++++++++++++-----
 1 file changed, 86 insertions(+), 32 deletions(-)
testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c +86 -32
index 1b976a271d28..60d0a2b7cf04 100644
@@ -2,11 +2,13 @@
 /* Copyright (c) Jiri Palecek<[email protected]>, 2009 */
 
 #include "tst_test.h"
+#include "tst_timer.h"
 #include <errno.h>
 #include <stdlib.h>
 #include <signal.h>
 #include <limits.h>
 #include "lapi/syscalls.h"
+#include "lapi/abisize.h"
 #include "tst_sig_proc.h"
 
 #define SUCCEED_OR_DIE(syscall, message, ...)				 \
@@ -54,12 +56,12 @@ static void empty_handler(int sig)
 }
 
 typedef int (*swi_func) (const sigset_t * set, siginfo_t * info,
-			 struct timespec * timeout);
-typedef void (*test_func) (swi_func, int);
+			 void * timeout);
+typedef void (*test_func) (swi_func, int, enum tst_ts_type type);
 
 #ifdef TEST_SIGWAIT
 static int my_sigwait(const sigset_t * set, siginfo_t * info,
-		      struct timespec *timeout)
+		      void *timeout)
 {
 	int ret;
 	int err = sigwait(set, &ret);
@@ -73,7 +75,7 @@ static int my_sigwait(const sigset_t * set, siginfo_t * info,
 
 #ifdef TEST_SIGWAITINFO
 static int my_sigwaitinfo(const sigset_t * set, siginfo_t * info,
-			  struct timespec *timeout)
+			  void *timeout)
 {
 	return sigwaitinfo(set, info);
 }
@@ -81,7 +83,7 @@ static int my_sigwaitinfo(const sigset_t * set, siginfo_t * info,
 
 #ifdef TEST_SIGTIMEDWAIT
 static int my_sigtimedwait(const sigset_t * set, siginfo_t * info,
-			   struct timespec *timeout)
+			   void *timeout)
 {
 	return sigtimedwait(set, info, timeout);
 }
@@ -89,14 +91,23 @@ static int my_sigtimedwait(const sigset_t * set, siginfo_t * info,
 
 #ifdef TEST_RT_SIGTIMEDWAIT
 static int my_rt_sigtimedwait(const sigset_t * set, siginfo_t * info,
-			      struct timespec *timeout)
+			      void *timeout)
 {
 	/* _NSIG is always the right number of bits of signal map for all arches */
 	return tst_syscall(__NR_rt_sigtimedwait, set, info, timeout, _NSIG/8);
 }
+
+#if (__NR_rt_sigtimedwait_time64 != __LTP__NR_INVALID_SYSCALL)
+static int my_rt_sigtimedwait_time64(const sigset_t * set, siginfo_t * info,
+				     void *timeout)
+{
+	/* _NSIG is always the right number of bits of signal map for all arches */
+	return tst_syscall(__NR_rt_sigtimedwait_time64, set, info, timeout, _NSIG/8);
+}
+#endif
 #endif
 
-void test_empty_set(swi_func sigwaitinfo, int signo)
+void test_empty_set(swi_func sigwaitinfo, int signo, enum tst_ts_type type)
 {
 	sigset_t sigs;
 	siginfo_t si;
@@ -113,19 +124,23 @@ void test_empty_set(swi_func sigwaitinfo, int signo)
 	SAFE_WAIT(NULL);
 }
 
-void test_timeout(swi_func sigwaitinfo, int signo)
+void test_timeout(swi_func sigwaitinfo, int signo, enum tst_ts_type type)
 {
 	sigset_t sigs;
 	siginfo_t si;
 	pid_t child;
-	struct timespec ts = {.tv_sec = 1 };
+	struct tst_ts ts;
+
+	ts.type = type;
+	tst_ts_set_sec(&ts, 1);
+	tst_ts_set_nsec(&ts, 0);
 
 	SUCCEED_OR_DIE(sigemptyset, "sigemptyset failed", &sigs);
 
 	/* Run a child that will wake us up */
 	child = create_sig_proc(signo, INT_MAX, 100000);
 
-	TEST(sigwaitinfo(&sigs, &si, &ts));
+	TEST(sigwaitinfo(&sigs, &si, tst_ts_get(&ts)));
 	REPORT_SUCCESS(-1, EAGAIN);
 
 	SAFE_KILL(child, SIGTERM);
@@ -135,7 +150,8 @@ void test_timeout(swi_func sigwaitinfo, int signo)
 /* Note: sigwait-ing for a signal that is not blocked is unspecified
  * by POSIX; but works for non-ignored signals under Linux
  */
-void test_unmasked_matching(swi_func sigwaitinfo, int signo)
+void test_unmasked_matching(swi_func sigwaitinfo, int signo,
+			    enum tst_ts_type type)
 {
 	sigset_t sigs;
 	siginfo_t si;
@@ -156,7 +172,8 @@ void test_unmasked_matching(swi_func sigwaitinfo, int signo)
 	SAFE_WAIT(NULL);
 }
 
-void test_unmasked_matching_noinfo(swi_func sigwaitinfo, int signo)
+void test_unmasked_matching_noinfo(swi_func sigwaitinfo, int signo,
+				   enum tst_ts_type type)
 {
 	sigset_t sigs;
 	pid_t child;
@@ -173,7 +190,8 @@ void test_unmasked_matching_noinfo(swi_func sigwaitinfo, int signo)
 	SAFE_WAIT(NULL);
 }
 
-void test_masked_matching(swi_func sigwaitinfo, int signo)
+void test_masked_matching(swi_func sigwaitinfo, int signo,
+			  enum tst_ts_type type)
 {
 	sigset_t sigs, oldmask;
 	siginfo_t si;
@@ -211,7 +229,8 @@ void test_masked_matching(swi_func sigwaitinfo, int signo)
 	SAFE_WAIT(NULL);
 }
 
-void test_masked_matching_rt(swi_func sigwaitinfo, int signo)
+void test_masked_matching_rt(swi_func sigwaitinfo, int signo,
+			     enum tst_ts_type type)
 {
 	sigset_t sigs, oldmask;
 	siginfo_t si;
@@ -262,7 +281,8 @@ void test_masked_matching_rt(swi_func sigwaitinfo, int signo)
 			 "sigwaitinfo failed to restore the original mask");
 }
 
-void test_masked_matching_noinfo(swi_func sigwaitinfo, int signo)
+void test_masked_matching_noinfo(swi_func sigwaitinfo, int signo,
+				 enum tst_ts_type type)
 {
 	sigset_t sigs, oldmask;
 	pid_t child;
@@ -297,7 +317,7 @@ void test_masked_matching_noinfo(swi_func sigwaitinfo, int signo)
 	SAFE_WAIT(NULL);
 }
 
-void test_bad_address(swi_func sigwaitinfo, int signo)
+void test_bad_address(swi_func sigwaitinfo, int signo, enum tst_ts_type type)
 {
 	sigset_t sigs, oldmask;
 	pid_t child;
@@ -326,7 +346,7 @@ void test_bad_address(swi_func sigwaitinfo, int signo)
 	SAFE_WAIT(NULL);
 }
 
-void test_bad_address2(swi_func sigwaitinfo, int signo)
+void test_bad_address2(swi_func sigwaitinfo, int signo, enum tst_ts_type type)
 {
 	pid_t pid;
 	int status;
@@ -372,7 +392,7 @@ void test_bad_address2(swi_func sigwaitinfo, int signo)
 	}
 }
 
-void test_bad_address3(swi_func sigwaitinfo, int signo)
+void test_bad_address3(swi_func sigwaitinfo, int signo, enum tst_ts_type type)
 {
 	sigset_t sigs;
 	SUCCEED_OR_DIE(sigemptyset, "sigemptyset failed", &sigs);
@@ -388,28 +408,28 @@ struct test_desc {
 } tests[] = {
 #ifdef TEST_RT_SIGTIMEDWAIT
 	{
-	test_empty_set, my_rt_sigtimedwait, SIGUSR1}, {
-	test_unmasked_matching, my_rt_sigtimedwait, SIGUSR1}, {
-	test_masked_matching, my_rt_sigtimedwait, SIGUSR1}, {
-	test_unmasked_matching_noinfo, my_rt_sigtimedwait, SIGUSR1}, {
-	test_masked_matching_noinfo, my_rt_sigtimedwait, SIGUSR1}, {
-	test_bad_address, my_rt_sigtimedwait, SIGUSR1}, {
-	test_bad_address2, my_rt_sigtimedwait, SIGUSR1}, {
-	test_bad_address3, my_rt_sigtimedwait, SIGUSR1}, {
-	test_timeout, my_rt_sigtimedwait, 0},
+	test_empty_set, NULL, SIGUSR1}, {
+	test_unmasked_matching, NULL, SIGUSR1}, {
+	test_masked_matching, NULL, SIGUSR1}, {
+	test_unmasked_matching_noinfo, NULL, SIGUSR1}, {
+	test_masked_matching_noinfo, NULL, SIGUSR1}, {
+	test_bad_address, NULL, SIGUSR1}, {
+	test_bad_address2, NULL, SIGUSR1}, {
+	test_bad_address3, NULL, SIGUSR1}, {
+	test_timeout, NULL, 0},
 	    /* Special cases */
 	    /* 1: sigwaitinfo does respond to ignored signal */
 	{
-	test_masked_matching, my_rt_sigtimedwait, SIGUSR2},
+	test_masked_matching, NULL, SIGUSR2},
 	    /* 2: An ignored signal doesn't cause sigwaitinfo to return EINTR */
 	{
-	test_timeout, my_rt_sigtimedwait, SIGUSR2},
+	test_timeout, NULL, SIGUSR2},
 	    /* 3: The handler is not called when the signal is waited for by sigwaitinfo */
 	{
-	test_masked_matching, my_rt_sigtimedwait, SIGTERM},
+	test_masked_matching, NULL, SIGTERM},
 	    /* 4: Simultaneous realtime signals are delivered in the order of increasing signal number */
 	{
-	test_masked_matching_rt, my_rt_sigtimedwait, -1},
+	test_masked_matching_rt, NULL, -1},
 #endif
 #if defined TEST_SIGWAIT
 	{
@@ -440,15 +460,48 @@ struct test_desc {
 #endif
 };
 
+static struct test_variants {
+	swi_func swi;
+	enum tst_ts_type type;
+	char *desc;
+} variants[] = {
+#ifdef TEST_RT_SIGTIMEDWAIT
+
+#if defined(TST_ABI32)
+	{ .swi = my_rt_sigtimedwait, .type = TST_LIBC_TIMESPEC, .desc = "syscall with libc spec"},
+	{ .swi = my_rt_sigtimedwait, .type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with kernel spec32"},
+#endif
+
+#if defined(TST_ABI64)
+	{ .swi = my_rt_sigtimedwait, .type = TST_KERN_TIMESPEC, .desc = "syscall with kernel spec64"},
+#endif
+
+#if (__NR_rt_sigtimedwait_time64 != __LTP__NR_INVALID_SYSCALL)
+	{ .swi = my_rt_sigtimedwait_time64, .type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec64"},
+#endif
+
+#else /* !TEST_RT_SIGTIMEDWAIT */
+
+	{ .swi = NULL, .type = TST_LIBC_TIMESPEC, .desc = "syscall with libc spec"},
+
+#endif /* TEST_RT_SIGTIMEDWAIT */
+};
+
 static void run(unsigned int i)
 {
+	struct test_variants *tv = &variants[tst_variant];
 	struct test_desc *tc = &tests[i];
+	swi_func swi;
 
-	tc->tf(tc->swi, tc->signo);
+	swi = tv->swi ? tv->swi : tc->swi;
+
+	tc->tf(swi, tc->signo, tv->type);
 }
 
 static void setup(void)
 {
+	tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
+
 	signal(SIGUSR1, empty_handler);
 	signal(SIGALRM, empty_handler);
 	signal(SIGUSR2, SIG_IGN);
@@ -464,6 +517,7 @@ static void cleanup(void)
 static struct tst_test test = {
 	.test= run,
 	.tcnt = ARRAY_SIZE(tests),
+	.test_variants = ARRAY_SIZE(variants),
 	.setup = setup,
 	.cleanup = cleanup,
 	.forks_child = 1,
Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
#13 lore raw

PATCH v2 10/17 syscalls/mq_timed{send|receive}: Add support for time64 tests

In reply to Viresh Kumar

This adds support for time64 tests to the existing mq_timed{send|receive}() syscall tests.

---
 include/tst_timer.h                           |  41 +++++++
 .../mq_timedreceive/mq_timedreceive01.c       |  97 ++++++++++++-----
 .../syscalls/mq_timedsend/mq_timedsend01.c    | 101 ++++++++++++------
 testcases/kernel/syscalls/utils/mq_timed.h    |  42 +++-----
 4 files changed, 192 insertions(+), 89 deletions(-)
include/tst_timer.h +41 -0
index b4280042c77f..28f11c7376b4 100644
@@ -14,6 +14,7 @@
 
 #include <sched.h>
 #include <sys/time.h>
+#include <mqueue.h>
 #include <time.h>
 #include "tst_test.h"
 #include "lapi/common_timers.h"
@@ -255,6 +256,46 @@ static inline int sys_futex_time64(int *uaddr, int futex_op, int val, void *to,
 	return tst_syscall(__NR_futex_time64, uaddr, futex_op, val, to, uaddr2, val3);
 }
 
+static inline int libc_mq_timedsend(mqd_t mqdes, const char *msg_ptr,
+		size_t msg_len, unsigned int msg_prio, void *abs_timeout)
+{
+	return mq_timedsend(mqdes, msg_ptr, msg_len, msg_prio, abs_timeout);
+}
+
+static inline int sys_mq_timedsend(mqd_t mqdes, const char *msg_ptr,
+		size_t msg_len, unsigned int msg_prio, void *abs_timeout)
+{
+	return tst_syscall(__NR_mq_timedsend, mqdes, msg_ptr, msg_len, msg_prio,
+			   abs_timeout);
+}
+
+static inline int sys_mq_timedsend64(mqd_t mqdes, const char *msg_ptr,
+		size_t msg_len, unsigned int msg_prio, void *abs_timeout)
+{
+	return tst_syscall(__NR_mq_timedsend_time64, mqdes, msg_ptr, msg_len,
+			   msg_prio, abs_timeout);
+}
+
+static inline ssize_t libc_mq_timedreceive(mqd_t mqdes, char *msg_ptr,
+		size_t msg_len, unsigned int *msg_prio, void *abs_timeout)
+{
+	return mq_timedreceive(mqdes, msg_ptr, msg_len, msg_prio, abs_timeout);
+}
+
+static inline ssize_t sys_mq_timedreceive(mqd_t mqdes, char *msg_ptr,
+		size_t msg_len, unsigned int *msg_prio, void *abs_timeout)
+{
+	return tst_syscall(__NR_mq_timedreceive, mqdes, msg_ptr, msg_len,
+			   msg_prio, abs_timeout);
+}
+
+static inline ssize_t sys_mq_timedreceive64(mqd_t mqdes, char *msg_ptr,
+		size_t msg_len, unsigned int *msg_prio, void *abs_timeout)
+{
+	return tst_syscall(__NR_mq_timedreceive_time64, mqdes, msg_ptr, msg_len,
+			   msg_prio, abs_timeout);
+}
+
 static inline int libc_sched_rr_get_interval(pid_t pid, void *ts)
 {
 	return sched_rr_get_interval(pid, ts);
testcases/kernel/syscalls/mq_timedreceive/mq_timedreceive01.c +68 -29

190 lines not on this page · raw message

testcases/kernel/syscalls/mq_timedsend/mq_timedsend01.c +70 -31

212 lines not on this page · raw message

testcases/kernel/syscalls/utils/mq_timed.h +13 -29

70 lines not on this page · raw message

Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
#14 lore raw

PATCH v2 11/17 syscalls/recvmmsg: Add support for time64 tests

In reply to Viresh Kumar

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

---
 .../kernel/syscalls/sendmmsg/sendmmsg01.c     | 45 +++++++++++----
 .../kernel/syscalls/sendmmsg/sendmmsg_var.h   | 55 ++++++++-----------
 2 files changed, 58 insertions(+), 42 deletions(-)
testcases/kernel/syscalls/sendmmsg/sendmmsg01.c +35 -10
index 37084102ee09..5d1fd1b6b9fa 100644
@@ -14,8 +14,8 @@
 #include "tst_test.h"
 #include "lapi/socket.h"
 #include "tst_safe_macros.h"
-
 #include "sendmmsg_var.h"
+#include "lapi/abisize.h"
 
 #define BUFSIZE 16
 #define VLEN 2
@@ -25,27 +25,52 @@ static int receive_sockfd;
 static struct mmsghdr *snd_msg, *rcv_msg;
 static struct iovec *snd1, *snd2, *rcv1, *rcv2;
 
+static struct test_variants {
+	int (*receive)(int sockfd, struct mmsghdr *msgvec, unsigned int vlen,
+		       unsigned int flags, void *timeout);
+	int (*send)(int sockfd, struct mmsghdr *msgvec, unsigned int vlen,
+		    unsigned int flags);
+	enum tst_ts_type type;
+	char *desc;
+} variants[] = {
+#if defined(TST_ABI32)
+	{ .receive = libc_recvmmsg, .send = libc_sendmmsg, .type = TST_LIBC_TIMESPEC, .desc = "vDSO or syscall with libc spec"},
+	{ .receive = sys_recvmmsg, .send = sys_sendmmsg, .type = TST_LIBC_TIMESPEC, .desc = "syscall with libc spec"},
+	{ .receive = sys_recvmmsg, .send = sys_sendmmsg, .type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with kernel spec32"},
+#endif
+
+#if defined(TST_ABI64)
+	{ .receive = sys_recvmmsg, .send = sys_sendmmsg, .type = TST_KERN_TIMESPEC, .desc = "syscall with kernel spec64"},
+#endif
+
+#if (__NR_recvmmsg_time64 != __LTP__NR_INVALID_SYSCALL)
+	{ .receive = sys_recvmmsg64, .send = sys_sendmmsg, .type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec64"},
+#endif
+};
+
 static void run(void)
 {
-	struct timespec timeout;
+	struct test_variants *tv = &variants[tst_variant];
+	struct tst_ts timeout;
 	int retval;
 
-	retval = do_sendmmsg(send_sockfd, snd_msg, VLEN, 0);
+	retval = tv->send(send_sockfd, snd_msg, VLEN, 0);
 	if (retval < 0 || snd_msg[0].msg_len != 6 || snd_msg[1].msg_len != 6) {
-		tst_res(TFAIL|TTERRNO, "sendmmsg failed");
+		tst_res(TFAIL|TTERRNO, "sendmmsg() failed");
 		return;
 	}
 
 	memset(rcv1->iov_base, 0, rcv1->iov_len);
 	memset(rcv2->iov_base, 0, rcv2->iov_len);
 
-	timeout.tv_sec = 1;
-	timeout.tv_nsec = 0;
+	timeout.type = tv->type;
+	tst_ts_set_sec(&timeout, 1);
+	tst_ts_set_nsec(&timeout, 0);
 
-	retval = do_recvmmsg(receive_sockfd, rcv_msg, VLEN, 0, &timeout);
+	retval = tv->receive(receive_sockfd, rcv_msg, VLEN, 0, tst_ts_get(&timeout));
 
 	if (retval == -1) {
-		tst_res(TFAIL | TTERRNO, "recvmmsg failed");
+		tst_res(TFAIL | TTERRNO, "recvmmsg() failed");
 		return;
 	}
 	if (retval != 2) {
@@ -96,7 +121,7 @@ static void setup(void)
 	rcv_msg[1].msg_hdr.msg_iov = rcv2;
 	rcv_msg[1].msg_hdr.msg_iovlen = 1;
 
-	test_info();
+	tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
 }
 
 static void cleanup(void)
@@ -111,7 +136,7 @@ static struct tst_test test = {
 	.test_all = run,
 	.setup = setup,
 	.cleanup = cleanup,
-	.test_variants = TEST_VARIANTS,
+	.test_variants = ARRAY_SIZE(variants),
 	.bufs = (struct tst_buffers []) {
 		{&snd1, .iov_sizes = (int[]){3, 3, -1}},
 		{&snd2, .iov_sizes = (int[]){6, -1}},
testcases/kernel/syscalls/sendmmsg/sendmmsg_var.h +23 -32

78 lines not on this page · raw message

Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
#15 lore raw

PATCH v2 12/17 syscalls/ppoll: Add support for time64 tests

In reply to Viresh Kumar

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

Note that the O_EXCL flag is removed from SAFE_OPEN() calls as it made the tests failed when run for the second variant as the file existed.

---
 testcases/kernel/syscalls/ppoll/ppoll01.c | 76 ++++++++++++++++++-----
 1 file changed, 60 insertions(+), 16 deletions(-)
testcases/kernel/syscalls/ppoll/ppoll01.c +60 -16
index 2fadd0653948..eb8a14534e2e 100644
@@ -21,6 +21,8 @@
 #include "ltp_signal.h"
 #include "tst_sig_proc.h"
 #include "tst_test.h"
+#include "tst_timer.h"
+#include "lapi/abisize.h"
 
 /* Older versions of glibc don't publish this constant's value. */
 #ifndef POLLRDHUP
@@ -38,7 +40,7 @@ struct test_case {
 	unsigned int nfds;	   /* nfds ppoll parameter */
 	sigset_t *sigmask;	   /* sigmask ppoll parameter */
 	sigset_t *sigmask_cur;	   /* sigmask set for current process */
-	struct timespec *ts;	   /* ts ppoll parameter */
+	struct tst_ts *ts;	   /* ts ppoll parameter */
 	struct pollfd *fds;	   /* fds ppoll parameter */
 	int sigint_count;	   /* if > 0, spawn process to send SIGINT */
 				   /* 'count' times to current process */
@@ -60,14 +62,7 @@ static int fd1 = -1;
 static sigset_t sigmask_empty, sigmask_sigint;
 static struct pollfd fds_good[1], fds_already_closed[1];
 
-static struct timespec ts_short = {
-	.tv_sec = 0,
-	.tv_nsec = 200000000,
-};
-static struct timespec ts_long = {
-	.tv_sec = 2,
-	.tv_nsec = 0,
-};
+static struct tst_ts ts_short, ts_long;
 
 /* Test cases
  *
@@ -160,14 +155,57 @@ static struct test_case tcase[] = {
 	},
 };
 
+static inline int libc_ppoll(struct pollfd *fds, nfds_t nfds, void *tmo_p,
+			     const sigset_t *sigmask, size_t sigsetsize)
+{
+	return ppoll(fds, nfds, tmo_p, sigmask);
+}
+
+static inline int sys_ppoll(struct pollfd *fds, nfds_t nfds, void *tmo_p,
+			    const sigset_t *sigmask, size_t sigsetsize)
+{
+	return tst_syscall(__NR_ppoll, fds, nfds, tmo_p, sigmask, sigsetsize);
+}
+
+static inline int sys_ppoll_time64(struct pollfd *fds, nfds_t nfds, void *tmo_p,
+				   const sigset_t *sigmask, size_t sigsetsize)
+{
+	return tst_syscall(__NR_ppoll_time64, fds, nfds, tmo_p, sigmask,
+			   sigsetsize);
+}
+
+static struct test_variants {
+	int (*ppoll)(struct pollfd *fds, nfds_t nfds, void *tmo_p,
+		     const sigset_t *sigmask, size_t sigsetsize);
+
+	enum tst_ts_type type;
+	char *desc;
+} variants[] = {
+#if defined(TST_ABI32)
+	{ .ppoll = libc_ppoll, .type = TST_LIBC_TIMESPEC, .desc = "vDSO or syscall with libc spec"},
+	{ .ppoll = sys_ppoll, .type = TST_LIBC_TIMESPEC, .desc = "syscall with libc spec"},
+	{ .ppoll = sys_ppoll, .type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with kernel spec32"},
+#endif
+
+#if defined(TST_ABI64)
+	{ .ppoll = sys_ppoll, .type = TST_KERN_TIMESPEC, .desc = "syscall with kernel spec64"},
+#endif
+
+#if (__NR_ppoll_time64 != __LTP__NR_INVALID_SYSCALL)
+	{ .ppoll = sys_ppoll_time64, .type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec64"},
+#endif
+};
+
 static void sighandler(int sig LTP_ATTRIBUTE_UNUSED)
 {
 }
 
 static void setup(void)
 {
+	struct test_variants *tv = &variants[tst_variant];
 	int fd2;
 
+	tst_res(TINFO, "Testing variant: %s", tv->desc);
 	SAFE_SIGNAL(SIGINT, sighandler);
 
 	if (sigemptyset(&sigmask_empty) == -1)
@@ -177,18 +215,22 @@ static void setup(void)
 	if (sigaddset(&sigmask_sigint, SIGINT) == -1)
 		tst_brk(TBROK | TERRNO, "sigaddset");
 
-	fd1 = SAFE_OPEN("testfile1", O_CREAT | O_EXCL | O_RDWR,
-		S_IRUSR | S_IWUSR);
+	fd1 = SAFE_OPEN("testfile1", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
 	fds_good[0].fd = fd1;
 	fds_good[0].events = POLLIN | POLLPRI | POLLOUT | POLLRDHUP;
 	fds_good[0].revents = 0;
 
-	fd2 = SAFE_OPEN("testfile2", O_CREAT | O_EXCL | O_RDWR,
-		S_IRUSR | S_IWUSR);
+	fd2 = SAFE_OPEN("testfile2", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
 	fds_already_closed[0].fd = fd2;
 	fds_already_closed[0].events = POLLIN | POLLPRI | POLLOUT | POLLRDHUP;
 	fds_already_closed[0].revents = 0;
 	SAFE_CLOSE(fd2);
+
+	ts_short.type = ts_long.type = tv->type;
+	tst_ts_set_sec(&ts_short, 0);
+	tst_ts_set_nsec(&ts_short, 200000000);
+	tst_ts_set_sec(&ts_long, 2);
+	tst_ts_set_nsec(&ts_long, 0);
 }
 
 static void cleanup(void)
@@ -199,10 +241,11 @@ static void cleanup(void)
 
 static void do_test(unsigned int i)
 {
+	struct test_variants *tv = &variants[tst_variant];
 	pid_t pid = 0;
 	int sys_ret, sys_errno = 0, dummy;
 	struct test_case *tc = &tcase[i];
-	struct timespec ts, *tsp = NULL;
+	struct tst_ts ts, *tsp = NULL;
 
 	if (tc->ts) {
 		memcpy(&ts, tc->ts, sizeof(ts));
@@ -223,8 +266,8 @@ static void do_test(unsigned int i)
 
 	/* test */
 	errno = 0;
-	sys_ret = tst_syscall(__NR_ppoll, tc->fds, tc->nfds, tsp,
-		tc->sigmask, SIGSETSIZE);
+	sys_ret = tv->ppoll(tc->fds, tc->nfds, tst_ts_get(tsp), tc->sigmask,
+			    SIGSETSIZE);
 	sys_errno = errno;
 
 	/* cleanup */
@@ -261,6 +304,7 @@ static void do_test(unsigned int i)
 static struct tst_test test = {
 	.tcnt = ARRAY_SIZE(tcase),
 	.test = do_test,
+	.test_variants = ARRAY_SIZE(variants),
 	.setup = setup,
 	.cleanup = cleanup,
 	.forks_child = 1,
Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
#16 lore raw

PATCH v2 13/17 syscalls/select6: Add support for time64 tests

In reply to Viresh Kumar

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

---
 testcases/kernel/syscalls/select/select_var.h | 27 ++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/select/select_var.h +24 -3
index b19a1d1bf085..6e8d44088217 100644
@@ -6,6 +6,8 @@
 #define SELECT_VAR__
 
 #include "lapi/syscalls.h"
+#include "tst_timer.h"
+#include "lapi/abisize.h"
 
 struct compat_sel_arg_struct {
 	long _n;
@@ -47,7 +49,24 @@ static int do_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *except
 		timeout->tv_usec = ts.tv_nsec / 1000;
 		return ret;
 	}
-	case 3:
+	case 3: {
+		int ret = 0;
+		struct __kernel_timespec ts = {
+			.tv_sec = timeout->tv_sec,
+			.tv_nsec = timeout->tv_usec * 1000,
+		};
+#if defined(TST_ABI64)
+		ret = tst_syscall(__NR_pselect6, nfds, readfds, writefds, exceptfds, &ts, NULL);
+#elif (__NR_clock_settime64 != __LTP__NR_INVALID_SYSCALL)
+		ret = tst_syscall(__NR_pselect6_time64, nfds, readfds, writefds, exceptfds, &ts, NULL);
+#else
+		tst_brk(TCONF, "__NR_pselect6 time64 variant not supported");
+#endif
+		timeout->tv_sec = ts.tv_sec;
+		timeout->tv_usec = ts.tv_nsec / 1000;
+		return ret;
+	}
+	case 4:
 #ifdef __NR__newselect
 		return tst_syscall(__NR__newselect, nfds, readfds, writefds, exceptfds, timeout);
 #else
@@ -55,7 +74,6 @@ static int do_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *except
 #endif
 	break;
 	}
-
 	return -1;
 }
 
@@ -72,11 +90,14 @@ static void select_info(void)
 		tst_res(TINFO, "Testing SYS_pselect6 syscall");
 	break;
 	case 3:
+		tst_res(TINFO, "Testing SYS_pselect6 time64 syscall");
+	break;
+	case 4:
 		tst_res(TINFO, "Testing SYS__newselect syscall");
 	break;
 	}
 }
 
-#define TEST_VARIANTS 4
+#define TEST_VARIANTS 5
 
 #endif /* SELECT_VAR__ */
Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
#17 lore raw

PATCH v2 13/17 syscalls/select6: Add support for time64 tests

testcases/kernel/syscalls/select/select_var.h static int do_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *except · line 59

Quoted 3 lines · Viresh Kumar
testcases/kernel/syscalls/select/select_var.h +3 -0
+               };
+#if defined(TST_ABI64)
+               ret = tst_syscall(__NR_pselect6, nfds, readfds, writefds, exceptfds, &ts, NULL);

Again, this is not the actual ABI: __NR_pselect6 should be called with a __kernel_old_timespec when the macro is defined, but it may not be defined on new 32-bit architectures.

Arnd

#18 lore raw

PATCH v2 14/17 syscalls/semop: Migrate to new test framework

In reply to Viresh Kumar

This migrates the semop tests to the new test framework.

---
 testcases/kernel/syscalls/ipc/semop/Makefile  |   2 +-
 testcases/kernel/syscalls/ipc/semop/semop01.c | 140 ++++----
 testcases/kernel/syscalls/ipc/semop/semop02.c | 145 +++------
 testcases/kernel/syscalls/ipc/semop/semop03.c | 150 +++------
 testcases/kernel/syscalls/ipc/semop/semop04.c | 165 ++++------
 testcases/kernel/syscalls/ipc/semop/semop05.c | 303 ++++++++----------
 6 files changed, 347 insertions(+), 558 deletions(-)
testcases/kernel/syscalls/ipc/semop/Makefile +1 -1
index 401e5e8cbb9f..5e4c695dd310 100644
@@ -4,5 +4,5 @@
 top_srcdir              ?= ../../../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
-include $(abs_srcdir)/../Makefile.inc
+include $(abs_srcdir)/../Makefile2.inc
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/ipc/semop/semop01.c +57 -83

181 lines not on this page · raw message

testcases/kernel/syscalls/ipc/semop/semop02.c +53 -92

204 lines not on this page · raw message

testcases/kernel/syscalls/ipc/semop/semop03.c +50 -100

180 lines not on this page · raw message

testcases/kernel/syscalls/ipc/semop/semop04.c +54 -111

201 lines not on this page · raw message

testcases/kernel/syscalls/ipc/semop/semop05.c +132 -171

367 lines not on this page · raw message

Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
#19 lore raw

PATCH v2 15/17 syscalls/semtimedop: Add support for semtimedop and its time64 version

In reply to Viresh Kumar

This adds support for semtimedop() and its time64 variant to the existing semop() syscall tests.

---
 testcases/kernel/syscalls/ipc/semop/semop.h   | 52 +++++++++++++++++++
 testcases/kernel/syscalls/ipc/semop/semop01.c | 11 +++-
 testcases/kernel/syscalls/ipc/semop/semop02.c | 12 ++++-
 testcases/kernel/syscalls/ipc/semop/semop03.c | 12 ++++-
 testcases/kernel/syscalls/ipc/semop/semop04.c | 12 ++++-
 testcases/kernel/syscalls/ipc/semop/semop05.c | 12 ++++-
 6 files changed, 106 insertions(+), 5 deletions(-)
 create mode 100644 testcases/kernel/syscalls/ipc/semop/semop.h
testcases/kernel/syscalls/ipc/semop/semop.h new file +52 -0
new file mode 100644
index 000000000000..8d1245b65ec0
@@ -0,0 +1,52 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#ifndef SEMOP_VAR__
+#define SEMOP_VAR__
+
+#include <sys/sem.h>
+#include "tst_timer.h"
+#include "lapi/abisize.h"
+
+static inline int sys_semtimedop(int semid, struct sembuf *sops, size_t nsops,
+		void *timeout)
+{
+	return tst_syscall(__NR_semtimedop, semid, sops, nsops, timeout);
+}
+
+static inline int sys_semtimedop_time64(int semid, struct sembuf *sops,
+					size_t nsops, void *timeout)
+{
+	return tst_syscall(__NR_semtimedop_time64, semid, sops, nsops, timeout);
+}
+
+struct test_variants {
+	int (*semop)(int semid, struct sembuf *sops, size_t nsops);
+	int (*semtimedop)(int semid, struct sembuf *sops, size_t nsops, void *timeout);
+	enum tst_ts_type type;
+	char *desc;
+} variants[] = {
+	{ .semop = semop, .type = TST_LIBC_TIMESPEC, .desc = "semop: vDSO or syscall"},
+#if defined(TST_ABI32)
+	{ .semtimedop = sys_semtimedop, .type = TST_LIBC_TIMESPEC, .desc = "semtimedop: syscall with libc spec"},
+	{ .semtimedop = sys_semtimedop, .type = TST_KERN_OLD_TIMESPEC, .desc = "semtimedop: syscall with kernel spec32"},
+#endif
+
+#if defined(TST_ABI64)
+	{ .semtimedop = sys_semtimedop, .type = TST_KERN_TIMESPEC, .desc = "semtimedop: syscall with kernel spec64"},
+#endif
+
+#if (__NR_semtimedop_time64 != __LTP__NR_INVALID_SYSCALL)
+	{ .semtimedop = sys_semtimedop_time64, .type = TST_KERN_TIMESPEC, .desc = "semtimedop: syscall time64 with kernel spec64"},
+#endif
+};
+
+static inline int call_semop(struct test_variants *tv, int semid,
+		struct sembuf *sops, size_t nsops, struct tst_ts *timeout)
+{
+	if (tv->semop)
+		return tv->semop(semid, sops, nsops);
+
+	return tv->semtimedop(semid, sops, nsops, tst_ts_get(timeout));
+}
+
+#endif /* SEMOP_VAR__ */
testcases/kernel/syscalls/ipc/semop/semop01.c +10 -1
index bcb45fa69320..a4924376e32c 100644
@@ -41,6 +41,7 @@
 #include "tst_test.h"
 #include "libnewipc.h"
 #include "lapi/semun.h"
+#include "semop.h"
 
 #define NSEMS	4		/* the number of primitive semaphores to test */
 
@@ -52,11 +53,16 @@ static struct sembuf sops[PSEMS];
 
 static void run(void)
 {
+	struct test_variants *tv = &variants[tst_variant];
 	union semun arr = { .val = 0 };
+	struct tst_ts timeout;
 	int fail = 0;
 	int i;
 
-	TEST(semop(sem_id, sops, NSEMS));
+	timeout.type = tv->type;
+	tst_ts_set_nsec(&timeout, 10000);
+
+	TEST(call_semop(tv, sem_id, sops, NSEMS, &timeout));
 
 	if (TST_RET == -1) {
 		tst_res(TFAIL | TTERRNO, "semop() failed");
@@ -94,6 +100,8 @@ static void setup(void)
 {
 	int i;
 
+	tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
+
 	get_arr.array = malloc(sizeof(unsigned short int) * PSEMS);
 	if (get_arr.array == NULL)
 		tst_brk(TBROK, "malloc failed");
@@ -124,6 +132,7 @@ static void cleanup(void)
 
 static struct tst_test test = {
 	.test_all = run,
+	.test_variants = ARRAY_SIZE(variants),
 	.setup = setup,
 	.cleanup = cleanup,
 	.needs_tmpdir = 1,
testcases/kernel/syscalls/ipc/semop/semop02.c +11 -1
index f24d284776a4..a51906340400 100644
@@ -20,6 +20,7 @@
 #include "tst_test.h"
 #include "libnewipc.h"
 #include "lapi/semun.h"
+#include "semop.h"
 
 static int sem_id_1 = -1;	/* a semaphore set with read & alter permissions */
 static int sem_id_2 = -1;	/* a semaphore set without read & alter permissions */
@@ -52,6 +53,8 @@ static void setup(void)
 	struct seminfo ipc_buf;
 	union semun arr;
 
+	tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
+
 	ltpuser = SAFE_GETPWNAM(nobody_uid);
 	SAFE_SETUID(ltpuser->pw_uid);
 
@@ -84,7 +87,13 @@ static void setup(void)
 
 static void run(unsigned int i)
 {
-	TEST(semop(*(tc[i].semid), tc[i].t_sbuf, tc[i].t_ops));
+	struct test_variants *tv = &variants[tst_variant];
+	struct tst_ts timeout;
+
+	timeout.type = tv->type;
+	tst_ts_set_nsec(&timeout, 10000);
+
+	TEST(call_semop(tv, *(tc[i].semid), tc[i].t_sbuf, tc[i].t_ops, &timeout));
 
 	if (TST_RET != -1) {
 		tst_res(TFAIL | TTERRNO, "call succeeded unexpectedly");
@@ -117,6 +126,7 @@ static void cleanup(void)
 static struct tst_test test = {
 	.test = run,
 	.tcnt = ARRAY_SIZE(tc),
+	.test_variants = ARRAY_SIZE(variants),
 	.setup = setup,
 	.cleanup = cleanup,
 	.needs_tmpdir = 1,
testcases/kernel/syscalls/ipc/semop/semop03.c +11 -1
index 4f5f78eb6d8d..d36194ce1f41 100644
@@ -38,6 +38,7 @@
 #include "tst_test.h"
 #include "libnewipc.h"
 #include "lapi/semun.h"
+#include "semop.h"
 
 static key_t semkey;
 static int sem_id = -1;
@@ -47,6 +48,12 @@ static int tc[] = { -1, PSEMS + 1 }; /* negative and too many "primitive" semas
 
 static void run(unsigned int i)
 {
+	struct test_variants *tv = &variants[tst_variant];
+	struct tst_ts timeout;
+
+	timeout.type = tv->type;
+	tst_ts_set_nsec(&timeout, 10000);
+
 	/* initialize two fields in the sembuf structure here */
 	s_buf.sem_op = 1;	/* add this value to struct sem.semval */
 	s_buf.sem_flg = SEM_UNDO;	/* undo when process exits */
@@ -61,7 +68,7 @@ static void run(unsigned int i)
 	 * use the TEST macro to make the call
 	 */
 
-	TEST(semop(sem_id, &s_buf, 1));
+	TEST(call_semop(tv, sem_id, &s_buf, 1, &timeout));
 
 	if (TST_RET != -1) {
 		tst_res(TFAIL | TTERRNO, "call succeeded unexpectedly");
@@ -80,6 +87,8 @@ static void run(unsigned int i)
 
 static void setup(void)
 {
+	tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
+
 	/* get an IPC resource key */
 	semkey = GETIPCKEY();
 
@@ -102,6 +111,7 @@ static void cleanup(void)
 static struct tst_test test = {
 	.test = run,
 	.tcnt = ARRAY_SIZE(tc),
+	.test_variants = ARRAY_SIZE(variants),
 	.setup = setup,
 	.cleanup = cleanup,
 	.needs_tmpdir = 1,
testcases/kernel/syscalls/ipc/semop/semop04.c +11 -1
index 0faf00a3585f..033065e7bbfc 100644
@@ -38,6 +38,7 @@
 #include "tst_test.h"
 #include "libnewipc.h"
 #include "lapi/semun.h"
+#include "semop.h"
 
 static int sem_id = -1;
 static int val; /* value for SETVAL */
@@ -62,6 +63,12 @@ static struct test_case_t {
 
 static void run(unsigned int i)
 {
+	struct test_variants *tv = &variants[tst_variant];
+	struct tst_ts timeout;
+
+	timeout.type = tv->type;
+	tst_ts_set_nsec(&timeout, 10000);
+
 	/* initialize the s_buf buffer */
 	s_buf.sem_op = tc[i].op;
 	s_buf.sem_flg = tc[i].flg;
@@ -72,7 +79,7 @@ static void run(unsigned int i)
 	if (semctl(sem_id, tc[i].num, SETVAL, tc[i].get_arr) == -1)
 		tst_brk(TBROK | TERRNO, "semctl() failed");
 
-	TEST(semop(sem_id, &s_buf, 1));
+	TEST(call_semop(tv, sem_id, &s_buf, 1, &timeout));
 	if (TST_RET != -1) {
 		tst_res(TFAIL, "call succeeded unexpectedly");
 		return;
@@ -86,6 +93,8 @@ static void run(unsigned int i)
 
 static void setup(void)
 {
+	tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
+
 	val = 1;
 
 	/* get an IPC resource key */
@@ -114,6 +123,7 @@ static void cleanup(void)
 static struct tst_test test = {
 	.test = run,
 	.tcnt = ARRAY_SIZE(tc),
+	.test_variants = ARRAY_SIZE(variants),
 	.setup = setup,
 	.cleanup = cleanup,
 	.needs_tmpdir = 1,
testcases/kernel/syscalls/ipc/semop/semop05.c +11 -1
index 9e8e040b0b19..f892cd519ecf 100644
@@ -52,6 +52,7 @@
 #include "tst_test.h"
 #include "libnewipc.h"
 #include "lapi/semun.h"
+#include "semop.h"
 
 static key_t semkey;
 static int sem_id = -1;
@@ -115,7 +116,13 @@ static inline int process_state_wait2(pid_t pid, const char state)
 
 static void do_child(int i)
 {
-	TEST(semop(sem_id, &s_buf, 1));
+	struct test_variants *tv = &variants[tst_variant];
+	struct tst_ts timeout;
+
+	timeout.type = tv->type;
+	tst_ts_set_nsec(&timeout, 10000);
+
+	TEST(call_semop(tv, sem_id, &s_buf, 1, &timeout));
 	if (TST_RET != -1) {
 		tst_res(TFAIL, "call succeeded when error expected");
 		exit(-1);
@@ -137,6 +144,8 @@ static void sighandler(int sig)
 
 static void setup(void)
 {
+	tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
+
 	SAFE_SIGNAL(SIGHUP, sighandler);
 
 	/* get an IPC resource key */
@@ -238,6 +247,7 @@ static void do_child_uclinux(void)
 static struct tst_test test = {
 	.test = run,
 	.tcnt = ARRAY_SIZE(tc),
+	.test_variants = ARRAY_SIZE(variants),
 	.setup = setup,
 	.cleanup = cleanup,
 	.needs_tmpdir = 1,
Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
#20 lore raw

PATCH v2 15/17 syscalls/semtimedop: Add support for semtimedop and its time64 version

Quoted 18 lines · Viresh Kumar
testcases/kernel/syscalls/ipc/semop/semop.h new file +18 -0
+
+static inline int sys_semtimedop(int semid, struct sembuf *sops, size_t nsops,
+               void *timeout)
+{
+       return tst_syscall(__NR_semtimedop, semid, sops, nsops, timeout);
+}
+
+static inline int sys_semtimedop_time64(int semid, struct sembuf *sops,
+                                       size_t nsops, void *timeout)
+{
+       return tst_syscall(__NR_semtimedop_time64, semid, sops, nsops, timeout);
+}
+
+struct test_variants {
+       int (*semop)(int semid, struct sembuf *sops, size_t nsops);
+       int (*semtimedop)(int semid, struct sembuf *sops, size_t nsops, void *timeout);
+       enum tst_ts_type type;
+       char *desc;

testcases/kernel/syscalls/ipc/semop/semop.h line 36

Quoted 10 lines
testcases/kernel/syscalls/ipc/semop/semop.h new file +10 -0
+} variants[] = {
+       { .semop = semop, .type = TST_LIBC_TIMESPEC, .desc = "semop: vDSO or syscall"},
+#if defined(TST_ABI32)
+       { .semtimedop = sys_semtimedop, .type = TST_LIBC_TIMESPEC, .desc = "semtimedop: syscall with libc spec"},
+       { .semtimedop = sys_semtimedop, .type = TST_KERN_OLD_TIMESPEC, .desc = "semtimedop: syscall with kernel spec32"},
+#endif
+
+#if defined(TST_ABI64)
+       { .semtimedop = sys_semtimedop, .type = TST_KERN_TIMESPEC, .desc = "semtimedop: syscall with kernel spec64"},
+#endif

It feels like this is more complicated than it need to be. The line

semtimedop = sys_semtimedop, .type = TST_KERN_OLD_TIMESPEC, .desc = "semtimedop: syscall with kernel spec32"},

should apply to any kernel that has "__NR_semtimedop != __LTP__NR_INVALID_SYSCALL",
regardless of any other macros set, and then you don't need the separate line

{ .semtimedop = sys_semtimedop, .type = TST_KERN_TIMESPEC, .desc = "semtimedop: syscall with kernel spec64"},

which is not what the ABI is meant to be anyway (sys_semtimedop takes a __kernel_old_timespec,
not a __kernel_timespec).

Similarly, the line

{ .semop = semop, .type = TST_LIBC_TIMESPEC, .desc = "semop: vDSO or syscall"},

should apply to both 32 and 64 bit machines

Arnd

#21 lore raw

PATCH v2 15/17 syscalls/semtimedop: Add support for semtimedop and its time64 version

Quoted 41 lines · Arnd Bergmann
Quoted 18 lines · Viresh Kumar
testcases/kernel/syscalls/ipc/semop/semop.h new file +18 -0
+
+static inline int sys_semtimedop(int semid, struct sembuf *sops, size_t nsops,
+               void *timeout)
+{
+       return tst_syscall(__NR_semtimedop, semid, sops, nsops, timeout);
+}
+
+static inline int sys_semtimedop_time64(int semid, struct sembuf *sops,
+                                       size_t nsops, void *timeout)
+{
+       return tst_syscall(__NR_semtimedop_time64, semid, sops, nsops, timeout);
+}
+
+struct test_variants {
+       int (*semop)(int semid, struct sembuf *sops, size_t nsops);
+       int (*semtimedop)(int semid, struct sembuf *sops, size_t nsops, void *timeout);
+       enum tst_ts_type type;
+       char *desc;

testcases/kernel/syscalls/ipc/semop/semop.h line 36

Quoted 10 lines
testcases/kernel/syscalls/ipc/semop/semop.h new file +10 -0
+} variants[] = {
+       { .semop = semop, .type = TST_LIBC_TIMESPEC, .desc = "semop: vDSO or syscall"},
+#if defined(TST_ABI32)
+       { .semtimedop = sys_semtimedop, .type = TST_LIBC_TIMESPEC, .desc = "semtimedop: syscall with libc spec"},
+       { .semtimedop = sys_semtimedop, .type = TST_KERN_OLD_TIMESPEC, .desc = "semtimedop: syscall with kernel spec32"},
+#endif
+
+#if defined(TST_ABI64)
+       { .semtimedop = sys_semtimedop, .type = TST_KERN_TIMESPEC, .desc = "semtimedop: syscall with kernel spec64"},
+#endif

It feels like this is more complicated than it need to be. The line

semtimedop = sys_semtimedop, .type = TST_KERN_OLD_TIMESPEC, .desc = "semtimedop: syscall with kernel spec32"},

should apply to any kernel that has "__NR_semtimedop != __LTP__NR_INVALID_SYSCALL",
regardless of any other macros set, and then you don't need the separate line

Quoted 6 lines

{ .semtimedop = sys_semtimedop, .type = TST_KERN_TIMESPEC, .desc = "semtimedop: syscall with kernel spec64"},

which is not what the ABI is meant to be anyway (sys_semtimedop takes a __kernel_old_timespec,
not a __kernel_timespec).

There is some misunderstanding here, surely from my side. The sys_ helpers here are the direct syscalls called from userspace with help of tst_syscall().

AFAIU, on 32 bit systems we need to call __NR_semtimedop with the 32 bit and 64 bit timespec (both), and on 64 bit systems which don't implement __NR_semtimedop_time64, we need to call __NR_semtimedop with the 64 bit timespec only.

What you are telling now is very different from that and so I don't get it.

Quoted 5 lines

Similarly, the line

{ .semop = semop, .type = TST_LIBC_TIMESPEC, .desc = "semop: vDSO or syscall"},

should apply to both 32 and 64 bit machines

Yes and so it is called without ifdef hackery. Isn't that correct ?

Signature · 1 line
viresh
#22 lore raw

PATCH v2 15/17 syscalls/semtimedop: Add support for semtimedop and its time64 version

Quoted 54 lines · Viresh Kumar
Quoted 41 lines · Arnd Bergmann
Quoted 18 lines · Viresh Kumar
testcases/kernel/syscalls/ipc/semop/semop.h new file +18 -0
+
+static inline int sys_semtimedop(int semid, struct sembuf *sops, size_t nsops,
+               void *timeout)
+{
+       return tst_syscall(__NR_semtimedop, semid, sops, nsops, timeout);
+}
+
+static inline int sys_semtimedop_time64(int semid, struct sembuf *sops,
+                                       size_t nsops, void *timeout)
+{
+       return tst_syscall(__NR_semtimedop_time64, semid, sops, nsops, timeout);
+}
+
+struct test_variants {
+       int (*semop)(int semid, struct sembuf *sops, size_t nsops);
+       int (*semtimedop)(int semid, struct sembuf *sops, size_t nsops, void *timeout);
+       enum tst_ts_type type;
+       char *desc;

testcases/kernel/syscalls/ipc/semop/semop.h line 36

Quoted 10 lines
testcases/kernel/syscalls/ipc/semop/semop.h new file +10 -0
+} variants[] = {
+       { .semop = semop, .type = TST_LIBC_TIMESPEC, .desc = "semop: vDSO or syscall"},
+#if defined(TST_ABI32)
+       { .semtimedop = sys_semtimedop, .type = TST_LIBC_TIMESPEC, .desc = "semtimedop: syscall with libc spec"},
+       { .semtimedop = sys_semtimedop, .type = TST_KERN_OLD_TIMESPEC, .desc = "semtimedop: syscall with kernel spec32"},
+#endif
+
+#if defined(TST_ABI64)
+       { .semtimedop = sys_semtimedop, .type = TST_KERN_TIMESPEC, .desc = "semtimedop: syscall with kernel spec64"},
+#endif

It feels like this is more complicated than it need to be. The line

semtimedop = sys_semtimedop, .type = TST_KERN_OLD_TIMESPEC, .desc = "semtimedop: syscall with kernel spec32"},

should apply to any kernel that has "__NR_semtimedop != __LTP__NR_INVALID_SYSCALL",
regardless of any other macros set, and then you don't need the separate line

Quoted 6 lines

{ .semtimedop = sys_semtimedop, .type = TST_KERN_TIMESPEC, .desc = "semtimedop: syscall with kernel spec64"},

which is not what the ABI is meant to be anyway (sys_semtimedop takes a __kernel_old_timespec,
not a __kernel_timespec).

There is some misunderstanding here, surely from my side. The sys_ helpers here are the direct syscalls called from userspace with help of tst_syscall().

Quoted 7 lines

AFAIU, on 32 bit systems we need to call __NR_semtimedop with the 32 bit and 64 bit timespec (both), and on 64 bit systems which don't implement __NR_semtimedop_time64, we need to call __NR_semtimedop with the 64 bit timespec only.

What you are telling now is very different from that and so I don't get it.

__NR_semtimedop can only be called with the 'old' timespec, which may have either 32 or 64 members depending on the architecture. On x32 it uses 64-bit members, and on riscv32 it does not exist at all.

I think you already have a correct __kernel_old_timespec definition, so what I'd expect to see here is code that passes __kernel_old_timespec into __NR_semtimedop whenever __NR_semtimedop is defined.

Passing the libc timespec into __kernel_old_timespec is a bug, as the libc may be using either the old or the new (always 64-bit) definition.

Quoted 5 lines
Quoted 3 lines

{ .semop = semop, .type = TST_LIBC_TIMESPEC, .desc = "semop: vDSO or syscall"},

should apply to both 32 and 64 bit machines

Yes and so it is called without ifdef hackery. Isn't that correct ?

My mistake, I confused the lines. What I meant is that there should be an unconditional test of the libc 'semtimedop' with the libc 'timespec' definition.

Arnd

#23 lore raw

PATCH v2 15/17 syscalls/semtimedop: Add support for semtimedop and its time64 version

Quoted 7 lines · Arnd Bergmann

__NR_semtimedop can only be called with the 'old' timespec, which may have either 32 or 64 members depending on the architecture. On x32 it uses 64-bit members, and on riscv32 it does not exist at all.

I think you already have a correct __kernel_old_timespec definition, so what I'd expect to see here is code that passes __kernel_old_timespec into __NR_semtimedop whenever __NR_semtimedop is defined.

Ahh, so on ARM64 and x86_64, fields will be 8 bytes long even with the old timespec. I missed that and so the confusion.

Signature · 1 line
viresh
#24 lore raw

PATCH v2 15/17 syscalls/semtimedop: Add support for semtimedop and its time64 version

In reply to Arnd Bergmann
Quoted 16 lines · Arnd Bergmann

It feels like this is more complicated than it need to be. The line

semtimedop = sys_semtimedop, .type = TST_KERN_OLD_TIMESPEC, .desc = "semtimedop: syscall with kernel spec32"},

should apply to any kernel that has "__NR_semtimedop != __LTP__NR_INVALID_SYSCALL",
regardless of any other macros set, and then you don't need the separate line

{ .semtimedop = sys_semtimedop, .type = TST_KERN_TIMESPEC, .desc = "semtimedop: syscall with kernel spec64"},

which is not what the ABI is meant to be anyway (sys_semtimedop takes a __kernel_old_timespec,
not a __kernel_timespec).

Quoted 5 lines

Similarly, the line

{ .semop = semop, .type = TST_LIBC_TIMESPEC, .desc = "semop: vDSO or syscall"},

should apply to both 32 and 64 bit machines

This is how I modified this and all other time64 tests, I hope this looks fine now ?

testcases/kernel/syscalls/ipc/semop/semop.h +3 -7
index 8d1245b65ec0..8647fa686bd3 100644
@@ -26,17 +26,13 @@ struct test_variants {
        char *desc;
 } variants[] = {
        { .semop = semop, .type = TST_LIBC_TIMESPEC, .desc = "semop: vDSO or syscall"},
-#if defined(TST_ABI32)
-       { .semtimedop = sys_semtimedop, .type = TST_LIBC_TIMESPEC, .desc = "semtimedop: syscall with libc spec"},
-       { .semtimedop = sys_semtimedop, .type = TST_KERN_OLD_TIMESPEC, .desc = "semtimedop: syscall with kernel spec32"},
-#endif
 
-#if defined(TST_ABI64)
-       { .semtimedop = sys_semtimedop, .type = TST_KERN_TIMESPEC, .desc = "semtimedop: syscall with kernel spec64"},
+#if (__NR_semtimedop != __LTP__NR_INVALID_SYSCALL)
+       { .semtimedop = sys_semtimedop, .type = TST_KERN_OLD_TIMESPEC, .desc = "semtimedop: syscall with old kernel spec"},
 #endif
 
 #if (__NR_semtimedop_time64 != __LTP__NR_INVALID_SYSCALL)
-       { .semtimedop = sys_semtimedop_time64, .type = TST_KERN_TIMESPEC, .desc = "semtimedop: syscall time64 with kernel spec64"},
+       { .semtimedop = sys_semtimedop_time64, .type = TST_KERN_TIMESPEC, .desc = "semtimedop: syscall time64 with kernel spec"},
 #endif
 };
 
Signature · 1 line
viresh
#25 lore raw

PATCH v2 15/17 syscalls/semtimedop: Add support for semtimedop and its time64 version

Quoted 24 lines · Viresh Kumar
Quoted 6 lines · Arnd Bergmann

Similarly, the line

{ .semop = semop, .type = TST_LIBC_TIMESPEC, .desc = "semop: vDSO or syscall"},

should apply to both 32 and 64 bit machines

This is how I modified this and all other time64 tests, I hope this looks fine now ?

testcases/kernel/syscalls/ipc/semop/semop.h +0 -5
index 8d1245b65ec0..8647fa686bd3 100644
@@ -26,17 +26,13 @@ struct test_variants {
        char *desc;
 } variants[] = {
        { .semop = semop, .type = TST_LIBC_TIMESPEC, .desc = "semop: vDSO or syscall"},
-#if defined(TST_ABI32)
-       { .semtimedop = sys_semtimedop, .type = TST_LIBC_TIMESPEC, .desc = "semtimedop: syscall with libc spec"},
-       { .semtimedop = sys_semtimedop, .type = TST_KERN_OLD_TIMESPEC, .desc = "semtimedop: syscall with kernel spec32"},
-#endif
 
-#if defined(TST_ABI64)

testcases/kernel/syscalls/ipc/semop/semop.h struct test_variants { · line 37

Quoted 10 lines
testcases/kernel/syscalls/ipc/semop/semop.h +3 -2
-       { .semtimedop = sys_semtimedop, .type = TST_KERN_TIMESPEC, .desc = "semtimedop: syscall with kernel spec64"},
+#if (__NR_semtimedop != __LTP__NR_INVALID_SYSCALL)
+       { .semtimedop = sys_semtimedop, .type = TST_KERN_OLD_TIMESPEC, .desc = "semtimedop: syscall with old kernel spec"},
 #endif
 
 #if (__NR_semtimedop_time64 != __LTP__NR_INVALID_SYSCALL)
-       { .semtimedop = sys_semtimedop_time64, .type = TST_KERN_TIMESPEC, .desc = "semtimedop: syscall time64 with kernel spec64"},
+       { .semtimedop = sys_semtimedop_time64, .type = TST_KERN_TIMESPEC, .desc = "semtimedop: syscall time64 with kernel spec"},
 #endif
 };

Yes, much better. Please do it like this for all the tests.

It looks like you are still missing a test for the libc semtimedop function with TST_LIBC_TIMESPEC, but perhaps this is in a different place?

There is one more complication regarding semtimedop, and that is how some architectures never had this as a separate syscall but instead require calling sys_ipc(SEMTIMEDOP, ...). All architectures that have sys_ipc() let you use both SEMOP and SEMTIMEDOP with __kernel_old_timespec. Some architectures define more than one of __NR_ipc, __NR_semtimedop and __NR_semop.

As of linux-5.1, all 64-bit architectures at least have __NR_semtimedop, and all 32-bit architectures at least have __NR_semtimedop64, plus whatever other variants they supported before then.

Arnd

#26 lore raw

PATCH v2 15/17 syscalls/semtimedop: Add support for semtimedop and its time64 version

Quoted 2 lines · Arnd Bergmann

It looks like you are still missing a test for the libc semtimedop function with TST_LIBC_TIMESPEC, but perhaps this is in a different place?

The libc test is missing for few of the syscalls, as it was already missing for them because the headers may not have the definition.

And so I didn't add them separately.

Signature · 1 line
viresh
#27 lore raw

PATCH v2 15/17 syscalls/semtimedop: Add support for semtimedop and its time64 version

Quoted 9 lines · Viresh Kumar
Quoted 2 lines · Arnd Bergmann

It looks like you are still missing a test for the libc semtimedop function with TST_LIBC_TIMESPEC, but perhaps this is in a different place?

The libc test is missing for few of the syscalls, as it was already missing for them because the headers may not have the definition.

And so I didn't add them separately.

Ok, I see. This one just looked curious because the you add tests for the kernel syscall (semtimedop) in a file that checks an older libc syscall (semop).

The libc semop is implemented in terms of the kernel's semtimedop for architectures that don't have their own semop by passing a NULL timeout argument. We should still check that five variants of it (sys_semop, sys_semtimedop, sys_semtimedop64, ipc(SEMTIMEDOP) and ipc(SEMOP)) correctly implement the semop semantics, but I would also note that testing the differences of the time types is only meaningful when you actually pass a non-NULL timeout.

Arnd

#28 lore raw

PATCH v2 15/17 syscalls/semtimedop: Add support for semtimedop and its time64 version

Quoted 3 lines · Arnd Bergmann

We should still check that five variants of it (sys_semop, sys_semtimedop, sys_semtimedop64, ipc(SEMTIMEDOP) and ipc(SEMOP)) correctly implement the semop semantics

How do you suggest I add tests for ipc() types? Should they be always tested? Or they should be tested only if the normal sys_* variant isn't implemented by the kernel/arch ?

Signature · 1 line
viresh
#29 lore raw

PATCH v2 15/17 syscalls/semtimedop: Add support for semtimedop and its time64 version

In reply to Viresh Kumar
Quoted 322 lines · Viresh Kumar

This adds support for semtimedop() and its time64 variant to the existing semop() syscall tests.

---
 testcases/kernel/syscalls/ipc/semop/semop.h   | 52 +++++++++++++++++++
 testcases/kernel/syscalls/ipc/semop/semop01.c | 11 +++-
 testcases/kernel/syscalls/ipc/semop/semop02.c | 12 ++++-
 testcases/kernel/syscalls/ipc/semop/semop03.c | 12 ++++-
 testcases/kernel/syscalls/ipc/semop/semop04.c | 12 ++++-
 testcases/kernel/syscalls/ipc/semop/semop05.c | 12 ++++-
 6 files changed, 106 insertions(+), 5 deletions(-)
 create mode 100644 testcases/kernel/syscalls/ipc/semop/semop.h
testcases/kernel/syscalls/ipc/semop/semop.h new file +10 -0
new file mode 100644
index 000000000000..8d1245b65ec0
@@ -0,0 +1,52 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#ifndef SEMOP_VAR__
+#define SEMOP_VAR__
+
+#include <sys/sem.h>
+#include "tst_timer.h"
+#include "lapi/abisize.h"
+
+static inline int sys_semtimedop(int semid, struct sembuf *sops, size_t

nsops,

testcases/kernel/syscalls/ipc/semop/semop.h new file +9 -0
+               void *timeout)
+{
+       return tst_syscall(__NR_semtimedop, semid, sops, nsops, timeout);
+}
+
+static inline int sys_semtimedop_time64(int semid, struct sembuf *sops,
+                                       size_t nsops, void *timeout)
+{
+       return tst_syscall(__NR_semtimedop_time64, semid, sops, nsops,

timeout);

testcases/kernel/syscalls/ipc/semop/semop.h new file +5 -0
+}
+
+struct test_variants {
+       int (*semop)(int semid, struct sembuf *sops, size_t nsops);
+       int (*semtimedop)(int semid, struct sembuf *sops, size_t nsops,

void *timeout);

testcases/kernel/syscalls/ipc/semop/semop.h new file +4 -0
+       enum tst_ts_type type;
+       char *desc;
+} variants[] = {
+       { .semop = semop, .type = TST_LIBC_TIMESPEC, .desc = "semop: vDSO

or syscall"},

testcases/kernel/syscalls/ipc/semop/semop.h new file +2 -0
+#if defined(TST_ABI32)
+       { .semtimedop = sys_semtimedop, .type = TST_LIBC_TIMESPEC, .desc =

"semtimedop: syscall with libc spec"},
+ { .semtimedop = sys_semtimedop, .type = TST_KERN_OLD_TIMESPEC,
.desc = "semtimedop: syscall with kernel spec32"},

testcases/kernel/syscalls/ipc/semop/semop.h new file +4 -0
+#endif
+
+#if defined(TST_ABI64)
+       { .semtimedop = sys_semtimedop, .type = TST_KERN_TIMESPEC, .desc =

"semtimedop: syscall with kernel spec64"},

testcases/kernel/syscalls/ipc/semop/semop.h new file +4 -0
+#endif
+
+#if (__NR_semtimedop_time64 != __LTP__NR_INVALID_SYSCALL)
+       { .semtimedop = sys_semtimedop_time64, .type = TST_KERN_TIMESPEC,

.desc = "semtimedop: syscall time64 with kernel spec64"},

testcases/kernel/syscalls/ipc/semop/semop.h new file +13 -0
+#endif
+};
+
+static inline int call_semop(struct test_variants *tv, int semid,
+               struct sembuf *sops, size_t nsops, struct tst_ts *timeout)
+{
+       if (tv->semop)
+               return tv->semop(semid, sops, nsops);
+
+       return tv->semtimedop(semid, sops, nsops, tst_ts_get(timeout));
+}
+
+#endif /* SEMOP_VAR__ */
testcases/kernel/syscalls/ipc/semop/semop01.c +1 -0
index bcb45fa69320..a4924376e32c 100644
@@ -41,6 +41,7 @@
 #include "tst_test.h"
 #include "libnewipc.h"
 #include "lapi/semun.h"
+#include "semop.h"
 
 #define NSEMS  4               /* the number of primitive semaphores to

test */

testcases/kernel/syscalls/ipc/semop/semop01.c +9 -1
@@ -52,11 +53,16 @@ static struct sembuf sops[PSEMS];
 
 static void run(void)
 {
+       struct test_variants *tv = &variants[tst_variant];
        union semun arr = { .val = 0 };
+       struct tst_ts timeout;
        int fail = 0;
        int i;
 
-       TEST(semop(sem_id, sops, NSEMS));
+       timeout.type = tv->type;
+       tst_ts_set_nsec(&timeout, 10000);
+
+       TEST(call_semop(tv, sem_id, sops, NSEMS, &timeout));
 
        if (TST_RET == -1) {
                tst_res(TFAIL | TTERRNO, "semop() failed");
@@ -94,6 +100,8 @@ static void setup(void)
 {
        int i;
 
+       tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
+
        get_arr.array = malloc(sizeof(unsigned short int) * PSEMS);
        if (get_arr.array == NULL)
                tst_brk(TBROK, "malloc failed");
@@ -124,6 +132,7 @@ static void cleanup(void)
 
 static struct tst_test test = {
        .test_all = run,
+       .test_variants = ARRAY_SIZE(variants),
        .setup = setup,
        .cleanup = cleanup,
        .needs_tmpdir = 1,
testcases/kernel/syscalls/ipc/semop/semop02.c +1 -0
index f24d284776a4..a51906340400 100644
@@ -20,6 +20,7 @@
 #include "tst_test.h"
 #include "libnewipc.h"
 #include "lapi/semun.h"
+#include "semop.h"
 
 static int sem_id_1 = -1;      /* a semaphore set with read & alter

permissions */
static int sem_id_2 = -1; /* a semaphore set without read & alter
permissions */

testcases/kernel/syscalls/ipc/semop/semop02.c +9 -1
@@ -52,6 +53,8 @@ static void setup(void)
        struct seminfo ipc_buf;
        union semun arr;
 
+       tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
+
        ltpuser = SAFE_GETPWNAM(nobody_uid);
        SAFE_SETUID(ltpuser->pw_uid);
 
@@ -84,7 +87,13 @@ static void setup(void)
 
 static void run(unsigned int i)
 {
-       TEST(semop(*(tc[i].semid), tc[i].t_sbuf, tc[i].t_ops));
+       struct test_variants *tv = &variants[tst_variant];
+       struct tst_ts timeout;
+
+       timeout.type = tv->type;
+       tst_ts_set_nsec(&timeout, 10000);
+
+       TEST(call_semop(tv, *(tc[i].semid), tc[i].t_sbuf, tc[i].t_ops,
 &timeout));
 
        if (TST_RET != -1) {
                tst_res(TFAIL | TTERRNO, "call succeeded unexpectedly");
testcases/kernel/syscalls/ipc/semop/semop02.c +1 -0
@@ -117,6 +126,7 @@ static void cleanup(void)
 static struct tst_test test = {
        .test = run,
        .tcnt = ARRAY_SIZE(tc),
+       .test_variants = ARRAY_SIZE(variants),
        .setup = setup,
        .cleanup = cleanup,
        .needs_tmpdir = 1,
testcases/kernel/syscalls/ipc/semop/semop03.c +1 -0
index 4f5f78eb6d8d..d36194ce1f41 100644
@@ -38,6 +38,7 @@
 #include "tst_test.h"
 #include "libnewipc.h"
 #include "lapi/semun.h"
+#include "semop.h"
 
 static key_t semkey;
 static int sem_id = -1;
@@ -47,6 +48,12 @@ static int tc[] = { -1, PSEMS + 1 }; /* negative and

too many "primitive" semas

static void run(unsigned int i)
{

testcases/kernel/syscalls/ipc/semop/semop03.c +10 -1
+       struct test_variants *tv = &variants[tst_variant];
+       struct tst_ts timeout;
+
+       timeout.type = tv->type;
+       tst_ts_set_nsec(&timeout, 10000);
+
        /* initialize two fields in the sembuf structure here */
        s_buf.sem_op = 1;       /* add this value to struct sem.semval */
        s_buf.sem_flg = SEM_UNDO;       /* undo when process exits */
@@ -61,7 +68,7 @@ static void run(unsigned int i)
         * use the TEST macro to make the call
         */
 
-       TEST(semop(sem_id, &s_buf, 1));
+       TEST(call_semop(tv, sem_id, &s_buf, 1, &timeout));
 
        if (TST_RET != -1) {
                tst_res(TFAIL | TTERRNO, "call succeeded unexpectedly");
@@ -80,6 +87,8 @@ static void run(unsigned int i)
 
 static void setup(void)
 {
+       tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
+
        /* get an IPC resource key */
        semkey = GETIPCKEY();
 
@@ -102,6 +111,7 @@ static void cleanup(void)
 static struct tst_test test = {
        .test = run,
        .tcnt = ARRAY_SIZE(tc),
+       .test_variants = ARRAY_SIZE(variants),
        .setup = setup,
        .cleanup = cleanup,
        .needs_tmpdir = 1,
testcases/kernel/syscalls/ipc/semop/semop04.c +11 -1
index 0faf00a3585f..033065e7bbfc 100644
@@ -38,6 +38,7 @@
 #include "tst_test.h"
 #include "libnewipc.h"
 #include "lapi/semun.h"
+#include "semop.h"
 
 static int sem_id = -1;
 static int val; /* value for SETVAL */
@@ -62,6 +63,12 @@ static struct test_case_t {
 
 static void run(unsigned int i)
 {
+       struct test_variants *tv = &variants[tst_variant];
+       struct tst_ts timeout;
+
+       timeout.type = tv->type;
+       tst_ts_set_nsec(&timeout, 10000);
+
        /* initialize the s_buf buffer */
        s_buf.sem_op = tc[i].op;
        s_buf.sem_flg = tc[i].flg;
@@ -72,7 +79,7 @@ static void run(unsigned int i)
        if (semctl(sem_id, tc[i].num, SETVAL, tc[i].get_arr) == -1)
                tst_brk(TBROK | TERRNO, "semctl() failed");
 
-       TEST(semop(sem_id, &s_buf, 1));
+       TEST(call_semop(tv, sem_id, &s_buf, 1, &timeout));
        if (TST_RET != -1) {
                tst_res(TFAIL, "call succeeded unexpectedly");
                return;
@@ -86,6 +93,8 @@ static void run(unsigned int i)
 
 static void setup(void)
 {
+       tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
+
        val = 1;
 
        /* get an IPC resource key */
@@ -114,6 +123,7 @@ static void cleanup(void)
 static struct tst_test test = {
        .test = run,
        .tcnt = ARRAY_SIZE(tc),
+       .test_variants = ARRAY_SIZE(variants),
        .setup = setup,
        .cleanup = cleanup,
        .needs_tmpdir = 1,
testcases/kernel/syscalls/ipc/semop/semop05.c +8 -1
index 9e8e040b0b19..f892cd519ecf 100644
@@ -52,6 +52,7 @@
 #include "tst_test.h"
 #include "libnewipc.h"
 #include "lapi/semun.h"
+#include "semop.h"
 
 static key_t semkey;
 static int sem_id = -1;
@@ -115,7 +116,13 @@ static inline int process_state_wait2(pid_t pid,
 const char state)
 
 static void do_child(int i)
 {
-       TEST(semop(sem_id, &s_buf, 1));
+       struct test_variants *tv = &variants[tst_variant];
+       struct tst_ts timeout;
+
+       timeout.type = tv->type;
+       tst_ts_set_nsec(&timeout, 10000);
+
+       TEST(call_semop(tv, sem_id, &s_buf, 1, &timeout));
        if (TST_RET != -1) {
                tst_res(TFAIL, "call succeeded when error expected");
                exit(-1);
testcases/kernel/syscalls/ipc/semop/semop05.c +2 -0
@@ -137,6 +144,8 @@ static void sighandler(int sig)
 
 static void setup(void)
 {
+       tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
+
        SAFE_SIGNAL(SIGHUP, sighandler);
 
        /* get an IPC resource key */

testcases/kernel/syscalls/ipc/semop/semop05.c static void do_child_uclinux(void) · line 251

Quoted 5 lines
testcases/kernel/syscalls/ipc/semop/semop05.c +1 -0
@@ -238,6 +247,7 @@ static void do_child_uclinux(void)
 static struct tst_test test = {
        .test = run,
        .tcnt = ARRAY_SIZE(tc),
+       .test_variants = ARRAY_SIZE(variants),
 

RHEL8.2(x84_64) failed as:

# ./semop05
tst_test.c:1246: INFO: Timeout per run is 0h 05m 00s
semop05.c:147: INFO: Testing variant: semop: vDSO or syscall
semop05.c:132: PASS: expected failure: EIDRM (43)
semop05.c:132: PASS: expected failure: EIDRM (43)
semop05.c:132: PASS: expected failure: EINTR (4)
semop05.c:132: PASS: expected failure: EINTR (4)
tst_test.c:1246: INFO: Timeout per run is 0h 05m 00s
semop05.c:147: INFO: Testing variant: semtimedop: syscall with kernel spec64
semop05.c:134: FAIL: unexpected failure: EAGAIN/EWOULDBLOCK (11)
Test timeouted, sending SIGKILL!
tst_test.c:1286: INFO: If you are running on slow machine, try exporting
LTP_TIMEOUT_MUL > 1
tst_test.c:1287: BROK: Test killed! (timeout?)

RHEL8.2(s390x) failed as:

tst_test.c:1246: INFO: Timeout per run is 0h 05m 00s semop05.c:147: INFO: Testing variant: semop: vDSO or syscall semop05.c:132: PASS: expected failure: EIDRM (43)
semop05.c:132: PASS: expected failure: EIDRM (43)
semop05.c:132: PASS: expected failure: EINTR (4)
semop05.c:132: PASS: expected failure: EINTR (4) tst_test.c:1246: INFO: Timeout per run is 0h 05m 00s semop05.c:147: INFO: Testing variant: semtimedop: syscall with kernel spec64 semop.h:13: CONF: syscall(392) __NR_semtimedop not supported Test timeouted, sending SIGKILL!
tst_test.c:1286: INFO: If you are running on slow machine, try exporting LTP_TIMEOUT_MUL > 1
tst_test.c:1287: BROK: Test killed! (timeout?)

Quoted 11 lines
testcases/kernel/syscalls/ipc/semop/semop05.c +0 -0
        .setup = setup,
        .cleanup = cleanup,
        .needs_tmpdir = 1,

--
2.25.0.rc1.19.g042ed3e048af

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

Signature · 5 lines
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20200509/01bea12c/attachment-0001.htm>
#30 lore raw

PATCH v2 15/17 syscalls/semtimedop: Add support for semtimedop and its time64 version

Quoted 20 lines · Li Wang

RHEL8.2(x84_64) failed as:

# ./semop05
tst_test.c:1246: INFO: Timeout per run is 0h 05m 00s
semop05.c:147: INFO: Testing variant: semop: vDSO or syscall
semop05.c:132: PASS: expected failure: EIDRM (43)
semop05.c:132: PASS: expected failure: EIDRM (43)
semop05.c:132: PASS: expected failure: EINTR (4)
semop05.c:132: PASS: expected failure: EINTR (4)
tst_test.c:1246: INFO: Timeout per run is 0h 05m 00s
semop05.c:147: INFO: Testing variant: semtimedop: syscall with kernel spec64
semop05.c:134: FAIL: unexpected failure: EAGAIN/EWOULDBLOCK (11)
Test timeouted, sending SIGKILL!
tst_test.c:1286: INFO: If you are running on slow machine, try exporting
LTP_TIMEOUT_MUL > 1
tst_test.c:1287: BROK: Test killed! (timeout?)

RHEL8.2(s390x) failed as:

Quoted 13 lines

tst_test.c:1246: INFO: Timeout per run is 0h 05m 00s semop05.c:147: INFO: Testing variant: semop: vDSO or syscall semop05.c:132: PASS: expected failure: EIDRM (43)
semop05.c:132: PASS: expected failure: EIDRM (43)
semop05.c:132: PASS: expected failure: EINTR (4)
semop05.c:132: PASS: expected failure: EINTR (4) tst_test.c:1246: INFO: Timeout per run is 0h 05m 00s semop05.c:147: INFO: Testing variant: semtimedop: syscall with kernel spec64 semop.h:13: CONF: syscall(392) __NR_semtimedop not supported Test timeouted, sending SIGKILL!
tst_test.c:1286: INFO: If you are running on slow machine, try exporting LTP_TIMEOUT_MUL > 1
tst_test.c:1287: BROK: Test killed! (timeout?)

Some part of the timeout was left uninitialized and so was causing some issues. Can you please try with this delta:

testcases/kernel/syscalls/ipc/semop/semop05.c +1 -0
index f892cd519ecf..0e18f77ba1f5 100644
@@ -120,6 +120,7 @@ static void do_child(int i)
        struct tst_ts timeout;
 
        timeout.type = tv->type;
+       tst_ts_set_sec(&timeout, 1);
        tst_ts_set_nsec(&timeout, 10000);
 
        TEST(call_semop(tv, sem_id, &s_buf, 1, &timeout));
Signature · 1 line
viresh
#31 lore raw

PATCH v2 15/17 syscalls/semtimedop: Add support for semtimedop and its time64 version

Quoted 31 lines · Viresh Kumar
Quoted 11 lines · Li Wang

RHEL8.2(x84_64) failed as:

# ./semop05
tst_test.c:1246: INFO: Timeout per run is 0h 05m 00s
semop05.c:147: INFO: Testing variant: semop: vDSO or syscall
semop05.c:132: PASS: expected failure: EIDRM (43)
semop05.c:132: PASS: expected failure: EIDRM (43)
semop05.c:132: PASS: expected failure: EINTR (4)
semop05.c:132: PASS: expected failure: EINTR (4)
tst_test.c:1246: INFO: Timeout per run is 0h 05m 00s
semop05.c:147: INFO: Testing variant: semtimedop: syscall with kernel

spec64

Quoted 9 lines

semop05.c:134: FAIL: unexpected failure: EAGAIN/EWOULDBLOCK (11) Test timeouted, sending SIGKILL!
tst_test.c:1286: INFO: If you are running on slow machine, try exporting LTP_TIMEOUT_MUL > 1
tst_test.c:1287: BROK: Test killed! (timeout?)

RHEL8.2(s390x) failed as:

Quoted 8 lines

tst_test.c:1246: INFO: Timeout per run is 0h 05m 00s semop05.c:147: INFO: Testing variant: semop: vDSO or syscall semop05.c:132: PASS: expected failure: EIDRM (43) semop05.c:132: PASS: expected failure: EIDRM (43) semop05.c:132: PASS: expected failure: EINTR (4) semop05.c:132: PASS: expected failure: EINTR (4) tst_test.c:1246: INFO: Timeout per run is 0h 05m 00s semop05.c:147: INFO: Testing variant: semtimedop: syscall with kernel

spec64

Quoted 9 lines
Quoted 5 lines

semop.h:13: CONF: syscall(392) __NR_semtimedop not supported Test timeouted, sending SIGKILL!
tst_test.c:1286: INFO: If you are running on slow machine, try exporting LTP_TIMEOUT_MUL > 1
tst_test.c:1287: BROK: Test killed! (timeout?)

Some part of the timeout was left uninitialized and so was causing some issues. Can you please try with this delta:

This delta works(on x86_64) for me. But the s390x issue looks like the same as the futex TCONF in another email.

Signature · 5 lines
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20200511/67b4f9ab/attachment-0001.htm>
#32 lore raw

PATCH v2 15/17 syscalls/semtimedop: Add support for semtimedop and its time64 version

Quoted 2 lines · Li Wang

This delta works(on x86_64) for me. But the s390x issue looks like the same as the futex TCONF in another email.

Ah, this should fix it then:

testcases/kernel/syscalls/ipc/semop/semop.h +8 -0
index 7180f6e35185..584d12c68e0d 100644
@@ -44,4 +44,12 @@ static inline int call_semop(struct test_variants *tv, int semid,
 	return tv->semtimedop(semid, sops, nsops, tst_ts_get(timeout));
 }
 
+static inline void semop_supported_by_kernel(struct test_variants *tv)
+{
+       /* Check if the syscall is implemented on the platform */
+       TEST(call_semop(tv, 0, NULL, 0, NULL));
+       if (TST_RET == -1 && TST_ERR == ENOSYS)
+               tst_brk(TCONF, "Test not supported on kernel/platform");
+}
+
 #endif /* SEMOP_VAR__ */
testcases/kernel/syscalls/ipc/semop/semop01.c +3 -1
index cc8725bdbed3..7947183c837b 100644
@@ -99,9 +99,11 @@ static void run(void)
 
 static void setup(void)
 {
+	struct test_variants *tv = &variants[tst_variant];
 	int i;
 
-	tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
+	tst_res(TINFO, "Testing variant: %s", tv->desc);
+	semop_supported_by_kernel(tv);
 
 	get_arr.array = malloc(sizeof(unsigned short int) * PSEMS);
 	if (get_arr.array == NULL)
testcases/kernel/syscalls/ipc/semop/semop02.c +3 -1
index 5af1909480b5..4ffb9dd72c1c 100644
@@ -47,13 +47,15 @@ static struct test_case_t {
 
 static void setup(void)
 {
+	struct test_variants *tv = &variants[tst_variant];
 	char nobody_uid[] = "nobody";
 	struct passwd *ltpuser;
 	key_t semkey2;
 	struct seminfo ipc_buf;
 	union semun arr;
 
-	tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
+	tst_res(TINFO, "Testing variant: %s", tv->desc);
+	semop_supported_by_kernel(tv);
 
 	ltpuser = SAFE_GETPWNAM(nobody_uid);
 	SAFE_SETUID(ltpuser->pw_uid);
testcases/kernel/syscalls/ipc/semop/semop03.c +4 -1
index e877f989edaa..40a6b095c57d 100644
@@ -88,7 +88,10 @@ static void run(unsigned int i)
 
 static void setup(void)
 {
-	tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
+	struct test_variants *tv = &variants[tst_variant];
+
+	tst_res(TINFO, "Testing variant: %s", tv->desc);
+	semop_supported_by_kernel(tv);
 
 	/* get an IPC resource key */
 	semkey = GETIPCKEY();
testcases/kernel/syscalls/ipc/semop/semop04.c +4 -1
index 226a64603943..5e4bfeb625e2 100644
@@ -94,7 +94,10 @@ static void run(unsigned int i)
 
 static void setup(void)
 {
-	tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
+	struct test_variants *tv = &variants[tst_variant];
+
+	tst_res(TINFO, "Testing variant: %s", tv->desc);
+	semop_supported_by_kernel(tv);
 
 	val = 1;
 
testcases/kernel/syscalls/ipc/semop/semop05.c +4 -1
index 0e18f77ba1f5..770646bc564c 100644
@@ -145,7 +145,10 @@ static void sighandler(int sig)
 
 static void setup(void)
 {
-	tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
+	struct test_variants *tv = &variants[tst_variant];
+
+	tst_res(TINFO, "Testing variant: %s", tv->desc);
+	semop_supported_by_kernel(tv);
 
 	SAFE_SIGNAL(SIGHUP, sighandler);
 
Signature · 1 line
viresh
#33 lore raw

PATCH v2 16/17 syscalls/utimensat: Migrate to new test framework

In reply to Viresh Kumar

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

---
 .../kernel/syscalls/utimensat/utimensat01.c   | 411 ++++++--------
 .../syscalls/utimensat/utimensat_tests.sh     | 517 ------------------
 2 files changed, 167 insertions(+), 761 deletions(-)
 delete mode 100755 testcases/kernel/syscalls/utimensat/utimensat_tests.sh
testcases/kernel/syscalls/utimensat/utimensat01.c +167 -244
index 264ca1e15120..2a029ecb17e9 100644
@@ -1,282 +1,205 @@
-/*************************************************************************************/
-/*                                                                                   */
-/* Copyright (C) 2008, Michael Kerrisk <[email protected]>,                     */
-/* Copyright (C) 2008, Linux Foundation                                              */
-/*                                                                                   */
-/* This program is free software;  you can redistribute it and/or modify             */
-/* it under the terms of the GNU General Public License as published by              */
-/* the Free Software Foundation; either version 2 of the License, or                 */
-/* (at your option) any later version.                                               */
-/*                                                                                   */
-/* This program is distributed in the hope that it will be useful,                   */
-/* but WITHOUT ANY WARRANTY;  without even the implied warranty of                   */
-/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See                         */
-/* the GNU General Public License for more details.                                  */
-/*                                                                                   */
-/* You should have received a copy of the GNU General Public License                 */
-/* along with this program;  if not, write to the Free Software                      */
-/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA           */
-/*************************************************************************************/
-/*                                                                                   */
-/* File: utimnsat01.c                                                                */
-/* Description: A command-line interface for testing the utimensat() system call.    */
-/* Author: Michael Kerrisk <[email protected]>                                  */
-/* History:                                                                          */
-/*	17 Mar  2008  Initial creation,                                              */
-/*	31 May  2008  Reworked for easier test automation,                           */
-/*	2  June 2008  Renamed from t_utimensat.c to test_utimensat.c,                */
-/*	05 June 2008  Submitted to LTP by Subrata Modak <[email protected]> */
-/*************************************************************************************/
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2008 Michael Kerrisk <[email protected]>
+ * Copyright (c) 2008 Subrata Modak <[email protected]>
+ * Copyright (c) 2020 Viresh Kumar <[email protected]>
+ *
+ * Basic utimnsat() test.
+ */
 
-#define _GNU_SOURCE
-#define _ATFILE_SOURCE
 #include <stdio.h>
 #include <time.h>
 #include <errno.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <sys/syscall.h>
 #include <fcntl.h>
 #include <string.h>
 #include <sys/stat.h>
-#include "test.h"
+#include "tst_test.h"
 #include "lapi/syscalls.h"
 
-char *TCID = "utimensat01";
-int TST_TOTAL = 0;
-
-#define cleanup tst_exit
-
-/* We use EXIT_FAILURE for an expected failure from utimensat()
-   (e.g., EACCES and EPERM), and one of the following for unexpected
-   failures (i.e., something broke in our test setup). */
-
-#ifndef AT_FDCWD
-#define AT_FDCWD -100
-#endif
-#ifndef AT_SYMLINK_NOFOLLOW
-#define AT_SYMLINK_NOFOLLOW 0x100
-#endif
-
-#define EXIT_bad_usage 3
-#define EXIT_failed_syscall 3
-
-#define errExit(msg)    do { perror(msg); exit(EXIT_failed_syscall); \
-                        } while (0)
-
-#define UTIME_NOW      ((1l << 30) - 1l)
-#define UTIME_OMIT     ((1l << 30) - 2l)
-
-static inline int
-utimensat_sc(int dirfd, const char *pathname,
-	     const struct timespec times[2], int flags)
+#define UTIME_NOW	((1l << 30) - 1l)
+#define UTIME_OMIT	((1l << 30) - 2l)
+
+#define TEST_FILE	"test_file"
+#define TEST_DIR	"test_dir"
+
+static void *bad_addr;
+
+struct mytime {
+	long access_tv_sec;
+	long access_tv_nsec;
+	long mod_tv_sec;
+	long mod_tv_nsec;
+};
+
+static struct mytime tnn = {0, UTIME_NOW, 0, UTIME_NOW}, *time_nn = &tnn;
+static struct mytime too = {0, UTIME_OMIT, 0, UTIME_OMIT}, *time_oo = &too;
+static struct mytime tno = {0, UTIME_NOW, 0, UTIME_OMIT}, *time_no = &tno;
+static struct mytime ton = {0, UTIME_OMIT, 0, UTIME_NOW}, *time_on = &ton;
+static struct mytime t11 = {1, 1, 1, 1}, *time_11 = &t11;
+
+struct test_case {
+	int dirfd;
+	char *pathname;
+	struct mytime **mytime;
+	int flags;
+	int oflags;
+	char *attr;
+	char *rattr;
+	int mode;
+	int exp_err;
+} tcase[] = {
+	/* Testing read-only file */
+	{AT_FDCWD, TEST_FILE, NULL, 0, O_RDONLY, NULL, NULL, 0400, 0},
+	{AT_FDCWD, TEST_FILE, &time_nn, 0, O_RDONLY, NULL, NULL, 0400, 0},
+	{AT_FDCWD, TEST_FILE, &time_oo, 0, O_RDONLY, NULL, NULL, 0400, 0},
+	{AT_FDCWD, TEST_FILE, &time_no, 0, O_RDONLY, NULL, NULL, 0400, 0},
+	{AT_FDCWD, TEST_FILE, &time_on, 0, O_RDONLY, NULL, NULL, 0400, 0},
+	{AT_FDCWD, TEST_FILE, &time_11, 0, O_RDONLY, NULL, NULL, 0400, 0},
+
+	/* Testing writable file */
+	{AT_FDCWD, TEST_FILE, NULL, 0, O_RDONLY, NULL, NULL, 0666, 0},
+	{AT_FDCWD, TEST_FILE, &time_nn, 0, O_RDONLY, NULL, NULL, 0666, 0},
+	{AT_FDCWD, TEST_FILE, &time_oo, 0, O_RDONLY, NULL, NULL, 0666, 0},
+	{AT_FDCWD, TEST_FILE, &time_no, 0, O_RDONLY, NULL, NULL, 0666, 0},
+	{AT_FDCWD, TEST_FILE, &time_on, 0, O_RDONLY, NULL, NULL, 0666, 0},
+	{AT_FDCWD, TEST_FILE, &time_11, 0, O_RDONLY, NULL, NULL, 0666, 0},
+
+	/* Testing append-only file */
+	{AT_FDCWD, TEST_FILE, NULL, 0, O_RDONLY, "+a", "-a", 0600, 0},
+	{AT_FDCWD, TEST_FILE, &time_nn, 0, O_RDONLY, "+a", "-a", 0600, 0},
+	{AT_FDCWD, TEST_FILE, &time_oo, 0, O_RDONLY, "+a", "-a", 0600, 0},
+	{AT_FDCWD, TEST_FILE, &time_no, 0, O_RDONLY, "+a", "-a", 0600, EPERM},
+	{AT_FDCWD, TEST_FILE, &time_on, 0, O_RDONLY, "+a", "-a", 0600, EPERM},
+	{AT_FDCWD, TEST_FILE, &time_11, 0, O_RDONLY, "+a", "-a", 0600, EPERM},
+
+	/* Testing immutable file */
+	{AT_FDCWD, TEST_FILE, NULL, 0, O_RDONLY, "+i", "-i", 0600, -1},
+	{AT_FDCWD, TEST_FILE, &time_nn, 0, O_RDONLY, "+i", "-i", 0600, -1},
+	{AT_FDCWD, TEST_FILE, &time_oo, 0, O_RDONLY, "+i", "-i", 0600, 0},
+	{AT_FDCWD, TEST_FILE, &time_no, 0, O_RDONLY, "+i", "-i", 0600, EPERM},
+	{AT_FDCWD, TEST_FILE, &time_on, 0, O_RDONLY, "+i", "-i", 0600, EPERM},
+	{AT_FDCWD, TEST_FILE, &time_11, 0, O_RDONLY, "+i", "-i", 0600, EPERM},
+
+	/* Testing immutable-append-only file */
+	{AT_FDCWD, TEST_FILE, NULL, 0, O_RDONLY, "+ai", "-ai", 0600, -1},
+	{AT_FDCWD, TEST_FILE, &time_nn, 0, O_RDONLY, "+ai", "-ai", 0600, -1},
+	{AT_FDCWD, TEST_FILE, &time_oo, 0, O_RDONLY, "+ai", "-ai", 0600, 0},
+	{AT_FDCWD, TEST_FILE, &time_no, 0, O_RDONLY, "+ai", "-ai", 0600, EPERM},
+	{AT_FDCWD, TEST_FILE, &time_on, 0, O_RDONLY, "+ai", "-ai", 0600, EPERM},
+	{AT_FDCWD, TEST_FILE, &time_11, 0, O_RDONLY, "+ai", "-ai", 0600, EPERM},
+
+	/* Other failure tests */
+	{AT_FDCWD, TEST_FILE, NULL, 0, O_RDONLY, NULL, NULL, 0400, EFAULT},
+	{AT_FDCWD, NULL, &time_nn, 0, O_RDONLY, NULL, NULL, 0400, EFAULT},
+	{-1, NULL, &time_nn, AT_SYMLINK_NOFOLLOW, O_RDONLY, NULL, NULL, 0400, EINVAL},
+	{-1, TEST_FILE, &time_nn, 0, O_RDONLY, NULL, NULL, 0400, ENOENT},
+};
+
+static inline int sys_utimensat(int dirfd, const char *pathname,
+				const struct timespec times[2], int flags)
 {
-	return ltp_syscall(__NR_utimensat, dirfd, pathname, times, flags);
+	return tst_syscall(__NR_utimensat, dirfd, pathname, times, flags);
 }
 
-static void usageError(char *progName)
+static void setup(void)
 {
-	fprintf(stderr, "Usage: %s pathname [atime-sec "
-		"atime-nsec mtime-sec mtime-nsec]\n\n", progName);
-	fprintf(stderr, "Permitted options are:\n");
-	fprintf(stderr, "    [-d path] "
-		"open a directory file descriptor"
-		" (instead of using AT_FDCWD)\n");
-	fprintf(stderr, "    -q        Quiet\n");
-	fprintf(stderr, "    -w        Open directory file "
-		"descriptor with O_RDWR|O_APPEND\n"
-		"              (instead of O_RDONLY)\n");
-	fprintf(stderr, "    -n        Use AT_SYMLINK_NOFOLLOW\n");
-	fprintf(stderr, "\n");
-
-	fprintf(stderr, "pathname can be \"NULL\" to use NULL "
-		"argument in call\n");
-	fprintf(stderr, "\n");
+	bad_addr = tst_get_bad_addr(NULL);
+}
 
-	fprintf(stderr, "Either nsec field can be\n");
-	fprintf(stderr, "    'n' for UTIME_NOW\n");
-	fprintf(stderr, "    'o' for UTIME_OMIT\n");
-	fprintf(stderr, "\n");
+static void update_error(struct test_case *tc)
+{
+	if (tc->exp_err != -1)
+		return;
+
+	/*
+	 * Starting with 4.8.0 operations on immutable files return EPERM
+	 * instead of EACCES.
+	 * This patch has also been merged to stable 4.4 with
+	 * b3b4283 ("vfs: move permission checking into notify_change() for utimes(NULL)")
+	 */
+	if (tst_kvercmp(4, 4, 27) < 0)
+		tc->exp_err = EACCES;
+	else
+		tc->exp_err = EPERM;
+}
 
-	fprintf(stderr, "If the time fields are omitted, "
-		"then a NULL 'times' argument is used\n");
-	fprintf(stderr, "\n");
+static int run_command(char *command, char *option, char *file)
+{
+	const char *const cmd[] = {command, option, file, NULL};
 
-	exit(EXIT_bad_usage);
+	return tst_cmd(cmd, NULL, NULL, TST_CMD_PASS_RETVAL);
 }
 
-int main(int argc, char *argv[])
+static void run(unsigned int i)
 {
-	int flags, dirfd, opt, oflag;
+	struct test_case *tc = &tcase[i];
 	struct timespec ts[2];
-	struct timespec *tsp;
-	char *pathname, *dirfdPath;
+	void *tsp = NULL;
+	char *pathname = NULL;
+	int fd = AT_FDCWD;
 	struct stat sb;
-	int verbose;
-
-	/* Command-line argument parsing */
-
-	flags = 0;
-	verbose = 1;
-	dirfd = AT_FDCWD;
-	dirfdPath = NULL;
-	oflag = O_RDONLY;
-
-	while ((opt = getopt(argc, argv, "d:nqw")) != -1) {
-		switch (opt) {
-		case 'd':
-			dirfdPath = optarg;
-			break;
-
-		case 'n':
-			flags |= AT_SYMLINK_NOFOLLOW;
-			if (verbose)
-				printf("Not following symbolic links\n");
-			break;
-
-		case 'q':
-			verbose = 0;
-			break;
-
-		case 'w':
-			oflag = O_RDWR | O_APPEND;
-			break;
-
-		default:
-			usageError(argv[0]);
-		}
-	}
-
-	if ((optind + 5 != argc) && (optind + 1 != argc))
-		usageError(argv[0]);
-
-	if (dirfdPath != NULL) {
-		dirfd = open(dirfdPath, oflag);
-		if (dirfd == -1)
-			errExit("open");
-
-		if (verbose) {
-			printf("Opened dirfd %d", oflag);
-			if ((oflag & O_ACCMODE) == O_RDWR)
-				printf(" O_RDWR");
-			if (oflag & O_APPEND)
-				printf(" O_APPEND");
-			printf(": %s\n", dirfdPath);
-		}
-	}
 
-	pathname = (strcmp(argv[optind], "NULL") == 0) ? NULL : argv[optind];
+	SAFE_MKDIR(TEST_DIR, 0700);
+	SAFE_TOUCH(TEST_FILE, 0666, NULL);
+	update_error(tc);
 
-	/* Either, we get no values for 'times' fields, in which case
-	   we give a NULL pointer to utimensat(), or we get four values,
-	   for secs+nsecs for each of atime and mtime.  The special
-	   values 'n' and 'o' can be used for tv_nsec settings of
-	   UTIME_NOW and UTIME_OMIT, respectively. */
+	if (tc->dirfd != AT_FDCWD)
+		fd = SAFE_OPEN(TEST_DIR, tc->oflags);
 
-	if (argc == optind + 1) {
-		tsp = NULL;
-
-	} else {
-		ts[0].tv_sec = atoi(argv[optind + 1]);
-		if (argv[optind + 2][0] == 'n') {
-			ts[0].tv_nsec = UTIME_NOW;
-		} else if (argv[optind + 2][0] == 'o') {
-			ts[0].tv_nsec = UTIME_OMIT;
-		} else {
-			ts[0].tv_nsec = atoi(argv[optind + 2]);
-		}
-
-		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]);
-		}
+	if (tc->mytime) {
+		struct mytime *mytime = *tc->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;
+	} else if (tc->exp_err == EFAULT) {
+		tsp = bad_addr;
 	}
 
-	/* For testing purposes, it may have been useful to run this program
-	   as set-user-ID-root so that a directory file descriptor could be
-	   opened as root.  (This allows us to obtain a file descriptor even
-	   if normal user doesn't have permissions on the file.)  Now we
-	   reset to the real UID before making the utimensat() call, so that
-	   the permission checking for the utimensat() call is performed
-	   under that UID. */
-
-	if (geteuid() == 0) {
-		uid_t u;
-
-		u = getuid();
-
-		if (verbose)
-			printf("Resetting UIDs to %ld\n", (long)u);
-
-		if (setresuid(u, u, u) == -1)
-			errExit("setresuid");
-	}
-
-	/* Display information allowing user to verify arguments for call */
-
-	if (verbose) {
-		printf("dirfd is %d\n", dirfd);
-		printf("pathname is %s\n", pathname);
-		printf("tsp is %p", tsp);
-		if (tsp != NULL) {
-			printf("; struct  = { %ld, %ld } { %ld, %ld }",
-			       (long)tsp[0].tv_sec, (long)tsp[0].tv_nsec,
-			       (long)tsp[1].tv_sec, (long)tsp[1].tv_nsec);
-		}
-		printf("\n");
-		printf("flags is %d\n", flags);
+	if (tc->pathname) {
+		pathname = tc->pathname;
+		SAFE_CHMOD(tc->pathname, tc->mode);
+		if (tc->attr)
+			run_command("chattr", tc->attr, tc->pathname);
+	} else if (tc->exp_err == EFAULT) {
+		pathname = bad_addr;
 	}
 
-	/* Make the call and see what happened */
-
-	if (utimensat_sc(dirfd, pathname, tsp, flags) == -1) {
-		if (errno == EPERM) {
-			if (verbose)
-				printf("utimensat() failed with EPERM\n");
-			else
-				printf("EPERM\n");
-			exit(EXIT_FAILURE);
-
-		} else if (errno == EACCES) {
-			if (verbose)
-				printf("utimensat() failed with EACCES\n");
-			else
-				printf("EACCES\n");
-			exit(EXIT_FAILURE);
-
-		} else if (errno == EINVAL) {
-			if (verbose)
-				printf("utimensat() failed with EINVAL\n");
-			else
-				printf("EINVAL\n");
-			exit(EXIT_FAILURE);
-
-		} else {	/* Unexpected failure case from utimensat() */
-			errExit("utimensat");
+	TEST(sys_utimensat(fd, pathname, tsp, tc->flags));
+	if (TST_RET) {
+		if (!tc->exp_err) {
+			tst_res(TFAIL | TTERRNO, "%2d: utimensat() failed", i);
+		} else if (tc->exp_err == TST_ERR) {
+			tst_res(TPASS | TTERRNO, "%2d: utimensat() failed expectedly", i);
+		} else {
+			tst_res(TFAIL | TTERRNO, "%2d: utimensat() failed with incorrect error, expected %s",
+				i, tst_strerrno(tc->exp_err));
 		}
+	} else if (tc->exp_err) {
+		tst_res(TFAIL, "%2d: utimensat() passed unexpectedly", i);
+	} else {
+		TEST(stat(tc->pathname ? tc->pathname : TEST_DIR, &sb));
+		tst_res(TPASS, "%2d: utimensat() passed: access time: %lu %lu", i,
+			sb.st_atime, sb.st_mtime);
 	}
 
-	if (verbose)
-		printf("utimensat() succeeded\n");
-
-	if (stat((pathname != NULL) ? pathname : dirfdPath, &sb) == -1)
-		errExit("stat");
-
-	if (verbose) {
-		printf("Last file access:         %s", ctime(&sb.st_atime));
-		printf("Last file modification:   %s", ctime(&sb.st_mtime));
-		printf("Last status change:       %s", ctime(&sb.st_ctime));
+	if (tc->rattr != NULL)
+		run_command("chattr", tc->rattr, tc->pathname);
 
-	} else {
-		printf("SUCCESS %ld %ld\n", (long)sb.st_atime,
-		       (long)sb.st_mtime);
-	}
+	if (fd != AT_FDCWD)
+		SAFE_CLOSE(fd);
 
-	exit(EXIT_SUCCESS);
+	SAFE_RMDIR(TEST_DIR);
 }
+
+static struct tst_test test = {
+	.test = run,
+	.tcnt = ARRAY_SIZE(tcase),
+	.setup = setup,
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+};
testcases/kernel/syscalls/utimensat/utimensat_tests.sh deleted +0 -517

517 lines not on this page · raw message

Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
#34 lore raw

PATCH v2 16/17 syscalls/utimensat: Migrate to new test framework

Hi Viresh,

Quoted 4 lines · Viresh Kumar

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

Since we have removed the utimensat01_test.sh script, the Makefile, runtest/syscalls should be updated too.

runtest/syscalls +1 -1
@@ -1600,7 +1600,7 @@ utime06 utime06
 utimes01 utimes01
 
 # Introduced from Kernel 2.6.22 onwards
-utimensat01 utimensat_tests.sh
+utimensat01 utimensat01
 
 vfork01 vfork01
 vfork02 vfork02
(quoted diff) +0 -0

b/testcases/kernel/syscalls/utimensat/Makefile
index 69cab8dbc..044619fb8 100644

testcases/kernel/syscalls/utimensat/Makefile +0 -4
@@ -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
Signature · 5 lines
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20200509/3d8982e1/attachment-0001.htm>
#35 lore raw

PATCH v2 16/17 syscalls/utimensat: Migrate to new test framework

In reply to Viresh Kumar

Hi!

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

Quoted 2 lines
testcases/kernel/syscalls/utimensat/utimensat01.c +2 -0
+	if (tc->rattr != NULL)
+		run_command("chattr", tc->rattr, tc->pathname);

Can we please use the FS_IOC_GETFLAGS and FS_IOC_SETFLAGS instead?

Have a look at fallocate06.c function toggle_cow()

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

PATCH v2 17/17 syscalls/utimensat: Add support for time64 tests

In reply to Viresh Kumar

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

---
 .../kernel/syscalls/utimensat/utimensat01.c   | 80 ++++++++++++++++---
 1 file changed, 70 insertions(+), 10 deletions(-)
testcases/kernel/syscalls/utimensat/utimensat01.c +70 -10
index 2a029ecb17e9..f29cfe5009eb 100644
@@ -15,8 +15,8 @@
 #include <fcntl.h>
 #include <string.h>
 #include <sys/stat.h>
-#include "tst_test.h"
-#include "lapi/syscalls.h"
+#include "tst_timer.h"
+#include "lapi/abisize.h"
 
 #define UTIME_NOW	((1l << 30) - 1l)
 #define UTIME_OMIT	((1l << 30) - 2l)
@@ -98,13 +98,73 @@ 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 defined(TST_ABI32)
+	{ .utimensat = sys_utimensat, .type = TST_LIBC_TIMESPEC, .desc = "syscall with libc spec"},
+	{ .utimensat = sys_utimensat, .type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with kernel spec32"},
+#endif
+
+#if defined(TST_ABI64)
+	{ .utimensat = sys_utimensat, .type = TST_KERN_TIMESPEC, .desc = "syscall with kernel spec64"},
+#endif
+
+#if (__NR_utimensat_time64 != __LTP__NR_INVALID_SYSCALL)
+	{ .utimensat = sys_utimensat_time64, .type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec64"},
+#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, long access_tv_sec,
+			long access_tv_nsec, long mod_tv_sec, long mod_tv_nsec)
+{
+	switch (type) {
+	case TST_LIBC_TIMESPEC:
+		ts.libc_ts[0].tv_sec = access_tv_sec;
+		ts.libc_ts[0].tv_nsec = access_tv_nsec;
+		ts.libc_ts[1].tv_sec = mod_tv_sec;
+		ts.libc_ts[1].tv_nsec = mod_tv_nsec;
+		break;
+	case TST_KERN_OLD_TIMESPEC:
+		ts.kern_old_ts[0].tv_sec = access_tv_sec;
+		ts.kern_old_ts[0].tv_nsec = access_tv_nsec;
+		ts.kern_old_ts[1].tv_sec = mod_tv_sec;
+		ts.kern_old_ts[1].tv_nsec = mod_tv_nsec;
+		break;
+	case TST_KERN_TIMESPEC:
+		ts.kern_ts[0].tv_sec = access_tv_sec;
+		ts.kern_ts[0].tv_nsec = access_tv_nsec;
+		ts.kern_ts[1].tv_sec = mod_tv_sec;
+		ts.kern_ts[1].tv_nsec = 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);
 }
 
@@ -134,8 +194,8 @@ static int run_command(char *command, char *option, char *file)
 
 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 fd = AT_FDCWD;
@@ -151,11 +211,10 @@ static void run(unsigned int i)
 	if (tc->mytime) {
 		struct mytime *mytime = *tc->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->access_tv_sec,
+				   mytime->access_tv_nsec, mytime->mod_tv_sec,
+				   mytime->mod_tv_nsec);
+		tsp = &ts.libc_ts;
 	} else if (tc->exp_err == EFAULT) {
 		tsp = bad_addr;
 	}
@@ -169,7 +228,7 @@ static void run(unsigned int i)
 		pathname = bad_addr;
 	}
 
-	TEST(sys_utimensat(fd, pathname, tsp, tc->flags));
+	TEST(tv->utimensat(fd, pathname, tsp, tc->flags));
 	if (TST_RET) {
 		if (!tc->exp_err) {
 			tst_res(TFAIL | TTERRNO, "%2d: utimensat() failed", i);
@@ -199,6 +258,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.25.0.rc1.19.g042ed3e048af