* [LTP] [PATCH 2/8] syscalls/futex: Add support for time64 tests
2020-05-05 9:12 [LTP] [PATCH 1/8] syscalls/futex: Merge futex_wait_bitset tests Viresh Kumar
@ 2020-05-05 9:12 ` Viresh Kumar
2020-05-07 14:52 ` Petr Vorel
2020-05-07 15:19 ` Petr Vorel
2020-05-05 9:12 ` [LTP] [PATCH 3/8] syscalls/io_pgetevents: " Viresh Kumar
` (6 subsequent siblings)
7 siblings, 2 replies; 15+ messages in thread
From: Viresh Kumar @ 2020-05-05 9:12 UTC (permalink / raw)
To: ltp
This adds support for time64 tests to the existing futex() syscall
tests.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
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 | 60 +++++---
.../kernel/syscalls/futex/futex_wait02.c | 83 +++++------
.../kernel/syscalls/futex/futex_wait03.c | 70 ++++++----
.../kernel/syscalls/futex/futex_wait04.c | 64 ++++++---
.../kernel/syscalls/futex/futex_wait05.c | 2 +-
.../syscalls/futex/futex_wait_bitset01.c | 50 +++++--
.../kernel/syscalls/futex/futex_wake01.c | 52 ++++---
.../kernel/syscalls/futex/futex_wake02.c | 80 ++++++-----
.../kernel/syscalls/futex/futex_wake03.c | 92 ++++++------
.../kernel/syscalls/futex/futex_wake04.c | 132 ++++++++++--------
testcases/kernel/syscalls/futex/futextest.h | 111 +++++++++------
15 files changed, 588 insertions(+), 332 deletions(-)
diff --git a/include/tst_timer.h b/include/tst_timer.h
index a726298b407d..b4280042c77f 100644
--- a/include/tst_timer.h
+++ b/include/tst_timer.h
@@ -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);
diff --git a/testcases/kernel/syscalls/futex/futex_cmp_requeue01.c b/testcases/kernel/syscalls/futex/futex_cmp_requeue01.c
index c50fade9f969..bc9d2a6bee37 100644
--- a/testcases/kernel/syscalls/futex/futex_cmp_requeue01.c
+++ b/testcases/kernel/syscalls/futex/futex_cmp_requeue01.c
@@ -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,
};
diff --git a/testcases/kernel/syscalls/futex/futex_cmp_requeue02.c b/testcases/kernel/syscalls/futex/futex_cmp_requeue02.c
index 228d8cff6ea0..5559b72a3a45 100644
--- a/testcases/kernel/syscalls/futex/futex_cmp_requeue02.c
+++ b/testcases/kernel/syscalls/futex/futex_cmp_requeue02.c
@@ -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"},
diff --git a/testcases/kernel/syscalls/futex/futex_utils.h b/testcases/kernel/syscalls/futex/futex_utils.h
index 63b97c00b631..f77b9d6b3b8a 100644
--- a/testcases/kernel/syscalls/futex/futex_utils.h
+++ b/testcases/kernel/syscalls/futex/futex_utils.h
@@ -20,10 +20,13 @@
#ifndef FUTEX_UTILS_H__
#define FUTEX_UTILS_H__
+#include <stdio.h>
+#include <stdlib.h>
+
/*
* Wait for nr_threads to be sleeping
*/
-static int wait_for_threads(unsigned int nr_threads)
+static inline int wait_for_threads(unsigned int nr_threads)
{
char thread_state, name[1024];
DIR *dir;
@@ -32,34 +35,63 @@ static int wait_for_threads(unsigned int nr_threads)
snprintf(name, sizeof(name), "/proc/%i/task/", getpid());
- dir = SAFE_OPENDIR(NULL, name);
+ dir = SAFE_OPENDIR(name);
- while ((dent = SAFE_READDIR(NULL, dir))) {
+ while ((dent = SAFE_READDIR(dir))) {
/* skip ".", ".." and the main thread */
if (atoi(dent->d_name) == getpid() || atoi(dent->d_name) == 0)
continue;
snprintf(name, sizeof(name), "/proc/%i/task/%s/stat",
- getpid(), dent->d_name);
+ getpid(), dent->d_name);
- SAFE_FILE_SCANF(NULL, name, "%*i %*s %c", &thread_state);
+ SAFE_FILE_SCANF(name, "%*i %*s %c", &thread_state);
if (thread_state != 'S') {
- tst_resm(TINFO, "Thread %s not sleeping yet", dent->d_name);
- SAFE_CLOSEDIR(NULL, dir);
+ tst_res(TINFO, "Thread %s not sleeping yet", dent->d_name);
+ SAFE_CLOSEDIR(dir);
return 1;
}
cnt++;
}
- SAFE_CLOSEDIR(NULL, dir);
+ SAFE_CLOSEDIR(dir);
if (cnt != nr_threads) {
- tst_resm(TINFO, "%u threads sleeping, expected %u",
- cnt, nr_threads);
+ tst_res(TINFO, "%u threads sleeping, expected %u", cnt,
+ nr_threads);
}
return 0;
}
+static inline int process_state_wait2(pid_t pid, const char state)
+{
+ char proc_path[128], cur_state;
+
+ snprintf(proc_path, sizeof(proc_path), "/proc/%i/stat", pid);
+
+ for (;;) {
+ FILE *f = fopen(proc_path, "r");
+ if (!f) {
+ tst_res(TFAIL, "Failed to open '%s': %s\n", proc_path,
+ strerror(errno));
+ return 1;
+ }
+
+ if (fscanf(f, "%*i %*s %c", &cur_state) != 1) {
+ fclose(f);
+ tst_res(TFAIL, "Failed to read '%s': %s\n", proc_path,
+ strerror(errno));
+ return 1;
+ }
+ fclose(f);
+
+ if (state == cur_state)
+ return 0;
+
+ usleep(10000);
+ }
+}
+
#endif /* FUTEX_UTILS_H__ */
diff --git a/testcases/kernel/syscalls/futex/futex_wait01.c b/testcases/kernel/syscalls/futex/futex_wait01.c
index 51a540d9e315..e7a283b69f9d 100644
--- a/testcases/kernel/syscalls/futex/futex_wait01.c
+++ b/testcases/kernel/syscalls/futex/futex_wait01.c
@@ -28,10 +28,8 @@
#include <errno.h>
-#include "test.h"
#include "futextest.h"
-
-const char *TCID="futex_wait01";
+#include "lapi/abisize.h"
struct testcase {
futex_t *f_addr;
@@ -41,7 +39,6 @@ struct testcase {
};
static futex_t futex = FUTEX_INITIALIZER;
-static struct timespec to = {.tv_sec = 0, .tv_nsec = 10000};
static struct testcase testcases[] = {
{&futex, FUTEX_INITIALIZER, 0, ETIMEDOUT},
@@ -50,38 +47,59 @@ static struct testcase testcases[] = {
{&futex, FUTEX_INITIALIZER+1, FUTEX_PRIVATE_FLAG, EWOULDBLOCK},
};
-const int TST_TOTAL=ARRAY_SIZE(testcases);
+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 verify_futex_wait(struct testcase *tc)
+static void run(unsigned int n)
{
+ struct test_variants *tv = &variants[tst_variant];
+ struct testcase *tc = &testcases[n];
+ static struct tst_ts to;
int res;
- res = futex_wait(tc->f_addr, tc->f_val, &to, tc->opflags);
+ to.type = tv->tstype;
+ tst_ts_set_sec(&to, 0);
+ tst_ts_set_nsec(&to, 10000);
+
+ res = futex_wait(tv->fntype, tc->f_addr, tc->f_val, &to, tc->opflags);
if (res != -1) {
- tst_resm(TFAIL, "futex_wait() returned %i, expected -1", res);
+ tst_res(TFAIL, "futex_wait() succeeded unexpectedly");
return;
}
if (errno != tc->exp_errno) {
- tst_resm(TFAIL | TERRNO, "expected errno=%s",
+ tst_res(TFAIL | TTERRNO, "futex_wait() failed with incorrect error, expected errno=%s",
tst_strerrno(tc->exp_errno));
return;
}
- tst_resm(TPASS | TERRNO, "futex_wait()");
+ tst_res(TPASS | TERRNO, "futex_wait() passed");
}
-int main(int argc, char *argv[])
+static void setup(void)
{
- int lc, i;
-
- tst_parse_opts(argc, argv, NULL, NULL);
-
- for (lc = 0; TEST_LOOPING(lc); lc++) {
- for (i = 0; i < TST_TOTAL; i++)
- verify_futex_wait(testcases + i);
- }
-
- tst_exit();
+ tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
}
+
+static struct tst_test test = {
+ .setup = setup,
+ .test = run,
+ .tcnt = ARRAY_SIZE(testcases),
+ .test_variants = ARRAY_SIZE(variants),
+};
diff --git a/testcases/kernel/syscalls/futex/futex_wait02.c b/testcases/kernel/syscalls/futex/futex_wait02.c
index 1ca1df457b4a..027d0e9a4eec 100644
--- a/testcases/kernel/syscalls/futex/futex_wait02.c
+++ b/testcases/kernel/syscalls/futex/futex_wait02.c
@@ -26,80 +26,85 @@
#include <sys/wait.h>
#include <errno.h>
-#include "test.h"
-#include "safe_macros.h"
#include "futextest.h"
-
-const char *TCID="futex_wait02";
-const int TST_TOTAL=1;
+#include "futex_utils.h"
+#include "lapi/abisize.h"
static futex_t *futex;
+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 do_child(void)
{
+ struct test_variants *tv = &variants[tst_variant];
int ret;
- tst_process_state_wait2(getppid(), 'S');
+ process_state_wait2(getppid(), 'S');
- ret = futex_wake(futex, 1, 0);
+ ret = futex_wake(tv->fntype, futex, 1, 0);
if (ret != 1)
- tst_brkm(TFAIL, NULL, "futex_wake() returned %i", ret);
+ tst_res(TFAIL | TTERRNO, "futex_wake() failed");
- exit(TPASS);
+ exit(0);
}
-static void verify_futex_wait(void)
+static void run(void)
{
- int res;
- int pid;
+ struct test_variants *tv = &variants[tst_variant];
+ int res, pid;
- pid = tst_fork();
+ pid = SAFE_FORK();
switch (pid) {
case 0:
do_child();
- break;
- case -1:
- tst_brkm(TBROK | TERRNO, NULL, "fork() failed");
- break;
default:
- break;
+ break;
}
- res = futex_wait(futex, *futex, NULL, 0);
-
+ res = futex_wait(tv->fntype, futex, *futex, NULL, 0);
if (res) {
- tst_resm(TFAIL, "futex_wait() returned %i, errno %s",
- res, tst_strerrno(errno));
+ tst_res(TFAIL | TTERRNO, "futex_wait() failed");
+ return;
}
- SAFE_WAIT(NULL, &res);
+ SAFE_WAIT(&res);
if (WIFEXITED(res) && WEXITSTATUS(res) == TPASS)
- tst_resm(TPASS, "futex_wait() woken up");
+ tst_res(TPASS, "futex_wait() woken up");
else
- tst_resm(TFAIL, "child failed");
+ tst_res(TFAIL, "child failed");
}
static void setup(void)
{
- futex = SAFE_MMAP(NULL, NULL, sizeof(*futex), PROT_READ | PROT_WRITE,
+ tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
+
+ futex = SAFE_MMAP(NULL, sizeof(*futex), PROT_READ | PROT_WRITE,
MAP_ANONYMOUS | MAP_SHARED, -1, 0);
*futex = FUTEX_INITIALIZER;
}
-int main(int argc, char *argv[])
-{
- int lc;
-
- tst_parse_opts(argc, argv, NULL, NULL);
-
- setup();
-
- for (lc = 0; TEST_LOOPING(lc); lc++)
- verify_futex_wait();
-
- tst_exit();
-}
+static struct tst_test test = {
+ .setup = setup,
+ .test_all = run,
+ .test_variants = ARRAY_SIZE(variants),
+ .forks_child = 1,
+};
diff --git a/testcases/kernel/syscalls/futex/futex_wait03.c b/testcases/kernel/syscalls/futex/futex_wait03.c
index 9683e76503c0..d2105716c941 100644
--- a/testcases/kernel/syscalls/futex/futex_wait03.c
+++ b/testcases/kernel/syscalls/futex/futex_wait03.c
@@ -25,63 +25,79 @@
#include <errno.h>
#include <pthread.h>
-#include "test.h"
#include "futextest.h"
-
-const char *TCID="futex_wait03";
-const int TST_TOTAL=1;
+#include "futex_utils.h"
+#include "lapi/abisize.h"
static futex_t futex = FUTEX_INITIALIZER;
+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 *threaded(void *arg LTP_ATTRIBUTE_UNUSED)
{
+ struct test_variants *tv = &variants[tst_variant];
long ret;
- tst_process_state_wait2(getpid(), 'S');
+ process_state_wait2(getpid(), 'S');
- ret = futex_wake(&futex, 1, FUTEX_PRIVATE_FLAG);
+ ret = futex_wake(tv->fntype, &futex, 1, FUTEX_PRIVATE_FLAG);
return (void*)ret;
}
-static void verify_futex_wait(void)
+static void run(void)
{
- long ret;
- int res;
+ struct test_variants *tv = &variants[tst_variant];
+ long ret, res;
pthread_t t;
res = pthread_create(&t, NULL, threaded, NULL);
if (res) {
- tst_brkm(TBROK, NULL, "pthread_create(): %s",
- tst_strerrno(res));
+ tst_res(TFAIL | TTERRNO, "pthread_create() failed");
+ return;
}
- res = futex_wait(&futex, futex, NULL, FUTEX_PRIVATE_FLAG);
+ res = futex_wait(tv->fntype, &futex, futex, NULL, FUTEX_PRIVATE_FLAG);
if (res) {
- tst_resm(TFAIL, "futex_wait() returned %i, errno %s",
- res, tst_strerrno(errno));
+ tst_res(TFAIL | TTERRNO, "futex_wait() failed");
pthread_join(t, NULL);
return;
}
res = pthread_join(t, (void*)&ret);
- if (res)
- tst_brkm(TBROK, NULL, "pthread_join(): %s", tst_strerrno(res));
+ if (res) {
+ tst_res(TFAIL | TTERRNO, "pthread_join() failed");
+ return;
+ }
if (ret != 1)
- tst_resm(TFAIL, "futex_wake() returned %li", ret);
+ tst_res(TFAIL, "futex_wake() returned %li", ret);
else
- tst_resm(TPASS, "futex_wait() woken up");
+ tst_res(TPASS, "futex_wait() woken up");
}
-int main(int argc, char *argv[])
+static void setup(void)
{
- int lc;
-
- tst_parse_opts(argc, argv, NULL, NULL);
-
- for (lc = 0; TEST_LOOPING(lc); lc++)
- verify_futex_wait();
-
- tst_exit();
+ tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
}
+
+static struct tst_test test = {
+ .setup = setup,
+ .test_all = run,
+ .test_variants = ARRAY_SIZE(variants),
+};
diff --git a/testcases/kernel/syscalls/futex/futex_wait04.c b/testcases/kernel/syscalls/futex/futex_wait04.c
index b8360ff80914..57085c5dd9c0 100644
--- a/testcases/kernel/syscalls/futex/futex_wait04.c
+++ b/testcases/kernel/syscalls/futex/futex_wait04.c
@@ -26,40 +26,58 @@
#include <errno.h>
-#include "test.h"
-#include "safe_macros.h"
#include "futextest.h"
+#include "lapi/abisize.h"
-const char *TCID="futex_wait04";
-const int TST_TOTAL=1;
-static struct timespec to = {.tv_sec = 0, .tv_nsec = 10000};
+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
-static void verify_futex_wait(void)
+#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 run(void)
{
- int res;
- void *buf;
+ struct test_variants *tv = &variants[tst_variant];
+ static struct tst_ts to;
size_t pagesize = getpagesize();
- buf = SAFE_MMAP(NULL, NULL, pagesize, PROT_READ|PROT_WRITE,
- MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
+ void *buf;
+ int res;
- res = futex_wait(buf, 1, &to, 0);
+ buf = SAFE_MMAP(NULL, pagesize, PROT_READ|PROT_WRITE,
+ MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
+ to.type = tv->tstype;
+ tst_ts_set_sec(&to, 0);
+ tst_ts_set_nsec(&to, 10000);
+
+ res = futex_wait(tv->fntype, buf, 1, &to, 0);
if (res == -1 && errno == EWOULDBLOCK)
- tst_resm(TPASS | TERRNO, "futex_wait() returned %i", res);
+ tst_res(TPASS | TERRNO, "futex_wait() returned %i", res);
else
- tst_resm(TFAIL | TERRNO, "futex_wait() returned %i", res);
+ tst_res(TFAIL | TERRNO, "futex_wait() returned %i", res);
- SAFE_MUNMAP(NULL, buf, pagesize);
+ SAFE_MUNMAP(buf, pagesize);
}
-int main(int argc, char *argv[])
+static void setup(void)
{
- int lc;
-
- tst_parse_opts(argc, argv, NULL, NULL);
-
- for (lc = 0; TEST_LOOPING(lc); lc++)
- verify_futex_wait();
-
- tst_exit();
+ tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
}
+
+static struct tst_test test = {
+ .setup = setup,
+ .test_all = run,
+ .test_variants = ARRAY_SIZE(variants),
+};
diff --git a/testcases/kernel/syscalls/futex/futex_wait05.c b/testcases/kernel/syscalls/futex/futex_wait05.c
index 2573ae177d5b..8fad5d858716 100644
--- a/testcases/kernel/syscalls/futex/futex_wait05.c
+++ b/testcases/kernel/syscalls/futex/futex_wait05.c
@@ -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();
diff --git a/testcases/kernel/syscalls/futex/futex_wait_bitset01.c b/testcases/kernel/syscalls/futex/futex_wait_bitset01.c
index b8546c3e640c..f3856697a964 100644
--- a/testcases/kernel/syscalls/futex/futex_wait_bitset01.c
+++ b/testcases/kernel/syscalls/futex/futex_wait_bitset01.c
@@ -12,6 +12,7 @@
#include "tst_test.h"
#include "tst_timer.h"
#include "futextest.h"
+#include "lapi/abisize.h"
#define THRESHOLD_US 100000
#define DEFAULT_TIMEOUT_US 100010
@@ -23,22 +24,44 @@ static struct test_case_t {
{ CLOCK_REALTIME }
};
+static struct test_variants {
+ enum futex_fn_type fntype;
+ enum tst_ts_type tstype;
+ int (*gettime)(clockid_t clk_id, void *ts);
+ char *desc;
+} variants[] = {
+#if defined(TST_ABI32)
+ { .fntype = FUTEX_FN_FUTEX, .tstype = TST_KERN_OLD_TIMESPEC, .gettime = sys_clock_gettime, .desc = "syscall with kernel spec32"},
+#endif
+
+#if defined(TST_ABI64)
+ { .fntype = FUTEX_FN_FUTEX, .tstype = TST_KERN_TIMESPEC, .gettime = sys_clock_gettime, .desc = "syscall with kernel spec64"},
+#endif
+
+#if (__NR_futex_time64 != __LTP__NR_INVALID_SYSCALL)
+ { .fntype = FUTEX_FN_FUTEX64, .tstype = TST_KERN_TIMESPEC, .gettime = sys_clock_gettime64, .desc = "syscall time64 with kernel spec64"},
+#endif
+};
+
static void verify_futex_wait_bitset(long long wait_us, clock_t clk_id)
{
- struct timespec start, to, end;
+ struct test_variants *tv = &variants[tst_variant];
+ struct tst_ts start, to, end;
futex_t futex = FUTEX_INITIALIZER;
u_int32_t bitset = 0xffffffff;
int flags = clk_id == CLOCK_REALTIME ? FUTEX_CLOCK_REALTIME : 0;
+ start.type = end.type = to.type = tv->tstype;
+
tst_res(TINFO, "testing futex_wait_bitset() timeout with %s",
clk_id == CLOCK_REALTIME ? "CLOCK_REALTIME" : "CLOCK_MONOTONIC");
- clock_gettime(clk_id, &start);
- to = tst_timespec_add_us(start, wait_us);
+ tv->gettime(clk_id, tst_ts_get(&start));
+ to = tst_ts_add_us(start, wait_us);
- TEST(futex_wait_bitset(&futex, futex, &to, bitset, flags));
+ TEST(futex_wait_bitset(tv->fntype, &futex, futex, &to, bitset, flags));
- clock_gettime(clk_id, &end);
+ tv->gettime(clk_id, tst_ts_get(&end));
if (TST_RET != -1) {
tst_res(TFAIL, "futex_wait_bitset() returned %li, expected -1",
@@ -58,22 +81,22 @@ static void verify_futex_wait_bitset(long long wait_us, clock_t clk_id)
return;
}
- if (tst_timespec_lt(end, to)) {
+ if (tst_ts_lt(end, to)) {
tst_res(TFAIL,
"futex_wait_bitset() woken up prematurely %llius, expected %llius",
- tst_timespec_diff_us(end, start), wait_us);
+ tst_ts_diff_us(end, start), wait_us);
return;
}
- if (tst_timespec_diff_us(end, to) > THRESHOLD_US) {
+ if (tst_ts_diff_us(end, to) > THRESHOLD_US) {
tst_res(TFAIL,
"futex_wait_bitset() waited too long %llius, expected %llius",
- tst_timespec_diff_us(end, start), wait_us);
+ tst_ts_diff_us(end, start), wait_us);
return;
}
tst_res(TPASS, "futex_wait_bitset() waited %llius, expected %llius",
- tst_timespec_diff_us(end, start), wait_us);
+ tst_ts_diff_us(end, start), wait_us);
}
static void run(unsigned int n)
@@ -82,7 +105,14 @@ static void run(unsigned int n)
verify_futex_wait_bitset(DEFAULT_TIMEOUT_US, tcases[n].clk_id);
}
+static void setup(void)
+{
+ tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
+}
+
static struct tst_test test = {
+ .setup = setup,
.test = run,
.tcnt = ARRAY_SIZE(tcases),
+ .test_variants = ARRAY_SIZE(variants),
};
diff --git a/testcases/kernel/syscalls/futex/futex_wake01.c b/testcases/kernel/syscalls/futex/futex_wake01.c
index 42ea6f6e6a75..795f11ed8af1 100644
--- a/testcases/kernel/syscalls/futex/futex_wake01.c
+++ b/testcases/kernel/syscalls/futex/futex_wake01.c
@@ -23,10 +23,8 @@
#include <errno.h>
#include <limits.h>
-#include "test.h"
#include "futextest.h"
-
-const char *TCID="futex_wake01";
+#include "lapi/abisize.h"
struct testcase {
futex_t *f_addr;
@@ -46,32 +44,46 @@ static struct testcase testcases[] = {
{&futex, INT_MAX, FUTEX_PRIVATE_FLAG},
};
-const int TST_TOTAL=ARRAY_SIZE(testcases);
+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_wake(struct testcase *tc)
+static void run(unsigned int n)
{
+ struct test_variants *tv = &variants[tst_variant];
+ struct testcase *tc = &testcases[n];
int res;
- res = futex_wake(tc->f_addr, tc->nr_wake, tc->opflags);
-
+ res = futex_wake(tv->fntype, tc->f_addr, tc->nr_wake, tc->opflags);
if (res != 0) {
- tst_resm(TFAIL, "futex_wake() returned %i, expected 0", res);
+ tst_res(TFAIL | TTERRNO, "futex_wake() failed");
return;
}
- tst_resm(TPASS, "futex_wake() returned 0");
+ tst_res(TPASS, "futex_wake() passed");
}
-int main(int argc, char *argv[])
+static void setup(void)
{
- int lc, i;
-
- tst_parse_opts(argc, argv, NULL, NULL);
-
- for (lc = 0; TEST_LOOPING(lc); lc++) {
- for (i = 0; i < TST_TOTAL; i++)
- verify_futex_wake(testcases + i);
- }
-
- tst_exit();
+ tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
}
+
+static struct tst_test test = {
+ .setup = setup,
+ .test = run,
+ .tcnt = ARRAY_SIZE(testcases),
+ .test_variants = ARRAY_SIZE(variants),
+};
diff --git a/testcases/kernel/syscalls/futex/futex_wake02.c b/testcases/kernel/syscalls/futex/futex_wake02.c
index 8a4c2d58e4b9..d1030529c082 100644
--- a/testcases/kernel/syscalls/futex/futex_wake02.c
+++ b/testcases/kernel/syscalls/futex/futex_wake02.c
@@ -22,19 +22,33 @@
#include <errno.h>
#include <pthread.h>
+#include <sys/types.h>
-#include "test.h"
-#include "safe_macros.h"
#include "futextest.h"
#include "futex_utils.h"
-
-const char *TCID="futex_wake02";
-const int TST_TOTAL=11;
+#include "lapi/abisize.h"
static futex_t futex = FUTEX_INITIALIZER;
static volatile int threads_flags[55];
+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 int threads_awake(void)
{
int ret = 0;
@@ -58,9 +72,10 @@ static void clear_threads_awake(void)
static void *threaded(void *arg)
{
+ struct test_variants *tv = &variants[tst_variant];
long i = (long)arg;
- futex_wait(&futex, futex, NULL, FUTEX_PRIVATE_FLAG);
+ futex_wait(tv->fntype, &futex, futex, NULL, FUTEX_PRIVATE_FLAG);
threads_flags[i] = 1;
@@ -69,14 +84,15 @@ static void *threaded(void *arg)
static void do_child(void)
{
+ struct test_variants *tv = &variants[tst_variant];
int res, i, j, awake;
pthread_t t[55];
for (i = 0; i < (int)ARRAY_SIZE(t); i++) {
res = pthread_create(&t[i], NULL, threaded, (void*)((long)i));
if (res) {
- tst_brkm(TBROK, NULL, "pthread_create(): %s",
- tst_strerrno(res));
+ tst_res(TFAIL | TTERRNO, "pthread_create() failed");
+ return;
}
}
@@ -85,9 +101,9 @@ static void do_child(void)
for (i = 1; i <= 10; i++) {
clear_threads_awake();
- res = futex_wake(&futex, i, FUTEX_PRIVATE_FLAG);
+ res = futex_wake(tv->fntype, &futex, i, FUTEX_PRIVATE_FLAG);
if (i != res) {
- tst_resm(TFAIL,
+ tst_res(TFAIL | TTERRNO,
"futex_wake() woken up %i threads, expected %i",
res, i);
}
@@ -101,26 +117,26 @@ static void do_child(void)
}
if (awake == i) {
- tst_resm(TPASS, "futex_wake() woken up %i threads", i);
+ tst_res(TPASS, "futex_wake() woken up %i threads", i);
} else {
- tst_resm(TFAIL, "Woken up %i threads, expected %i",
- awake, i);
+ tst_res(TFAIL | TTERRNO, "Woken up %i threads, expected %i",
+ awake, i);
}
}
- res = futex_wake(&futex, 1, FUTEX_PRIVATE_FLAG);
+ res = futex_wake(tv->fntype, &futex, 1, FUTEX_PRIVATE_FLAG);
if (res) {
- tst_resm(TFAIL, "futex_wake() woken up %i, none were waiting",
- res);
+ tst_res(TFAIL | TTERRNO, "futex_wake() woken up %i, none were waiting",
+ res);
} else {
- tst_resm(TPASS, "futex_wake() woken up 0 threads");
+ tst_res(TPASS, "futex_wake() woken up 0 threads");
}
for (i = 0; i < (int)ARRAY_SIZE(t); i++)
pthread_join(t[i], NULL);
- tst_exit();
+ exit(0);
}
/*
@@ -135,30 +151,28 @@ static void do_child(void)
* under /proc/$PID/tasks/, but the subsequent open() fails with ENOENT because
* the thread was removed meanwhile.
*/
-static void verify_futex_wake(void)
+static void run(void)
{
- int pid;
+ int status, pid;
- pid = tst_fork();
+ pid = SAFE_FORK();
switch (pid) {
case 0:
do_child();
- case -1:
- tst_brkm(TBROK | TERRNO, NULL, "fork() failed");
default:
- tst_record_childstatus(NULL, pid);
+ SAFE_WAITPID(pid, &status, 0);
}
}
-int main(int argc, char *argv[])
+static void setup(void)
{
- int lc;
-
- tst_parse_opts(argc, argv, NULL, NULL);
-
- for (lc = 0; TEST_LOOPING(lc); lc++)
- verify_futex_wake();
-
- tst_exit();
+ tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
}
+
+static struct tst_test test = {
+ .setup = setup,
+ .test_all = run,
+ .test_variants = ARRAY_SIZE(variants),
+ .forks_child = 1,
+};
diff --git a/testcases/kernel/syscalls/futex/futex_wake03.c b/testcases/kernel/syscalls/futex/futex_wake03.c
index d6e5e5422db9..5af9093c0178 100644
--- a/testcases/kernel/syscalls/futex/futex_wake03.c
+++ b/testcases/kernel/syscalls/futex/futex_wake03.c
@@ -24,31 +24,48 @@
#include <sys/types.h>
#include <sys/wait.h>
-#include "test.h"
-#include "safe_macros.h"
#include "futextest.h"
-
-const char *TCID="futex_wake03";
-const int TST_TOTAL=11;
+#include "futex_utils.h"
+#include "lapi/abisize.h"
static futex_t *futex;
+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 do_child(void)
{
- futex_wait(futex, *futex, NULL, 0);
+ struct test_variants *tv = &variants[tst_variant];
+
+ futex_wait(tv->fntype, futex, *futex, NULL, 0);
exit(0);
}
static void do_wake(int nr_children)
{
+ struct test_variants *tv = &variants[tst_variant];
int res, i, cnt;
- res = futex_wake(futex, nr_children, 0);
+ res = futex_wake(tv->fntype, futex, nr_children, 0);
if (res != nr_children) {
- tst_resm(TFAIL,
- "futex_wake() woken up %i children, expected %i",
- res, nr_children);
+ tst_res(TFAIL | TTERRNO,
+ "futex_wake() woken up %i children, expected %i",
+ res, nr_children);
return;
}
@@ -63,65 +80,60 @@ static void do_wake(int nr_children)
}
if (cnt != nr_children) {
- tst_resm(TFAIL, "reaped only %i childs, expected %i",
- cnt, nr_children);
+ tst_res(TFAIL | TTERRNO, "reaped only %i childs, expected %i",
+ cnt, nr_children);
} else {
- tst_resm(TPASS, "futex_wake() woken up %i childs", cnt);
+ tst_res(TPASS, "futex_wake() woken up %i childs", cnt);
}
}
-static void verify_futex_wake(void)
+static void run(void)
{
- int i, res;
+ struct test_variants *tv = &variants[tst_variant];
pid_t pids[55];
+ unsigned int i;
+ int res;
- for (i = 0; i < (int)ARRAY_SIZE(pids); i++) {
- pids[i] = tst_fork();
+ for (i = 0; i < ARRAY_SIZE(pids); i++) {
+ pids[i] = SAFE_FORK();
switch (pids[i]) {
- case -1:
- tst_brkm(TBROK | TERRNO, NULL, "fork()");
case 0:
do_child();
default:
- break;
+ break;
}
}
- for (i = 0; i < (int)ARRAY_SIZE(pids); i++)
- tst_process_state_wait2(pids[i], 'S');
+ for (i = 0; i < ARRAY_SIZE(pids); i++)
+ process_state_wait2(pids[i], 'S');
for (i = 1; i <= 10; i++)
do_wake(i);
- res = futex_wake(futex, 1, 0);
+ res = futex_wake(tv->fntype, futex, 1, 0);
if (res) {
- tst_resm(TFAIL, "futex_wake() woken up %u, none were waiting",
- res);
+ tst_res(TFAIL | TTERRNO, "futex_wake() woken up %u, none were waiting",
+ res);
} else {
- tst_resm(TPASS, "futex_wake() woken up 0 children");
+ tst_res(TPASS, "futex_wake() woken up 0 children");
}
}
static void setup(void)
{
- futex = SAFE_MMAP(NULL, NULL, sizeof(*futex), PROT_READ | PROT_WRITE,
+ tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
+
+ futex = SAFE_MMAP(NULL, sizeof(*futex), PROT_READ | PROT_WRITE,
MAP_ANONYMOUS | MAP_SHARED, -1, 0);
*futex = FUTEX_INITIALIZER;
}
-int main(int argc, char *argv[])
-{
- int lc;
-
- tst_parse_opts(argc, argv, NULL, NULL);
-
- setup();
-
- for (lc = 0; TEST_LOOPING(lc); lc++)
- verify_futex_wake();
-
- tst_exit();
-}
+static struct tst_test test = {
+ .setup = setup,
+ .test_all = run,
+ .test_variants = ARRAY_SIZE(variants),
+ .forks_child = 1,
+};
diff --git a/testcases/kernel/syscalls/futex/futex_wake04.c b/testcases/kernel/syscalls/futex/futex_wake04.c
index f92bda53f6c7..f063c48c4449 100644
--- a/testcases/kernel/syscalls/futex/futex_wake04.c
+++ b/testcases/kernel/syscalls/futex/futex_wake04.c
@@ -42,53 +42,63 @@
#include <sys/time.h>
#include <string.h>
-#include "test.h"
-#include "safe_macros.h"
#include "futextest.h"
#include "futex_utils.h"
#include "lapi/mmap.h"
+#include "lapi/abisize.h"
+#include "tst_safe_stdio.h"
#define PATH_MEMINFO "/proc/meminfo"
#define PATH_NR_HUGEPAGES "/proc/sys/vm/nr_hugepages"
#define PATH_HUGEPAGES "/sys/kernel/mm/hugepages/"
-const char *TCID = "futex_wake04";
-const int TST_TOTAL = 1;
-
static futex_t *futex1, *futex2;
-static struct timespec to = {.tv_sec = 30, .tv_nsec = 0};
+static struct tst_ts to;
static long orig_hugepages;
+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 setup(void)
{
- tst_require_root();
+ struct test_variants *tv = &variants[tst_variant];
- if ((tst_kvercmp(2, 6, 32)) < 0) {
- tst_brkm(TCONF, NULL, "This test can only run on kernels "
- "that are 2.6.32 or higher");
- }
+ tst_res(TINFO, "Testing variant: %s", tv->desc);
- if (access(PATH_HUGEPAGES, F_OK))
- tst_brkm(TCONF, NULL, "Huge page is not supported.");
+ to.type = tv->tstype;
+ tst_ts_set_sec(&to, 30);
+ tst_ts_set_nsec(&to, 0);
- tst_tmpdir();
+ if (access(PATH_HUGEPAGES, F_OK))
+ tst_brk(TCONF, "Huge page is not supported.");
- SAFE_FILE_SCANF(NULL, PATH_NR_HUGEPAGES, "%ld", &orig_hugepages);
+ SAFE_FILE_SCANF(PATH_NR_HUGEPAGES, "%ld", &orig_hugepages);
if (orig_hugepages <= 0)
- SAFE_FILE_PRINTF(NULL, PATH_NR_HUGEPAGES, "%d", 1);
-
- TEST_PAUSE;
+ SAFE_FILE_PRINTF(PATH_NR_HUGEPAGES, "%d", 1);
}
static void cleanup(void)
{
if (orig_hugepages <= 0)
- SAFE_FILE_PRINTF(NULL, PATH_NR_HUGEPAGES, "%ld", orig_hugepages);
-
- tst_rmdir();
+ SAFE_FILE_PRINTF(PATH_NR_HUGEPAGES, "%ld", orig_hugepages);
}
static int read_hugepagesize(void)
@@ -97,60 +107,64 @@ static int read_hugepagesize(void)
char line[BUFSIZ], buf[BUFSIZ];
int val;
- fp = SAFE_FOPEN(cleanup, PATH_MEMINFO, "r");
+ fp = SAFE_FOPEN(PATH_MEMINFO, "r");
while (fgets(line, BUFSIZ, fp) != NULL) {
if (sscanf(line, "%64s %d", buf, &val) == 2)
if (strcmp(buf, "Hugepagesize:") == 0) {
- SAFE_FCLOSE(cleanup, fp);
+ SAFE_FCLOSE(fp);
return 1024 * val;
}
}
- SAFE_FCLOSE(cleanup, fp);
- tst_brkm(TBROK, NULL, "can't find \"%s\" in %s",
- "Hugepagesize:", PATH_MEMINFO);
+ SAFE_FCLOSE(fp);
+ tst_res(TFAIL, "can't find \"%s\" in %s", "Hugepagesize:",
+ PATH_MEMINFO);
+ return 0;
}
static void *wait_thread1(void *arg LTP_ATTRIBUTE_UNUSED)
{
- futex_wait(futex1, *futex1, &to, 0);
+ struct test_variants *tv = &variants[tst_variant];
+
+ futex_wait(tv->fntype, futex1, *futex1, &to, 0);
return NULL;
}
static void *wait_thread2(void *arg LTP_ATTRIBUTE_UNUSED)
{
+ struct test_variants *tv = &variants[tst_variant];
int res;
- res = futex_wait(futex2, *futex2, &to, 0);
+ res = futex_wait(tv->fntype, futex2, *futex2, &to, 0);
if (!res)
- tst_resm(TPASS, "Hi hydra, thread2 awake!");
+ tst_res(TPASS, "Hi hydra, thread2 awake!");
else
- tst_resm(TFAIL, "Bug: wait_thread2 did not wake after 30 secs.");
+ tst_res(TFAIL | TTERRNO, "Bug: wait_thread2 did not wake after 30 secs.");
return NULL;
}
static void wakeup_thread2(void)
{
+ struct test_variants *tv = &variants[tst_variant];
void *addr;
int hpsz, pgsz, res;
pthread_t th1, th2;
hpsz = read_hugepagesize();
- tst_resm(TINFO, "Hugepagesize %i", hpsz);
+ tst_res(TINFO, "Hugepagesize %i", hpsz);
/*allocate some shared memory*/
addr = mmap(NULL, hpsz, PROT_WRITE | PROT_READ,
MAP_SHARED | MAP_ANONYMOUS | MAP_HUGETLB, -1, 0);
if (addr == MAP_FAILED) {
- if (errno == ENOMEM) {
- tst_brkm(TCONF, NULL,
- "Cannot allocate hugepage, memory too fragmented?");
- }
+ if (errno == ENOMEM)
+ tst_res(TCONF, "Cannot allocate hugepage, memory too fragmented?");
- tst_brkm(TBROK | TERRNO, NULL, "Cannot allocate hugepage");
+ tst_res(TFAIL | TERRNO, "Cannot allocate hugepage");
+ return;
}
pgsz = getpagesize();
@@ -165,45 +179,47 @@ static void wakeup_thread2(void)
/*thread1 block on futex1 first,then thread2 block on futex2*/
res = pthread_create(&th1, NULL, wait_thread1, NULL);
if (res) {
- tst_brkm(TBROK, NULL, "pthread_create(): %s",
- tst_strerrno(res));
+ tst_res(TFAIL | TTERRNO, "pthread_create() failed");
+ return;
}
res = pthread_create(&th2, NULL, wait_thread2, NULL);
if (res) {
- tst_brkm(TBROK, NULL, "pthread_create(): %s",
- tst_strerrno(res));
+ tst_res(TFAIL | TTERRNO, "pthread_create() failed");
+ return;
}
while (wait_for_threads(2))
usleep(1000);
- futex_wake(futex2, 1, 0);
+ futex_wake(tv->fntype, futex2, 1, 0);
res = pthread_join(th2, NULL);
- if (res)
- tst_brkm(TBROK, NULL, "pthread_join(): %s", tst_strerrno(res));
+ if (res) {
+ tst_res(TFAIL | TTERRNO, "pthread_join() failed");
+ return;
+ }
- futex_wake(futex1, 1, 0);
+ futex_wake(tv->fntype, futex1, 1, 0);
res = pthread_join(th1, NULL);
if (res)
- tst_brkm(TBROK, NULL, "pthread_join(): %s", tst_strerrno(res));
+ tst_res(TFAIL | TTERRNO, "pthread_join() failed");
- SAFE_MUNMAP(NULL, addr, hpsz);
+ SAFE_MUNMAP(addr, hpsz);
}
-int main(int argc, char *argv[])
+static void run(void)
{
- int lc;
-
- tst_parse_opts(argc, argv, NULL, NULL);
-
- setup();
-
- for (lc = 0; TEST_LOOPING(lc); lc++)
- wakeup_thread2();
-
- cleanup();
- tst_exit();
+ wakeup_thread2();
}
+
+static struct tst_test test = {
+ .setup = setup,
+ .cleanup = cleanup,
+ .test_all = run,
+ .test_variants = ARRAY_SIZE(variants),
+ .needs_root = 1,
+ .min_kver = "2.6.32",
+ .needs_tmpdir = 1,
+};
diff --git a/testcases/kernel/syscalls/futex/futextest.h b/testcases/kernel/syscalls/futex/futextest.h
index 5754d36dae51..a9dcbbedd249 100644
--- a/testcases/kernel/syscalls/futex/futextest.h
+++ b/testcases/kernel/syscalls/futex/futextest.h
@@ -39,6 +39,7 @@
#include <sys/types.h>
#include <linux/futex.h>
#include "lapi/futex.h"
+#include "tst_timer.h"
#define FUTEX_INITIALIZER 0
@@ -82,18 +83,24 @@
# define FUTEX_CLOCK_REALTIME 256
#endif
+enum futex_fn_type {
+ FUTEX_FN_FUTEX,
+ FUTEX_FN_FUTEX64,
+};
+
/**
- * futex() - SYS_futex syscall wrapper
+ * futex_syscall() - futex syscall wrapper
+ * @fntype: Futex function type
* @uaddr: address of first futex
* @op: futex op code
* @val: typically expected value of uaddr, but varies by op
- * @timeout: typically an absolute struct timespec (except where noted
+ * @timeout: typically an absolute struct tst_ts (except where noted
* otherwise). Overloaded by some ops
* @uaddr2: address of second futex for some ops\
* @val3: varies by op
* @opflags: flags to be bitwise OR'd with op, such as FUTEX_PRIVATE_FLAG
*
- * futex() is used by all the following futex op wrappers. It can also be
+ * futex_syscall() is used by all the following futex op wrappers. It can also be
* used for misuse and abuse testing. Generally, the specific op wrappers
* should be used instead. It is a macro instead of an static inline function as
* some of the types over overloaded (timeout is used for nr_requeue for
@@ -102,17 +109,30 @@
* These argument descriptions are the defaults for all
* like-named arguments in the following wrappers except where noted below.
*/
-#define futex(uaddr, op, val, timeout, uaddr2, val3, opflags) \
- syscall(SYS_futex, uaddr, op | opflags, val, timeout, uaddr2, val3)
+static inline int futex_syscall(enum futex_fn_type fntype, futex_t *uaddr,
+ int futex_op, futex_t val, void *timeout,
+ futex_t *uaddr2, int val3, int opflags)
+{
+ int (*func)(int *uaddr, int futex_op, int val, void *to, int *uaddr2, int val3);
+
+ if (fntype == FUTEX_FN_FUTEX)
+ func = sys_futex;
+ else
+ func = sys_futex_time64;
+
+ return func((int *)uaddr, futex_op | opflags, val, timeout, (int *)uaddr2, val3);
+}
/**
* futex_wait() - block on uaddr with optional timeout
* @timeout: relative timeout
*/
static inline int
-futex_wait(futex_t *uaddr, futex_t val, struct timespec *timeout, int opflags)
+futex_wait(enum futex_fn_type fntype, futex_t *uaddr, futex_t val,
+ struct tst_ts *timeout, int opflags)
{
- return futex(uaddr, FUTEX_WAIT, val, timeout, NULL, 0, opflags);
+ return futex_syscall(fntype, uaddr, FUTEX_WAIT, val,
+ tst_ts_get(timeout), NULL, 0, opflags);
}
/**
@@ -120,9 +140,10 @@ futex_wait(futex_t *uaddr, futex_t val, struct timespec *timeout, int opflags)
* @nr_wake: wake up to this many tasks
*/
static inline int
-futex_wake(futex_t *uaddr, int nr_wake, int opflags)
+futex_wake(enum futex_fn_type fntype, futex_t *uaddr, int nr_wake, int opflags)
{
- return futex(uaddr, FUTEX_WAKE, nr_wake, NULL, NULL, 0, opflags);
+ return futex_syscall(fntype, uaddr, FUTEX_WAKE, nr_wake, NULL, NULL, 0,
+ opflags);
}
/**
@@ -130,11 +151,11 @@ futex_wake(futex_t *uaddr, int nr_wake, int opflags)
* @bitset: bitset to be used with futex_wake_bitset
*/
static inline int
-futex_wait_bitset(futex_t *uaddr, futex_t val, struct timespec *timeout,
- u_int32_t bitset, int opflags)
+futex_wait_bitset(enum futex_fn_type fntype, futex_t *uaddr, futex_t val,
+ struct tst_ts *timeout, u_int32_t bitset, int opflags)
{
- return futex(uaddr, FUTEX_WAIT_BITSET, val, timeout, NULL, bitset,
- opflags);
+ return futex_syscall(fntype, uaddr, FUTEX_WAIT_BITSET, val,
+ tst_ts_get(timeout), NULL, bitset, opflags);
}
/**
@@ -142,10 +163,11 @@ futex_wait_bitset(futex_t *uaddr, futex_t val, struct timespec *timeout,
* @bitset: bitset to compare with that used in futex_wait_bitset
*/
static inline int
-futex_wake_bitset(futex_t *uaddr, int nr_wake, u_int32_t bitset, int opflags)
+futex_wake_bitset(enum futex_fn_type fntype, futex_t *uaddr, int nr_wake,
+ u_int32_t bitset, int opflags)
{
- return futex(uaddr, FUTEX_WAKE_BITSET, nr_wake, NULL, NULL, bitset,
- opflags);
+ return futex_syscall(fntype, uaddr, FUTEX_WAKE_BITSET, nr_wake, NULL,
+ NULL, bitset, opflags);
}
/**
@@ -153,30 +175,32 @@ futex_wake_bitset(futex_t *uaddr, int nr_wake, u_int32_t bitset, int opflags)
* @detect: whether (1) or not (0) to perform deadlock detection
*/
static inline int
-futex_lock_pi(futex_t *uaddr, struct timespec *timeout, int detect,
- int opflags)
+futex_lock_pi(enum futex_fn_type fntype, futex_t *uaddr, struct tst_ts *timeout,
+ int detect, int opflags)
{
- return futex(uaddr, FUTEX_LOCK_PI, detect, timeout, NULL, 0, opflags);
+ return futex_syscall(fntype, uaddr, FUTEX_LOCK_PI, detect,
+ tst_ts_get(timeout), NULL, 0, opflags);
}
/**
* futex_unlock_pi() - release uaddr as a PI mutex, waking the top waiter
*/
static inline int
-futex_unlock_pi(futex_t *uaddr, int opflags)
+futex_unlock_pi(enum futex_fn_type fntype, futex_t *uaddr, int opflags)
{
- return futex(uaddr, FUTEX_UNLOCK_PI, 0, NULL, NULL, 0, opflags);
-}
+ return futex_syscall(fntype, uaddr, FUTEX_UNLOCK_PI, 0, NULL, NULL, 0,
+ opflags); }
/**
* futex_wake_op() - FIXME: COME UP WITH A GOOD ONE LINE DESCRIPTION
*/
static inline int
-futex_wake_op(futex_t *uaddr, futex_t *uaddr2, int nr_wake, int nr_wake2,
- int wake_op, int opflags)
+futex_wake_op(enum futex_fn_type fntype, futex_t *uaddr, futex_t *uaddr2,
+ int nr_wake, int nr_wake2, int wake_op, int opflags)
{
- return futex(uaddr, FUTEX_WAKE_OP, nr_wake, nr_wake2, uaddr2, wake_op,
- opflags);
+ return futex_syscall(fntype, uaddr, FUTEX_WAKE_OP, nr_wake,
+ (void *)((unsigned long)nr_wake2), uaddr2, wake_op,
+ opflags);
}
/**
@@ -188,11 +212,12 @@ futex_wake_op(futex_t *uaddr, futex_t *uaddr2, int nr_wake, int nr_wake2,
* favor of futex_cmp_requeue().
*/
static inline int
-futex_requeue(futex_t *uaddr, futex_t *uaddr2, int nr_wake, int nr_requeue,
- int opflags)
+futex_requeue(enum futex_fn_type fntype, futex_t *uaddr, futex_t *uaddr2,
+ int nr_wake, int nr_requeue, int opflags)
{
- return futex(uaddr, FUTEX_REQUEUE, nr_wake, nr_requeue, uaddr2, 0,
- opflags);
+ return futex_syscall(fntype, uaddr, FUTEX_REQUEUE, nr_wake,
+ (void *)((unsigned long)nr_requeue), uaddr2, 0,
+ opflags);
}
/**
@@ -201,11 +226,12 @@ futex_requeue(futex_t *uaddr, futex_t *uaddr2, int nr_wake, int nr_requeue,
* @nr_requeue: requeue up to this many tasks
*/
static inline int
-futex_cmp_requeue(futex_t *uaddr, futex_t val, futex_t *uaddr2, int nr_wake,
- int nr_requeue, int opflags)
+futex_cmp_requeue(enum futex_fn_type fntype, futex_t *uaddr, futex_t val,
+ futex_t *uaddr2, int nr_wake, int nr_requeue, int opflags)
{
- return futex(uaddr, FUTEX_CMP_REQUEUE, nr_wake, nr_requeue, uaddr2,
- val, opflags);
+ return futex_syscall(fntype, uaddr, FUTEX_CMP_REQUEUE, nr_wake,
+ (void *)((unsigned long)nr_requeue), uaddr2, val,
+ opflags);
}
/**
@@ -217,11 +243,11 @@ futex_cmp_requeue(futex_t *uaddr, futex_t val, futex_t *uaddr2, int nr_wake,
* paired with futex_cmp_requeue_pi().
*/
static inline int
-futex_wait_requeue_pi(futex_t *uaddr, futex_t val, futex_t *uaddr2,
- struct timespec *timeout, int opflags)
+futex_wait_requeue_pi(enum futex_fn_type fntype, futex_t *uaddr, futex_t val,
+ futex_t *uaddr2, struct tst_ts *timeout, int opflags)
{
- return futex(uaddr, FUTEX_WAIT_REQUEUE_PI, val, timeout, uaddr2, 0,
- opflags);
+ return futex_syscall(fntype, uaddr, FUTEX_WAIT_REQUEUE_PI, val,
+ tst_ts_get(timeout), uaddr2, 0, opflags);
}
/**
@@ -232,11 +258,12 @@ futex_wait_requeue_pi(futex_t *uaddr, futex_t val, futex_t *uaddr2,
* @nr_requeue: requeue up to this many tasks
*/
static inline int
-futex_cmp_requeue_pi(futex_t *uaddr, futex_t val, futex_t *uaddr2, int nr_wake,
- int nr_requeue, int opflags)
+futex_cmp_requeue_pi(enum futex_fn_type fntype, futex_t *uaddr, futex_t val,
+ futex_t *uaddr2, int nr_wake, int nr_requeue, int opflags)
{
- return futex(uaddr, FUTEX_CMP_REQUEUE_PI, nr_wake, nr_requeue, uaddr2, val,
- opflags);
+ return futex_syscall(fntype, uaddr, FUTEX_CMP_REQUEUE_PI, nr_wake,
+ (void *)((unsigned long)nr_requeue), uaddr2, val,
+ opflags);
}
/**
--
2.25.0.rc1.19.g042ed3e048af
^ permalink raw reply related [flat|nested] 15+ messages in thread* [LTP] [PATCH 2/8] syscalls/futex: Add support for time64 tests
2020-05-05 9:12 ` [LTP] [PATCH 2/8] syscalls/futex: Add support for time64 tests Viresh Kumar
@ 2020-05-07 14:52 ` Petr Vorel
2020-05-08 3:30 ` Viresh Kumar
2020-05-07 15:19 ` Petr Vorel
1 sibling, 1 reply; 15+ messages in thread
From: Petr Vorel @ 2020-05-07 14:52 UTC (permalink / raw)
To: ltp
Hi,
FYI, 2nd and 6th patch didn't apply cleanly.
Trivial fixes, but for anybody who is lazy to repeat the work here it's done:
https://github.com/pevik/ltp/tree/Viresh_Kumar/futex_wait_bitset.v1
Kind regards,
Petr
^ permalink raw reply [flat|nested] 15+ messages in thread
* [LTP] [PATCH 2/8] syscalls/futex: Add support for time64 tests
2020-05-07 14:52 ` Petr Vorel
@ 2020-05-08 3:30 ` Viresh Kumar
2020-05-08 4:24 ` Viresh Kumar
0 siblings, 1 reply; 15+ messages in thread
From: Viresh Kumar @ 2020-05-08 3:30 UTC (permalink / raw)
To: ltp
On 07-05-20, 16:52, Petr Vorel wrote:
> Hi,
>
> FYI, 2nd and 6th patch didn't apply cleanly.
> Trivial fixes, but for anybody who is lazy to repeat the work here it's done:
> https://github.com/pevik/ltp/tree/Viresh_Kumar/futex_wait_bitset.v1
I was wondering on why it won't rebase properly, unless I tried to do
it again the way you have it. I forgot to mention that these patches
were based on the earlier patches I sent and so there was some
dependency in tst_timer.h. If you apply following series first, you
won't get these rebase issues.
[PATCH 1/4] syscalls/timer_gettime: Add support for time64 tests
Will it be easier if I resend all my patches again in a single series
? I can also add the new tests I have converted then.
--
viresh
^ permalink raw reply [flat|nested] 15+ messages in thread
* [LTP] [PATCH 2/8] syscalls/futex: Add support for time64 tests
2020-05-08 3:30 ` Viresh Kumar
@ 2020-05-08 4:24 ` Viresh Kumar
2020-05-08 6:55 ` Petr Vorel
0 siblings, 1 reply; 15+ messages in thread
From: Viresh Kumar @ 2020-05-08 4:24 UTC (permalink / raw)
To: ltp
On 08-05-20, 09:00, Viresh Kumar wrote:
> On 07-05-20, 16:52, Petr Vorel wrote:
> > Hi,
> >
> > FYI, 2nd and 6th patch didn't apply cleanly.
> > Trivial fixes, but for anybody who is lazy to repeat the work here it's done:
> > https://github.com/pevik/ltp/tree/Viresh_Kumar/futex_wait_bitset.v1
>
> I was wondering on why it won't rebase properly, unless I tried to do
> it again the way you have it. I forgot to mention that these patches
> were based on the earlier patches I sent and so there was some
> dependency in tst_timer.h. If you apply following series first, you
> won't get these rebase issues.
>
> [PATCH 1/4] syscalls/timer_gettime: Add support for time64 tests
>
> Will it be easier if I resend all my patches again in a single series
> ? I can also add the new tests I have converted then.
Okay, I cleaned up the GPL licensing thing and resent everything in a
single series. That should simplify everyone's life.
--
viresh
^ permalink raw reply [flat|nested] 15+ messages in thread
* [LTP] [PATCH 2/8] syscalls/futex: Add support for time64 tests
2020-05-08 4:24 ` Viresh Kumar
@ 2020-05-08 6:55 ` Petr Vorel
2020-05-08 7:03 ` Viresh Kumar
0 siblings, 1 reply; 15+ messages in thread
From: Petr Vorel @ 2020-05-08 6:55 UTC (permalink / raw)
To: ltp
Hi Viresh,
> > Will it be easier if I resend all my patches again in a single series
> > ? I can also add the new tests I have converted then.
> Okay, I cleaned up the GPL licensing thing and resent everything in a
> single series. That should simplify everyone's life.
Thanks a lot!
It might not make it to this release (freeze should be from Monday and probably
nobody from reviewers work on the weekend + there is a bank holiday today for
some countries).
Kind regards,
Petr
^ permalink raw reply [flat|nested] 15+ messages in thread
* [LTP] [PATCH 2/8] syscalls/futex: Add support for time64 tests
2020-05-08 6:55 ` Petr Vorel
@ 2020-05-08 7:03 ` Viresh Kumar
0 siblings, 0 replies; 15+ messages in thread
From: Viresh Kumar @ 2020-05-08 7:03 UTC (permalink / raw)
To: ltp
On 08-05-20, 08:55, Petr Vorel wrote:
> It might not make it to this release (freeze should be from Monday and probably
> nobody from reviewers work on the weekend + there is a bank holiday today for
> some countries).
That should be fine. I just wanted to post everything I had planned
for LTP :)
I may not have any more significant patches after this. :)
--
viresh
^ permalink raw reply [flat|nested] 15+ messages in thread
* [LTP] [PATCH 2/8] syscalls/futex: Add support for time64 tests
2020-05-05 9:12 ` [LTP] [PATCH 2/8] syscalls/futex: Add support for time64 tests Viresh Kumar
2020-05-07 14:52 ` Petr Vorel
@ 2020-05-07 15:19 ` Petr Vorel
1 sibling, 0 replies; 15+ messages in thread
From: Petr Vorel @ 2020-05-07 15:19 UTC (permalink / raw)
To: ltp
> This adds support for time64 tests to the existing futex() syscall
> tests.
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Nice!
I'd personally drop that bogus GPL text and replace it with SPDX,
but that's unimportant and can be done later.
BTW I guess it's already git freeze before release, otherwise I'd merge these
two.
Kind regards,
Petr
^ permalink raw reply [flat|nested] 15+ messages in thread
* [LTP] [PATCH 3/8] syscalls/io_pgetevents: Add support for time64 tests
2020-05-05 9:12 [LTP] [PATCH 1/8] syscalls/futex: Merge futex_wait_bitset tests Viresh Kumar
2020-05-05 9:12 ` [LTP] [PATCH 2/8] syscalls/futex: Add support for time64 tests Viresh Kumar
@ 2020-05-05 9:12 ` Viresh Kumar
2020-05-05 9:12 ` [LTP] [PATCH 4/8] syscalls/sigwaitinfo: Migrate to new test framework Viresh Kumar
` (5 subsequent siblings)
7 siblings, 0 replies; 15+ messages in thread
From: Viresh Kumar @ 2020-05-05 9:12 UTC (permalink / raw)
To: ltp
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.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
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(-)
diff --git a/include/lapi/io_pgetevents.h b/include/lapi/io_pgetevents.h
index 3c9d5b2d7618..5bb9a60c352a 100644
--- a/include/lapi/io_pgetevents.h
+++ b/include/lapi/io_pgetevents.h
@@ -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 */
diff --git a/testcases/kernel/syscalls/io_pgetevents/io_pgetevents01.c b/testcases/kernel/syscalls/io_pgetevents/io_pgetevents01.c
index 50d2c5f9a3ab..f99879c07ea6 100644
--- a/testcases/kernel/syscalls/io_pgetevents/io_pgetevents01.c
+++ b/testcases/kernel/syscalls/io_pgetevents/io_pgetevents01.c
@@ -6,11 +6,38 @@
* Basic io_pgetevents() test to receive 1 event successfully.
*/
#include "tst_test.h"
+#include "tst_timer.h"
#include "lapi/io_pgetevents.h"
+#include "lapi/abisize.h"
#ifdef HAVE_LIBAIO
static int fd;
+static struct test_variants {
+ int (*io_pgetevents)(io_context_t ctx, long min_nr, long max_nr,
+ struct io_event *events, void *timeout, sigset_t *sigmask);
+ enum tst_ts_type type;
+ char *desc;
+} variants[] = {
+#if defined(TST_ABI32)
+ { .io_pgetevents = sys_io_pgetevents, .type = TST_LIBC_TIMESPEC, .desc = "syscall with libc spec"},
+ { .io_pgetevents = sys_io_pgetevents, .type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with kernel spec32"},
+#endif
+
+#if defined(TST_ABI64)
+ { .io_pgetevents = sys_io_pgetevents, .type = TST_KERN_TIMESPEC, .desc = "syscall with kernel spec64"},
+#endif
+
+#if (__NR_io_pgetevents_time64 != __LTP__NR_INVALID_SYSCALL)
+ { .io_pgetevents = sys_io_pgetevents_time64, .type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec64"},
+#endif
+};
+
+static void setup(void)
+{
+ tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
+}
+
static void cleanup(void)
{
if (fd > 0)
@@ -19,17 +46,23 @@ static void cleanup(void)
static void run(void)
{
+ struct test_variants *tv = &variants[tst_variant];
struct io_event events[1];
struct iocb cb, *cbs[1];
io_context_t ctx = 0;
+ struct tst_ts to;
sigset_t sigmask;
char data[4096];
- int ret, fd;
+ int ret;
+
+ to.type = tv->type;
+ tst_ts_set_sec(&to, 0);
+ tst_ts_set_nsec(&to, 10000);
cbs[0] = &cb;
sigemptyset(&sigmask);
- fd = SAFE_OPEN("io_pgetevents_file", O_RDWR | O_CREAT);
+ fd = SAFE_OPEN("io_pgetevents_file", O_RDWR | O_CREAT, 0644);
io_prep_pwrite(&cb, fd, data, 4096, 0);
ret = io_setup(1, &ctx);
@@ -41,7 +74,7 @@ static void run(void)
tst_brk(TBROK | TERRNO, "io_submit() failed");
/* get the reply */
- ret = io_pgetevents(ctx, 1, 1, events, NULL, &sigmask);
+ ret = tv->io_pgetevents(ctx, 1, 1, events, tst_ts_get(&to), &sigmask);
if (ret == 1)
tst_res(TPASS, "io_pgetevents() works as expected");
@@ -55,8 +88,10 @@ static void run(void)
static struct tst_test test = {
.min_kver = "4.18",
.test_all = run,
+ .test_variants = ARRAY_SIZE(variants),
.needs_tmpdir = 1,
.cleanup = cleanup,
+ .setup = setup,
};
#else
diff --git a/testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c b/testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c
index 7cca7fc08567..7c0c6806d005 100644
--- a/testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c
+++ b/testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c
@@ -6,7 +6,9 @@
* Basic io_pgetevents() test to check various failures.
*/
#include "tst_test.h"
+#include "tst_timer.h"
#include "lapi/io_pgetevents.h"
+#include "lapi/abisize.h"
#ifdef HAVE_LIBAIO
static sigset_t sigmask;
@@ -14,35 +16,65 @@ static struct io_event events[1];
static io_context_t ctx, invalid_ctx = 0;
static int fd, ctx_initialized;
+static struct tst_ts to;
+static void *bad_addr;
+
static struct tcase {
char *name;
io_context_t *ctx;
long min_nr;
long max_nr;
struct io_event *events;
- struct timespec *timeout;
+ struct tst_ts *timeout;
sigset_t *sigmask;
int exp_errno;
} tcases[] = {
- {"invalid ctx", &invalid_ctx, 1, 1, events, NULL, &sigmask, EINVAL},
- {"invalid min_nr", &ctx, -1, 1, events, NULL, &sigmask, EINVAL},
- {"invalid max_nr", &ctx, 1, -1, events, NULL, &sigmask, EINVAL},
- {"invalid events", &ctx, 1, 1, NULL, NULL, &sigmask, EFAULT},
- {"invalid timeout", &ctx, 1, 1, events, (void *)(0xDEAD), &sigmask, EFAULT},
- {"invalid sigmask", &ctx, 1, 1, events, NULL, (void *)(0xDEAD), EFAULT},
+ {"invalid ctx", &invalid_ctx, 1, 1, events, &to, &sigmask, EINVAL},
+ {"invalid min_nr", &ctx, -1, 1, events, &to, &sigmask, EINVAL},
+ {"invalid max_nr", &ctx, 1, -1, events, &to, &sigmask, EINVAL},
+ {"invalid events", &ctx, 1, 1, NULL, &to, &sigmask, EFAULT},
+ {"invalid timeout", &ctx, 1, 1, events, NULL, &sigmask, EFAULT},
+ {"invalid sigmask", &ctx, 1, 1, events, &to, NULL, EFAULT},
+};
+
+static struct test_variants {
+ int (*io_pgetevents)(io_context_t ctx, long min_nr, long max_nr,
+ struct io_event *events, void *timeout, sigset_t *sigmask);
+ enum tst_ts_type type;
+ char *desc;
+} variants[] = {
+#if defined(TST_ABI32)
+ { .io_pgetevents = sys_io_pgetevents, .type = TST_LIBC_TIMESPEC, .desc = "syscall with libc spec"},
+ { .io_pgetevents = sys_io_pgetevents, .type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with kernel spec32"},
+#endif
+
+#if defined(TST_ABI64)
+ { .io_pgetevents = sys_io_pgetevents, .type = TST_KERN_TIMESPEC, .desc = "syscall with kernel spec64"},
+#endif
+
+#if (__NR_io_pgetevents_time64 != __LTP__NR_INVALID_SYSCALL)
+ { .io_pgetevents = sys_io_pgetevents_time64, .type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec64"},
+#endif
};
static void setup(void)
{
+ struct test_variants *tv = &variants[tst_variant];
struct iocb cb, *cbs[1];
char data[4096];
int ret;
+ tst_res(TINFO, "Testing variant: %s", tv->desc);
+ bad_addr = tst_get_bad_addr(NULL);
+ to.type = tv->type;
+ tst_ts_set_sec(&to, 0);
+ tst_ts_set_nsec(&to, 10000);
+
cbs[0] = &cb;
sigemptyset(&sigmask);
- fd = SAFE_OPEN("io_pgetevents_file", O_RDWR | O_CREAT);
+ fd = SAFE_OPEN("io_pgetevents_file", O_RDWR | O_CREAT, 0644);
io_prep_pwrite(&cb, fd, data, 4096, 0);
ret = io_setup(1, &ctx);
@@ -69,10 +101,16 @@ static void cleanup(void)
static void run(unsigned int n)
{
+ struct test_variants *tv = &variants[tst_variant];
struct tcase *tc = &tcases[n];
+ struct timespec *to;
+ sigset_t *sigmask;
+
+ sigmask = tc->sigmask ? tc->sigmask : bad_addr;
+ to = tc->timeout ? tc->timeout : bad_addr;
- TEST(io_pgetevents(*tc->ctx, tc->min_nr, tc->max_nr, tc->events,
- tc->timeout, tc->sigmask));
+ TEST(tv->io_pgetevents(*tc->ctx, tc->min_nr, tc->max_nr, tc->events, to,
+ sigmask));
if (TST_RET == 1) {
tst_res(TFAIL, "%s: io_pgetevents() passed unexpectedly",
@@ -95,6 +133,7 @@ static struct tst_test test = {
.needs_tmpdir = 1,
.tcnt = ARRAY_SIZE(tcases),
.test = run,
+ .test_variants = ARRAY_SIZE(variants),
.setup = setup,
.cleanup = cleanup,
};
--
2.25.0.rc1.19.g042ed3e048af
^ permalink raw reply related [flat|nested] 15+ messages in thread* [LTP] [PATCH 4/8] syscalls/sigwaitinfo: Migrate to new test framework
2020-05-05 9:12 [LTP] [PATCH 1/8] syscalls/futex: Merge futex_wait_bitset tests Viresh Kumar
2020-05-05 9:12 ` [LTP] [PATCH 2/8] syscalls/futex: Add support for time64 tests Viresh Kumar
2020-05-05 9:12 ` [LTP] [PATCH 3/8] syscalls/io_pgetevents: " Viresh Kumar
@ 2020-05-05 9:12 ` Viresh Kumar
2020-05-05 9:12 ` [LTP] [PATCH 5/8] syscalls/rt_sigtimedwait: Add support for time64 tests Viresh Kumar
` (4 subsequent siblings)
7 siblings, 0 replies; 15+ messages in thread
From: Viresh Kumar @ 2020-05-05 9:12 UTC (permalink / raw)
To: ltp
This migrates the sigwaitinfo tests to use the new test framework.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
.../syscalls/sigwaitinfo/sigwaitinfo01.c | 184 ++++++++----------
1 file changed, 81 insertions(+), 103 deletions(-)
diff --git a/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c b/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c
index 6a30c27f6f2f..4eee27b0db29 100644
--- a/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c
+++ b/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c
@@ -20,74 +20,58 @@
* with this program; if not, write the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include "test.h"
+#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 +94,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 +102,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 +111,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 +123,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 +142,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 +164,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 +183,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 +210,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 +220,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 +252,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 +265,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 +274,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 +298,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 +306,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 +333,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 +341,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 +352,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 +362,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 +459,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;
+ struct test_desc *tc = &tests[i];
- tst_parse_opts(argc, argv, NULL, NULL);
-
- 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,
+};
--
2.25.0.rc1.19.g042ed3e048af
^ permalink raw reply related [flat|nested] 15+ messages in thread* [LTP] [PATCH 5/8] syscalls/rt_sigtimedwait: Add support for time64 tests
2020-05-05 9:12 [LTP] [PATCH 1/8] syscalls/futex: Merge futex_wait_bitset tests Viresh Kumar
` (2 preceding siblings ...)
2020-05-05 9:12 ` [LTP] [PATCH 4/8] syscalls/sigwaitinfo: Migrate to new test framework Viresh Kumar
@ 2020-05-05 9:12 ` Viresh Kumar
2020-05-05 9:12 ` [LTP] [PATCH 6/8] syscalls/mq_timed{send|receive}: " Viresh Kumar
` (3 subsequent siblings)
7 siblings, 0 replies; 15+ messages in thread
From: Viresh Kumar @ 2020-05-05 9:12 UTC (permalink / raw)
To: ltp
This adds support for time64 tests to the existing rt_sigtimedwait()
syscall tests.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
.../syscalls/sigwaitinfo/sigwaitinfo01.c | 118 +++++++++++++-----
1 file changed, 86 insertions(+), 32 deletions(-)
diff --git a/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c b/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c
index 4eee27b0db29..404036c40aac 100644
--- a/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c
+++ b/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c
@@ -21,11 +21,13 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#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, ...) \
@@ -73,12 +75,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);
@@ -92,7 +94,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);
}
@@ -100,7 +102,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);
}
@@ -108,14 +110,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;
@@ -132,19 +143,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);
@@ -154,7 +169,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;
@@ -175,7 +191,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;
@@ -192,7 +209,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;
@@ -230,7 +248,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;
@@ -281,7 +300,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;
@@ -316,7 +336,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;
@@ -345,7 +365,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;
@@ -391,7 +411,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);
@@ -407,28 +427,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
{
@@ -459,15 +479,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);
@@ -483,6 +536,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,
--
2.25.0.rc1.19.g042ed3e048af
^ permalink raw reply related [flat|nested] 15+ messages in thread* [LTP] [PATCH 6/8] syscalls/mq_timed{send|receive}: Add support for time64 tests
2020-05-05 9:12 [LTP] [PATCH 1/8] syscalls/futex: Merge futex_wait_bitset tests Viresh Kumar
` (3 preceding siblings ...)
2020-05-05 9:12 ` [LTP] [PATCH 5/8] syscalls/rt_sigtimedwait: Add support for time64 tests Viresh Kumar
@ 2020-05-05 9:12 ` Viresh Kumar
2020-05-05 9:12 ` [LTP] [PATCH 7/8] syscalls/recvmmsg: " Viresh Kumar
` (2 subsequent siblings)
7 siblings, 0 replies; 15+ messages in thread
From: Viresh Kumar @ 2020-05-05 9:12 UTC (permalink / raw)
To: ltp
This adds support for time64 tests to the existing
mq_timed{send|receive}() syscall tests.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
include/tst_timer.h | 41 +++++++++
.../mq_timedreceive/mq_timedreceive01.c | 83 ++++++++++++++----
.../syscalls/mq_timedsend/mq_timedsend01.c | 87 +++++++++++++++----
testcases/kernel/syscalls/utils/mq_timed.h | 28 +++---
4 files changed, 189 insertions(+), 50 deletions(-)
diff --git a/include/tst_timer.h b/include/tst_timer.h
index b4280042c77f..28f11c7376b4 100644
--- a/include/tst_timer.h
+++ b/include/tst_timer.h
@@ -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);
diff --git a/testcases/kernel/syscalls/mq_timedreceive/mq_timedreceive01.c b/testcases/kernel/syscalls/mq_timedreceive/mq_timedreceive01.c
index 1be515ced671..0ba88b9552cc 100644
--- a/testcases/kernel/syscalls/mq_timedreceive/mq_timedreceive01.c
+++ b/testcases/kernel/syscalls/mq_timedreceive/mq_timedreceive01.c
@@ -23,12 +23,13 @@
#include <errno.h>
#include <limits.h>
+#include "lapi/abisize.h"
static int fd, fd_root, fd_nonblock, fd_maxint = INT_MAX - 1, fd_invalid = -1;
#include "mq_timed.h"
-static struct timespec ts;
+static struct tst_ts ts;
static struct test_case tcase[] = {
{
@@ -95,21 +96,27 @@ static struct test_case tcase[] = {
{
.fd = &fd,
.len = 16,
- .rq = &(struct timespec) {.tv_sec = -1, .tv_nsec = 0},
+ .tv_sec = -1,
+ .tv_nsec = 0,
+ .rq = &ts,
.ret = -1,
.err = EINVAL,
},
{
.fd = &fd,
.len = 16,
- .rq = &(struct timespec) {.tv_sec = 0, .tv_nsec = -1},
+ .tv_sec = 0,
+ .tv_nsec = -1,
+ .rq = &ts,
.ret = -1,
.err = EINVAL,
},
{
.fd = &fd,
.len = 16,
- .rq = &(struct timespec) {.tv_sec = 0, .tv_nsec = 1000000000},
+ .tv_sec = 0,
+ .tv_nsec = 1000000000,
+ .rq = &ts,
.ret = -1,
.err = EINVAL,
},
@@ -131,8 +138,44 @@ static struct test_case tcase[] = {
},
};
+static struct test_variants {
+ int (*send)(mqd_t mqdes, const char *msg_ptr, size_t msg_len,
+ unsigned int msg_prio, void *abs_timeout);
+ ssize_t (*receive)(mqd_t mqdes, char *msg_ptr, size_t msg_len,
+ unsigned int *msg_prio, void *abs_timeout);
+
+ int (*gettime)(clockid_t clk_id, void *ts);
+ enum tst_ts_type type;
+ char *desc;
+} variants[] = {
+#if defined(TST_ABI32)
+ { .gettime = libc_clock_gettime, .send = libc_mq_timedsend, .receive = libc_mq_timedreceive, .type = TST_LIBC_TIMESPEC, .desc = "vDSO or syscall with libc spec"},
+ { .gettime = sys_clock_gettime, .send = sys_mq_timedsend, .receive = sys_mq_timedreceive, .type = TST_LIBC_TIMESPEC, .desc = "syscall with libc spec"},
+ { .gettime = sys_clock_gettime, .send = sys_mq_timedsend, .receive = sys_mq_timedreceive, .type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with kernel spec32"},
+#endif
+
+#if defined(TST_ABI64)
+ { .gettime = sys_clock_gettime, .send = sys_mq_timedsend, .receive = sys_mq_timedreceive, .type = TST_KERN_TIMESPEC, .desc = "syscall with kernel spec64"},
+#endif
+
+#if (__NR_mq_timedsend_time64 != __LTP__NR_INVALID_SYSCALL)
+ { .gettime = sys_clock_gettime64, .send = sys_mq_timedsend64, .receive = sys_mq_timedreceive64, .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);
+ ts.type = tv->type;
+
+ setup_common();
+}
+
static void do_test(unsigned int i)
{
+ struct test_variants *tv = &variants[tst_variant];
const struct test_case *tc = &tcase[i];
unsigned int j;
unsigned int prio;
@@ -140,19 +183,26 @@ static void do_test(unsigned int i)
char rmsg[len];
pid_t pid = -1;
+ tst_ts_set_sec(&ts, tc->tv_sec);
+ tst_ts_set_nsec(&ts, tc->tv_nsec);
+
if (tc->signal)
- pid = set_sig(tc->rq);
+ pid = set_sig(tc->rq, tv->gettime);
if (tc->timeout)
- set_timeout(tc->rq);
+ set_timeout(tc->rq, tv->gettime);
- if (tc->send)
- send_msg(*tc->fd, tc->len, tc->prio);
+ if (tc->send) {
+ if (tv->send(*tc->fd, smsg, tc->len, tc->prio, NULL) < 0) {
+ tst_res(TFAIL | TTERRNO, "mq_timedsend() failed");
+ return;
+ }
+ }
if (tc->invalid_msg)
len -= 1;
- TEST(mq_timedreceive(*tc->fd, rmsg, len, &prio, tc->rq));
+ TEST(tv->receive(*tc->fd, rmsg, len, &prio, tst_ts_get(tc->rq)));
if (pid > 0)
kill_pid(pid);
@@ -163,22 +213,22 @@ static void do_test(unsigned int i)
if (TST_RET < 0) {
if (tc->err != TST_ERR)
tst_res(TFAIL | TTERRNO,
- "mq_timedreceive failed unexpectedly, expected %s",
+ "mq_timedreceive() failed unexpectedly, expected %s",
tst_strerrno(tc->err));
else
- tst_res(TPASS | TTERRNO, "mq_timedreceive failed expectedly");
+ tst_res(TPASS | TTERRNO, "mq_timedreceive() failed expectedly");
return;
}
if (tc->len != TST_RET) {
- tst_res(TFAIL, "mq_timedreceive wrong length %ld, expected %zu",
+ tst_res(TFAIL, "mq_timedreceive() wrong length %ld, expected %u",
TST_RET, tc->len);
return;
}
if (tc->prio != prio) {
- tst_res(TFAIL, "mq_timedreceive wrong prio %d, expected %d",
+ tst_res(TFAIL, "mq_timedreceive() wrong prio %d, expected %d",
prio, tc->prio);
return;
}
@@ -186,20 +236,21 @@ static void do_test(unsigned int i)
for (j = 0; j < tc->len; j++) {
if (rmsg[j] != smsg[j]) {
tst_res(TFAIL,
- "mq_timedreceive wrong data %d in %u, expected %d",
+ "mq_timedreceive() wrong data %d in %u, expected %d",
rmsg[j], i, smsg[j]);
return;
}
}
- tst_res(TPASS, "mq_timedreceive returned %ld, priority %u, length: %zu",
+ tst_res(TPASS, "mq_timedreceive() returned %ld, priority %u, length: %zu",
TST_RET, prio, len);
}
static struct tst_test test = {
.tcnt = ARRAY_SIZE(tcase),
.test = do_test,
- .setup = setup_common,
+ .test_variants = ARRAY_SIZE(variants),
+ .setup = setup,
.cleanup = cleanup_common,
.forks_child = 1,
};
diff --git a/testcases/kernel/syscalls/mq_timedsend/mq_timedsend01.c b/testcases/kernel/syscalls/mq_timedsend/mq_timedsend01.c
index 8f209d396040..2206b5199ab8 100644
--- a/testcases/kernel/syscalls/mq_timedsend/mq_timedsend01.c
+++ b/testcases/kernel/syscalls/mq_timedsend/mq_timedsend01.c
@@ -23,12 +23,14 @@
#include <errno.h>
#include <limits.h>
+#include "lapi/abisize.h"
static int fd, fd_root, fd_nonblock, fd_maxint = INT_MAX - 1, fd_invalid = -1;
-static struct timespec ts;
#include "mq_timed.h"
+static struct tst_ts ts;
+
static struct test_case tcase[] = {
{
.fd = &fd,
@@ -95,7 +97,9 @@ static struct test_case tcase[] = {
{
.fd = &fd,
.len = 16,
- .rq = &(struct timespec) {.tv_sec = -1, .tv_nsec = 0},
+ .tv_sec = -1,
+ .tv_nsec = 0,
+ .rq = &ts,
.send = 1,
.ret = -1,
.err = EINVAL,
@@ -103,7 +107,9 @@ static struct test_case tcase[] = {
{
.fd = &fd,
.len = 16,
- .rq = &(struct timespec) {.tv_sec = 0, .tv_nsec = -1},
+ .tv_sec = 0,
+ .tv_nsec = -1,
+ .rq = &ts,
.send = 1,
.ret = -1,
.err = EINVAL,
@@ -111,7 +117,9 @@ static struct test_case tcase[] = {
{
.fd = &fd,
.len = 16,
- .rq = &(struct timespec) {.tv_sec = 0, .tv_nsec = 1000000000},
+ .tv_sec = 0,
+ .tv_nsec = 1000000000,
+ .rq = &ts,
.send = 1,
.ret = -1,
.err = EINVAL,
@@ -136,8 +144,44 @@ static struct test_case tcase[] = {
},
};
+static struct test_variants {
+ int (*send)(mqd_t mqdes, const char *msg_ptr, size_t msg_len,
+ unsigned int msg_prio, void *abs_timeout);
+ ssize_t (*receive)(mqd_t mqdes, char *msg_ptr, size_t msg_len,
+ unsigned int *msg_prio, void *abs_timeout);
+
+ int (*gettime)(clockid_t clk_id, void *ts);
+ enum tst_ts_type type;
+ char *desc;
+} variants[] = {
+#if defined(TST_ABI32)
+ { .gettime = libc_clock_gettime, .send = libc_mq_timedsend, .receive = libc_mq_timedreceive, .type = TST_LIBC_TIMESPEC, .desc = "vDSO or syscall with libc spec"},
+ { .gettime = sys_clock_gettime, .send = sys_mq_timedsend, .receive = sys_mq_timedreceive, .type = TST_LIBC_TIMESPEC, .desc = "syscall with libc spec"},
+ { .gettime = sys_clock_gettime, .send = sys_mq_timedsend, .receive = sys_mq_timedreceive, .type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with kernel spec32"},
+#endif
+
+#if defined(TST_ABI64)
+ { .gettime = sys_clock_gettime, .send = sys_mq_timedsend, .receive = sys_mq_timedreceive, .type = TST_KERN_TIMESPEC, .desc = "syscall with kernel spec64"},
+#endif
+
+#if (__NR_mq_timedsend_time64 != __LTP__NR_INVALID_SYSCALL)
+ { .gettime = sys_clock_gettime64, .send = sys_mq_timedsend64, .receive = sys_mq_timedreceive64, .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);
+ ts.type = tv->type;
+
+ setup_common();
+}
+
static void do_test(unsigned int i)
{
+ struct test_variants *tv = &variants[tst_variant];
const struct test_case *tc = &tcase[i];
unsigned int j;
unsigned int prio;
@@ -145,18 +189,24 @@ static void do_test(unsigned int i)
char rmsg[len];
pid_t pid = -1;
+ tst_ts_set_sec(&ts, tc->tv_sec);
+ tst_ts_set_nsec(&ts, tc->tv_nsec);
+
if (tc->signal)
- pid = set_sig(tc->rq);
+ pid = set_sig(tc->rq, tv->gettime);
if (tc->timeout)
- set_timeout(tc->rq);
+ set_timeout(tc->rq, tv->gettime);
if (tc->send) {
for (j = 0; j < MSG_LENGTH; j++)
- send_msg(*tc->fd, tc->len, tc->prio);
+ if (tv->send(*tc->fd, smsg, tc->len, tc->prio, NULL) < 0) {
+ tst_res(TFAIL | TTERRNO, "mq_timedsend() failed");
+ return;
+ }
}
- TEST(mq_timedsend(*tc->fd, smsg, tc->len, tc->prio, tc->rq));
+ TEST(tv->send(*tc->fd, smsg, tc->len, tc->prio, tst_ts_get(tc->rq)));
if (pid > 0)
kill_pid(pid);
@@ -164,10 +214,10 @@ static void do_test(unsigned int i)
if (TST_RET < 0) {
if (tc->err != TST_ERR)
tst_res(TFAIL | TTERRNO,
- "mq_timedsend failed unexpectedly, expected %s",
+ "mq_timedsend() failed unexpectedly, expected %s",
tst_strerrno(tc->err));
else
- tst_res(TPASS | TTERRNO, "mq_timedreceive failed expectedly");
+ tst_res(TPASS | TTERRNO, "mq_timedreceive() failed expectedly");
if (*tc->fd == fd)
cleanup_queue(fd);
@@ -175,7 +225,7 @@ static void do_test(unsigned int i)
return;
}
- TEST(mq_timedreceive(*tc->fd, rmsg, len, &prio, tc->rq));
+ TEST(tv->receive(*tc->fd, rmsg, len, &prio, tst_ts_get(tc->rq)));
if (*tc->fd == fd)
cleanup_queue(fd);
@@ -183,26 +233,26 @@ static void do_test(unsigned int i)
if (TST_RET < 0) {
if (tc->err != TST_ERR) {
tst_res(TFAIL | TTERRNO,
- "mq_timedreceive failed unexpectedly, expected %s",
+ "mq_timedreceive() failed unexpectedly, expected %s",
tst_strerrno(tc->err));
return;
}
if (tc->ret >= 0) {
- tst_res(TFAIL | TTERRNO, "mq_timedreceive returned %ld, expected %d",
+ tst_res(TFAIL | TTERRNO, "mq_timedreceive() returned %ld, expected %d",
TST_RET, tc->ret);
return;
}
}
if (tc->len != TST_RET) {
- tst_res(TFAIL, "mq_timedreceive wrong length %ld, expected %d",
+ tst_res(TFAIL, "mq_timedreceive() wrong length %ld, expected %u",
TST_RET, tc->len);
return;
}
if (tc->prio != prio) {
- tst_res(TFAIL, "mq_timedreceive wrong prio %d, expected %d",
+ tst_res(TFAIL, "mq_timedreceive() wrong prio %d, expected %d",
prio, tc->prio);
return;
}
@@ -210,20 +260,21 @@ static void do_test(unsigned int i)
for (j = 0; j < tc->len; j++) {
if (rmsg[j] != smsg[j]) {
tst_res(TFAIL,
- "mq_timedreceive wrong data %d in %u, expected %d",
+ "mq_timedreceive() wrong data %d in %u, expected %d",
rmsg[j], i, smsg[j]);
return;
}
}
- tst_res(TPASS, "mq_timedreceive returned %ld, priority %u, length: %zu",
+ tst_res(TPASS, "mq_timedreceive() returned %ld, priority %u, length: %zu",
TST_RET, prio, len);
}
static struct tst_test test = {
.tcnt = ARRAY_SIZE(tcase),
.test = do_test,
- .setup = setup_common,
+ .test_variants = ARRAY_SIZE(variants),
+ .setup = setup,
.cleanup = cleanup_common,
.forks_child = 1,
};
diff --git a/testcases/kernel/syscalls/utils/mq_timed.h b/testcases/kernel/syscalls/utils/mq_timed.h
index a163ddcee3af..85b316334d7f 100644
--- a/testcases/kernel/syscalls/utils/mq_timed.h
+++ b/testcases/kernel/syscalls/utils/mq_timed.h
@@ -19,12 +19,15 @@
#define MQ_TIMED_H
#include "mq.h"
+#include "tst_timer.h"
struct test_case {
int *fd;
unsigned int len;
unsigned int prio;
- struct timespec *rq;
+ struct tst_ts *rq;
+ long tv_sec;
+ long tv_nsec;
int invalid_msg;
int send;
int signal;
@@ -33,27 +36,20 @@ struct test_case {
int err;
};
-static pid_t set_sig(struct timespec *ts)
+static pid_t set_sig(struct tst_ts *ts,
+ int (*gettime)(clockid_t clk_id, void *ts))
{
- clock_gettime(CLOCK_REALTIME, ts);
- ts->tv_sec += 3;
+ gettime(CLOCK_REALTIME, tst_ts_get(ts));
+ *ts = tst_ts_add_us(*ts, 3000000);
return create_sig_proc(SIGINT, 40, 200000);
}
-static void set_timeout(struct timespec *ts)
+static void set_timeout(struct tst_ts *ts,
+ int (*gettime)(clockid_t clk_id, void *ts))
{
- clock_gettime(CLOCK_REALTIME, ts);
- ts->tv_nsec += 50000000;
- ts->tv_sec += ts->tv_nsec / 1000000000;
- ts->tv_nsec %= 1000000000;
-}
-
-static void send_msg(int fd, int len, int prio)
-{
- if (mq_timedsend(fd, smsg, len, prio,
- &((struct timespec){0})) < 0)
- tst_brk(TBROK | TERRNO, "mq_timedsend failed");
+ gettime(CLOCK_REALTIME, tst_ts_get(ts));
+ *ts = tst_ts_add_us(*ts, 50000);
}
static void kill_pid(pid_t pid)
--
2.25.0.rc1.19.g042ed3e048af
^ permalink raw reply related [flat|nested] 15+ messages in thread* [LTP] [PATCH 7/8] syscalls/recvmmsg: Add support for time64 tests
2020-05-05 9:12 [LTP] [PATCH 1/8] syscalls/futex: Merge futex_wait_bitset tests Viresh Kumar
` (4 preceding siblings ...)
2020-05-05 9:12 ` [LTP] [PATCH 6/8] syscalls/mq_timed{send|receive}: " Viresh Kumar
@ 2020-05-05 9:12 ` Viresh Kumar
2020-05-05 9:12 ` [LTP] [PATCH 8/8] syscalls/ppoll: " Viresh Kumar
2020-05-07 14:59 ` [LTP] [PATCH 1/8] syscalls/futex: Merge futex_wait_bitset tests Petr Vorel
7 siblings, 0 replies; 15+ messages in thread
From: Viresh Kumar @ 2020-05-05 9:12 UTC (permalink / raw)
To: ltp
This adds support for time64 tests to the existing recvmmsg() syscall
tests.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
.../kernel/syscalls/sendmmsg/sendmmsg01.c | 45 +++++++++++----
.../kernel/syscalls/sendmmsg/sendmmsg_var.h | 55 ++++++++-----------
2 files changed, 58 insertions(+), 42 deletions(-)
diff --git a/testcases/kernel/syscalls/sendmmsg/sendmmsg01.c b/testcases/kernel/syscalls/sendmmsg/sendmmsg01.c
index 37084102ee09..5d1fd1b6b9fa 100644
--- a/testcases/kernel/syscalls/sendmmsg/sendmmsg01.c
+++ b/testcases/kernel/syscalls/sendmmsg/sendmmsg01.c
@@ -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}},
diff --git a/testcases/kernel/syscalls/sendmmsg/sendmmsg_var.h b/testcases/kernel/syscalls/sendmmsg/sendmmsg_var.h
index f00cf056a747..a142b17f9718 100644
--- a/testcases/kernel/syscalls/sendmmsg/sendmmsg_var.h
+++ b/testcases/kernel/syscalls/sendmmsg/sendmmsg_var.h
@@ -6,55 +6,46 @@
#ifndef SENDMMSG_VAR__
#define SENDMMSG_VAR__
+#include "tst_timer.h"
#include "lapi/syscalls.h"
-static int do_sendmmsg(int sockfd, struct mmsghdr *msgvec, unsigned int vlen,
- int flags)
+static inline int libc_sendmmsg(int sockfd, struct mmsghdr *msgvec,
+ unsigned int vlen, unsigned int flags)
{
- switch (tst_variant) {
- case 0:
- return tst_syscall(__NR_sendmmsg, sockfd, msgvec, vlen, flags);
- case 1:
#ifdef HAVE_SENDMMSG
- return sendmmsg(sockfd, msgvec, vlen, flags);
+ return sendmmsg(sockfd, msgvec, vlen, flags);
#else
- tst_brk(TCONF, "libc sendmmsg not present");
+ tst_brk(TCONF, "libc sendmmsg not present");
#endif
- }
+}
- return -1;
+static inline int sys_sendmmsg(int sockfd, struct mmsghdr *msgvec,
+ unsigned int vlen, unsigned int flags)
+{
+ return tst_syscall(__NR_sendmmsg, sockfd, msgvec, vlen, flags);
}
-static int do_recvmmsg(int sockfd, struct mmsghdr *msgvec, unsigned int vlen,
- int flags, struct timespec *timeout)
+static inline int libc_recvmmsg(int sockfd, struct mmsghdr *msgvec,
+ unsigned int vlen, unsigned int flags, void *timeout)
{
- switch (tst_variant) {
- case 0:
- return tst_syscall(__NR_recvmmsg, sockfd, msgvec, vlen, flags,
- timeout);
- case 1:
#ifdef HAVE_RECVMMSG
- return recvmmsg(sockfd, msgvec, vlen, flags, timeout);
+ return recvmmsg(sockfd, msgvec, vlen, flags, timeout);
#else
- tst_brk(TCONF, "libc recvmmsg not present");
+ tst_brk(TCONF, "libc recvmmsg not present");
#endif
- }
-
- return -1;
}
-static void test_info(void)
+static inline int sys_recvmmsg(int sockfd, struct mmsghdr *msgvec,
+ unsigned int vlen, unsigned int flags, void *timeout)
{
- switch (tst_variant) {
- case 0:
- tst_res(TINFO, "Testing direct sendmmsg and recvmmsg syscalls");
- break;
- case 1:
- tst_res(TINFO, "Testing libc sendmmsg and recvmmsg syscalls");
- break;
- }
+ return tst_syscall(__NR_recvmmsg, sockfd, msgvec, vlen, flags, timeout);
}
-#define TEST_VARIANTS 2
+static inline int sys_recvmmsg64(int sockfd, struct mmsghdr *msgvec,
+ unsigned int vlen, unsigned int flags, void *timeout)
+{
+ return tst_syscall(__NR_recvmmsg_time64, sockfd, msgvec, vlen, flags,
+ timeout);
+}
#endif /* SENDMMSG_VAR__ */
--
2.25.0.rc1.19.g042ed3e048af
^ permalink raw reply related [flat|nested] 15+ messages in thread* [LTP] [PATCH 8/8] syscalls/ppoll: Add support for time64 tests
2020-05-05 9:12 [LTP] [PATCH 1/8] syscalls/futex: Merge futex_wait_bitset tests Viresh Kumar
` (5 preceding siblings ...)
2020-05-05 9:12 ` [LTP] [PATCH 7/8] syscalls/recvmmsg: " Viresh Kumar
@ 2020-05-05 9:12 ` Viresh Kumar
2020-05-07 14:59 ` [LTP] [PATCH 1/8] syscalls/futex: Merge futex_wait_bitset tests Petr Vorel
7 siblings, 0 replies; 15+ messages in thread
From: Viresh Kumar @ 2020-05-05 9:12 UTC (permalink / raw)
To: ltp
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.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
testcases/kernel/syscalls/ppoll/ppoll01.c | 76 ++++++++++++++++++-----
1 file changed, 60 insertions(+), 16 deletions(-)
diff --git a/testcases/kernel/syscalls/ppoll/ppoll01.c b/testcases/kernel/syscalls/ppoll/ppoll01.c
index 2fadd0653948..eb8a14534e2e 100644
--- a/testcases/kernel/syscalls/ppoll/ppoll01.c
+++ b/testcases/kernel/syscalls/ppoll/ppoll01.c
@@ -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,
--
2.25.0.rc1.19.g042ed3e048af
^ permalink raw reply related [flat|nested] 15+ messages in thread* [LTP] [PATCH 1/8] syscalls/futex: Merge futex_wait_bitset tests
2020-05-05 9:12 [LTP] [PATCH 1/8] syscalls/futex: Merge futex_wait_bitset tests Viresh Kumar
` (6 preceding siblings ...)
2020-05-05 9:12 ` [LTP] [PATCH 8/8] syscalls/ppoll: " Viresh Kumar
@ 2020-05-07 14:59 ` Petr Vorel
7 siblings, 0 replies; 15+ messages in thread
From: Petr Vorel @ 2020-05-07 14:59 UTC (permalink / raw)
To: ltp
Hi Viresh,
> We can handle them easily in a single test, lets do it.
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
LGTM.
Kind regards,
Petr
^ permalink raw reply [flat|nested] 15+ messages in thread