diff options
| author | Cyril Bur <cyrilbur@gmail.com> | 2016-09-23 02:18:19 -0400 |
|---|---|---|
| committer | Michael Ellerman <mpe@ellerman.id.au> | 2016-10-04 05:26:36 -0400 |
| commit | ef186331b427fdf2bf791d184921df6c6c6e9a63 (patch) | |
| tree | 76847aa838ac0a4a6707b91905dc9bfeb57632df /tools/testing | |
| parent | 8e03bd4e70b6a4c70ac3ea6766b2bc06a8ad91a3 (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>
Diffstat (limited to 'tools/testing')
| -rw-r--r-- | tools/testing/selftests/powerpc/Makefile | 1 | ||||
| -rw-r--r-- | tools/testing/selftests/powerpc/signal/Makefile | 13 | ||||
| -rw-r--r-- | tools/testing/selftests/powerpc/signal/signal.S | 50 | ||||
| -rw-r--r-- | tools/testing/selftests/powerpc/signal/signal.c | 111 | ||||
| -rw-r--r-- | tools/testing/selftests/powerpc/signal/signal_tm.c | 110 |
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 @@ | |||
| 1 | TEST_PROGS := signal signal_tm | ||
| 2 | |||
| 3 | all: $(TEST_PROGS) | ||
| 4 | |||
| 5 | $(TEST_PROGS): ../harness.c ../utils.c signal.S | ||
| 6 | |||
| 7 | CFLAGS += -maltivec | ||
| 8 | signal_tm: CFLAGS += -mhtm | ||
| 9 | |||
| 10 | include ../../lib.mk | ||
| 11 | |||
| 12 | clean: | ||
| 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); */ | ||
| 13 | FUNC_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 | ||
| 20 | 1: blr | ||
| 21 | FUNC_END(signal_self) | ||
| 22 | |||
| 23 | /* long tm_signal_self(pid_t pid, int sig, int *ret); */ | ||
| 24 | FUNC_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 | ||
| 37 | 2: 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 | ||
| 47 | 1: li r3,0 | ||
| 48 | POP_BASIC_STACK(8) | ||
| 49 | blr | ||
| 50 | FUNC_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 | |||
| 27 | extern long signal_self(pid_t pid, int sig); | ||
| 28 | |||
| 29 | static sig_atomic_t signaled; | ||
| 30 | static sig_atomic_t fail; | ||
| 31 | |||
| 32 | static void signal_handler(int sig) | ||
| 33 | { | ||
| 34 | if (sig == SIGUSR1) | ||
| 35 | signaled = 1; | ||
| 36 | else | ||
| 37 | fail = 1; | ||
| 38 | } | ||
| 39 | |||
| 40 | static 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 | |||
| 107 | int 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/nul | |||
