Skip to content

Commit

Permalink
Issue SimonKagstrom#42: tests: Add (failing) test for clang coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonKagstrom committed Feb 10, 2017
1 parent fd1aac2 commit b13d4e2
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ add_executable(s short-file.c)
add_executable(fork+exec fork/fork+exec.c)
add_executable(thread-test threads/thread-main.c)

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
add_executable(sanitizer-coverage sanitizer-coverage.c)
set_target_properties(sanitizer-coverage PROPERTIES COMPILE_FLAGS "-g -fsanitize=address -fsanitize-coverage=bb")
set_target_properties(sanitizer-coverage PROPERTIES LINK_FLAGS "-fsanitize=address -fsanitize-coverage=bb")
endif()

add_executable(pie pie.c)
set_target_properties(pie PROPERTIES POISITION_INDEPENDENT_CODE True)

Expand Down
26 changes: 26 additions & 0 deletions tests/sanitizer-coverage.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <stdio.h>

static int fn(int a)
{
printf("fn %d\n", a);

a = a + 1;
a = a + 2;

return a + 3;
}

int main(int argc, const char *argv[])
{
if (argc == 1) {
int out = fn(argc + 1);

out++;

return out;
} else {
fn(5);
}

return 0;
}
21 changes: 21 additions & 0 deletions tests/tools/compiled.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,3 +452,24 @@ def runTest(self):
dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/test_daemon/cobertura.xml")
assert parse_cobertura.hitsPerLine(dom, "test-daemon.cc", 31) == 1


class address_sanitizer_coverage(testbase.KcovTestCase):
@unittest.skipIf(not sys.platform.startswith("linux"), "Linux-only")
@unittest.expectedFailure
def runTest(self):
self.setUp()
if (not os.path.isfile(testbase.testbuild + "/sanitizer-coverage")):
print "Clang-only"
return True
rv,o = self.do(testbase.kcov + " --clang " + testbase.outbase + "/kcov " + testbase.testbuild + "/sanitizer-coverage", False)

dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/sanitizer-coverage/cobertura.xml")
assert parse_cobertura.hitsPerLine(dom, "sanitizer-coverage.c", 5) == 1
assert parse_cobertura.hitsPerLine(dom, "sanitizer-coverage.c", 7) == 1
assert parse_cobertura.hitsPerLine(dom, "sanitizer-coverage.c", 8) == 1

assert parse_cobertura.hitsPerLine(dom, "sanitizer-coverage.c", 16) == 1
assert parse_cobertura.hitsPerLine(dom, "sanitizer-coverage.c", 18) == 1

assert parse_cobertura.hitsPerLine(dom, "sanitizer-coverage.c", 22) == 0
assert parse_cobertura.hitsPerLine(dom, "sanitizer-coverage.c", 25) == 0

0 comments on commit b13d4e2

Please sign in to comment.