selftests: sigaltstack: convert to use TAP13 ksft framework

Convert to use TAP13 ksft framework to output results.

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
This commit is contained in:
Shuah Khan 2017-07-26 18:58:12 -06:00
parent 5b1b9c5851
commit 5ec8d6ce61
1 changed files with 31 additions and 22 deletions

View File

@ -17,6 +17,8 @@
#include <assert.h>
#include <errno.h>
#include "../kselftest.h"
#ifndef SS_AUTODISARM
#define SS_AUTODISARM (1U << 31)
#endif
@ -41,8 +43,7 @@ void my_usr1(int sig, siginfo_t *si, void *u)
if (sp < (unsigned long)sstack ||
sp >= (unsigned long)sstack + SIGSTKSZ) {
printf("[FAIL]\tSP is not on sigaltstack\n");
exit(EXIT_FAILURE);
ksft_exit_fail_msg("SP is not on sigaltstack\n");
}
/* put some data on stack. other sighandler will try to overwrite it */
aa = alloca(1024);
@ -50,21 +51,22 @@ void my_usr1(int sig, siginfo_t *si, void *u)
p = (struct stk_data *)(aa + 512);
strcpy(p->msg, msg);
p->flag = 1;
printf("[RUN]\tsignal USR1\n");
ksft_print_msg("[RUN]\tsignal USR1\n");
err = sigaltstack(NULL, &stk);
if (err) {
perror("[FAIL]\tsigaltstack()");
ksft_exit_fail_msg("sigaltstack() - %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
if (stk.ss_flags != SS_DISABLE)
printf("[FAIL]\tss_flags=%x, should be SS_DISABLE\n",
ksft_test_result_fail("tss_flags=%x, should be SS_DISABLE\n",
stk.ss_flags);
else
printf("[OK]\tsigaltstack is disabled in sighandler\n");
ksft_test_result_pass(
"sigaltstack is disabled in sighandler\n");
swapcontext(&sc, &uc);
printf("%s\n", p->msg);
ksft_print_msg("%s\n", p->msg);
if (!p->flag) {
printf("[RUN]\tAborting\n");
ksft_exit_skip("[RUN]\tAborting\n");
exit(EXIT_FAILURE);
}
}
@ -74,13 +76,13 @@ void my_usr2(int sig, siginfo_t *si, void *u)
char *aa;
struct stk_data *p;
printf("[RUN]\tsignal USR2\n");
ksft_print_msg("[RUN]\tsignal USR2\n");
aa = alloca(1024);
/* dont run valgrind on this */
/* try to find the data stored by previous sighandler */
p = memmem(aa, 1024, msg, strlen(msg));
if (p) {
printf("[FAIL]\tsigaltstack re-used\n");
ksft_test_result_fail("sigaltstack re-used\n");
/* corrupt the data */
strcpy(p->msg, msg2);
/* tell other sighandler that his data is corrupted */
@ -90,7 +92,7 @@ void my_usr2(int sig, siginfo_t *si, void *u)
static void switch_fn(void)
{
printf("[RUN]\tswitched to user ctx\n");
ksft_print_msg("[RUN]\tswitched to user ctx\n");
raise(SIGUSR2);
setcontext(&sc);
}
@ -101,6 +103,8 @@ int main(void)
stack_t stk;
int err;
ksft_print_header();
sigemptyset(&act.sa_mask);
act.sa_flags = SA_ONSTACK | SA_SIGINFO;
act.sa_sigaction = my_usr1;
@ -110,19 +114,20 @@ int main(void)
sstack = mmap(NULL, SIGSTKSZ, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, -1, 0);
if (sstack == MAP_FAILED) {
perror("mmap()");
ksft_exit_fail_msg("mmap() - %s\n", strerror(errno));
return EXIT_FAILURE;
}
err = sigaltstack(NULL, &stk);
if (err) {
perror("[FAIL]\tsigaltstack()");
ksft_exit_fail_msg("sigaltstack() - %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
if (stk.ss_flags == SS_DISABLE) {
printf("[OK]\tInitial sigaltstack state was SS_DISABLE\n");
ksft_test_result_pass(
"Initial sigaltstack state was SS_DISABLE\n");
} else {
printf("[FAIL]\tInitial sigaltstack state was %x; "
ksft_exit_fail_msg("Initial sigaltstack state was %x; "
"should have been SS_DISABLE\n", stk.ss_flags);
return EXIT_FAILURE;
}
@ -133,7 +138,8 @@ int main(void)
err = sigaltstack(&stk, NULL);
if (err) {
if (errno == EINVAL) {
printf("[NOTE]\tThe running kernel doesn't support SS_AUTODISARM\n");
ksft_exit_skip(
"[NOTE]\tThe running kernel doesn't support SS_AUTODISARM\n");
/*
* If test cases for the !SS_AUTODISARM variant were
* added, we could still run them. We don't have any
@ -142,7 +148,9 @@ int main(void)
*/
return 0;
} else {
perror("[FAIL]\tsigaltstack(SS_ONSTACK | SS_AUTODISARM)");
ksft_exit_fail_msg(
"sigaltstack(SS_ONSTACK | SS_AUTODISARM) %s\n",
strerror(errno));
return EXIT_FAILURE;
}
}
@ -150,7 +158,7 @@ int main(void)
ustack = mmap(NULL, SIGSTKSZ, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, -1, 0);
if (ustack == MAP_FAILED) {
perror("mmap()");
ksft_exit_fail_msg("mmap() - %s\n", strerror(errno));
return EXIT_FAILURE;
}
getcontext(&uc);
@ -162,16 +170,17 @@ int main(void)
err = sigaltstack(NULL, &stk);
if (err) {
perror("[FAIL]\tsigaltstack()");
ksft_exit_fail_msg("sigaltstack() - %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
if (stk.ss_flags != SS_AUTODISARM) {
printf("[FAIL]\tss_flags=%x, should be SS_AUTODISARM\n",
ksft_exit_fail_msg("ss_flags=%x, should be SS_AUTODISARM\n",
stk.ss_flags);
exit(EXIT_FAILURE);
}
printf("[OK]\tsigaltstack is still SS_AUTODISARM after signal\n");
ksft_test_result_pass(
"sigaltstack is still SS_AUTODISARM after signal\n");
printf("[OK]\tTest passed\n");
ksft_exit_pass();
return 0;
}