aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCyril Bur <cyrilbur@gmail.com>2016-09-23 02:18:19 -0400
committerMichael Ellerman <mpe@ellerman.id.au>2016-10-04 05:26:36 -0400
commitef186331b427fdf2bf791d184921df6c6c6e9a63 (patch)
tree76847aa838ac0a4a6707b91905dc9bfeb57632df
parent8e03bd4e70b6a4c70ac3ea6766b2bc06a8ad91a3 (diff)
selftests/powerpc: Check that signals always get delivered
Signed-off-by: Cyril Bur <cyrilbur@gmail.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
-rw-r--r--tools/testing/selftests/powerpc/Makefile1
-rw-r--r--tools/testing/selftests/powerpc/signal/Makefile13
-rw-r--r--tools/testing/selftests/powerpc/signal/signal.S50
-rw-r--r--tools/testing/selftests/powerpc/signal/signal.c111
-rw-r--r--tools/testing/selftests/powerpc/signal/signal_tm.c110
5 files changed, 285 insertions, 0 deletions
diff --git a/tools/testing/selftests/powerpc/Makefile b/tools/testing/selftests/powerpc/Makefile
index 1cc6d64c39b7..db54a33f850f 100644
--- a/tools/testing/selftests/powerpc/Makefile
+++ b/tools/testing/selftests/powerpc/Makefile
@@ -19,6 +19,7 @@ SUB_DIRS = alignment \
19 dscr \ 19 dscr \
20 mm \ 20 mm \
21 pmu \ 21 pmu \
22 signal \
22 primitives \ 23 primitives \
23 stringloops \ 24 stringloops \
24 switch_endian \ 25 switch_endian \
diff --git a/tools/testing/selftests/powerpc/signal/Makefile b/tools/testing/selftests/powerpc/signal/Makefile
new file mode 100644
index 000000000000..f0eef27458e2
--- /dev/null
+++ b/tools/testing/selftests/powerpc/signal/Makefile
@@ -0,0 +1,13 @@
1TEST_PROGS := signal signal_tm
2
3all: $(TEST_PROGS)
4
5$(TEST_PROGS): ../harness.c ../utils.c signal.S
6
7CFLAGS += -maltivec
8signal_tm: CFLAGS += -mhtm
9
10include ../../lib.mk
11
12clean:
13 rm -f $(TEST_PROGS) *.o
diff --git a/tools/testing/selftests/powerpc/signal/signal.S b/tools/testing/selftests/powerpc/signal/signal.S
new file mode 100644
index 000000000000..7043d521df0a
--- /dev/null
+++ b/tools/testing/selftests/powerpc/signal/signal.S
@@ -0,0 +1,50 @@
1/*
2 * Copyright 2015, Cyril Bur, IBM Corp.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 */
9
10#include "../basic_asm.h"
11
12/* long signal_self(pid_t pid, int sig); */
13FUNC_START(signal_self)
14 li r0,37 /* sys_kill */
15 /* r3 already has our pid in it */
16 /* r4 already has signal type in it */
17 sc
18 bc 4,3,1f
19 subfze r3,r3
201: blr
21FUNC_END(signal_self)
22
23/* long tm_signal_self(pid_t pid, int sig, int *ret); */
24FUNC_START(tm_signal_self)
25 PUSH_BASIC_STACK(8)
26 std r5,STACK_FRAME_PARAM(0)(sp) /* ret */
27 tbegin.
28 beq 1f
29 tsuspend.
30 li r0,37 /* sys_kill */
31 /* r3 already has our pid in it */
32 /* r4 already has signal type in it */
33 sc
34 ld r5,STACK_FRAME_PARAM(0)(sp) /* ret */
35 bc 4,3,2f
36 subfze r3,r3
372: std r3,0(r5)
38 tabort. 0
39 tresume. /* Be nice to some cleanup, jumps back to tbegin then to 1: */
40 /*
41 * Transaction should be proper doomed and we should never get
42 * here
43 */
44 li r3,1
45 POP_BASIC_STACK(8)
46 blr
471: li r3,0
48 POP_BASIC_STACK(8)
49 blr
50FUNC_END(tm_signal_self)
diff --git a/tools/testing/selftests/powerpc/signal/signal.c b/tools/testing/selftests/powerpc/signal/signal.c
new file mode 100644
index 000000000000..e7dedd28b3c2
--- /dev/null
+++ b/tools/testing/selftests/powerpc/signal/signal.c
@@ -0,0 +1,111 @@
1/*
2 * Copyright 2016, Cyril Bur, IBM Corp.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 *
9 * Sending one self a signal should always get delivered.
10 */
11
12#include <signal.h>
13#include <stdio.h>
14#include <stdlib.h>
15#include <string.h>
16#include <sys/types.h>
17#include <sys/wait.h>
18#include <unistd.h>
19
20#include <altivec.h>
21
22#include "utils.h"
23
24#define MAX_ATTEMPT 500000
25#define TIMEOUT 5
26
27extern long signal_self(pid_t pid, int sig);
28
29static sig_atomic_t signaled;
30static sig_atomic_t fail;
31
32static void signal_handler(int sig)
33{
34 if (sig == SIGUSR1)
35 signaled = 1;
36 else
37 fail = 1;
38}
39
40static int test_signal()
41{
42 int i;
43 struct sigaction act;
44 pid_t ppid = getpid();
45 pid_t pid;
46
47 act.sa_handler = signal_handler;
48 act.sa_flags = 0;
49 sigemptyset(&act.sa_mask);
50 if (sigaction(SIGUSR1, &act, NULL) < 0) {
51 perror("sigaction SIGUSR1");
52 exit(1);
53 }
54 if (sigaction(SIGALRM, &act, NULL) < 0) {
55 perror("sigaction SIGALRM");
56 exit(1);
57 }
58
59 /* Don't do this for MAX_ATTEMPT, its simply too long */
60 for(i = 0; i < 1000; i++) {
61 pid = fork();
62 if (pid == -1) {
63 perror("fork");
64 exit(1);
65 }
66 if (pid == 0) {
67 signal_self(ppid, SIGUSR1);
68 exit(1);
69 } else {
70 alarm(0); /* Disable any pending */
71 alarm(2);
72 while (!signaled && !fail)
73 asm volatile("": : :"memory");
74 if (!signaled) {
75 fprintf(stderr, "Didn't get signal from child\n");
76 FAIL_IF(1); /* For the line number */
77 }
78 /* Otherwise we'll loop too fast and fork() will eventually fail */
79 waitpid(pid, NULL, 0);
80 }
81 }
82
83 for (i = 0; i < MAX_ATTEMPT; i++) {
84 long rc;
85
86 alarm(0); /* Disable any pending */
87 signaled = 0;
88 alarm(TIMEOUT);
89 rc = signal_self(ppid, SIGUSR1);
90 if (rc) {
91 fprintf(stderr, "(%d) Fail reason: %d rc=0x%lx",
92 i, fail, rc);
93 FAIL_IF(1); /* For the line number */
94 }
95 while (!signaled && !fail)
96 asm volatile("": : :"memory");
97 if (!signaled) {
98 fprintf(stderr, "(%d) Fail reason: %d rc=0x%lx",
99 i, fail, rc);
100 FAIL_IF(1); /* For the line number */
101 }
102 }
103
104 return 0;
105}
106
107int main(void)
108{
109 test_harness_set_timeout(300);
110 return test_harness(test_signal, "signal");
111}
diff --git a/tools/testing/selftests/powerpc/signal/signal_tm.c b/tools/testing/selftests/powerpc/signal/signal_tm.c
new file mode 100644
index 000000000000..2e7451a37cc6
--- /dev/null
+++ b/tools/testing/selftests/powerpc/signal/signal_tm.c
@@ -0,0 +1,110 @@
1/*
2 * Copyright 2016, Cyril Bur, IBM Corp.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 *
9 * Sending one self a signal should always get delivered.
10 */
11
12#include <errno.h>
13#include <stdlib.h>
14#include <stdio.h>
15#include <string.h>
16#include <signal.h>
17#include <unistd.h>
18
19#include <altivec.h>
20
21#include "utils.h"
22#include "../tm/tm.h"
23
24#define MAX_ATTEMPT 500000
25#define TIMEOUT 10
26
27extern long tm_signal_self(pid_t pid, int sig, long *ret);
28
29static sig_atomic_t signaled;
30static sig_atomic_t fail;
31
32static void signal_handler(int sig)
33{
34 if (tcheck_active()) {
35 fail = 2;
36 return;
37 }
38
39 if (sig == SIGUSR1)
40 signaled = 1;
41 else
42 fail = 1;
43}
44
45static int test_signal_tm()
46{
47 int i;
48 struct sigaction act;
49
50 act.sa_handler = signal_handler;
51 act.sa_flags = 0;
52 sigemptyset(&act.sa_mask);
53 if (sigaction(SIGUSR1, &act, NULL) < 0) {
54 perror("sigaction SIGUSR1");
55 exit(1);
56 }
57 if (sigaction(SIGALRM, &act, NULL) < 0) {
58 perror("sigaction SIGALRM");
59 exit(1);
60 }
61
62 SKIP_IF(!have_htm());
63
64 for (i = 0; i < MAX_ATTEMPT; i++) {
65 /*
66 * If anything bad happens in ASM and we fail to set ret
67 * because *handwave* TM this will cause failure
68 */
69 long ret = 0xdead;
70 long rc = 0xbeef;
71
72 alarm(0); /* Disable any pending */
73 signaled = 0;
74 alarm(TIMEOUT);
75 FAIL_IF(tcheck_transactional());
76 rc = tm_signal_self(getpid(), SIGUSR1, &ret);
77 if (ret == 0xdead)
78 /*
79 * This basically means the transaction aborted before we
80 * even got to the suspend... this is crazy but it
81 * happens.
82 * Yes this also means we might never make forward
83 * progress... the alarm() will trip eventually...
84 */
85 continue;
86
87 if (rc || ret) {
88 /* Ret is actually an errno */
89 printf("TEXASR 0x%016lx, TFIAR 0x%016lx\n",
90 __builtin_get_texasr(), __builtin_get_tfiar());
91 fprintf(stderr, "(%d) Fail reason: %d rc=0x%lx ret=0x%lx\n",
92 i, fail, rc, ret);
93 FAIL_IF(ret);
94 }
95 while(!signaled && !fail)
96 asm volatile("": : :"memory");
97 if (!signaled) {
98 fprintf(stderr, "(%d) Fail reason: %d rc=0x%lx ret=0x%lx\n",
99 i, fail, rc, ret);
100 FAIL_IF(fail); /* For the line number */
101 }
102 }
103
104 return 0;
105}
106
107int main(void)
108{
109 return test_harness(test_signal_tm, "signal_tm");
110}