[LTP] [PATCH v3 08/12] sigwaitinfo01: catch SEGV and report success for bad_address2 testcase
Punit Agrawal
punit.agrawal@arm.com
Mon Dec 4 17:36:51 CET 2017
The bad_address2 testcase passes (void *)1 as a sigset pointer to the
sigwaitinfo syscall. Unsurprisingly, this segfaults in libc rather than
returning -1 (errno = EFAULT) as LTP expects.
Instead, fork a child process which registers a default handler for
SIGSEGV to catch any SEGV's generated by the sigwaitinfo syscall. The
parent checks that the child was terminated by SIGSEGV to evaluate the
success of the test.
Signed-off-by: Punit Agrawal <punit.agrawal@arm.com>
---
.../kernel/syscalls/sigwaitinfo/sigwaitinfo01.c | 23 ++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c b/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c
index 16b5096b8..95a9436a4 100644
--- a/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c
+++ b/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c
@@ -363,8 +363,27 @@ void test_bad_address(swi_func sigwaitinfo, int signo)
void test_bad_address2(swi_func sigwaitinfo, int signo)
{
- TEST(sigwaitinfo((void *)1, NULL, NULL));
- REPORT_SUCCESS(-1, EFAULT);
+ pid_t pid;
+ int status;
+
+ switch (pid = fork()) {
+ case -1:
+ tst_brkm(TBROK | TERRNO, NULL, "fork() failed");
+ case 0:
+ signal(SIGSEGV, SIG_DFL);
+ TEST(sigwaitinfo((void *)1, NULL, NULL));
+
+ _exit(0);
+ break;
+ default:
+ break;
+ }
+
+ SUCCEED_OR_DIE(waitpid, "waitpid failed", pid, &status, 0);
+ if (WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV)
+ tst_resm(TPASS, "Test passed");
+ else
+ tst_resm(TFAIL, "Unrecognised child exit code");
}
void test_bad_address3(swi_func sigwaitinfo, int signo)
--
2.15.0
More information about the ltp
mailing list