]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/lsan/TestCases/Linux/fork_with_threads.cc
Vendor import of compiler-rt trunk r338536:
[FreeBSD/FreeBSD.git] / test / lsan / TestCases / Linux / fork_with_threads.cc
1 // Test forked process does not run lsan.
2 // RUN: %clangxx_lsan %s -o %t && %run %t 2>&1 | FileCheck %s
3
4 #include <pthread.h>
5 #include <stdlib.h>
6 #include <sys/wait.h>
7 #include <unistd.h>
8
9 static pthread_barrier_t barrier;
10
11 // CHECK-NOT: SUMMARY: {{(Leak|Address)}}Sanitizer:
12 static void *thread_func(void *arg) {
13   void *buffer = malloc(1337);
14   pthread_barrier_wait(&barrier);
15   for (;;)
16     pthread_yield();
17   return 0;
18 }
19
20 int main() {
21   pthread_barrier_init(&barrier, 0, 2);
22   pthread_t tid;
23   int res = pthread_create(&tid, 0, thread_func, 0);
24   pthread_barrier_wait(&barrier);
25   pthread_barrier_destroy(&barrier);
26
27   pid_t pid = fork();
28   if (pid > 0) {
29     int status = 0;
30     waitpid(pid, &status, 0);
31   }
32   return 0;
33 }
34
35 // CHECK: WARNING: LeakSanitizer is disabled in forked process