blob: 4c6ba260510b2fc60196591bfc524ad86b1c425a [file] [log] [blame]
Pirama Arumuga Nainarcdce50b2015-07-01 12:26:56 -07001// Test for "sancov.py missing ...".
2
3// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_dir=%T/coverage-missing
4
5// First case: coverage from executable. main() is called on every code path.
6// RUN: %clangxx_asan -fsanitize-coverage=func %s -o %t -DFOOBAR -DMAIN
7// RUN: rm -rf %T/coverage-missing
8// RUN: mkdir -p %T/coverage-missing
9// RUN: cd %T/coverage-missing
10// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS %t
11// RUN: %sancov print *.sancov > main.txt
12// RUN: rm *.sancov
13// RUN: [ $(cat main.txt | wc -l) == 1 ]
14// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS %t x
15// RUN: %sancov print *.sancov > foo.txt
16// RUN: rm *.sancov
17// RUN: [ $(cat foo.txt | wc -l) == 3 ]
18// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS %t x x
19// RUN: %sancov print *.sancov > bar.txt
20// RUN: rm *.sancov
21// RUN: [ $(cat bar.txt | wc -l) == 4 ]
22// RUN: %sancov missing %t < foo.txt > foo-missing.txt
23// RUN: sort main.txt foo-missing.txt -o foo-missing-with-main.txt
24// The "missing from foo" set may contain a few bogus PCs from the sanitizer
25// runtime, but it must include the entire "bar" code path as a subset. Sorted
26// lists can be tested for set inclusion with diff + grep.
27// RUN: ( diff bar.txt foo-missing-with-main.txt || true ) | not grep "^<"
28
29// Second case: coverage from DSO.
30// cd %T
31// RUN: %clangxx_asan -fsanitize-coverage=func %s -o %dynamiclib -DFOOBAR -shared -fPIC
32// RUN: %clangxx_asan -fsanitize-coverage=func %s %dynamiclib -o %t -DMAIN
33// RUN: env LIBNAME=`basename %dynamiclib`
34// RUN: rm -rf %T/coverage-missing
35// RUN: mkdir -p %T/coverage-missing
36// RUN: cd %T/coverage-missing
37// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS %t x
38// RUN: %sancov print $LIBNAME.*.sancov > foo.txt
39// RUN: rm *.sancov
40// RUN: [ $(cat foo.txt | wc -l) == 2 ]
41// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS %t x x
42// RUN: %sancov print $LIBNAME.*.sancov > bar.txt
43// RUN: rm *.sancov
44// RUN: [ $(cat bar.txt | wc -l) == 3 ]
45// RUN: %sancov missing %dynamiclib < foo.txt > foo-missing.txt
46// RUN: ( diff bar.txt foo-missing.txt || true ) | not grep "^<"
47
48// REQUIRES: x86_64-supported-target, i386-supported-target
49// XFAIL: android
50
51#include <stdio.h>
52
53void foo1();
54void foo2();
55void bar1();
56void bar2();
57void bar3();
58
59#if defined(FOOBAR)
60void foo1() { fprintf(stderr, "foo1\n"); }
61void foo2() { fprintf(stderr, "foo2\n"); }
62
63void bar1() { fprintf(stderr, "bar1\n"); }
64void bar2() { fprintf(stderr, "bar2\n"); }
65void bar3() { fprintf(stderr, "bar3\n"); }
66#endif
67
68#if defined(MAIN)
69int main(int argc, char **argv) {
70 switch (argc) {
71 case 1:
72 break;
73 case 2:
74 foo1();
75 foo2();
76 break;
77 case 3:
78 bar1();
79 bar2();
80 bar3();
81 break;
82 }
83}
84#endif