* [LTP] [PATCH 1/4] libs: sigwait: Use SAFE_FORK()
@ 2020-07-23 13:42 Viresh Kumar
2020-07-23 13:42 ` [LTP] [PATCH 2/4] libs: sigwait: Add SAFE_SIG*() macros Viresh Kumar
` (3 more replies)
0 siblings, 4 replies; 15+ messages in thread
From: Viresh Kumar @ 2020-07-23 13:42 UTC (permalink / raw)
To: ltp
Use SAFE_FORK(), which also gets rid of a compilation warning for us.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
libs/libltpsigwait/sigwait.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/libs/libltpsigwait/sigwait.c b/libs/libltpsigwait/sigwait.c
index 5fbcdebf1295..bb8d2dd05a30 100644
--- a/libs/libltpsigwait/sigwait.c
+++ b/libs/libltpsigwait/sigwait.c
@@ -356,10 +356,8 @@ void test_bad_address2(swi_func sigwaitinfo, int signo LTP_ATTRIBUTE_UNUSED,
pid_t pid;
int status;
- switch (pid = fork()) {
- case -1:
- tst_brk(TBROK | TERRNO, "fork() failed");
- case 0:
+ pid = SAFE_FORK();
+ if (pid == 0) {
signal(SIGSEGV, SIG_DFL);
/*
@@ -374,9 +372,6 @@ void test_bad_address2(swi_func sigwaitinfo, int signo LTP_ATTRIBUTE_UNUSED,
tst_res(TINFO | TTERRNO, "swi_func returned: %ld",
TST_RET);
_exit(1);
- break;
- default:
- break;
}
SAFE_WAITPID(pid, &status, 0);
--
2.14.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [LTP] [PATCH 2/4] libs: sigwait: Add SAFE_SIG*() macros
2020-07-23 13:42 [LTP] [PATCH 1/4] libs: sigwait: Use SAFE_FORK() Viresh Kumar
@ 2020-07-23 13:42 ` Viresh Kumar
2020-07-24 5:51 ` Petr Vorel
2020-07-24 8:43 ` Cyril Hrubis
2020-07-23 13:42 ` [LTP] [PATCH 3/4] libs: sigwait: Remove alarm() from setup() and cleanup() Viresh Kumar
` (2 subsequent siblings)
3 siblings, 2 replies; 15+ messages in thread
From: Viresh Kumar @ 2020-07-23 13:42 UTC (permalink / raw)
To: ltp
Add them to simplify code.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
include/tst_safe_macros.h | 43 ++++++++++++++++++
libs/libltpsigwait/sigwait.c | 103 ++++++++++---------------------------------
2 files changed, 67 insertions(+), 79 deletions(-)
diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h
index c39d8768b1fb..3fce473cc380 100644
--- a/include/tst_safe_macros.h
+++ b/include/tst_safe_macros.h
@@ -431,6 +431,49 @@ int safe_sigaction(const char *file, const int lineno,
#define SAFE_SIGACTION(signum, act, oldact) \
safe_sigaction(__FILE__, __LINE__, (signum), (act), (oldact))
+static inline void safe_sigaddset(const char *file, const int lineno,
+ sigset_t *sigs, int signo)
+{
+ int rval;
+
+ rval = sigaddset(sigs, signo);
+ if (rval == -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO, "sigaddset(%d) failed",
+ signo);
+ }
+}
+
+#define SAFE_SIGADDSET(sigs, signo) \
+ safe_sigaddset(__FILE__, __LINE__, (sigs), (signo))
+
+static inline void safe_sigdelset(const char *file, const int lineno,
+ sigset_t *sigs, int signo)
+{
+ int rval;
+
+ rval = sigdelset(sigs, signo);
+ if (rval == -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO, "sigdelset(%d) failed",
+ signo);
+ }
+}
+
+#define SAFE_SIGDELSET(sigs, signo) \
+ safe_sigdelset(__FILE__, __LINE__, (sigs), (signo))
+
+static inline void safe_sigemptyset(const char *file, const int lineno,
+ sigset_t *sigs)
+{
+ int rval;
+
+ rval = sigemptyset(sigs);
+ if (rval == -1)
+ tst_brk_(file, lineno, TBROK | TERRNO, "sigemptyset() failed");
+}
+
+#define SAFE_SIGEMPTYSET(sigs) \
+ safe_sigemptyset(__FILE__, __LINE__, (sigs))
+
#define SAFE_EXECLP(file, arg, ...) do { \
execlp((file), (arg), ##__VA_ARGS__); \
tst_brk_(__FILE__, __LINE__, TBROK | TERRNO, \
diff --git a/libs/libltpsigwait/sigwait.c b/libs/libltpsigwait/sigwait.c
index bb8d2dd05a30..0a658625a984 100644
--- a/libs/libltpsigwait/sigwait.c
+++ b/libs/libltpsigwait/sigwait.c
@@ -49,9 +49,7 @@ void test_empty_set(swi_func sigwaitinfo, int signo,
siginfo_t si;
pid_t child;
- TEST(sigemptyset(&sigs));
- if (TST_RET == -1)
- tst_brk(TBROK | TTERRNO, "sigemptyset() failed");
+ SAFE_SIGEMPTYSET(&sigs);
/* Run a child that will wake us up */
child = create_sig_proc(signo, INT_MAX, 100000);
@@ -74,9 +72,7 @@ void test_timeout(swi_func sigwaitinfo, int signo, enum tst_ts_type type)
tst_ts_set_sec(&ts, 1);
tst_ts_set_nsec(&ts, 0);
- TEST(sigemptyset(&sigs));
- if (TST_RET == -1)
- tst_brk(TBROK | TTERRNO, "sigemptyset() failed");
+ SAFE_SIGEMPTYSET(&sigs);
/* Run a child that will wake us up */
child = create_sig_proc(signo, INT_MAX, 100000);
@@ -98,13 +94,8 @@ void test_unmasked_matching(swi_func sigwaitinfo, int signo,
siginfo_t si;
pid_t child;
- TEST(sigemptyset(&sigs));
- if (TST_RET == -1)
- tst_brk(TBROK | TTERRNO, "sigemptyset() failed");
-
- TEST(sigaddset(&sigs, signo));
- if (TST_RET == -1)
- tst_brk(TBROK | TTERRNO, "sigaddset() failed");
+ SAFE_SIGEMPTYSET(&sigs);
+ SAFE_SIGADDSET(&sigs, signo);
/* Run a child that will wake us up */
child = create_sig_proc(signo, INT_MAX, 100000);
@@ -124,13 +115,8 @@ void test_unmasked_matching_noinfo(swi_func sigwaitinfo, int signo,
sigset_t sigs;
pid_t child;
- TEST(sigemptyset(&sigs));
- if (TST_RET == -1)
- tst_brk(TBROK | TTERRNO, "sigemptyset() failed");
-
- TEST(sigaddset(&sigs, signo));
- if (TST_RET == -1)
- tst_brk(TBROK | TTERRNO, "sigaddset() failed");
+ SAFE_SIGEMPTYSET(&sigs);
+ SAFE_SIGADDSET(&sigs, signo);
/* Run a child that will wake us up */
child = create_sig_proc(signo, INT_MAX, 100000);
@@ -149,27 +135,18 @@ void test_masked_matching(swi_func sigwaitinfo, int signo,
siginfo_t si;
pid_t child;
- TEST(sigemptyset(&sigs));
- if (TST_RET == -1)
- tst_brk(TBROK | TTERRNO, "sigemptyset() failed");
-
- TEST(sigaddset(&sigs, signo));
- if (TST_RET == -1)
- tst_brk(TBROK | TTERRNO, "sigaddset() failed");
+ SAFE_SIGEMPTYSET(&sigs);
+ SAFE_SIGADDSET(&sigs, signo);
/* let's not get interrupted by our dying child */
- TEST(sigaddset(&sigs, SIGCHLD));
- if (TST_RET == -1)
- tst_brk(TBROK | TTERRNO, "sigaddset() failed");
+ SAFE_SIGADDSET(&sigs, SIGCHLD);
TEST(sigprocmask(SIG_SETMASK, &sigs, &oldmask));
if (TST_RET == -1)
tst_brk(TBROK | TTERRNO, "sigprocmask() failed");
/* don't wait on a SIGCHLD */
- TEST(sigdelset(&sigs, SIGCHLD));
- if (TST_RET == -1)
- tst_brk(TBROK | TTERRNO, "sigdelset() failed");
+ SAFE_SIGDELSET(&sigs, SIGCHLD);
/* Run a child that will wake us up */
child = create_sig_proc(signo, 1, 0);
@@ -203,31 +180,19 @@ void test_masked_matching_rt(swi_func sigwaitinfo, int signo,
signo = SIGRTMIN + 1;
- TEST(sigemptyset(&sigs));
- if (TST_RET == -1)
- tst_brk(TBROK | TTERRNO, "sigemptyset() failed");
-
- TEST(sigaddset(&sigs, signo));
- if (TST_RET == -1)
- tst_brk(TBROK | TTERRNO, "sigaddset() failed");
-
- TEST(sigaddset(&sigs, signo + 1));
- if (TST_RET == -1)
- tst_brk(TBROK | TTERRNO, "sigaddset() failed");
+ SAFE_SIGEMPTYSET(&sigs);
+ SAFE_SIGADDSET(&sigs, signo);
+ SAFE_SIGADDSET(&sigs, signo + 1);
/* let's not get interrupted by our dying child */
- TEST(sigaddset(&sigs, SIGCHLD));
- if (TST_RET == -1)
- tst_brk(TBROK | TTERRNO, "sigaddset() failed");
+ SAFE_SIGADDSET(&sigs, SIGCHLD);
TEST(sigprocmask(SIG_SETMASK, &sigs, &oldmask));
if (TST_RET == -1)
tst_brk(TBROK | TTERRNO, "sigprocmask() failed");
/* don't wait on a SIGCHLD */
- TEST(sigdelset(&sigs, SIGCHLD));
- if (TST_RET == -1)
- tst_brk(TBROK | TTERRNO, "sigdelset() failed");
+ SAFE_SIGDELSET(&sigs, SIGCHLD);
/* Run a child that will wake us up */
child[0] = create_sig_proc(signo, 1, 0);
@@ -266,27 +231,18 @@ void test_masked_matching_noinfo(swi_func sigwaitinfo, int signo,
sigset_t sigs, oldmask;
pid_t child;
- TEST(sigemptyset(&sigs));
- if (TST_RET == -1)
- tst_brk(TBROK | TTERRNO, "sigemptyset() failed");
-
- TEST(sigaddset(&sigs, signo));
- if (TST_RET == -1)
- tst_brk(TBROK | TTERRNO, "sigaddset() failed");
+ SAFE_SIGEMPTYSET(&sigs);
+ SAFE_SIGADDSET(&sigs, signo);
/* let's not get interrupted by our dying child */
- TEST(sigaddset(&sigs, SIGCHLD));
- if (TST_RET == -1)
- tst_brk(TBROK | TTERRNO, "sigaddset() failed");
+ SAFE_SIGADDSET(&sigs, SIGCHLD);
TEST(sigprocmask(SIG_SETMASK, &sigs, &oldmask));
if (TST_RET == -1)
tst_brk(TBROK | TTERRNO, "sigprocmask() failed");
/* don't wait on a SIGCHLD */
- TEST(sigdelset(&sigs, SIGCHLD));
- if (TST_RET == -1)
- tst_brk(TBROK | TTERRNO, "sigdelset() failed");
+ SAFE_SIGDELSET(&sigs, SIGCHLD);
/* Run a child that will wake us up */
child = create_sig_proc(signo, 1, 0);
@@ -314,27 +270,18 @@ void test_bad_address(swi_func sigwaitinfo, int signo,
sigset_t sigs, oldmask;
pid_t child;
- TEST(sigemptyset(&sigs));
- if (TST_RET == -1)
- tst_brk(TBROK | TTERRNO, "sigemptyset() failed");
-
- TEST(sigaddset(&sigs, signo));
- if (TST_RET == -1)
- tst_brk(TBROK | TTERRNO, "sigaddset() failed");
+ SAFE_SIGEMPTYSET(&sigs);
+ SAFE_SIGADDSET(&sigs, signo);
/* let's not get interrupted by our dying child */
- TEST(sigaddset(&sigs, SIGCHLD));
- if (TST_RET == -1)
- tst_brk(TBROK | TTERRNO, "sigaddset() failed");
+ SAFE_SIGADDSET(&sigs, SIGCHLD);
TEST(sigprocmask(SIG_SETMASK, &sigs, &oldmask));
if (TST_RET == -1)
tst_brk(TBROK | TTERRNO, "sigprocmask() failed");
/* don't wait on a SIGCHLD */
- TEST(sigdelset(&sigs, SIGCHLD));
- if (TST_RET == -1)
- tst_brk(TBROK | TTERRNO, "sigdelset() failed");
+ SAFE_SIGDELSET(&sigs, SIGCHLD);
/* Run a child that will wake us up */
child = create_sig_proc(signo, 1, 0);
@@ -396,10 +343,8 @@ void test_bad_address3(swi_func sigwaitinfo, int signo LTP_ATTRIBUTE_UNUSED,
enum tst_ts_type type LTP_ATTRIBUTE_UNUSED)
{
sigset_t sigs;
- TEST(sigemptyset(&sigs));
- if (TST_RET == -1)
- tst_brk(TBROK | TTERRNO, "sigemptyset() failed");
+ SAFE_SIGEMPTYSET(&sigs);
TEST(sigwaitinfo(&sigs, NULL, (void *)1));
REPORT_SUCCESS(-1, EFAULT);
}
--
2.14.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [LTP] [PATCH 3/4] libs: sigwait: Remove alarm() from setup() and cleanup()
2020-07-23 13:42 [LTP] [PATCH 1/4] libs: sigwait: Use SAFE_FORK() Viresh Kumar
2020-07-23 13:42 ` [LTP] [PATCH 2/4] libs: sigwait: Add SAFE_SIG*() macros Viresh Kumar
@ 2020-07-23 13:42 ` Viresh Kumar
2020-07-24 5:52 ` Petr Vorel
2020-07-24 8:44 ` Cyril Hrubis
2020-07-23 13:42 ` [LTP] [PATCH 4/4] libs: sigwait: Get rid of REPORT_SUCCESS() macro Viresh Kumar
2020-07-24 5:49 ` [LTP] [PATCH 1/4] libs: sigwait: Use SAFE_FORK() Petr Vorel
3 siblings, 2 replies; 15+ messages in thread
From: Viresh Kumar @ 2020-07-23 13:42 UTC (permalink / raw)
To: ltp
These aren't required anymore as the new library maintains timeouts
properly. While at it, remove sigwait_cleanup() as well.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
include/libsigwait.h | 1 -
libs/libltpsigwait/sigwait.c | 7 -------
testcases/kernel/syscalls/rt_sigtimedwait/rt_sigtimedwait01.c | 1 -
testcases/kernel/syscalls/sigtimedwait/sigtimedwait01.c | 1 -
testcases/kernel/syscalls/sigwait/sigwait01.c | 1 -
testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c | 1 -
6 files changed, 12 deletions(-)
diff --git a/include/libsigwait.h b/include/libsigwait.h
index 7202fc78fde8..2fca578b19ac 100644
--- a/include/libsigwait.h
+++ b/include/libsigwait.h
@@ -41,5 +41,4 @@ void test_bad_address2(swi_func sigwaitinfo, int signo LTP_ATTRIBUTE_UNUSED,
void test_bad_address3(swi_func sigwaitinfo, int signo LTP_ATTRIBUTE_UNUSED,
enum tst_ts_type type LTP_ATTRIBUTE_UNUSED);
void sigwait_setup(void);
-void sigwait_cleanup(void);
#endif /* SIGWAIT_H__ */
diff --git a/libs/libltpsigwait/sigwait.c b/libs/libltpsigwait/sigwait.c
index 0a658625a984..dbd33a61f2b1 100644
--- a/libs/libltpsigwait/sigwait.c
+++ b/libs/libltpsigwait/sigwait.c
@@ -358,11 +358,4 @@ void sigwait_setup(void)
signal(SIGUSR1, empty_handler);
signal(SIGALRM, empty_handler);
signal(SIGUSR2, SIG_IGN);
-
- alarm(10); /* arrange a 10 second timeout */
-}
-
-void sigwait_cleanup(void)
-{
- alarm(0);
}
diff --git a/testcases/kernel/syscalls/rt_sigtimedwait/rt_sigtimedwait01.c b/testcases/kernel/syscalls/rt_sigtimedwait/rt_sigtimedwait01.c
index 8b6153744938..db4901a40ea1 100644
--- a/testcases/kernel/syscalls/rt_sigtimedwait/rt_sigtimedwait01.c
+++ b/testcases/kernel/syscalls/rt_sigtimedwait/rt_sigtimedwait01.c
@@ -73,6 +73,5 @@ static struct tst_test test = {
.tcnt = ARRAY_SIZE(tests),
.test_variants = ARRAY_SIZE(variants),
.setup = setup,
- .cleanup = sigwait_cleanup,
.forks_child = 1,
};
diff --git a/testcases/kernel/syscalls/sigtimedwait/sigtimedwait01.c b/testcases/kernel/syscalls/sigtimedwait/sigtimedwait01.c
index 946d8e7239a0..fa36c455fb6d 100644
--- a/testcases/kernel/syscalls/sigtimedwait/sigtimedwait01.c
+++ b/testcases/kernel/syscalls/sigtimedwait/sigtimedwait01.c
@@ -32,6 +32,5 @@ static struct tst_test test = {
.test= run,
.tcnt = ARRAY_SIZE(tests),
.setup = sigwait_setup,
- .cleanup = sigwait_cleanup,
.forks_child = 1,
};
diff --git a/testcases/kernel/syscalls/sigwait/sigwait01.c b/testcases/kernel/syscalls/sigwait/sigwait01.c
index 563d15635fd9..92544c141e85 100644
--- a/testcases/kernel/syscalls/sigwait/sigwait01.c
+++ b/testcases/kernel/syscalls/sigwait/sigwait01.c
@@ -32,6 +32,5 @@ static struct tst_test test = {
.test= run,
.tcnt = ARRAY_SIZE(tests),
.setup = sigwait_setup,
- .cleanup = sigwait_cleanup,
.forks_child = 1,
};
diff --git a/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c b/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c
index 6563d14f0ec7..f7d90047f8a2 100644
--- a/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c
+++ b/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c
@@ -30,6 +30,5 @@ static struct tst_test test = {
.test= run,
.tcnt = ARRAY_SIZE(tests),
.setup = sigwait_setup,
- .cleanup = sigwait_cleanup,
.forks_child = 1,
};
--
2.14.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [LTP] [PATCH 4/4] libs: sigwait: Get rid of REPORT_SUCCESS() macro
2020-07-23 13:42 [LTP] [PATCH 1/4] libs: sigwait: Use SAFE_FORK() Viresh Kumar
2020-07-23 13:42 ` [LTP] [PATCH 2/4] libs: sigwait: Add SAFE_SIG*() macros Viresh Kumar
2020-07-23 13:42 ` [LTP] [PATCH 3/4] libs: sigwait: Remove alarm() from setup() and cleanup() Viresh Kumar
@ 2020-07-23 13:42 ` Viresh Kumar
2020-07-24 5:58 ` Petr Vorel
2020-07-24 12:32 ` Cyril Hrubis
2020-07-24 5:49 ` [LTP] [PATCH 1/4] libs: sigwait: Use SAFE_FORK() Petr Vorel
3 siblings, 2 replies; 15+ messages in thread
From: Viresh Kumar @ 2020-07-23 13:42 UTC (permalink / raw)
To: ltp
This is rather making the code difficult to read, get rid of it and its
associated functions.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
libs/libltpsigwait/sigwait.c | 158 +++++++++++++++++++++++++------------------
1 file changed, 93 insertions(+), 65 deletions(-)
diff --git a/libs/libltpsigwait/sigwait.c b/libs/libltpsigwait/sigwait.c
index dbd33a61f2b1..7315eb2ff13f 100644
--- a/libs/libltpsigwait/sigwait.c
+++ b/libs/libltpsigwait/sigwait.c
@@ -9,39 +9,6 @@
#include "libsigwait.h"
#include "tst_sig_proc.h"
-/* 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, int line,
- long exp_return, int exp_errno, int condition,
- char *condition_errmsg)
-{
- if (exp_return == TST_RET
- && (exp_return != -1 || exp_errno == TST_ERR))
- if (condition)
- tst_res(TPASS, "%s (%d): Test passed", func, line);
- else
- tst_res(TFAIL, "%s (%d): %s", func, line,
- condition_errmsg);
- 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_res(TFAIL | TTERRNO, "%s (%d): Unexpected failure",
- func, line);
-}
-
-#define REPORT_SUCCESS_COND(exp_return, exp_errno, condition, condition_errmsg) \
- report_success_cond(__FUNCTION__, __LINE__, exp_return, exp_errno, condition, condition_errmsg);
-
-/* 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, "");
-
void test_empty_set(swi_func sigwaitinfo, int signo,
enum tst_ts_type type LTP_ATTRIBUTE_UNUSED)
{
@@ -55,7 +22,15 @@ void test_empty_set(swi_func sigwaitinfo, int signo,
child = create_sig_proc(signo, INT_MAX, 100000);
TEST(sigwaitinfo(&sigs, &si, NULL));
- REPORT_SUCCESS(-1, EINTR);
+ if (TST_RET == -1) {
+ if (TST_ERR == EINTR)
+ tst_res(TPASS, "%s: Test passed", __func__);
+ else
+ tst_res(TFAIL | TTERRNO, "%s: Unexpected failure", __func__);
+ } else {
+ tst_res(TFAIL, "%s: Unexpected return value: %ld", __func__,
+ TST_RET);
+ }
SAFE_KILL(child, SIGTERM);
SAFE_WAIT(NULL);
@@ -78,7 +53,15 @@ void test_timeout(swi_func sigwaitinfo, int signo, enum tst_ts_type type)
child = create_sig_proc(signo, INT_MAX, 100000);
TEST(sigwaitinfo(&sigs, &si, tst_ts_get(&ts)));
- REPORT_SUCCESS(-1, EAGAIN);
+ if (TST_RET == -1) {
+ if (TST_ERR == EAGAIN)
+ tst_res(TPASS, "%s: Test passed", __func__);
+ else
+ tst_res(TFAIL | TTERRNO, "%s: Unexpected failure", __func__);
+ } else {
+ tst_res(TFAIL, "%s: Unexpected return value: %ld",
+ __func__, TST_RET);
+ }
SAFE_KILL(child, SIGTERM);
SAFE_WAIT(NULL);
@@ -101,9 +84,15 @@ void test_unmasked_matching(swi_func sigwaitinfo, int signo,
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");
+ if (TST_RET == signo) {
+ if (si.si_pid == child && si.si_code == SI_USER &&
+ si.si_signo == signo)
+ tst_res(TPASS, "%s: Test passed", __func__);
+ else
+ tst_res(TFAIL, "%s: Struct siginfo mismatch", __func__);
+ } else {
+ tst_res(TFAIL | TTERRNO, "%s: Test failed", __func__);
+ }
SAFE_KILL(child, SIGTERM);
SAFE_WAIT(NULL);
@@ -122,7 +111,10 @@ void test_unmasked_matching_noinfo(swi_func sigwaitinfo, int signo,
child = create_sig_proc(signo, INT_MAX, 100000);
TEST(sigwaitinfo(&sigs, NULL, NULL));
- REPORT_SUCCESS(signo, 0);
+ if (TST_RET == signo)
+ tst_res(TPASS, "%s: Test passed", __func__);
+ else
+ tst_res(TFAIL | TTERRNO, "%s: Test failed", __func__);
SAFE_KILL(child, SIGTERM);
SAFE_WAIT(NULL);
@@ -152,19 +144,25 @@ void test_masked_matching(swi_func sigwaitinfo, int signo,
child = create_sig_proc(signo, 1, 0);
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");
+ if (TST_RET == signo) {
+ if (si.si_pid == child && si.si_code == SI_USER &&
+ si.si_signo == signo)
+ tst_res(TPASS, "%s: Test passed", __func__);
+ else
+ tst_res(TFAIL, "%s: Struct siginfo mismatch", __func__);
+ } else {
+ tst_res(TFAIL | TTERRNO, "%s: Test failed", __func__);
+ }
TEST(sigprocmask(SIG_SETMASK, &oldmask, &oldmask));
if (TST_RET == -1)
tst_brk(TBROK | TTERRNO, "restoring original signal mask failed");
if (sigismember(&oldmask, signo))
- tst_res(TPASS, "sigwaitinfo restored the original mask");
+ tst_res(TPASS, "%s: sigwaitinfo restored the original mask", __func__);
else
tst_res(TFAIL,
- "sigwaitinfo failed to restore the original mask");
+ "%s: sigwaitinfo failed to restore the original mask", __func__);
SAFE_KILL(child, SIGTERM);
SAFE_WAIT(NULL);
@@ -203,26 +201,37 @@ void test_masked_matching_rt(swi_func sigwaitinfo, int signo,
SAFE_WAITPID(child[1], &status, 0);
TEST(sigwaitinfo(&sigs, &si, NULL));
- REPORT_SUCCESS_COND(signo, 0, si.si_pid == child[0]
- && si.si_code == SI_USER
- && si.si_signo == signo, "Struct siginfo mismatch");
+ if (TST_RET == signo) {
+ if (si.si_pid == child[0] && si.si_code == SI_USER &&
+ si.si_signo == signo)
+ tst_res(TPASS, "%s: Test passed", __func__);
+ else
+ tst_res(TFAIL, "%s: Struct siginfo mismatch", __func__);
+ } else {
+ tst_res(TFAIL | TTERRNO, "%s: Test failed", __func__);
+ }
/* eat the other signal */
TEST(sigwaitinfo(&sigs, &si, NULL));
- REPORT_SUCCESS_COND(signo + 1, 0, si.si_pid == child[1]
- && si.si_code == SI_USER
- && si.si_signo == signo + 1,
- "Struct siginfo mismatch");
+ if (TST_RET == signo + 1) {
+ if (si.si_pid == child[1] && si.si_code == SI_USER &&
+ si.si_signo == signo + 1)
+ tst_res(TPASS, "%s: Test passed", __func__);
+ else
+ tst_res(TFAIL, "%s: Struct siginfo mismatch", __func__);
+ } else {
+ tst_res(TFAIL | TTERRNO, "%s: Test failed", __func__);
+ }
TEST(sigprocmask(SIG_SETMASK, &oldmask, &oldmask));
if (TST_RET == -1)
tst_brk(TBROK | TTERRNO, "restoring original signal mask failed");
if (sigismember(&oldmask, signo))
- tst_res(TPASS, "sigwaitinfo restored the original mask");
+ tst_res(TPASS, "%s: sigwaitinfo restored the original mask", __func__);
else
tst_res(TFAIL,
- "sigwaitinfo failed to restore the original mask");
+ "%s: sigwaitinfo failed to restore the original mask", __func__);
}
void test_masked_matching_noinfo(swi_func sigwaitinfo, int signo,
@@ -248,17 +257,20 @@ void test_masked_matching_noinfo(swi_func sigwaitinfo, int signo,
child = create_sig_proc(signo, 1, 0);
TEST(sigwaitinfo(&sigs, NULL, NULL));
- REPORT_SUCCESS(signo, 0);
+ if (TST_RET == signo)
+ tst_res(TPASS, "%s: Test passed", __func__);
+ else
+ tst_res(TFAIL | TTERRNO, "%s: Test failed", __func__);
TEST(sigprocmask(SIG_SETMASK, &oldmask, &oldmask));
if (TST_RET == -1)
tst_brk(TBROK | TTERRNO, "restoring original signal mask failed");
if (sigismember(&oldmask, signo))
- tst_res(TPASS, "sigwaitinfo restored the original mask");
+ tst_res(TPASS, "%s: sigwaitinfo restored the original mask", __func__);
else
tst_res(TFAIL,
- "sigwaitinfo failed to restore the original mask");
+ "%s: sigwaitinfo failed to restore the original mask", __func__);
SAFE_KILL(child, SIGTERM);
SAFE_WAIT(NULL);
@@ -287,7 +299,15 @@ void test_bad_address(swi_func sigwaitinfo, int signo,
child = create_sig_proc(signo, 1, 0);
TEST(sigwaitinfo(&sigs, (void *)1, NULL));
- REPORT_SUCCESS(-1, EFAULT);
+ if (TST_RET == -1) {
+ if (TST_ERR == EFAULT)
+ tst_res(TPASS, "%s: Test passed", __func__);
+ else
+ tst_res(TFAIL | TTERRNO, "%s: Unexpected failure", __func__);
+ } else {
+ tst_res(TFAIL, "%s: Unexpected return value: %ld",
+ __func__, TST_RET);
+ }
TEST(sigprocmask(SIG_SETMASK, &oldmask, &oldmask));
if (TST_RET == -1)
@@ -316,8 +336,8 @@ void test_bad_address2(swi_func sigwaitinfo, int signo LTP_ATTRIBUTE_UNUSED,
if (TST_RET == -1 && TST_ERR == EFAULT)
_exit(0);
- tst_res(TINFO | TTERRNO, "swi_func returned: %ld",
- TST_RET);
+ tst_res(TINFO | TTERRNO, "%s: swi_func returned: %ld",
+ __func__, TST_RET);
_exit(1);
}
@@ -325,17 +345,17 @@ void test_bad_address2(swi_func sigwaitinfo, int signo LTP_ATTRIBUTE_UNUSED,
if ((WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV)
|| (WIFEXITED(status) && WEXITSTATUS(status) == 0)) {
- tst_res(TPASS, "Test passed");
+ tst_res(TPASS, "%s: Test passed", __func__);
return;
}
if (WIFEXITED(status)) {
- tst_res(TFAIL, "Unrecognised child exit code: %d",
- WEXITSTATUS(status));
+ tst_res(TFAIL, "%s: Unrecognised child exit code: %d",
+ __func__, WEXITSTATUS(status));
}
if (WIFSIGNALED(status)) {
- tst_res(TFAIL, "Unrecognised child termsig: %d",
- WTERMSIG(status));
+ tst_res(TFAIL, "%s: Unrecognised child termsig: %d",
+ __func__, WTERMSIG(status));
}
}
@@ -346,7 +366,15 @@ void test_bad_address3(swi_func sigwaitinfo, int signo LTP_ATTRIBUTE_UNUSED,
SAFE_SIGEMPTYSET(&sigs);
TEST(sigwaitinfo(&sigs, NULL, (void *)1));
- REPORT_SUCCESS(-1, EFAULT);
+ if (TST_RET == -1) {
+ if (TST_ERR == EFAULT)
+ tst_res(TPASS, "%s: Test passed", __func__);
+ else
+ tst_res(TFAIL | TTERRNO, "%s: Unexpected failure", __func__);
+ } else {
+ tst_res(TFAIL, "%s: Unexpected return value: %ld",
+ __func__, TST_RET);
+ }
}
static void empty_handler(int sig LTP_ATTRIBUTE_UNUSED)
--
2.14.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [LTP] [PATCH 1/4] libs: sigwait: Use SAFE_FORK()
2020-07-23 13:42 [LTP] [PATCH 1/4] libs: sigwait: Use SAFE_FORK() Viresh Kumar
` (2 preceding siblings ...)
2020-07-23 13:42 ` [LTP] [PATCH 4/4] libs: sigwait: Get rid of REPORT_SUCCESS() macro Viresh Kumar
@ 2020-07-24 5:49 ` Petr Vorel
3 siblings, 0 replies; 15+ messages in thread
From: Petr Vorel @ 2020-07-24 5:49 UTC (permalink / raw)
To: ltp
Hi Viresh,
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Kind regards,
Petr
^ permalink raw reply [flat|nested] 15+ messages in thread
* [LTP] [PATCH 2/4] libs: sigwait: Add SAFE_SIG*() macros
2020-07-23 13:42 ` [LTP] [PATCH 2/4] libs: sigwait: Add SAFE_SIG*() macros Viresh Kumar
@ 2020-07-24 5:51 ` Petr Vorel
2020-07-24 8:43 ` Cyril Hrubis
1 sibling, 0 replies; 15+ messages in thread
From: Petr Vorel @ 2020-07-24 5:51 UTC (permalink / raw)
To: ltp
Hi Viresh,
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Kind regards,
Petr
^ permalink raw reply [flat|nested] 15+ messages in thread
* [LTP] [PATCH 3/4] libs: sigwait: Remove alarm() from setup() and cleanup()
2020-07-23 13:42 ` [LTP] [PATCH 3/4] libs: sigwait: Remove alarm() from setup() and cleanup() Viresh Kumar
@ 2020-07-24 5:52 ` Petr Vorel
2020-07-24 8:44 ` Cyril Hrubis
1 sibling, 0 replies; 15+ messages in thread
From: Petr Vorel @ 2020-07-24 5:52 UTC (permalink / raw)
To: ltp
Hi Viresh,
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Kind regards,
Petr
^ permalink raw reply [flat|nested] 15+ messages in thread
* [LTP] [PATCH 4/4] libs: sigwait: Get rid of REPORT_SUCCESS() macro
2020-07-23 13:42 ` [LTP] [PATCH 4/4] libs: sigwait: Get rid of REPORT_SUCCESS() macro Viresh Kumar
@ 2020-07-24 5:58 ` Petr Vorel
2020-07-24 10:34 ` Viresh Kumar
2020-07-24 12:32 ` Cyril Hrubis
1 sibling, 1 reply; 15+ messages in thread
From: Petr Vorel @ 2020-07-24 5:58 UTC (permalink / raw)
To: ltp
Hi Viresh,
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Although these errors are still here:
sigwait.c: In function ?test_masked_matching?:
sigwait.c:157:42: warning: passing argument 3 to restrict-qualified parameter aliases with argument 2 [-Wrestrict]
157 | TEST(sigprocmask(SIG_SETMASK, &oldmask, &oldmask));
| ~~~~~~~~ ^~~~~~~~
../../include/tst_test.h:266:13: note: in definition of macro ?TEST?
266 | TST_RET = SCALL; \
| ^~~~~
sigwait.c: In function ?test_masked_matching_rt?:
sigwait.c:226:42: warning: passing argument 3 to restrict-qualified parameter aliases with argument 2 [-Wrestrict]
226 | TEST(sigprocmask(SIG_SETMASK, &oldmask, &oldmask));
| ~~~~~~~~ ^~~~~~~~
../../include/tst_test.h:266:13: note: in definition of macro ?TEST?
266 | TST_RET = SCALL; \
| ^~~~~
sigwait.c: In function ?test_masked_matching_noinfo?:
sigwait.c:265:42: warning: passing argument 3 to restrict-qualified parameter aliases with argument 2 [-Wrestrict]
265 | TEST(sigprocmask(SIG_SETMASK, &oldmask, &oldmask));
| ~~~~~~~~ ^~~~~~~~
../../include/tst_test.h:266:13: note: in definition of macro ?TEST?
266 | TST_RET = SCALL; \
| ^~~~~
sigwait.c: In function ?test_bad_address?:
sigwait.c:312:42: warning: passing argument 3 to restrict-qualified parameter aliases with argument 2 [-Wrestrict]
312 | TEST(sigprocmask(SIG_SETMASK, &oldmask, &oldmask));
| ~~~~~~~~ ^~~~~~~~
IMHO we shouldn't use oldmask for src and dest.
Kind regards,
Petr
^ permalink raw reply [flat|nested] 15+ messages in thread
* [LTP] [PATCH 2/4] libs: sigwait: Add SAFE_SIG*() macros
2020-07-23 13:42 ` [LTP] [PATCH 2/4] libs: sigwait: Add SAFE_SIG*() macros Viresh Kumar
2020-07-24 5:51 ` Petr Vorel
@ 2020-07-24 8:43 ` Cyril Hrubis
1 sibling, 0 replies; 15+ messages in thread
From: Cyril Hrubis @ 2020-07-24 8:43 UTC (permalink / raw)
To: ltp
Hi!
Pushed with a minor change, thanks.
diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h
index 3fce473cc..f3f83cddd 100644
--- a/include/tst_safe_macros.h
+++ b/include/tst_safe_macros.h
@@ -438,8 +438,9 @@ static inline void safe_sigaddset(const char *file, const int lineno,
rval = sigaddset(sigs, signo);
if (rval == -1) {
- tst_brk_(file, lineno, TBROK | TERRNO, "sigaddset(%d) failed",
- signo);
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "sigaddset() %s (%i) failed",
+ tst_strsig(signo), signo);
}
}
@@ -453,8 +454,9 @@ static inline void safe_sigdelset(const char *file, const int lineno,
rval = sigdelset(sigs, signo);
if (rval == -1) {
- tst_brk_(file, lineno, TBROK | TERRNO, "sigdelset(%d) failed",
- signo);
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "sigdelset() %s (%i) failed",
+ tst_strsig(signo), signo);
}
}
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [LTP] [PATCH 3/4] libs: sigwait: Remove alarm() from setup() and cleanup()
2020-07-23 13:42 ` [LTP] [PATCH 3/4] libs: sigwait: Remove alarm() from setup() and cleanup() Viresh Kumar
2020-07-24 5:52 ` Petr Vorel
@ 2020-07-24 8:44 ` Cyril Hrubis
1 sibling, 0 replies; 15+ messages in thread
From: Cyril Hrubis @ 2020-07-24 8:44 UTC (permalink / raw)
To: ltp
Hi!
Pushed, thanks.
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 15+ messages in thread
* [LTP] [PATCH 4/4] libs: sigwait: Get rid of REPORT_SUCCESS() macro
2020-07-24 5:58 ` Petr Vorel
@ 2020-07-24 10:34 ` Viresh Kumar
2020-07-24 12:20 ` Cyril Hrubis
2020-07-24 13:37 ` Petr Vorel
0 siblings, 2 replies; 15+ messages in thread
From: Viresh Kumar @ 2020-07-24 10:34 UTC (permalink / raw)
To: ltp
On 24-07-20, 07:58, Petr Vorel wrote:
> Hi Viresh,
>
> Reviewed-by: Petr Vorel <pvorel@suse.cz>
>
> Although these errors are still here:
I went to libs/ directory and I don't get any warnings with
$ make clean; make
How can I generate these easily ?
> sigwait.c: In function ?test_masked_matching?:
> sigwait.c:157:42: warning: passing argument 3 to restrict-qualified parameter aliases with argument 2 [-Wrestrict]
> 157 | TEST(sigprocmask(SIG_SETMASK, &oldmask, &oldmask));
> | ~~~~~~~~ ^~~~~~~~
> ../../include/tst_test.h:266:13: note: in definition of macro ?TEST?
> 266 | TST_RET = SCALL; \
> IMHO we shouldn't use oldmask for src and dest.
And I am not really sure what the error says and why it is there.
--
viresh
^ permalink raw reply [flat|nested] 15+ messages in thread
* [LTP] [PATCH 4/4] libs: sigwait: Get rid of REPORT_SUCCESS() macro
2020-07-24 10:34 ` Viresh Kumar
@ 2020-07-24 12:20 ` Cyril Hrubis
2020-07-24 13:37 ` Petr Vorel
1 sibling, 0 replies; 15+ messages in thread
From: Cyril Hrubis @ 2020-07-24 12:20 UTC (permalink / raw)
To: ltp
Hi!
> > sigwait.c: In function ???test_masked_matching???:
> > sigwait.c:157:42: warning: passing argument 3 to restrict-qualified parameter aliases with argument 2 [-Wrestrict]
> > 157 | TEST(sigprocmask(SIG_SETMASK, &oldmask, &oldmask));
> > | ~~~~~~~~ ^~~~~~~~
> > ../../include/tst_test.h:266:13: note: in definition of macro ???TEST???
> > 266 | TST_RET = SCALL; \
>
> > IMHO we shouldn't use oldmask for src and dest.
>
> And I am not really sure what the error says and why it is there.
I guess that new enough glibc has restrict keyword used on the
sigprocmask() pointer parameters, which basically means that compiler
can assume that for the lifetime of the pointer a piece of memory can be
accessed only via that pointer or pointers directly derived from it.
And passing the same pointer twice obviously violates that promise,
hence the warning.
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 15+ messages in thread
* [LTP] [PATCH 4/4] libs: sigwait: Get rid of REPORT_SUCCESS() macro
2020-07-23 13:42 ` [LTP] [PATCH 4/4] libs: sigwait: Get rid of REPORT_SUCCESS() macro Viresh Kumar
2020-07-24 5:58 ` Petr Vorel
@ 2020-07-24 12:32 ` Cyril Hrubis
2020-07-24 13:35 ` Petr Vorel
1 sibling, 1 reply; 15+ messages in thread
From: Cyril Hrubis @ 2020-07-24 12:32 UTC (permalink / raw)
To: ltp
Hi!
> void test_empty_set(swi_func sigwaitinfo, int signo,
> enum tst_ts_type type LTP_ATTRIBUTE_UNUSED)
> {
> @@ -55,7 +22,15 @@ void test_empty_set(swi_func sigwaitinfo, int signo,
> child = create_sig_proc(signo, INT_MAX, 100000);
>
> TEST(sigwaitinfo(&sigs, &si, NULL));
> - REPORT_SUCCESS(-1, EINTR);
> + if (TST_RET == -1) {
> + if (TST_ERR == EINTR)
> + tst_res(TPASS, "%s: Test passed", __func__);
> + else
> + tst_res(TFAIL | TTERRNO, "%s: Unexpected failure", __func__);
Can we please make the messages a bit more user friendly?
- the tst_res() already prints line and filename the __func__ is a bit
redundant
- it also prints PASS/FAIL so we can omit the "Test passed" we can print
something that describes the testcase instead e.g.
"Wait interrupted by a signal"
- also in the "Unexpected failure" case we should print which error we
expected with someting as: tst_res(TFAIL | TTERRNO, "Expected to return EINTER, got");
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 15+ messages in thread
* [LTP] [PATCH 4/4] libs: sigwait: Get rid of REPORT_SUCCESS() macro
2020-07-24 12:32 ` Cyril Hrubis
@ 2020-07-24 13:35 ` Petr Vorel
0 siblings, 0 replies; 15+ messages in thread
From: Petr Vorel @ 2020-07-24 13:35 UTC (permalink / raw)
To: ltp
Hi,
...
> > TEST(sigwaitinfo(&sigs, &si, NULL));
> > - REPORT_SUCCESS(-1, EINTR);
> > + if (TST_RET == -1) {
> > + if (TST_ERR == EINTR)
> > + tst_res(TPASS, "%s: Test passed", __func__);
> > + else
> > + tst_res(TFAIL | TTERRNO, "%s: Unexpected failure", __func__);
> Can we please make the messages a bit more user friendly?
> - the tst_res() already prints line and filename the __func__ is a bit
> redundant
> - it also prints PASS/FAIL so we can omit the "Test passed" we can print
> something that describes the testcase instead e.g.
> "Wait interrupted by a signal"
> - also in the "Unexpected failure" case we should print which error we
> expected with someting as: tst_res(TFAIL | TTERRNO, "Expected to return EINTER, got");
+1, sorry for overlooking it.
Kind regards,
Petr
^ permalink raw reply [flat|nested] 15+ messages in thread
* [LTP] [PATCH 4/4] libs: sigwait: Get rid of REPORT_SUCCESS() macro
2020-07-24 10:34 ` Viresh Kumar
2020-07-24 12:20 ` Cyril Hrubis
@ 2020-07-24 13:37 ` Petr Vorel
1 sibling, 0 replies; 15+ messages in thread
From: Petr Vorel @ 2020-07-24 13:37 UTC (permalink / raw)
To: ltp
Hi Viresh,
> > Although these errors are still here:
> I went to libs/ directory and I don't get any warnings with
> $ make clean; make
> How can I generate these easily ?
Use new gcc. I was able to generate this even with gcc 9:
$ gcc --version
gcc (SUSE Linux) 9.3.1 20200406 [revision 6db837a5288ee3ca5ec504fbd5a765817e556ac2]
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Kind regards,
Petr
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2020-07-24 13:37 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-23 13:42 [LTP] [PATCH 1/4] libs: sigwait: Use SAFE_FORK() Viresh Kumar
2020-07-23 13:42 ` [LTP] [PATCH 2/4] libs: sigwait: Add SAFE_SIG*() macros Viresh Kumar
2020-07-24 5:51 ` Petr Vorel
2020-07-24 8:43 ` Cyril Hrubis
2020-07-23 13:42 ` [LTP] [PATCH 3/4] libs: sigwait: Remove alarm() from setup() and cleanup() Viresh Kumar
2020-07-24 5:52 ` Petr Vorel
2020-07-24 8:44 ` Cyril Hrubis
2020-07-23 13:42 ` [LTP] [PATCH 4/4] libs: sigwait: Get rid of REPORT_SUCCESS() macro Viresh Kumar
2020-07-24 5:58 ` Petr Vorel
2020-07-24 10:34 ` Viresh Kumar
2020-07-24 12:20 ` Cyril Hrubis
2020-07-24 13:37 ` Petr Vorel
2020-07-24 12:32 ` Cyril Hrubis
2020-07-24 13:35 ` Petr Vorel
2020-07-24 5:49 ` [LTP] [PATCH 1/4] libs: sigwait: Use SAFE_FORK() Petr Vorel
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.