signal_tm.c 2.4 KB

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