From mboxrd@z Thu Jan 1 00:00:00 1970 From: Punit Agrawal Date: Tue, 14 Nov 2017 15:59:24 +0000 Subject: [LTP] [PATCH v2 08/13] sigwaitinfo01: catch SEGV and report success for bad_address2 testcase In-Reply-To: <20171114155929.24237-1-punit.agrawal@arm.com> References: <20171114155929.24237-1-punit.agrawal@arm.com> Message-ID: <20171114155929.24237-9-punit.agrawal@arm.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: ltp@lists.linux.it 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 SIGSEGV handler to catch any SEGV's generated by the sigwaitinfo syscall. The signal handler exits the child process with a return code which is checked by the parent to evaluate test outcome. Signed-off-by: Punit Agrawal --- .../kernel/syscalls/sigwaitinfo/sigwaitinfo01.c | 29 ++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c b/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c index 16b5096b8..8f517e918 100644 --- a/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c +++ b/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c @@ -361,10 +361,35 @@ void test_bad_address(swi_func sigwaitinfo, int signo) kill(child, SIGTERM); } +static void segv_handler(int signo) +{ + /* SIGSEGV is expected, exit with 0xff */ + _exit(0xff); +} + 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_OR_VFORK()) { + case -1: + tst_brkm(TBROK | TERRNO, NULL, "fork() failed"); + case 0: + signal(SIGSEGV, segv_handler); + TEST(sigwaitinfo((void *)1, NULL, NULL)); + + _exit(0); + break; + default: + break; + } + + SUCCEED_OR_DIE(waitpid, "waitpid failed", pid, &status, 0); + if (WIFEXITED(status) && WEXITSTATUS(status) == 0xff) + tst_resm(TPASS, "Test passed"); + else + tst_resm(TFAIL, "Unrecognised child exit code"); } void test_bad_address3(swi_func sigwaitinfo, int signo) -- 2.14.2