From: Mike Aizatsky Date: Thu, 12 Nov 2015 19:34:21 +0000 (+0000) Subject: sancov test suite X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=91e7b1246cbbcb7b16624788dd6e313d59d988bc;p=oota-llvm.git sancov test suite Differential Revision: http://reviews.llvm.org/D14589 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252933 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 50dc98a8121..9bee504efec 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -19,11 +19,12 @@ endif() # Set the depends list as a variable so that it can grow conditionally. # NOTE: Sync the substitutions in test/lit.cfg when adding to this list. set(LLVM_TEST_DEPENDS - llvm-config - UnitTests BugpointPasses + FileCheck LLVMHello + UnitTests bugpoint + count llc lli lli-child-target @@ -31,6 +32,7 @@ set(LLVM_TEST_DEPENDS llvm-as llvm-bcanalyzer llvm-c-test + llvm-config llvm-cov llvm-cxxdump llvm-diff @@ -54,14 +56,13 @@ set(LLVM_TEST_DEPENDS llvm-split llvm-symbolizer llvm-tblgen - opt - FileCheck - count not - yaml-bench - yaml2obj obj2yaml + opt + sancov verify-uselistorder + yaml-bench + yaml2obj ) # If Intel JIT events are supported, depend on a tool that tests the listener. diff --git a/test/tools/sancov/Inputs/foo.cpp b/test/tools/sancov/Inputs/foo.cpp new file mode 100644 index 00000000000..71b35b32392 --- /dev/null +++ b/test/tools/sancov/Inputs/foo.cpp @@ -0,0 +1,5 @@ +#include +#include + +__attribute__((noinline)) +void foo() { printf("foo\n"); } diff --git a/test/tools/sancov/Inputs/test-linux_x86_64 b/test/tools/sancov/Inputs/test-linux_x86_64 new file mode 100755 index 00000000000..50060166ac3 Binary files /dev/null and b/test/tools/sancov/Inputs/test-linux_x86_64 differ diff --git a/test/tools/sancov/Inputs/test-linux_x86_64-1.sancov b/test/tools/sancov/Inputs/test-linux_x86_64-1.sancov new file mode 100644 index 00000000000..08a0521277b Binary files /dev/null and b/test/tools/sancov/Inputs/test-linux_x86_64-1.sancov differ diff --git a/test/tools/sancov/Inputs/test-linux_x86_64.sancov b/test/tools/sancov/Inputs/test-linux_x86_64.sancov new file mode 100644 index 00000000000..f8030c33d6c Binary files /dev/null and b/test/tools/sancov/Inputs/test-linux_x86_64.sancov differ diff --git a/test/tools/sancov/Inputs/test.cpp b/test/tools/sancov/Inputs/test.cpp new file mode 100644 index 00000000000..795468b4bcb --- /dev/null +++ b/test/tools/sancov/Inputs/test.cpp @@ -0,0 +1,19 @@ +// compile & generate coverage data using: +// clang++ -g -o test-linux_x86_64 -fsanitize=address -fsanitize-coverage=edge *.cpp +// ASAN_OPTIONS="coverage=1" ./test-linux_x86_64 && mv test-linux_x86_64.*.sancov test-linux_x86_64.sancov +// ASAN_OPTIONS="coverage=1" ./test-linux_x86_64 1 && mv test-linux_x86_64.*.sancov test-linux_x86_64-1.sancov + +#include +#include + +void foo(); + +__attribute__((noinline)) +std::string bar(std::string str) { printf("bar\n"); return str; } + +int main(int argc, char **argv) { + if (argc == 2) + foo(); + bar("str"); + printf("main\n"); +} diff --git a/test/tools/sancov/covered_functions.test b/test/tools/sancov/covered_functions.test new file mode 100644 index 00000000000..0e110b16482 --- /dev/null +++ b/test/tools/sancov/covered_functions.test @@ -0,0 +1,13 @@ +RUN: sancov -obj %p/Inputs/test-linux_x86_64 -covered_functions %p/Inputs/test-linux_x86_64.sancov | FileCheck %s +RUN: sancov -obj %p/Inputs/test-linux_x86_64 -covered_functions %p/Inputs/test-linux_x86_64-1.sancov | FileCheck --check-prefix=MULTIPLE_FILES %s +RUN: sancov -obj %p/Inputs/test-linux_x86_64 -demangle=0 -covered_functions %p/Inputs/test-linux_x86_64.sancov | FileCheck --check-prefix=NO_DEMANGLE %s + +CHECK: Inputs/test.cpp:12 bar(std::string) +CHECK: Inputs/test.cpp:14 main + +MULTIPLE_FILES: {{^}}foo.cpp:5 foo() +MULTIPLE_FILES: {{^}}test.cpp:12 bar(std::string) +MULTIPLE_FILES: {{^}}test.cpp:14 main + +NO_DEMANGLE: Inputs/test.cpp:12 _Z3barSs +NO_DEMANGLE: Inputs/test.cpp:14 main diff --git a/test/tools/sancov/print.test b/test/tools/sancov/print.test new file mode 100644 index 00000000000..abc4b3faa63 --- /dev/null +++ b/test/tools/sancov/print.test @@ -0,0 +1,10 @@ +RUN: sancov -obj %p/Inputs/test-linux_x86_64 -print %p/Inputs/test-linux_x86_64.sancov | FileCheck %s + +CHECK: 0x4db18b +CHECK: 0x4db2d2 +CHECK: 0x4db322 +CHECK: 0x4db376 +CHECK: 0x4db3bd +CHECK: 0x4db3f4 +CHECK: 0x4db427 +CHECK: 0x4db45a diff --git a/tools/sancov/sancov.cc b/tools/sancov/sancov.cc index 7a3d7f171c5..9b54575028a 100644 --- a/tools/sancov/sancov.cc +++ b/tools/sancov/sancov.cc @@ -178,7 +178,7 @@ class CoverageData { return; symbolize::LLVMSymbolizer::Options SymbolizerOptions; SymbolizerOptions.Demangle = ClDemangle; - symbolize::LLVMSymbolizer Symbolizer; + symbolize::LLVMSymbolizer Symbolizer(SymbolizerOptions); struct FileLoc { std::string FileName; @@ -226,8 +226,11 @@ class CoverageData { if (!ProcessedFunctions.insert(FunctionName).second) continue; - out << FileName.substr(FilePrefix.size()) << ":" << Line << " " - << FunctionName << "\n"; + // Don't strip prefix if we only have a single file. + if (FileName.size() > FilePrefix.size()) + FileName = FileName.substr(FilePrefix.size()); + + out << FileName << ":" << Line << " " << FunctionName << "\n"; } } }