1
2
3
4
5
6
7
8
9
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
67
68
69 long ret = 0xdead;
70 long rc = 0xbeef;
71
72 alarm(0);
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
80
81
82
83
84
85 continue;
86
87 if (rc || ret) {
88
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);
101 }
102 }
103
104 return 0;
105}
106
107int main(void)
108{
109 return test_harness(test_signal_tm, "signal_tm");
110}
111