Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / sigsuspend.cpp
bloba5930d4e87aa7c2946bc1117c14655402a091a88
1 // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
3 // Always enable asserts.
4 #ifdef NDEBUG
5 #undef NDEBUG
6 #endif
8 #include <assert.h>
9 #include <stdlib.h>
10 #include <signal.h>
11 #include <unistd.h>
12 #include <stdio.h>
14 static bool signal_handler_ran = false;
16 void do_nothing_signal_handler(int signum) {
17 write(1, "HANDLER\n", 8);
18 signal_handler_ran = true;
21 int main() {
22 const int kSignalToTest = SIGSYS;
23 assert(SIG_ERR != signal(kSignalToTest, do_nothing_signal_handler));
24 sigset_t empty_set;
25 assert(0 == sigemptyset(&empty_set));
26 sigset_t one_signal = empty_set;
27 assert(0 == sigaddset(&one_signal, kSignalToTest));
28 sigset_t old_set;
29 assert(0 == sigprocmask(SIG_BLOCK, &one_signal, &old_set));
30 raise(kSignalToTest);
31 assert(!signal_handler_ran);
32 sigset_t all_but_one;
33 assert(0 == sigfillset(&all_but_one));
34 assert(0 == sigdelset(&all_but_one, kSignalToTest));
35 sigsuspend(&all_but_one);
36 assert(signal_handler_ran);
38 // Restore the original set.
39 assert(0 == sigprocmask(SIG_SETMASK, &old_set, NULL));
40 printf("DONE\n");
43 // CHECK: HANDLER
44 // CHECK: DONE