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 // 8 // Ideally a forked-subprocess should only report it's own coverage, 9 // not parent's one. But trace-pc-guard currently does nothing special for fork, 10 // and thus this test is relaxed. 11 12 #include <stdio.h> 13 #include <string.h> 14 #include <unistd.h> 15 16 __attribute__((noinline)) 17 void foo() { printf("foo\n"); } 18 19 __attribute__((noinline)) 20 void bar() { printf("bar\n"); } 21 22 __attribute__((noinline)) 23 void baz() { printf("baz\n"); } 24 25 int main(int argc, char **argv) { 26 pid_t child_pid = fork(); 27 if (child_pid == 0) { 28 fprintf(stderr, "Child PID: %d\n", getpid()); 29 baz(); 30 } else { 31 fprintf(stderr, "Parent PID: %d\n", getpid()); 32 foo(); 33 bar(); 34 } 35 return 0; 36 } 37 38 // CHECK-DAG: Child PID: [[ChildPID:[0-9]+]] 39 // CHECK-DAG: [[ChildPID]].sancov: {{.*}} PCs written 40 // CHECK-DAG: Parent PID: [[ParentPID:[0-9]+]] 41 // CHECK-DAG: [[ParentPID]].sancov: 3 PCs written 42