1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include <stdlib.h>
25#include <stdio.h>
26#include <signal.h>
27#include <unistd.h>
28
29#include <altivec.h>
30
31#include "utils.h"
32#include "tm.h"
33
34#define MAX_ATTEMPT 500000
35
36#define NV_FPU_REGS 18
37
38long tm_signal_self_context_load(pid_t pid, long *gprs, double *fps, vector int *vms, vector int *vss);
39
40
41static double fps[] = {
42 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
43 -1,-2,-3,-4,-5,-6,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18
44};
45
46static sig_atomic_t fail;
47
48static void signal_usr1(int signum, siginfo_t *info, void *uc)
49{
50 int i;
51 ucontext_t *ucp = uc;
52 ucontext_t *tm_ucp = ucp->uc_link;
53
54 for (i = 0; i < NV_FPU_REGS && !fail; i++) {
55 fail = (ucp->uc_mcontext.fp_regs[i + 14] != fps[i]);
56 fail |= (tm_ucp->uc_mcontext.fp_regs[i + 14] != fps[i + NV_FPU_REGS]);
57 if (fail)
58 printf("Failed on %d FP %g or %g\n", i, ucp->uc_mcontext.fp_regs[i + 14], tm_ucp->uc_mcontext.fp_regs[i + 14]);
59 }
60}
61
62static int tm_signal_context_chk_fpu()
63{
64 struct sigaction act;
65 int i;
66 long rc;
67 pid_t pid = getpid();
68
69 SKIP_IF(!have_htm());
70
71 act.sa_sigaction = signal_usr1;
72 sigemptyset(&act.sa_mask);
73 act.sa_flags = SA_SIGINFO;
74 if (sigaction(SIGUSR1, &act, NULL) < 0) {
75 perror("sigaction sigusr1");
76 exit(1);
77 }
78
79 i = 0;
80 while (i < MAX_ATTEMPT && !fail) {
81 rc = tm_signal_self_context_load(pid, NULL, fps, NULL, NULL);
82 FAIL_IF(rc != pid);
83 i++;
84 }
85
86 return fail;
87}
88
89int main(void)
90{
91 return test_harness(tm_signal_context_chk_fpu, "tm_signal_context_chk_fpu");
92}
93