1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright 2016, Cyril Bur, IBM Corp.
5 * Sending one self a signal should always get delivered.
20 #define MAX_ATTEMPT 500000
23 extern long tm_signal_self(pid_t pid
, int sig
, long *ret
);
25 static sig_atomic_t signaled
;
26 static sig_atomic_t fail
;
28 static void signal_handler(int sig
)
30 if (tcheck_active()) {
41 static int test_signal_tm()
46 act
.sa_handler
= signal_handler
;
48 sigemptyset(&act
.sa_mask
);
49 if (sigaction(SIGUSR1
, &act
, NULL
) < 0) {
50 perror("sigaction SIGUSR1");
53 if (sigaction(SIGALRM
, &act
, NULL
) < 0) {
54 perror("sigaction SIGALRM");
60 for (i
= 0; i
< MAX_ATTEMPT
; i
++) {
62 * If anything bad happens in ASM and we fail to set ret
63 * because *handwave* TM this will cause failure
68 alarm(0); /* Disable any pending */
71 FAIL_IF(tcheck_transactional());
72 rc
= tm_signal_self(getpid(), SIGUSR1
, &ret
);
75 * This basically means the transaction aborted before we
76 * even got to the suspend... this is crazy but it
78 * Yes this also means we might never make forward
79 * progress... the alarm() will trip eventually...
84 /* Ret is actually an errno */
85 printf("TEXASR 0x%016lx, TFIAR 0x%016lx\n",
86 __builtin_get_texasr(), __builtin_get_tfiar());
87 fprintf(stderr
, "(%d) Fail reason: %d rc=0x%lx ret=0x%lx\n",
91 while(!signaled
&& !fail
)
92 asm volatile("": : :"memory");
94 fprintf(stderr
, "(%d) Fail reason: %d rc=0x%lx ret=0x%lx\n",
96 FAIL_IF(fail
); /* For the line number */
105 return test_harness(test_signal_tm
, "signal_tm");