aboutsummaryrefslogtreecommitdiff
path: root/test/asan/TestCases/Posix/coverage-fork-direct.cc
diff options
context:
space:
mode:
Diffstat (limited to 'test/asan/TestCases/Posix/coverage-fork-direct.cc')
-rw-r--r--test/asan/TestCases/Posix/coverage-fork-direct.cc38
1 files changed, 38 insertions, 0 deletions
diff --git a/test/asan/TestCases/Posix/coverage-fork-direct.cc b/test/asan/TestCases/Posix/coverage-fork-direct.cc
new file mode 100644
index 000000000000..39363911fec3
--- /dev/null
+++ b/test/asan/TestCases/Posix/coverage-fork-direct.cc
@@ -0,0 +1,38 @@
+// RUN: %clangxx_asan -fsanitize-coverage=func %s -o %t
+// RUN: rm -rf %T/coverage-fork-direct
+// RUN: mkdir -p %T/coverage-fork-direct && cd %T/coverage-fork-direct
+// RUN: (ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=1:verbosity=1 %run %t; \
+// RUN: %sancov rawunpack *.sancov.raw; %sancov print *.sancov) 2>&1
+//
+// XFAIL: android
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+__attribute__((noinline))
+void foo() { printf("foo\n"); }
+
+__attribute__((noinline))
+void bar() { printf("bar\n"); }
+
+__attribute__((noinline))
+void baz() { printf("baz\n"); }
+
+int main(int argc, char **argv) {
+ pid_t child_pid = fork();
+ if (child_pid == 0) {
+ fprintf(stderr, "Child PID: %d\n", getpid());
+ baz();
+ } else {
+ fprintf(stderr, "Parent PID: %d\n", getpid());
+ foo();
+ bar();
+ }
+ return 0;
+}
+
+// CHECK-DAG: Child PID: [[ChildPID:[0-9]+]]
+// CHECK-DAG: Parent PID: [[ParentPID:[0-9]+]]
+// CHECK-DAG: read 3 PCs from {{.*}}.[[ParentPID]].sancov
+// CHECK-DAG: read 1 PCs from {{.*}}.[[ChildPID]].sancov