brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.9 KiB · 3ac68f3 Raw
88 lines · cpp
1// Test for "sancov.py missing ...".2 3// First case: coverage from executable. main() is called on every code path.4// RUN: rm -rf %t.dir && mkdir -p %t.dir && cd %t.dir5// RUN: %clangxx_asan -fsanitize-coverage=func,trace-pc-guard %s -o %t.dir/exe -DFOOBAR -DMAIN6// RUN: %env_asan_opts=coverage=1:coverage_dir=%t.dir %run %t.dir/exe7// RUN: %sancov print *.sancov > main.txt8// RUN: rm *.sancov9// RUN: count 1 < main.txt10// RUN: %env_asan_opts=coverage=1:coverage_dir=%t.dir %run %t.dir/exe x11// RUN: %sancov print *.sancov > foo.txt12// RUN: rm *.sancov13// RUN: count 3 < foo.txt14// RUN: %env_asan_opts=coverage=1:coverage_dir=%t.dir %run %t.dir/exe x x15// RUN: %sancov print *.sancov > bar.txt16// RUN: rm *.sancov17// RUN: count 4 < bar.txt18// RUN: %sancov missing %t.dir/exe < foo.txt > foo-missing.txt19// RUN: sort main.txt foo-missing.txt -o foo-missing-with-main.txt20// The "missing from foo" set may contain a few bogus PCs from the sanitizer21// runtime, but it must include the entire "bar" code path as a subset. Sorted22// lists can be tested for set inclusion with diff + grep.23// RUN: diff bar.txt foo-missing-with-main.txt > %t.log || true24// RUN: not grep "^<" %t.log25 26// Second case: coverage from DSO.27// RUN: cd ..28// RUN: rm -rf %t.dir && mkdir -p %t.dir && cd %t.dir29// RUN: %clangxx_asan -fsanitize-coverage=func,trace-pc-guard %s -o %dynamiclib -DFOOBAR -shared -fPIC30// RUN: %clangxx_asan -fsanitize-coverage=func,trace-pc-guard %s %dynamiclib -o %t.dir/exe -DMAIN31// RUN: %env_asan_opts=coverage=1:coverage_dir=%t.dir %run %t.dir/exe x32// RUN: %sancov print %xdynamiclib_filename.*.sancov > foo.txt33// RUN: rm *.sancov34// RUN: count 2 < foo.txt35// RUN: %env_asan_opts=coverage=1:coverage_dir=%t.dir %run %t.dir/exe x x36// RUN: %sancov print %xdynamiclib_filename.*.sancov > bar.txt37// RUN: rm *.sancov38// RUN: count 3 < bar.txt39// RUN: %sancov missing %dynamiclib < foo.txt > foo-missing.txt40// RUN: diff bar.txt foo-missing.txt > %t.log || true41// RUN: not grep "^<" %t.log42 43// FIXME %sancov GetInstrumentedPCs relies on objdump -d to44// obtain the number of instrumented PCs.  The i38645// %dynamiclib has .plt entries that are not recognized by46// objdump,47// "sancov.py: found 0 instrumented PCs in *.so",48// causing AddressSanitizer-i386-linux to fail.49// Change it back to x86-target-arch after %sancov switches to a more robust approach.50 51// REQUIRES: x86_64-target-arch52// XFAIL: android53 54#include <stdio.h>55 56void foo1();57void foo2();58void bar1();59void bar2();60void bar3();61 62#if defined(FOOBAR)63void foo1() { fprintf(stderr, "foo1\n"); }64void foo2() { fprintf(stderr, "foo2\n"); }65 66void bar1() { fprintf(stderr, "bar1\n"); }67void bar2() { fprintf(stderr, "bar2\n"); }68void bar3() { fprintf(stderr, "bar3\n"); }69#endif70 71#if defined(MAIN)72int main(int argc, char **argv) {73  switch (argc) {74    case 1:75      break;76    case 2:77      foo1();78      foo2();79      break;80    case 3:81      bar1();82      bar2();83      bar3();84      break;85  }86}87#endif88