0001
0002
0003
0004
0005
0006
0007
0008 #include <errno.h>
0009 #include <stdlib.h>
0010 #include <stdio.h>
0011 #include <string.h>
0012 #include <signal.h>
0013 #include <unistd.h>
0014
0015 #include <altivec.h>
0016
0017 #include "utils.h"
0018 #include "../tm/tm.h"
0019
0020 #define MAX_ATTEMPT 500000
0021 #define TIMEOUT 10
0022
0023 extern long tm_signal_self(pid_t pid, int sig, long *ret);
0024
0025 static sig_atomic_t signaled;
0026 static sig_atomic_t fail;
0027
0028 static void signal_handler(int sig)
0029 {
0030 if (tcheck_active()) {
0031 fail = 2;
0032 return;
0033 }
0034
0035 if (sig == SIGUSR1)
0036 signaled = 1;
0037 else
0038 fail = 1;
0039 }
0040
0041 static int test_signal_tm()
0042 {
0043 int i;
0044 struct sigaction act;
0045
0046 act.sa_handler = signal_handler;
0047 act.sa_flags = 0;
0048 sigemptyset(&act.sa_mask);
0049 if (sigaction(SIGUSR1, &act, NULL) < 0) {
0050 perror("sigaction SIGUSR1");
0051 exit(1);
0052 }
0053 if (sigaction(SIGALRM, &act, NULL) < 0) {
0054 perror("sigaction SIGALRM");
0055 exit(1);
0056 }
0057
0058 SKIP_IF(!have_htm());
0059 SKIP_IF(htm_is_synthetic());
0060
0061 for (i = 0; i < MAX_ATTEMPT; i++) {
0062
0063
0064
0065
0066 long ret = 0xdead;
0067 long rc = 0xbeef;
0068
0069 alarm(0);
0070 signaled = 0;
0071 alarm(TIMEOUT);
0072 FAIL_IF(tcheck_transactional());
0073 rc = tm_signal_self(getpid(), SIGUSR1, &ret);
0074 if (ret == 0xdead)
0075
0076
0077
0078
0079
0080
0081
0082 continue;
0083
0084 if (rc || ret) {
0085
0086 printf("TEXASR 0x%016lx, TFIAR 0x%016lx\n",
0087 __builtin_get_texasr(), __builtin_get_tfiar());
0088 fprintf(stderr, "(%d) Fail reason: %d rc=0x%lx ret=0x%lx\n",
0089 i, fail, rc, ret);
0090 FAIL_IF(ret);
0091 }
0092 while(!signaled && !fail)
0093 asm volatile("": : :"memory");
0094 if (!signaled) {
0095 fprintf(stderr, "(%d) Fail reason: %d rc=0x%lx ret=0x%lx\n",
0096 i, fail, rc, ret);
0097 FAIL_IF(fail);
0098 }
0099 }
0100
0101 return 0;
0102 }
0103
0104 int main(void)
0105 {
0106 return test_harness(test_signal_tm, "signal_tm");
0107 }