1 // RUN: %clangxx_asan -fsanitize-coverage=1 %s -o %t
2 // RUN: export ASAN_OPTIONS=coverage=1:coverage_direct=0:verbosity=1
3 // RUN: rm -rf %T/coverage-fork
4 // RUN: mkdir -p %T/coverage-fork && cd %T/coverage-fork
5 // RUN: %run %t 2>&1 | FileCheck %s
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: [[ChildPID]].sancov: 1 PCs written
37 // CHECK-DAG: Parent PID: [[ParentPID:[0-9]+]]
38 // CHECK-DAG: [[ParentPID]].sancov: 3 PCs written
39