[LVI] Add trunc to i1 handling. (#124480)
[llvm-project.git] / compiler-rt / test / asan / TestCases / Posix / coverage-fork.cpp
bloba8768479de2f675c5bc0cd7718cc595cf2792fa2
1 // RUN: %clangxx_asan -fsanitize-coverage=func,trace-pc-guard %s -o %t
2 // RUN: rm -rf %t-dir
3 // RUN: mkdir -p %t-dir && cd %t-dir
4 // RUN: %env_asan_opts=coverage=1:verbosity=1 %run %t 2>&1 | FileCheck %s
5 //
6 // UNSUPPORTED: android
7 // UNSUPPORTED: iossim
8 //
9 // Ideally a forked-subprocess should only report it's own coverage,
10 // not parent's one. But trace-pc-guard currently does nothing special for fork,
11 // and thus this test is relaxed.
13 #include <stdio.h>
14 #include <string.h>
15 #include <sys/wait.h>
16 #include <unistd.h>
18 __attribute__((noinline))
19 void foo() { printf("foo\n"); }
21 __attribute__((noinline))
22 void bar() { printf("bar\n"); }
24 __attribute__((noinline))
25 void baz() { printf("baz\n"); }
27 int main(int argc, char **argv) {
28 pid_t child_pid = fork();
29 char buf[100];
30 if (child_pid == 0) {
31 snprintf(buf, sizeof(buf), "Child PID: %ld\n", (long)getpid());
32 write(2, buf, strlen(buf));
33 baz();
34 } else {
35 snprintf(buf, sizeof(buf), "Parent PID: %ld\n", (long)getpid());
36 write(2, buf, strlen(buf));
37 foo();
38 bar();
40 // Wait for the child process(s) to finish
41 while (wait(NULL) > 0)
44 return 0;
47 // CHECK-DAG: Child PID: [[ChildPID:[0-9]+]]
48 // CHECK-DAG: [[ChildPID]].sancov: {{.*}} PCs written
49 // CHECK-DAG: Parent PID: [[ParentPID:[0-9]+]]
50 // CHECK-DAG: [[ParentPID]].sancov: 3 PCs written