1 | // Test for "sancov.py missing ...". |
2 | |
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 |
5 | // RUN: rm -rf %t-dir |
6 | // RUN: mkdir -p %t-dir |
7 | // RUN: cd %t-dir |
8 | // RUN: %env_asan_opts=coverage=1:coverage_dir=%t-dir %run %t |
9 | // RUN: %sancov print *.sancov > main.txt |
10 | // RUN: rm *.sancov |
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 |
14 | // RUN: rm *.sancov |
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 |
18 | // RUN: rm *.sancov |
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 |
27 | |
28 | // Second case: coverage from DSO. |
29 | // cd %t-dir |
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 |
32 | // RUN: cd .. |
33 | // RUN: rm -rf %t-dir |
34 | // RUN: mkdir -p %t-dir |
35 | // RUN: cd %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 |
38 | // RUN: rm *.sancov |
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 |
42 | // RUN: rm *.sancov |
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 |
47 | |
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 |
51 | // objdump, |
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. |
55 | |
56 | // REQUIRES: x86_64-target-arch |
57 | // XFAIL: android |
58 | |
59 | #include <stdio.h> |
60 | |
61 | void foo1(); |
62 | void foo2(); |
63 | void bar1(); |
64 | void bar2(); |
65 | void bar3(); |
66 | |
67 | #if defined(FOOBAR) |
68 | void foo1() { fprintf(stderr, "foo1\n" ); } |
69 | void foo2() { fprintf(stderr, "foo2\n" ); } |
70 | |
71 | void bar1() { fprintf(stderr, "bar1\n" ); } |
72 | void bar2() { fprintf(stderr, "bar2\n" ); } |
73 | void bar3() { fprintf(stderr, "bar3\n" ); } |
74 | #endif |
75 | |
76 | #if defined(MAIN) |
77 | int main(int argc, char **argv) { |
78 | switch (argc) { |
79 | case 1: |
80 | break; |
81 | case 2: |
82 | foo1(); |
83 | foo2(); |
84 | break; |
85 | case 3: |
86 | bar1(); |
87 | bar2(); |
88 | bar3(); |
89 | break; |
90 | } |
91 | } |
92 | #endif |
93 | |