~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/powerpc/signal/signal_tm.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-or-later
  2 /*
  3  * Copyright 2016, Cyril Bur, IBM Corp.
  4  *
  5  * Sending one self a signal should always get delivered.
  6  */
  7 
  8 #include <errno.h>
  9 #include <stdlib.h>
 10 #include <stdio.h>
 11 #include <string.h>
 12 #include <signal.h>
 13 #include <unistd.h>
 14 
 15 #include <altivec.h>
 16 
 17 #include "utils.h"
 18 #include "../tm/tm.h"
 19 
 20 #define MAX_ATTEMPT 500000
 21 #define TIMEOUT 10
 22 
 23 extern long tm_signal_self(pid_t pid, int sig, long *ret);
 24 
 25 static sig_atomic_t signaled;
 26 static sig_atomic_t fail;
 27 
 28 static void signal_handler(int sig)
 29 {
 30         if (tcheck_active()) {
 31                 fail = 2;
 32                 return;
 33         }
 34 
 35         if (sig == SIGUSR1)
 36                 signaled = 1;
 37         else
 38                 fail = 1;
 39 }
 40 
 41 static int test_signal_tm()
 42 {
 43         int i;
 44         struct sigaction act;
 45 
 46         act.sa_handler = signal_handler;
 47         act.sa_flags = 0;
 48         sigemptyset(&act.sa_mask);
 49         if (sigaction(SIGUSR1, &act, NULL) < 0) {
 50                 perror("sigaction SIGUSR1");
 51                 exit(1);
 52         }
 53         if (sigaction(SIGALRM, &act, NULL) < 0) {
 54                 perror("sigaction SIGALRM");
 55                 exit(1);
 56         }
 57 
 58         SKIP_IF(!have_htm());
 59         SKIP_IF(htm_is_synthetic());
 60 
 61         for (i = 0; i < MAX_ATTEMPT; i++) {
 62                 /*
 63                  * If anything bad happens in ASM and we fail to set ret
 64                  * because *handwave* TM this will cause failure
 65                  */
 66                 long ret = 0xdead;
 67                 long rc = 0xbeef;
 68 
 69                 alarm(0); /* Disable any pending */
 70                 signaled = 0;
 71                 alarm(TIMEOUT);
 72                 FAIL_IF(tcheck_transactional());
 73                 rc = tm_signal_self(getpid(), SIGUSR1, &ret);
 74                 if (ret == 0xdead)
 75                         /*
 76                          * This basically means the transaction aborted before we
 77                          * even got to the suspend... this is crazy but it
 78                          * happens.
 79                          * Yes this also means we might never make forward
 80                          * progress... the alarm() will trip eventually...
 81                          */
 82                         continue;
 83 
 84                 if (rc || ret) {
 85                         /* Ret is actually an errno */
 86                         printf("TEXASR 0x%016lx, TFIAR 0x%016lx\n",
 87                                         __builtin_get_texasr(), __builtin_get_tfiar());
 88                         fprintf(stderr, "(%d) Fail reason: %d rc=0x%lx ret=0x%lx\n",
 89                                         i, fail, rc, ret);
 90                         FAIL_IF(ret);
 91                 }
 92                 while(!signaled && !fail)
 93                         asm volatile("": : :"memory");
 94                 if (!signaled) {
 95                         fprintf(stderr, "(%d) Fail reason: %d rc=0x%lx ret=0x%lx\n",
 96                                         i, fail, rc, ret);
 97                         FAIL_IF(fail); /* For the line number */
 98                 }
 99         }
100 
101         return 0;
102 }
103 
104 int main(void)
105 {
106         return test_harness(test_signal_tm, "signal_tm");
107 }
108 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php