1 // Test for "sancov.py missing ...".
3 // First case: coverage from executable. main() is called on every code path.
4 // RUN: %clangxx_asan -fsanitize-coverage=func,trace-pc-guard %s -o %t -DFOOBAR -DMAIN
6 // RUN: mkdir -p %t-dir
8 // RUN: %env_asan_opts=coverage=1:coverage_dir=%t-dir %run %t
9 // RUN: %sancov print *.sancov > main.txt
11 // RUN: count 1 < main.txt
12 // RUN: %env_asan_opts=coverage=1:coverage_dir=%t-dir %run %t x
13 // RUN: %sancov print *.sancov > foo.txt
15 // RUN: count 3 < foo.txt
16 // RUN: %env_asan_opts=coverage=1:coverage_dir=%t-dir %run %t x x
17 // RUN: %sancov print *.sancov > bar.txt
19 // RUN: count 4 < bar.txt
20 // RUN: %sancov missing %t < foo.txt > foo-missing.txt
21 // RUN: sort main.txt foo-missing.txt -o foo-missing-with-main.txt
22 // The "missing from foo" set may contain a few bogus PCs from the sanitizer
23 // runtime, but it must include the entire "bar" code path as a subset. Sorted
24 // lists can be tested for set inclusion with diff + grep.
25 // RUN: diff bar.txt foo-missing-with-main.txt > %t.log || true
26 // RUN: not grep "^<" %t.log
28 // Second case: coverage from DSO.
30 // RUN: %clangxx_asan -fsanitize-coverage=func,trace-pc-guard %s -o %dynamiclib -DFOOBAR -shared -fPIC
31 // RUN: %clangxx_asan -fsanitize-coverage=func,trace-pc-guard %s %dynamiclib -o %t -DMAIN
34 // RUN: mkdir -p %t-dir
36 // RUN: %env_asan_opts=coverage=1:coverage_dir=%t-dir %run %t x
37 // RUN: %sancov print %xdynamiclib_filename.*.sancov > foo.txt
39 // RUN: count 2 < foo.txt
40 // RUN: %env_asan_opts=coverage=1:coverage_dir=%t-dir %run %t x x
41 // RUN: %sancov print %xdynamiclib_filename.*.sancov > bar.txt
43 // RUN: count 3 < bar.txt
44 // RUN: %sancov missing %dynamiclib < foo.txt > foo-missing.txt
45 // RUN: diff bar.txt foo-missing.txt > %t.log || true
46 // RUN: not grep "^<" %t.log
48 // FIXME %sancov GetInstrumentedPCs relies on objdump -d to
49 // obtain the number of instrumented PCs. The i386
50 // %dynamiclib has .plt entries that are not recognized by
52 // "sancov.py: found 0 instrumented PCs in *.so",
53 // causing AddressSanitizer-i386-linux to fail.
54 // Change it back to x86-target-arch after %sancov switches to a more robust approach.
56 // REQUIRES: x86_64-target-arch
68 void foo1() { fprintf(stderr
, "foo1\n"); }
69 void foo2() { fprintf(stderr
, "foo2\n"); }
71 void bar1() { fprintf(stderr
, "bar1\n"); }
72 void bar2() { fprintf(stderr
, "bar2\n"); }
73 void bar3() { fprintf(stderr
, "bar3\n"); }
77 int main(int argc
, char **argv
) {