1 // RUN: %clangxx_asan -fsanitize-coverage=func %s -o %t
2 // RUN: rm -rf %T/coverage-fork-direct
3 // RUN: mkdir -p %T/coverage-fork-direct && cd %T/coverage-fork-direct
4 // RUN: (%env_asan_opts=coverage=1:coverage_direct=1:verbosity=1 %run %t; \
5 // RUN:  %sancov rawunpack *.sancov.raw; %sancov print *.sancov) 2>&1
6 //
7 // XFAIL: android
8 
9 #include <stdio.h>
10 #include <string.h>
11 #include <unistd.h>
12 
13 __attribute__((noinline))
foo()14 void foo() { printf("foo\n"); }
15 
16 __attribute__((noinline))
bar()17 void bar() { printf("bar\n"); }
18 
19 __attribute__((noinline))
baz()20 void baz() { printf("baz\n"); }
21 
main(int argc,char ** argv)22 int main(int argc, char **argv) {
23   pid_t child_pid = fork();
24   if (child_pid == 0) {
25     fprintf(stderr, "Child PID: %d\n", getpid());
26     baz();
27   } else {
28     fprintf(stderr, "Parent PID: %d\n", getpid());
29     foo();
30     bar();
31   }
32   return 0;
33 }
34 
35 // CHECK-DAG: Child PID: [[ChildPID:[0-9]+]]
36 // CHECK-DAG: Parent PID: [[ParentPID:[0-9]+]]
37 // CHECK-DAG: read 3 PCs from {{.*}}.[[ParentPID]].sancov
38 // CHECK-DAG: read 1 PCs from {{.*}}.[[ChildPID]].sancov
39