Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / mmap_stress.cpp
blobc6fd8f02dd1d90e42985c00fbd2b44afe4759b9e
1 // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
2 // This test is flaky on several builders:
3 // https://groups.google.com/d/msg/llvm-dev/KUFPdLhBN3Q/L75rwW9xBgAJ
4 // The cause is unknown (lit hides test output on failures).
5 // Let's try to re-enable it at least in one configutaion.
6 // REQUIRES: linux, x86_64-target-arch
7 #include "test.h"
8 #include <errno.h>
9 #include <sys/mman.h>
11 void *SubWorker(void *arg) {
12 (void)arg;
13 const int kMmapSize = 65536;
14 for (int i = 0; i < 500; i++) {
15 int *ptr = (int*)mmap(0, kMmapSize, PROT_READ | PROT_WRITE,
16 MAP_PRIVATE | MAP_ANON, -1, 0);
17 if (ptr == MAP_FAILED)
18 exit(printf("mmap failed: %d\n", errno));
19 *ptr = 42;
20 if (munmap(ptr, kMmapSize))
21 exit(printf("munmap failed: %d\n", errno));
23 return 0;
26 void *Worker1(void *arg) {
27 (void)arg;
28 pthread_t th[4];
29 for (int i = 0; i < 4; i++) {
30 if (pthread_create(&th[i], 0, SubWorker, 0))
31 exit(printf("pthread_create failed: %d\n", errno));
33 for (int i = 0; i < 4; i++) {
34 if (pthread_join(th[i], 0))
35 exit(printf("pthread_join failed: %d\n", errno));
37 return 0;
40 void *Worker(void *arg) {
41 (void)arg;
42 pthread_t th[4];
43 for (int i = 0; i < 4; i++) {
44 if (pthread_create(&th[i], 0, Worker1, 0))
45 exit(printf("pthread_create failed: %d\n", errno));
47 for (int i = 0; i < 4; i++) {
48 if (pthread_join(th[i], 0))
49 exit(printf("pthread_join failed: %d\n", errno));
51 return 0;
54 int main() {
55 pthread_t th[4];
56 for (int i = 0; i < 4; i++) {
57 if (pthread_create(&th[i], 0, Worker, 0))
58 exit(printf("pthread_create failed: %d\n", errno));
60 for (int i = 0; i < 4; i++) {
61 if (pthread_join(th[i], 0))
62 exit(printf("pthread_join failed: %d\n", errno));
64 fprintf(stderr, "DONE\n");
67 // CHECK: DONE