diff options
author | Shuah Khan <shuahkh@osg.samsung.com> | 2017-07-26 20:58:12 -0400 |
---|---|---|
committer | Shuah Khan <shuahkh@osg.samsung.com> | 2017-08-02 15:55:48 -0400 |
commit | 5ec8d6ce615bada0e75717492f2291de62fd7d54 (patch) | |
tree | 6c5407b3614b84c0f0959ff8444752a3bd18776d | |
parent | 5b1b9c5851348c941ec0705c7c0baa5bef637ceb (diff) |
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>
-rw-r--r-- | tools/testing/selftests/sigaltstack/sas.c | 53 |
1 files changed, 31 insertions, 22 deletions
diff --git a/tools/testing/selftests/sigaltstack/sas.c b/tools/testing/selftests/sigaltstack/sas.c index ccd07343d418..7d406c3973ba 100644 --- a/tools/testing/selftests/sigaltstack/sas.c +++ b/tools/testing/selftests/sigaltstack/sas.c | |||
@@ -17,6 +17,8 @@ | |||
17 | #include <assert.h> | 17 | #include <assert.h> |
18 | #include <errno.h> | 18 | #include <errno.h> |
19 | 19 | ||
20 | #include "../kselftest.h" | ||
21 | |||
20 | #ifndef SS_AUTODISARM | 22 | #ifndef SS_AUTODISARM |
21 | #define SS_AUTODISARM (1U << 31) | 23 | #define SS_AUTODISARM (1U << 31) |
22 | #endif | 24 | #endif |
@@ -41,8 +43,7 @@ void my_usr1(int sig, siginfo_t *si, void *u) | |||
41 | 43 | ||
42 | if (sp < (unsigned long)sstack || | 44 | if (sp < (unsigned long)sstack || |
43 | sp >= (unsigned long)sstack + SIGSTKSZ) { | 45 | sp >= (unsigned long)sstack + SIGSTKSZ) { |
44 | printf("[FAIL]\tSP is not on sigaltstack\n"); | 46 | ksft_exit_fail_msg("SP is not on sigaltstack\n"); |
45 | exit(EXIT_FAILURE); | ||
46 | } | 47 | } |
47 | /* put some data on stack. other sighandler will try to overwrite it */ | 48 | /* put some data on stack. other sighandler will try to overwrite it */ |
48 | aa = alloca(1024); | 49 | aa = alloca(1024); |
@@ -50,21 +51,22 @@ void my_usr1(int sig, siginfo_t *si, void *u) | |||
50 | p = (struct stk_data *)(aa + 512); | 51 | p = (struct stk_data *)(aa + 512); |
51 | strcpy(p->msg, msg); | 52 | strcpy(p->msg, msg); |
52 | p->flag = 1; | 53 | p->flag = 1; |
53 | printf("[RUN]\tsignal USR1\n"); | 54 | ksft_print_msg("[RUN]\tsignal USR1\n"); |
54 | err = sigaltstack(NULL, &stk); | 55 | err = sigaltstack(NULL, &stk); |
55 | if (err) { | 56 | if (err) { |
56 | perror("[FAIL]\tsigaltstack()"); | 57 | ksft_exit_fail_msg("sigaltstack() - %s\n", strerror(errno)); |
57 | exit(EXIT_FAILURE); | 58 | exit(EXIT_FAILURE); |
58 | } | 59 | } |
59 | if (stk.ss_flags != SS_DISABLE) | 60 | if (stk.ss_flags != SS_DISABLE) |
60 | printf("[FAIL]\tss_flags=%x, should be SS_DISABLE\n", | 61 | ksft_test_result_fail("tss_flags=%x, should be SS_DISABLE\n", |
61 | stk.ss_flags); | 62 | stk.ss_flags); |
62 | else | 63 | else |
63 | printf("[OK]\tsigaltstack is disabled in sighandler\n"); | 64 | ksft_test_result_pass( |
65 | "sigaltstack is disabled in sighandler\n"); | ||
64 | swapcontext(&sc, &uc); | 66 | swapcontext(&sc, &uc); |
65 | printf("%s\n", p->msg); | 67 | ksft_print_msg("%s\n", p->msg); |
66 | if (!p->flag) { | 68 | if (!p->flag) { |
67 | printf("[RUN]\tAborting\n"); | 69 | ksft_exit_skip("[RUN]\tAborting\n"); |
68 | exit(EXIT_FAILURE); | 70 | exit(EXIT_FAILURE); |
69 | } | 71 | } |
70 | } | 72 | } |
@@ -74,13 +76,13 @@ void my_usr2(int sig, siginfo_t *si, void *u) | |||
74 | char *aa; | 76 | char *aa; |
75 | struct stk_data *p; | 77 | struct stk_data *p; |
76 | 78 | ||
77 | printf("[RUN]\tsignal USR2\n"); | 79 | ksft_print_msg("[RUN]\tsignal USR2\n"); |
78 | aa = alloca(1024); | 80 | aa = alloca(1024); |
79 | /* dont run valgrind on this */ | 81 | /* dont run valgrind on this */ |
80 | /* try to find the data stored by previous sighandler */ | 82 | /* try to find the data stored by previous sighandler */ |
81 | p = memmem(aa, 1024, msg, strlen(msg)); | 83 | p = memmem(aa, 1024, msg, strlen(msg)); |
82 | if (p) { | 84 | if (p) { |
83 | printf("[FAIL]\tsigaltstack re-used\n"); | 85 | ksft_test_result_fail("sigaltstack re-used\n"); |
84 | /* corrupt the data */ | 86 | /* corrupt the data */ |
85 | strcpy(p->msg, msg2); | 87 | strcpy(p->msg, msg2); |
86 | /* tell other sighandler that his data is corrupted */ | 88 | /* tell other sighandler that his data is corrupted */ |
@@ -90,7 +92,7 @@ void my_usr2(int sig, siginfo_t *si, void *u) | |||
90 | 92 | ||
91 | static void switch_fn(void) | 93 | static void switch_fn(void) |
92 | { | 94 | { |
93 | printf("[RUN]\tswitched to user ctx\n"); | 95 | ksft_print_msg("[RUN]\tswitched to user ctx\n"); |
94 | raise(SIGUSR2); | 96 | raise(SIGUSR2); |
95 | setcontext(&sc); | 97 | setcontext(&sc); |
96 | } | 98 | } |
@@ -101,6 +103,8 @@ int main(void) | |||
101 | stack_t stk; | 103 | stack_t stk; |
102 | int err; | 104 | int err; |
103 | 105 | ||
106 | ksft_print_header(); | ||
107 | |||
104 | sigemptyset(&act.sa_mask); | 108 | sigemptyset(&act.sa_mask); |
105 | act.sa_flags = SA_ONSTACK | SA_SIGINFO; | 109 | act.sa_flags = SA_ONSTACK | SA_SIGINFO; |
106 | act.sa_sigaction = my_usr1; | 110 | act.sa_sigaction = my_usr1; |
@@ -110,19 +114,20 @@ int main(void) | |||
110 | sstack = mmap(NULL, SIGSTKSZ, PROT_READ | PROT_WRITE, | 114 | sstack = mmap(NULL, SIGSTKSZ, PROT_READ | PROT_WRITE, |
111 | MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, -1, 0); | 115 | MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, -1, 0); |
112 | if (sstack == MAP_FAILED) { | 116 | if (sstack == MAP_FAILED) { |
113 | perror("mmap()"); | 117 | ksft_exit_fail_msg("mmap() - %s\n", strerror(errno)); |
114 | return EXIT_FAILURE; | 118 | return EXIT_FAILURE; |
115 | } | 119 | } |
116 | 120 | ||
117 | err = sigaltstack(NULL, &stk); | 121 | err = sigaltstack(NULL, &stk); |
118 | if (err) { | 122 | if (err) { |
119 | perror("[FAIL]\tsigaltstack()"); | 123 | ksft_exit_fail_msg("sigaltstack() - %s\n", strerror(errno)); |
120 | exit(EXIT_FAILURE); | 124 | exit(EXIT_FAILURE); |
121 | } | 125 | } |
122 | if (stk.ss_flags == SS_DISABLE) { | 126 | if (stk.ss_flags == SS_DISABLE) { |
123 | printf("[OK]\tInitial sigaltstack state was SS_DISABLE\n"); | 127 | ksft_test_result_pass( |
128 | "Initial sigaltstack state was SS_DISABLE\n"); | ||
124 | } else { | 129 | } else { |
125 | printf("[FAIL]\tInitial sigaltstack state was %x; " | 130 | ksft_exit_fail_msg("Initial sigaltstack state was %x; " |
126 | "should have been SS_DISABLE\n", stk.ss_flags); | 131 | "should have been SS_DISABLE\n", stk.ss_flags); |
127 | return EXIT_FAILURE; | 132 | return EXIT_FAILURE; |
128 | } | 133 | } |
@@ -133,7 +138,8 @@ int main(void) | |||
133 | err = sigaltstack(&stk, NULL); | 138 | err = sigaltstack(&stk, NULL); |
134 | if (err) { | 139 | if (err) { |
135 | if (errno == EINVAL) { | 140 | if (errno == EINVAL) { |
136 | printf("[NOTE]\tThe running kernel doesn't support SS_AUTODISARM\n"); | 141 | ksft_exit_skip( |
142 | "[NOTE]\tThe running kernel doesn't support SS_AUTODISARM\n"); | ||
137 | /* | 143 | /* |
138 | * If test cases for the !SS_AUTODISARM variant were | 144 | * If test cases for the !SS_AUTODISARM variant were |
139 | * added, we could still run them. We don't have any | 145 | * added, we could still run them. We don't have any |
@@ -142,7 +148,9 @@ int main(void) | |||
142 | */ | 148 | */ |
143 | return 0; | 149 | return 0; |
144 | } else { | 150 | } else { |
145 | perror("[FAIL]\tsigaltstack(SS_ONSTACK | SS_AUTODISARM)"); | 151 | ksft_exit_fail_msg( |
152 | "sigaltstack(SS_ONSTACK | SS_AUTODISARM) %s\n", | ||
153 | strerror(errno)); | ||
146 | return EXIT_FAILURE; | 154 | return EXIT_FAILURE; |
147 | } | 155 | } |
148 | } | 156 | } |
@@ -150,7 +158,7 @@ int main(void) | |||
150 | ustack = mmap(NULL, SIGSTKSZ, PROT_READ | PROT_WRITE, | 158 | ustack = mmap(NULL, SIGSTKSZ, PROT_READ | PROT_WRITE, |
151 | MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, -1, 0); | 159 | MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, -1, 0); |
152 | if (ustack == MAP_FAILED) { | 160 | if (ustack == MAP_FAILED) { |
153 | perror("mmap()"); | 161 | ksft_exit_fail_msg("mmap() - %s\n", strerror(errno)); |
154 | return EXIT_FAILURE; | 162 | return EXIT_FAILURE; |
155 | } | 163 | } |
156 | getcontext(&uc); | 164 | getcontext(&uc); |
@@ -162,16 +170,17 @@ int main(void) | |||
162 | 170 | ||
163 | err = sigaltstack(NULL, &stk); | 171 | err = sigaltstack(NULL, &stk); |
164 | if (err) { | 172 | if (err) { |
165 | perror("[FAIL]\tsigaltstack()"); | 173 | ksft_exit_fail_msg("sigaltstack() - %s\n", strerror(errno)); |
166 | exit(EXIT_FAILURE); | 174 | exit(EXIT_FAILURE); |
167 | } | 175 | } |
168 | if (stk.ss_flags != SS_AUTODISARM) { | 176 | if (stk.ss_flags != SS_AUTODISARM) { |
169 | printf("[FAIL]\tss_flags=%x, should be SS_AUTODISARM\n", | 177 | ksft_exit_fail_msg("ss_flags=%x, should be SS_AUTODISARM\n", |
170 | stk.ss_flags); | 178 | stk.ss_flags); |
171 | exit(EXIT_FAILURE); | 179 | exit(EXIT_FAILURE); |
172 | } | 180 | } |
173 | printf("[OK]\tsigaltstack is still SS_AUTODISARM after signal\n"); | 181 | ksft_test_result_pass( |
182 | "sigaltstack is still SS_AUTODISARM after signal\n"); | ||
174 | 183 | ||
175 | printf("[OK]\tTest passed\n"); | 184 | ksft_exit_pass(); |
176 | return 0; | 185 | return 0; |
177 | } | 186 | } |