• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 %s -o %t -DFOOBAR -DMAIN
5 // RUN: rm -rf %T/coverage-missing
6 // RUN: mkdir -p %T/coverage-missing
7 // RUN: cd %T/coverage-missing
8 // RUN: %env_asan_opts=coverage=1:coverage_dir=%T/coverage-missing %run %t
9 // RUN: %sancov print *.sancov > main.txt
10 // RUN: rm *.sancov
11 // RUN: [ $(cat main.txt | wc -l) == 1 ]
12 // RUN: %env_asan_opts=coverage=1:coverage_dir=%T/coverage-missing %run %t x
13 // RUN: %sancov print *.sancov > foo.txt
14 // RUN: rm *.sancov
15 // RUN: [ $(cat foo.txt | wc -l) == 3 ]
16 // RUN: %env_asan_opts=coverage=1:coverage_dir=%T/coverage-missing %run %t x x
17 // RUN: %sancov print *.sancov > bar.txt
18 // RUN: rm *.sancov
19 // RUN: [ $(cat bar.txt | wc -l) == 4 ]
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 || true ) | not grep "^<"
26 
27 // Second case: coverage from DSO.
28 // cd %T
29 // RUN: %clangxx_asan -fsanitize-coverage=func %s -o %dynamiclib -DFOOBAR -shared -fPIC
30 // RUN: %clangxx_asan -fsanitize-coverage=func %s %dynamiclib -o %t -DMAIN
31 // RUN: export LIBNAME=`basename %dynamiclib`
32 // RUN: rm -rf %T/coverage-missing
33 // RUN: mkdir -p %T/coverage-missing
34 // RUN: cd %T/coverage-missing
35 // RUN: %env_asan_opts=coverage=1:coverage_dir=%T/coverage-missing %run %t x
36 // RUN: %sancov print $LIBNAME.*.sancov > foo.txt
37 // RUN: rm *.sancov
38 // RUN: [ $(cat foo.txt | wc -l) == 2 ]
39 // RUN: %env_asan_opts=coverage=1:coverage_dir=%T/coverage-missing %run %t x x
40 // RUN: %sancov print $LIBNAME.*.sancov > bar.txt
41 // RUN: rm *.sancov
42 // RUN: [ $(cat bar.txt | wc -l) == 3 ]
43 // RUN: %sancov missing %dynamiclib < foo.txt > foo-missing.txt
44 // RUN: ( diff bar.txt foo-missing.txt || true ) | not grep "^<"
45 
46 // REQUIRES: x86-target-arch
47 // XFAIL: android
48 
49 #include <stdio.h>
50 
51 void foo1();
52 void foo2();
53 void bar1();
54 void bar2();
55 void bar3();
56 
57 #if defined(FOOBAR)
foo1()58 void foo1() { fprintf(stderr, "foo1\n"); }
foo2()59 void foo2() { fprintf(stderr, "foo2\n"); }
60 
bar1()61 void bar1() { fprintf(stderr, "bar1\n"); }
bar2()62 void bar2() { fprintf(stderr, "bar2\n"); }
bar3()63 void bar3() { fprintf(stderr, "bar3\n"); }
64 #endif
65 
66 #if defined(MAIN)
main(int argc,char ** argv)67 int main(int argc, char **argv) {
68   switch (argc) {
69     case 1:
70       break;
71     case 2:
72       foo1();
73       foo2();
74       break;
75     case 3:
76       bar1();
77       bar2();
78       bar3();
79       break;
80   }
81 }
82 #endif
83