1 // RUN: %clangxx_asan -fsanitize-coverage=func,trace-pc-guard %s -o %t
3 // RUN: mkdir -p %t-dir && cd %t-dir
4 // RUN: %env_asan_opts=coverage=1:verbosity=1 %run %t 2>&1 | FileCheck %s
6 // UNSUPPORTED: android
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.
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();
31 snprintf(buf
, sizeof(buf
), "Child PID: %ld\n", (long)getpid());
32 write(2, buf
, strlen(buf
));
35 snprintf(buf
, sizeof(buf
), "Parent PID: %ld\n", (long)getpid());
36 write(2, buf
, strlen(buf
));
40 // Wait for the child process(s) to finish
41 while (wait(NULL
) > 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