diff --git a/tests/tools/accumulate.py b/tests/tools/accumulate.py index 9326d4ab..cec2681d 100644 --- a/tests/tools/accumulate.py +++ b/tests/tools/accumulate.py @@ -1,199 +1,162 @@ -import parse_cobertura +import cobertura import testbase class accumulate_data(testbase.KcovTestCase): def runTest(self): rv, o = self.do( - testbase.kcov - + " " - + testbase.outbase - + "/kcov " - + testbase.sources - + "/tests/python/main" + self.kcov + " " + self.outbase + "/kcov " + self.sources + "/tests/python/main" ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/main/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "main", 16) == 1 - assert parse_cobertura.hitsPerLine(dom, "main", 19) == 0 - assert parse_cobertura.hitsPerLine(dom, "main", 14) == 1 + dom = cobertura.parseFile(self.outbase + "/kcov/main/cobertura.xml") + assert cobertura.hitsPerLine(dom, "main", 16) == 1 + assert cobertura.hitsPerLine(dom, "main", 19) == 0 + assert cobertura.hitsPerLine(dom, "main", 14) == 1 rv, o = self.do( - testbase.kcov - + " " - + testbase.outbase - + "/kcov " - + testbase.sources - + "/tests/python/main 5" + self.kcov + " " + self.outbase + "/kcov " + self.sources + "/tests/python/main 5" ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/main/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "main", 16) == 1 - assert parse_cobertura.hitsPerLine(dom, "main", 19) == 1 - assert parse_cobertura.hitsPerLine(dom, "main", 14) == 2 + dom = cobertura.parseFile(self.outbase + "/kcov/main/cobertura.xml") + assert cobertura.hitsPerLine(dom, "main", 16) == 1 + assert cobertura.hitsPerLine(dom, "main", 19) == 1 + assert cobertura.hitsPerLine(dom, "main", 14) == 2 class dont_accumulate_data_with_clean(testbase.KcovTestCase): def runTest(self): rv, o = self.do( - testbase.kcov - + " " - + testbase.outbase - + "/kcov " - + testbase.sources - + "/tests/python/main" + self.kcov + " " + self.outbase + "/kcov " + self.sources + "/tests/python/main" ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/main/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "main", 16) == 1 - assert parse_cobertura.hitsPerLine(dom, "main", 19) == 0 - assert parse_cobertura.hitsPerLine(dom, "main", 14) == 1 + dom = cobertura.parseFile(self.outbase + "/kcov/main/cobertura.xml") + assert cobertura.hitsPerLine(dom, "main", 16) == 1 + assert cobertura.hitsPerLine(dom, "main", 19) == 0 + assert cobertura.hitsPerLine(dom, "main", 14) == 1 rv, o = self.do( - testbase.kcov + self.kcov + " --clean " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.sources + + self.sources + "/tests/python/main 5" ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/main/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "main", 16) == 0 - assert parse_cobertura.hitsPerLine(dom, "main", 19) == 1 - assert parse_cobertura.hitsPerLine(dom, "main", 14) == 1 + dom = cobertura.parseFile(self.outbase + "/kcov/main/cobertura.xml") + assert cobertura.hitsPerLine(dom, "main", 16) == 0 + assert cobertura.hitsPerLine(dom, "main", 19) == 1 + assert cobertura.hitsPerLine(dom, "main", 14) == 1 class merge_basic(testbase.KcovTestCase): def runTest(self): rv, o = self.do( - testbase.kcov - + " " - + testbase.outbase - + "/kcov " - + testbase.sources - + "/tests/python/main 5" + self.kcov + " " + self.outbase + "/kcov " + self.sources + "/tests/python/main 5" ) rv, o = self.do( - testbase.kcov - + " " - + testbase.outbase - + "/kcov " - + testbase.sources - + "/tests/bash/shell-main" + self.kcov + " " + self.outbase + "/kcov " + self.sources + "/tests/bash/shell-main" ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/kcov-merged/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "main", 10) == 1 - assert parse_cobertura.hitsPerLine(dom, "shell-main", 4) == 1 + dom = cobertura.parseFile(self.outbase + "/kcov/kcov-merged/cobertura.xml") + assert cobertura.hitsPerLine(dom, "main", 10) == 1 + assert cobertura.hitsPerLine(dom, "shell-main", 4) == 1 class merge_multiple_output_directories(testbase.KcovTestCase): def runTest(self): rv, o = self.do( - testbase.kcov - + " " - + testbase.outbase - + "/kcov/first " - + testbase.sources - + "/tests/python/main 5" + self.kcov + " " + self.outbase + "/kcov/first " + self.sources + "/tests/python/main 5" ) rv, o = self.do( - testbase.kcov + self.kcov + " " - + testbase.outbase + + self.outbase + "/kcov/second " - + testbase.sources + + self.sources + "/tests/bash/shell-main" ) rv, o = self.do( - testbase.kcov + self.kcov + " --merge " - + testbase.outbase + + self.outbase + "/kcov/merged " - + testbase.outbase + + self.outbase + "/kcov/first " - + testbase.outbase + + self.outbase + "/kcov/second" ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/merged/kcov-merged/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "main", 10) == 1 - assert parse_cobertura.hitsPerLine(dom, "shell-main", 4) == 1 + dom = cobertura.parseFile(self.outbase + "/kcov/merged/kcov-merged/cobertura.xml") + assert cobertura.hitsPerLine(dom, "main", 10) == 1 + assert cobertura.hitsPerLine(dom, "shell-main", 4) == 1 class merge_merged_output(testbase.KcovTestCase): def runTest(self): rv, o = self.do( - testbase.kcov - + " " - + testbase.outbase - + "/kcov/first " - + testbase.sources - + "/tests/python/main 5" + self.kcov + " " + self.outbase + "/kcov/first " + self.sources + "/tests/python/main 5" ) rv, o = self.do( - testbase.kcov + self.kcov + " " - + testbase.outbase + + self.outbase + "/kcov/second " - + testbase.sources + + self.sources + "/tests/bash/shell-main" ) rv, o = self.do( - testbase.kcov + self.kcov + " " - + testbase.outbase + + self.outbase + "/kcov/third " - + testbase.sources + + self.sources + "/tests/bash/dollar-var-replacements.sh" ) rv, o = self.do( - testbase.kcov + self.kcov + " --merge " - + testbase.outbase + + self.outbase + "/kcov/merged " - + testbase.outbase + + self.outbase + "/kcov/first " - + testbase.outbase + + self.outbase + "/kcov/second" ) rv, o = self.do( - testbase.kcov + self.kcov + " --merge " - + testbase.outbase + + self.outbase + "/kcov/merged2 " - + testbase.outbase + + self.outbase + "/kcov/merged " - + testbase.outbase + + self.outbase + "/kcov/third" ) - dom = parse_cobertura.parseFile( - testbase.outbase + "/kcov/merged2/kcov-merged/cobertura.xml" - ) - assert parse_cobertura.hitsPerLine(dom, "main", 10) == 1 - assert parse_cobertura.hitsPerLine(dom, "shell-main", 4) == 1 - assert parse_cobertura.hitsPerLine(dom, "dollar-var-replacements.sh", 2) == 1 + dom = cobertura.parseFile(self.outbase + "/kcov/merged2/kcov-merged/cobertura.xml") + assert cobertura.hitsPerLine(dom, "main", 10) == 1 + assert cobertura.hitsPerLine(dom, "shell-main", 4) == 1 + assert cobertura.hitsPerLine(dom, "dollar-var-replacements.sh", 2) == 1 class merge_coveralls(testbase.KcovTestCase): def runTest(self): rv, o = self.do( - testbase.kcov + self.kcov + " --coveralls-id=dry-run " - + testbase.outbase + + self.outbase + "/kcov/ " - + testbase.sources + + self.sources + "/tests/python/main 5" ) rv, o = self.do( - testbase.kcov + self.kcov + " --coveralls-id=dry-run " - + testbase.outbase + + self.outbase + "/kcov/ " - + testbase.sources + + self.sources + "/tests/bash/shell-main" ) - rv, o = self.doShell(f"grep second.py {(testbase.outbase)}/kcov/main/coveralls.out") + rv, o = self.doShell(f"grep second.py {(self.outbase)}/kcov/main/coveralls.out") assert rv == 0 - rv, o = self.doShell(f"grep shell-main {(testbase.outbase)}/kcov/shell-main/coveralls.out") + rv, o = self.doShell(f"grep shell-main {(self.outbase)}/kcov/shell-main/coveralls.out") assert rv == 0 diff --git a/tests/tools/bash.py b/tests/tools/bash.py index 80ac1a61..9cd44024 100644 --- a/tests/tools/bash.py +++ b/tests/tools/bash.py @@ -3,51 +3,46 @@ import sys import unittest -import parse_cobertura +import cobertura import testbase class BashBase(testbase.KcovTestCase): def doTest(self, args): rv, o = self.do( - testbase.kcov + self.kcov + " " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.sources + + self.sources + "/tests/bash/shell-main " + args ) - return parse_cobertura.parseFile(testbase.outbase + "/kcov/shell-main/cobertura.xml") + return cobertura.parseFile(self.outbase + "/kcov/shell-main/cobertura.xml") class bash_coverage(testbase.KcovTestCase): def runTest(self): rv, o = self.do( - testbase.kcov - + " " - + testbase.outbase - + "/kcov " - + testbase.sources - + "/tests/bash/shell-main" + self.kcov + " " + self.outbase + "/kcov " + self.sources + "/tests/bash/shell-main" ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/shell-main/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "shell-main", 3) is None - assert parse_cobertura.hitsPerLine(dom, "shell-main", 4) == 1 - assert parse_cobertura.hitsPerLine(dom, "shell-main", 13) == 0 - assert parse_cobertura.hitsPerLine(dom, "shell-main", 26) is None - assert parse_cobertura.hitsPerLine(dom, "shell-main", 30) == 5 - assert parse_cobertura.hitsPerLine(dom, "shell-main", 34) is None - assert parse_cobertura.hitsPerLine(dom, "shell-main", 38) is None - assert parse_cobertura.hitsPerLine(dom, "other.sh", 5) == 1 - - assert parse_cobertura.hitsPerLine(dom, "short-test.sh", 5) == 11 - assert parse_cobertura.hitsPerLine(dom, "shell-main", 128) == 1 - assert parse_cobertura.hitsPerLine(dom, "shell-main", 132) is None - assert parse_cobertura.hitsPerLine(dom, "shell-main", 135) == 1 - assert parse_cobertura.hitsPerLine(dom, "shell-main", 136) == 1 + dom = cobertura.parseFile(self.outbase + "/kcov/shell-main/cobertura.xml") + assert cobertura.hitsPerLine(dom, "shell-main", 3) is None + assert cobertura.hitsPerLine(dom, "shell-main", 4) == 1 + assert cobertura.hitsPerLine(dom, "shell-main", 13) == 0 + assert cobertura.hitsPerLine(dom, "shell-main", 26) is None + assert cobertura.hitsPerLine(dom, "shell-main", 30) == 5 + assert cobertura.hitsPerLine(dom, "shell-main", 34) is None + assert cobertura.hitsPerLine(dom, "shell-main", 38) is None + assert cobertura.hitsPerLine(dom, "other.sh", 5) == 1 + + assert cobertura.hitsPerLine(dom, "short-test.sh", 5) == 11 + assert cobertura.hitsPerLine(dom, "shell-main", 128) == 1 + assert cobertura.hitsPerLine(dom, "shell-main", 132) is None + assert cobertura.hitsPerLine(dom, "shell-main", 135) == 1 + assert cobertura.hitsPerLine(dom, "shell-main", 136) == 1 assert b"I'm echoing to stderr via some" in o @@ -56,117 +51,112 @@ def runTest(self): class bash_coverage_debug_trap(testbase.KcovTestCase): def runTest(self): rv, o = self.do( - testbase.kcov + self.kcov + " --bash-method=DEBUG " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.sources + + self.sources + "/tests/bash/shell-main 5" ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/shell-main/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "shell-main", 3) is None - assert parse_cobertura.hitsPerLine(dom, "shell-main", 4) == 1 - assert parse_cobertura.hitsPerLine(dom, "shell-main", 22) == 1 + dom = cobertura.parseFile(self.outbase + "/kcov/shell-main/cobertura.xml") + assert cobertura.hitsPerLine(dom, "shell-main", 3) is None + assert cobertura.hitsPerLine(dom, "shell-main", 4) == 1 + assert cobertura.hitsPerLine(dom, "shell-main", 22) == 1 class bash_short_file(testbase.KcovTestCase): def runTest(self): rv, o = self.do( - testbase.kcov - + " " - + testbase.outbase - + "/kcov " - + testbase.sources - + "/tests/bash/short-test.sh" + self.kcov + " " + self.outbase + "/kcov " + self.sources + "/tests/bash/short-test.sh" ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/short-test.sh/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "short-test.sh", 5) == 11 + dom = cobertura.parseFile(self.outbase + "/kcov/short-test.sh/cobertura.xml") + assert cobertura.hitsPerLine(dom, "short-test.sh", 5) == 11 class bash_heredoc_backslashes(BashBase): def runTest(self): dom = self.doTest("5") - assert parse_cobertura.hitsPerLine(dom, "shell-main", 52) == 4 - assert parse_cobertura.hitsPerLine(dom, "shell-main", 53) is None - assert parse_cobertura.hitsPerLine(dom, "shell-main", 55) is None - assert parse_cobertura.hitsPerLine(dom, "shell-main", 59) == 1 - assert parse_cobertura.hitsPerLine(dom, "shell-main", 61) is None - assert parse_cobertura.hitsPerLine(dom, "shell-main", 62) is None + assert cobertura.hitsPerLine(dom, "shell-main", 52) == 4 + assert cobertura.hitsPerLine(dom, "shell-main", 53) is None + assert cobertura.hitsPerLine(dom, "shell-main", 55) is None + assert cobertura.hitsPerLine(dom, "shell-main", 59) == 1 + assert cobertura.hitsPerLine(dom, "shell-main", 61) is None + assert cobertura.hitsPerLine(dom, "shell-main", 62) is None class bash_heredoc_special_cases_issue_44(BashBase): def runTest(self): dom = self.doTest("") - assert parse_cobertura.hitsPerLine(dom, "shell-main", 77) == 1 - assert parse_cobertura.hitsPerLine(dom, "shell-main", 83) == 1 - assert parse_cobertura.hitsPerLine(dom, "shell-main", 88) == 1 - assert parse_cobertura.hitsPerLine(dom, "shell-main", 93) == 1 - assert parse_cobertura.hitsPerLine(dom, "shell-main", 109) == 1 - assert parse_cobertura.hitsPerLine(dom, "shell-main", 118) == 1 + assert cobertura.hitsPerLine(dom, "shell-main", 77) == 1 + assert cobertura.hitsPerLine(dom, "shell-main", 83) == 1 + assert cobertura.hitsPerLine(dom, "shell-main", 88) == 1 + assert cobertura.hitsPerLine(dom, "shell-main", 93) == 1 + assert cobertura.hitsPerLine(dom, "shell-main", 109) == 1 + assert cobertura.hitsPerLine(dom, "shell-main", 118) == 1 class bash_non_empty_braces(BashBase): def runTest(self): dom = self.doTest("") - assert parse_cobertura.hitsPerLine(dom, "shell-main", 102) == 1 - assert parse_cobertura.hitsPerLine(dom, "shell-main", 103) == 3 + assert cobertura.hitsPerLine(dom, "shell-main", 102) == 1 + assert cobertura.hitsPerLine(dom, "shell-main", 103) == 3 class bash_coverage_tricky(BashBase): def runTest(self): dom = self.doTest("5") - assert parse_cobertura.hitsPerLine(dom, "shell-main", 36) is None - assert parse_cobertura.hitsPerLine(dom, "shell-main", 44) is None - assert parse_cobertura.hitsPerLine(dom, "shell-main", 7) is None + assert cobertura.hitsPerLine(dom, "shell-main", 36) is None + assert cobertura.hitsPerLine(dom, "shell-main", 44) is None + assert cobertura.hitsPerLine(dom, "shell-main", 7) is None class bash_honor_signal(testbase.KcovTestCase): def runTest(self): rv, o = self.do( - testbase.sources + self.sources + "/tests/setpgid-kill/test-script.sh " - + testbase.kcov + + self.kcov + " " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.sources + + self.sources + "/tests/bash/trap.sh", False, ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/trap.sh/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "trap.sh", 5) == 1 + dom = cobertura.parseFile(self.outbase + "/kcov/trap.sh/cobertura.xml") + assert cobertura.hitsPerLine(dom, "trap.sh", 5) == 1 class bash_accumulate_data(testbase.KcovTestCase): def runTest(self): rv, o = self.do( - testbase.kcov + self.kcov + " " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.sources + + self.sources + "/tests/bash/unitundertest.sh 1" ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/unitundertest.sh/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "unitundertest.sh", 6) == 1 - assert parse_cobertura.hitsPerLine(dom, "unitundertest.sh", 16) == 0 + dom = cobertura.parseFile(self.outbase + "/kcov/unitundertest.sh/cobertura.xml") + assert cobertura.hitsPerLine(dom, "unitundertest.sh", 6) == 1 + assert cobertura.hitsPerLine(dom, "unitundertest.sh", 16) == 0 rv, o = self.do( - testbase.kcov + self.kcov + " " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.sources + + self.sources + "/tests/bash/unitundertest.sh 2" ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/unitundertest.sh/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "unitundertest.sh", 6) == 1 - assert parse_cobertura.hitsPerLine(dom, "unitundertest.sh", 16) == 1 + dom = cobertura.parseFile(self.outbase + "/kcov/unitundertest.sh/cobertura.xml") + assert cobertura.hitsPerLine(dom, "unitundertest.sh", 6) == 1 + assert cobertura.hitsPerLine(dom, "unitundertest.sh", 16) == 1 class bash_accumulate_changed_data(testbase.KcovTestCase): @@ -174,111 +164,102 @@ class bash_accumulate_changed_data(testbase.KcovTestCase): @unittest.skipUnless(platform.machine() in ["x86_64", "i686", "i386"], "Only for x86") def runTest(self): os.system("mkdir -p /tmp/test-kcov") - os.system("cp " + testbase.sources + "/tests/bash/shell-main /tmp/test-kcov") - os.system("cp " + testbase.sources + "/tests/bash/other.sh /tmp/test-kcov") - rv, o = self.do( - testbase.kcov + " " + testbase.outbase + "/kcov /tmp/test-kcov/shell-main 5 9" - ) - - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/shell-main/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "shell-main", 40) == 1 - assert parse_cobertura.hitsPerLine(dom, "shell-main", 67) == 2 - assert parse_cobertura.hitsPerLine(dom, "other.sh", 6) == 2 + os.system("cp " + self.sources + "/tests/bash/shell-main /tmp/test-kcov") + os.system("cp " + self.sources + "/tests/bash/other.sh /tmp/test-kcov") + rv, o = self.do(self.kcov + " " + self.outbase + "/kcov /tmp/test-kcov/shell-main 5 9") + + dom = cobertura.parseFile(self.outbase + "/kcov/shell-main/cobertura.xml") + assert cobertura.hitsPerLine(dom, "shell-main", 40) == 1 + assert cobertura.hitsPerLine(dom, "shell-main", 67) == 2 + assert cobertura.hitsPerLine(dom, "other.sh", 6) == 2 os.system("echo \"echo 'arne-anka'\" >> /tmp/test-kcov/shell-main") - rv, o = self.do( - testbase.kcov + " " + testbase.outbase + "/kcov /tmp/test-kcov/shell-main 5" - ) + rv, o = self.do(self.kcov + " " + self.outbase + "/kcov /tmp/test-kcov/shell-main 5") - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/shell-main/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "shell-main", 40) == 0 - assert parse_cobertura.hitsPerLine(dom, "shell-main", 67) == 0 - assert parse_cobertura.hitsPerLine(dom, "other.sh", 6) == 3 + dom = cobertura.parseFile(self.outbase + "/kcov/shell-main/cobertura.xml") + assert cobertura.hitsPerLine(dom, "shell-main", 40) == 0 + assert cobertura.hitsPerLine(dom, "shell-main", 67) == 0 + assert cobertura.hitsPerLine(dom, "other.sh", 6) == 3 class bash_merge_data_issue_38(testbase.KcovTestCase): def runTest(self): rv, o = self.do( - testbase.kcov + self.kcov + " " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.sources + + self.sources + "/tests/bash/unitundertest.sh 1" ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/unitundertest.sh/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "unitundertest.sh", 6) == 1 - assert parse_cobertura.hitsPerLine(dom, "unitundertest.sh", 16) == 0 + dom = cobertura.parseFile(self.outbase + "/kcov/unitundertest.sh/cobertura.xml") + assert cobertura.hitsPerLine(dom, "unitundertest.sh", 6) == 1 + assert cobertura.hitsPerLine(dom, "unitundertest.sh", 16) == 0 rv, o = self.do( - testbase.kcov + self.kcov + " " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.sources + + self.sources + "/tests/bash/unitundertest.sh 2" ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/unitundertest.sh/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "unitundertest.sh", 6) == 1 - assert parse_cobertura.hitsPerLine(dom, "unitundertest.sh", 16) == 1 + dom = cobertura.parseFile(self.outbase + "/kcov/unitundertest.sh/cobertura.xml") + assert cobertura.hitsPerLine(dom, "unitundertest.sh", 6) == 1 + assert cobertura.hitsPerLine(dom, "unitundertest.sh", 16) == 1 rv, o = self.do( - testbase.kcov + self.kcov + " " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.sources + + self.sources + "/tests/bash/unitundertest.sh all" ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/unitundertest.sh/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "unitundertest.sh", 36) == 1 - assert parse_cobertura.hitsPerLine(dom, "unitundertest.sh", 30) == 1 - assert parse_cobertura.hitsPerLine(dom, "unitundertest.sh", 33) == 1 - assert parse_cobertura.hitsPerLine(dom, "unitundertest.sh", 36) == 1 + dom = cobertura.parseFile(self.outbase + "/kcov/unitundertest.sh/cobertura.xml") + assert cobertura.hitsPerLine(dom, "unitundertest.sh", 36) == 1 + assert cobertura.hitsPerLine(dom, "unitundertest.sh", 30) == 1 + assert cobertura.hitsPerLine(dom, "unitundertest.sh", 33) == 1 + assert cobertura.hitsPerLine(dom, "unitundertest.sh", 36) == 1 class bash_issue_116_arithmetic_and_heredoc_issue_117_comment_within_string(testbase.KcovTestCase): def runTest(self): rv, o = self.do( - testbase.kcov - + " " - + testbase.outbase - + "/kcov " - + testbase.sources - + "/tests/bash/shell-main" + self.kcov + " " + self.outbase + "/kcov " + self.sources + "/tests/bash/shell-main" ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/shell-main/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "shell-main", 142) == 1 - assert parse_cobertura.hitsPerLine(dom, "shell-main", 149) == 1 - assert parse_cobertura.hitsPerLine(dom, "shell-main", 151) == 1 - assert parse_cobertura.hitsPerLine(dom, "shell-main", 152) == 1 + dom = cobertura.parseFile(self.outbase + "/kcov/shell-main/cobertura.xml") + assert cobertura.hitsPerLine(dom, "shell-main", 142) == 1 + assert cobertura.hitsPerLine(dom, "shell-main", 149) == 1 + assert cobertura.hitsPerLine(dom, "shell-main", 151) == 1 + assert cobertura.hitsPerLine(dom, "shell-main", 152) == 1 class bash_multiline_quotes(testbase.KcovTestCase): def runTest(self): rv, o = self.do( - testbase.kcov + self.kcov + " " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.sources + + self.sources + "/tests/bash/multiline-alias.sh" ) assert b"echo called test_alias" not in o - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/multiline-alias.sh/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "multiline-alias.sh", 6) == 1 + dom = cobertura.parseFile(self.outbase + "/kcov/multiline-alias.sh/cobertura.xml") + assert cobertura.hitsPerLine(dom, "multiline-alias.sh", 6) == 1 class bash_multiline_backslashes(testbase.KcovTestCase): def runTest(self): rv, o = self.do( - testbase.kcov + self.kcov + " " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.sources + + self.sources + "/tests/bash/multiline-backslash.sh" ) @@ -288,39 +269,37 @@ def runTest(self): class bash_no_executed_lines(testbase.KcovTestCase): def runTest(self): rv, o = self.do( - testbase.kcov + self.kcov + " " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.sources + + self.sources + "/tests/bash/no-executed-statements.sh" ) assert b"echo called test_alias" not in o - dom = parse_cobertura.parseFile( - testbase.outbase + "/kcov/no-executed-statements.sh/cobertura.xml" - ) - assert parse_cobertura.hitsPerLine(dom, "no-executed-statements.sh", 4) == 0 + dom = cobertura.parseFile(self.outbase + "/kcov/no-executed-statements.sh/cobertura.xml") + assert cobertura.hitsPerLine(dom, "no-executed-statements.sh", 4) == 0 class bash_stderr_redirection(testbase.KcovTestCase): def runTest(self): rv, o = self.do( - testbase.kcov + self.kcov + " " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.sources + + self.sources + "/tests/bash/redirect-stderr.sh" ) assert b"kcov" not in o rv, o = self.do( - testbase.kcov + self.kcov + " --debug-force-bash-stderr " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.sources + + self.sources + "/tests/bash/redirect-stderr.sh" ) assert b"kcov" not in o @@ -329,98 +308,70 @@ def runTest(self): class bash_dollar_var_replacement(testbase.KcovTestCase): def runTest(self): rv, o = self.do( - testbase.kcov + self.kcov + " " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.sources + + self.sources + "/tests/bash/dollar-var-replacements.sh" ) - dom = parse_cobertura.parseFile( - testbase.outbase + "/kcov/dollar-var-replacements.sh/cobertura.xml" - ) - assert parse_cobertura.hitsPerLine(dom, "dollar-var-replacements.sh", 2) == 1 - assert parse_cobertura.hitsPerLine(dom, "dollar-var-replacements.sh", 4) == 1 - assert parse_cobertura.hitsPerLine(dom, "dollar-var-replacements.sh", 5) == 1 + dom = cobertura.parseFile(self.outbase + "/kcov/dollar-var-replacements.sh/cobertura.xml") + assert cobertura.hitsPerLine(dom, "dollar-var-replacements.sh", 2) == 1 + assert cobertura.hitsPerLine(dom, "dollar-var-replacements.sh", 4) == 1 + assert cobertura.hitsPerLine(dom, "dollar-var-replacements.sh", 5) == 1 # Issue #152 class bash_done_eof(testbase.KcovTestCase): def runTest(self): rv, o = self.do( - testbase.kcov - + " " - + testbase.outbase - + "/kcov " - + testbase.sources - + "/tests/bash/shell-main 5" + self.kcov + " " + self.outbase + "/kcov " + self.sources + "/tests/bash/shell-main 5" ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/shell-main/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "shell-main", 163) is None - assert parse_cobertura.hitsPerLine(dom, "shell-main", 169) is None + dom = cobertura.parseFile(self.outbase + "/kcov/shell-main/cobertura.xml") + assert cobertura.hitsPerLine(dom, "shell-main", 163) is None + assert cobertura.hitsPerLine(dom, "shell-main", 169) is None # Issue #154 class bash_eof_backtick(testbase.KcovTestCase): def runTest(self): rv, o = self.do( - testbase.kcov - + " " - + testbase.outbase - + "/kcov " - + testbase.sources - + "/tests/bash/shell-main" + self.kcov + " " + self.outbase + "/kcov " + self.sources + "/tests/bash/shell-main" ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/shell-main/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "shell-main", 180) == 1 + dom = cobertura.parseFile(self.outbase + "/kcov/shell-main/cobertura.xml") + assert cobertura.hitsPerLine(dom, "shell-main", 180) == 1 class bash_subshell(testbase.KcovTestCase): def runTest(self): rv, o = self.do( - testbase.kcov - + " " - + testbase.outbase - + "/kcov " - + testbase.sources - + "/tests/bash/subshell.sh" + self.kcov + " " + self.outbase + "/kcov " + self.sources + "/tests/bash/subshell.sh" ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/subshell.sh/cobertura.xml") - self.assertIsNone(parse_cobertura.hitsPerLine(dom, "subshell.sh", 1)) - self.assertEqual(2, parse_cobertura.hitsPerLine(dom, "subshell.sh", 4)) - self.assertEqual(0, parse_cobertura.hitsPerLine(dom, "subshell.sh", 8)) + dom = cobertura.parseFile(self.outbase + "/kcov/subshell.sh/cobertura.xml") + self.assertIsNone(cobertura.hitsPerLine(dom, "subshell.sh", 1)) + self.assertEqual(2, cobertura.hitsPerLine(dom, "subshell.sh", 4)) + self.assertEqual(0, cobertura.hitsPerLine(dom, "subshell.sh", 8)) class bash_handle_all_output(testbase.KcovTestCase): def runTest(self): script = "handle-all-output.sh" rv, o = self.do( - testbase.kcov - + " " - + testbase.outbase - + "/kcov " - + testbase.sources - + "/tests/bash/" - + script, + self.kcov + " " + self.outbase + "/kcov " + self.sources + "/tests/bash/" + script, timeout=5.0, ) self.assertEqual(0, rv, "kcov exited unsuccessfully") - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/" + script + "/cobertura.xml") - self.assertIsNone(parse_cobertura.hitsPerLine(dom, script, 1)) - self.assertEqual(1000, parse_cobertura.hitsPerLine(dom, script, 4)) + dom = cobertura.parseFile(self.outbase + "/kcov/" + script + "/cobertura.xml") + self.assertIsNone(cobertura.hitsPerLine(dom, script, 1)) + self.assertEqual(1000, cobertura.hitsPerLine(dom, script, 4)) class bash_exit_status(testbase.KcovTestCase): def runTest(self): - noKcovRv, o = self.do(testbase.sources + "/tests/bash/shell-main 5", False) + noKcovRv, o = self.doCmd(self.sources + "/tests/bash/shell-main 5") rv, o = self.do( - testbase.kcov - + " " - + testbase.outbase - + "/kcov " - + testbase.sources - + "/tests/bash/shell-main 5" + self.kcov + " " + self.outbase + "/kcov " + self.sources + "/tests/bash/shell-main 5" ) assert rv == noKcovRv @@ -430,135 +381,131 @@ def runTest(self): class bash_ignore_uncovered(testbase.KcovTestCase): def runTest(self): rv, o = self.do( - testbase.kcov + self.kcov + " --exclude-region=CUSTOM_RANGE_START:CUSTOM_RANGE_END " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.sources + + self.sources + "/tests/bash/other.sh" ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/other.sh/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "other.sh", 22) is None - assert parse_cobertura.hitsPerLine(dom, "other.sh", 23) == 1 - - assert parse_cobertura.hitsPerLine(dom, "other.sh", 26) is None - assert parse_cobertura.hitsPerLine(dom, "other.sh", 27) is None - assert parse_cobertura.hitsPerLine(dom, "other.sh", 28) is None - assert parse_cobertura.hitsPerLine(dom, "other.sh", 29) == 1 - - assert parse_cobertura.hitsPerLine(dom, "other.sh", 32) is None - assert parse_cobertura.hitsPerLine(dom, "other.sh", 34) is None - assert parse_cobertura.hitsPerLine(dom, "other.sh", 35) is None - assert parse_cobertura.hitsPerLine(dom, "other.sh", 36) is None - assert parse_cobertura.hitsPerLine(dom, "other.sh", 37) == 1 - - assert parse_cobertura.hitsPerLine(dom, "other.sh", 40) is None - assert parse_cobertura.hitsPerLine(dom, "other.sh", 42) is None - assert parse_cobertura.hitsPerLine(dom, "other.sh", 43) == 1 - - assert parse_cobertura.hitsPerLine(dom, "other.sh", 47) is None - assert parse_cobertura.hitsPerLine(dom, "other.sh", 48) is None - assert parse_cobertura.hitsPerLine(dom, "other.sh", 49) is None - assert parse_cobertura.hitsPerLine(dom, "other.sh", 51) == 1 + dom = cobertura.parseFile(self.outbase + "/kcov/other.sh/cobertura.xml") + assert cobertura.hitsPerLine(dom, "other.sh", 22) is None + assert cobertura.hitsPerLine(dom, "other.sh", 23) == 1 + + assert cobertura.hitsPerLine(dom, "other.sh", 26) is None + assert cobertura.hitsPerLine(dom, "other.sh", 27) is None + assert cobertura.hitsPerLine(dom, "other.sh", 28) is None + assert cobertura.hitsPerLine(dom, "other.sh", 29) == 1 + + assert cobertura.hitsPerLine(dom, "other.sh", 32) is None + assert cobertura.hitsPerLine(dom, "other.sh", 34) is None + assert cobertura.hitsPerLine(dom, "other.sh", 35) is None + assert cobertura.hitsPerLine(dom, "other.sh", 36) is None + assert cobertura.hitsPerLine(dom, "other.sh", 37) == 1 + + assert cobertura.hitsPerLine(dom, "other.sh", 40) is None + assert cobertura.hitsPerLine(dom, "other.sh", 42) is None + assert cobertura.hitsPerLine(dom, "other.sh", 43) == 1 + + assert cobertura.hitsPerLine(dom, "other.sh", 47) is None + assert cobertura.hitsPerLine(dom, "other.sh", 48) is None + assert cobertura.hitsPerLine(dom, "other.sh", 49) is None + assert cobertura.hitsPerLine(dom, "other.sh", 51) == 1 # Rust stuff - assert parse_cobertura.hitsPerLine(dom, "other.sh", 54) is None - assert parse_cobertura.hitsPerLine(dom, "other.sh", 55) == 1 + assert cobertura.hitsPerLine(dom, "other.sh", 54) is None + assert cobertura.hitsPerLine(dom, "other.sh", 55) == 1 # Issue #224 class bash_can_find_non_executed_scripts(testbase.KcovTestCase): def runTest(self): rv, o = self.do( - testbase.kcov + self.kcov + " " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.sources + + self.sources + "/tests/bash/first-dir/a.sh 5" ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/a.sh/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "a.sh", 5) == 1 + dom = cobertura.parseFile(self.outbase + "/kcov/a.sh/cobertura.xml") + assert cobertura.hitsPerLine(dom, "a.sh", 5) == 1 # Not executed - assert parse_cobertura.hitsPerLine(dom, "c.sh", 3) == 0 + assert cobertura.hitsPerLine(dom, "c.sh", 3) == 0 class bash_can_find_non_executed_scripts_manually(testbase.KcovTestCase): def runTest(self): rv, o = self.do( - testbase.kcov + self.kcov + " --bash-parse-files-in-dir=" - + testbase.sources + + self.sources + "/tests/bash " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.sources + + self.sources + "/tests/bash/first-dir/a.sh 5" ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/a.sh/cobertura.xml") + dom = cobertura.parseFile(self.outbase + "/kcov/a.sh/cobertura.xml") # Not executed - assert parse_cobertura.hitsPerLine(dom, "c.sh", 3) == 0 - assert parse_cobertura.hitsPerLine(dom, "other.sh", 3) == 0 + assert cobertura.hitsPerLine(dom, "c.sh", 3) == 0 + assert cobertura.hitsPerLine(dom, "other.sh", 3) == 0 class bash_can_ignore_non_executed_scripts(testbase.KcovTestCase): def runTest(self): rv, o = self.do( - testbase.kcov + self.kcov + " --bash-dont-parse-binary-dir " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.sources + + self.sources + "/tests/bash/first-dir/a.sh 5" ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/a.sh/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "a.sh", 5) == 1 + dom = cobertura.parseFile(self.outbase + "/kcov/a.sh/cobertura.xml") + assert cobertura.hitsPerLine(dom, "a.sh", 5) == 1 # Not included in report - assert parse_cobertura.hitsPerLine(dom, "c.sh", 3) is None - assert parse_cobertura.hitsPerLine(dom, "other.sh", 3) is None + assert cobertura.hitsPerLine(dom, "c.sh", 3) is None + assert cobertura.hitsPerLine(dom, "other.sh", 3) is None class bash_can_ignore_function_with_spaces(testbase.KcovTestCase): def runTest(self): rv, o = self.do( - testbase.kcov + self.kcov + " --bash-dont-parse-binary-dir " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.sources + + self.sources + "/tests/bash/function-with-spaces.sh" ) - dom = parse_cobertura.parseFile( - testbase.outbase + "/kcov/function-with-spaces.sh/cobertura.xml" - ) - assert parse_cobertura.hitsPerLine(dom, "function-with-spaces.sh", 5) is None - assert parse_cobertura.hitsPerLine(dom, "function-with-spaces.sh", 6) == 1 - assert parse_cobertura.hitsPerLine(dom, "function-with-spaces.sh", 9) is None - assert parse_cobertura.hitsPerLine(dom, "function-with-spaces.sh", 10) is None - assert parse_cobertura.hitsPerLine(dom, "function-with-spaces.sh", 11) == 1 + dom = cobertura.parseFile(self.outbase + "/kcov/function-with-spaces.sh/cobertura.xml") + assert cobertura.hitsPerLine(dom, "function-with-spaces.sh", 5) is None + assert cobertura.hitsPerLine(dom, "function-with-spaces.sh", 6) == 1 + assert cobertura.hitsPerLine(dom, "function-with-spaces.sh", 9) is None + assert cobertura.hitsPerLine(dom, "function-with-spaces.sh", 10) is None + assert cobertura.hitsPerLine(dom, "function-with-spaces.sh", 11) == 1 class bash_drain_stdout_without_return(testbase.KcovTestCase): @unittest.skipIf(sys.platform.startswith("darwin"), "Not for OSX") def runTest(self): rv, o = self.do( - testbase.kcov + self.kcov + " " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.sources + + self.sources + "/tests/bash/long-output-without-return.sh", timeout=5.0, ) self.assertEqual(0, rv, "kcov exited unsuccessfully") - dom = parse_cobertura.parseFile( - testbase.outbase + "/kcov/long-output-without-return.sh/cobertura.xml" - ) - self.assertIsNone(parse_cobertura.hitsPerLine(dom, "long-output-without-return.sh", 1)) - self.assertEqual( - 32768, parse_cobertura.hitsPerLine(dom, "long-output-without-return.sh", 4) + dom = cobertura.parseFile( + self.outbase + "/kcov/long-output-without-return.sh/cobertura.xml" ) + self.assertIsNone(cobertura.hitsPerLine(dom, "long-output-without-return.sh", 1)) + self.assertEqual(32768, cobertura.hitsPerLine(dom, "long-output-without-return.sh", 4)) diff --git a/tests/tools/bash_linux_only.py b/tests/tools/bash_linux_only.py index 056f0258..3fe9963f 100644 --- a/tests/tools/bash_linux_only.py +++ b/tests/tools/bash_linux_only.py @@ -1,56 +1,53 @@ -import parse_cobertura +import cobertura import testbase class bash_sh_shebang(testbase.KcovTestCase): def runTest(self): rv, o = self.do( - testbase.kcov + self.kcov + " --bash-handle-sh-invocation " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.sources + + self.sources + "/tests/bash/shell-main" ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/shell-main/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "sh-shebang.sh", 4) == 1 + dom = cobertura.parseFile(self.outbase + "/kcov/shell-main/cobertura.xml") + assert cobertura.hitsPerLine(dom, "sh-shebang.sh", 4) == 1 class bash_exit_before_child(testbase.KcovTestCase): def runTest(self): # kcovKcov shouldn't wait for the background process, so call it with kcovKcov = False rv, o = self.do( - testbase.kcov + self.kcov + " --bash-tracefd-cloexec " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.sources + + self.sources + "/tests/bash/background-child.sh", kcovKcov=False, timeout=3.0, - kill=True, ) self.assertEqual(0, rv, "kcov exited unsuccessfully") - dom = parse_cobertura.parseFile( - testbase.outbase + "/kcov/background-child.sh/cobertura.xml" - ) - self.assertIsNone(parse_cobertura.hitsPerLine(dom, "background-child.sh", 1)) - self.assertEqual(1, parse_cobertura.hitsPerLine(dom, "background-child.sh", 3)) - self.assertEqual(1, parse_cobertura.hitsPerLine(dom, "background-child.sh", 4)) + dom = cobertura.parseFile(self.outbase + "/kcov/background-child.sh/cobertura.xml") + self.assertIsNone(cobertura.hitsPerLine(dom, "background-child.sh", 1)) + self.assertEqual(1, cobertura.hitsPerLine(dom, "background-child.sh", 3)) + self.assertEqual(1, cobertura.hitsPerLine(dom, "background-child.sh", 4)) class bash_ldpreload_multilib(testbase.KcovTestCase): def runTest(self): rv, o = self.do( - testbase.kcov + self.kcov + " --bash-handle-sh-invocation --bash-tracefd-cloexec " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.sources + + self.sources + "/tests/bash/sh-shebang.sh" ) self.assertEqual(0, rv, "kcov exited unsuccessfully") - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/sh-shebang.sh/cobertura.xml") - self.assertIsNone(parse_cobertura.hitsPerLine(dom, "sh-shebang.sh", 1)) - self.assertEqual(1, parse_cobertura.hitsPerLine(dom, "sh-shebang.sh", 4)) + dom = cobertura.parseFile(self.outbase + "/kcov/sh-shebang.sh/cobertura.xml") + self.assertIsNone(cobertura.hitsPerLine(dom, "sh-shebang.sh", 1)) + self.assertEqual(1, cobertura.hitsPerLine(dom, "sh-shebang.sh", 4)) diff --git a/tests/tools/basic.py b/tests/tools/basic.py index 94f256cc..9a2bbca7 100644 --- a/tests/tools/basic.py +++ b/tests/tools/basic.py @@ -1,52 +1,47 @@ import os import unittest -import parse_cobertura +import cobertura import testbase -class TooFewArguments(testbase.KcovTestCase): +class too_few_arguments(testbase.KcovTestCase): def runTest(self): - rv, output = self.do(testbase.kcov + " " + testbase.outbase + "/kcov") + rv, output = self.do(self.kcov + " " + self.outbase + "/kcov") assert b"Usage: kcov" in output assert rv == 1 -class WrongArguments(testbase.KcovTestCase): +class wrong_arguments(testbase.KcovTestCase): def runTest(self): rv, output = self.do( - testbase.kcov - + " --abc=efg " - + testbase.outbase - + "/kcov " - + testbase.testbuild - + "/tests-stripped" + self.kcov + " --abc=efg " + self.outbase + "/kcov " + self.testbuild + "/tests-stripped" ) assert b"kcov: error: Unrecognized option: --abc=efg" in output assert rv == 1 -class LookupBinaryInPath(testbase.KcovTestCase): +class lookup_binary_in_path(testbase.KcovTestCase): @unittest.expectedFailure def runTest(self): - os.environ["PATH"] += testbase.sources + "/tests/python" - noKcovRv, o = self.do(testbase.sources + "/tests/python/main 5") - rv, o = self.do(testbase.kcov + " " + testbase.outbase + "/kcov " + "main 5") + os.environ["PATH"] += self.sources + "/tests/python" + noKcovRv, o = self.do(self.sources + "/tests/python/main 5") + rv, o = self.do(self.kcov + " " + self.outbase + "/kcov " + "main 5") - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/main/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "second.py", 34) == 2 + dom = cobertura.parseFile(self.outbase + "/kcov/main/cobertura.xml") + assert cobertura.hitsPerLine(dom, "second.py", 34) == 2 assert noKcovRv, rv # Issue #414 -class OutDirectoryIsExecutable(testbase.KcovTestCase): +class outdir_is_executable(testbase.KcovTestCase): def runTest(self): # Running a system executable on Linux may cause ptrace to fails with # "Operation not permitted", even with ptrace_scope set to 0. # See https://www.kernel.org/doc/Documentation/security/Yama.txt - executable = testbase.sources + "/tests/python/short-test.py" - rv, o = self.do(testbase.kcov + " echo " + executable) + executable = self.sources + "/tests/python/short-test.py" + rv, o = self.do(self.kcov + " echo " + executable) assert rv == 0 diff --git a/tests/tools/parse_cobertura.py b/tests/tools/cobertura.py similarity index 100% rename from tests/tools/parse_cobertura.py rename to tests/tools/cobertura.py diff --git a/tests/tools/compiled.py b/tests/tools/compiled.py index 6c0900d9..ca52d098 100644 --- a/tests/tools/compiled.py +++ b/tests/tools/compiled.py @@ -3,7 +3,7 @@ import sys import unittest -import parse_cobertura +import cobertura import testbase @@ -12,12 +12,7 @@ class illegal_insn(testbase.KcovTestCase): @unittest.skipUnless(platform.machine() in ["x86_64", "i686", "i386"], "Only for x86") def runTest(self): rv, output = self.do( - testbase.kcov - + " " - + testbase.outbase - + "/kcov " - + testbase.testbuild - + "/illegal-insn", + self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/illegal-insn", False, ) assert rv != 0 @@ -27,39 +22,34 @@ def runTest(self): class fork_no_wait(testbase.KcovTestCase): @unittest.skipIf(sys.platform.startswith("darwin"), "Not for OSX") def runTest(self): - noKcovRv, o = self.do(testbase.testbuild + "/fork_no_wait", False) + noKcovRv, o = self.doCmd(self.testbuild + "/fork_no_wait") rv, o = self.do( - testbase.kcov - + " " - + testbase.outbase - + "/kcov " - + testbase.testbuild - + "/fork_no_wait", + self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/fork_no_wait", False, ) assert rv == noKcovRv - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/fork_no_wait/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "fork-no-wait.c", 20) >= 1 - assert parse_cobertura.hitsPerLine(dom, "fork-no-wait.c", 22) >= 1 - assert parse_cobertura.hitsPerLine(dom, "fork-no-wait.c", 24) >= 1 + dom = cobertura.parseFile(self.outbase + "/kcov/fork_no_wait/cobertura.xml") + assert cobertura.hitsPerLine(dom, "fork-no-wait.c", 20) >= 1 + assert cobertura.hitsPerLine(dom, "fork-no-wait.c", 22) >= 1 + assert cobertura.hitsPerLine(dom, "fork-no-wait.c", 24) >= 1 class ForkBase(testbase.KcovTestCase): def doTest(self, binary): - noKcovRv, o = self.do(testbase.testbuild + "/" + binary, False) + noKcovRv, o = self.doCmd(self.testbuild + "/" + binary) rv, o = self.do( - testbase.kcov + " " + testbase.outbase + "/kcov " + testbase.testbuild + "/" + binary, + self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/" + binary, False, ) assert rv == noKcovRv - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/" + binary + "/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "fork.c", 21) == 0 - assert parse_cobertura.hitsPerLine(dom, "fork.c", 26) >= 1 - assert parse_cobertura.hitsPerLine(dom, "fork.c", 34) >= 1 - assert parse_cobertura.hitsPerLine(dom, "fork.c", 37) >= 1 - assert parse_cobertura.hitsPerLine(dom, "fork.c", 46) >= 1 + dom = cobertura.parseFile(self.outbase + "/kcov/" + binary + "/cobertura.xml") + assert cobertura.hitsPerLine(dom, "fork.c", 21) == 0 + assert cobertura.hitsPerLine(dom, "fork.c", 26) >= 1 + assert cobertura.hitsPerLine(dom, "fork.c", 34) >= 1 + assert cobertura.hitsPerLine(dom, "fork.c", 37) >= 1 + assert cobertura.hitsPerLine(dom, "fork.c", 46) >= 1 class fork_64(ForkBase): @@ -83,21 +73,21 @@ class vfork(testbase.KcovTestCase): ) def runTest(self): rv, o = self.do( - testbase.kcov + " " + testbase.outbase + "/kcov " + testbase.testbuild + "/vfork", False + self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/vfork", False ) assert rv == 0 - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/vfork/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "vfork.c", 12) >= 1 - assert parse_cobertura.hitsPerLine(dom, "vfork.c", 18) >= 1 + dom = cobertura.parseFile(self.outbase + "/kcov/vfork/cobertura.xml") + assert cobertura.hitsPerLine(dom, "vfork.c", 12) >= 1 + assert cobertura.hitsPerLine(dom, "vfork.c", 18) >= 1 class popen_test(testbase.KcovTestCase): @unittest.skipUnless(platform.machine() in ["x86_64", "i686", "i386"], "Only for x86") def runTest(self): - noKcovRv, o = self.do(testbase.testbuild + "/test_popen", False) + noKcovRv, o = self.doCmd(self.testbuild + "/test_popen") rv, o = self.do( - testbase.kcov + " " + testbase.outbase + "/kcov " + testbase.testbuild + "/test_popen", + self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/test_popen", False, ) assert rv == noKcovRv @@ -108,33 +98,31 @@ def runTest(self): class short_filename(testbase.KcovTestCase): @unittest.expectedFailure def runTest(self): - rv, o = self.do(testbase.kcov + " " + testbase.outbase + "/kcov ./s", False) + rv, o = self.do(self.kcov + " " + self.outbase + "/kcov ./s", False) assert rv == 99 class Pie(testbase.KcovTestCase): def runTest(self): - noKcovRv, o = self.do(testbase.testbuild + "/pie", False) - rv, o = self.do( - testbase.kcov + " " + testbase.outbase + "/kcov " + testbase.testbuild + "/pie", False - ) + noKcovRv, o = self.doCmd(self.testbuild + "/pie") + rv, o = self.do(self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/pie", False) assert rv == noKcovRv - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/pie/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "pie.c", 5) == 1 + dom = cobertura.parseFile(self.outbase + "/kcov/pie/cobertura.xml") + assert cobertura.hitsPerLine(dom, "pie.c", 5) == 1 class pie_argv_basic(testbase.KcovTestCase): def runTest(self): rv, o = self.do( - testbase.kcov + " " + testbase.outbase + "/kcov " + testbase.testbuild + "/pie-test", + self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/pie-test", False, ) assert rv == 0 - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/pie-test/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "argv-dependent.c", 5) == 1 - assert parse_cobertura.hitsPerLine(dom, "argv-dependent.c", 11) == 0 + dom = cobertura.parseFile(self.outbase + "/kcov/pie-test/cobertura.xml") + assert cobertura.hitsPerLine(dom, "argv-dependent.c", 5) == 1 + assert cobertura.hitsPerLine(dom, "argv-dependent.c", 11) == 0 class pie_accumulate(testbase.KcovTestCase): @@ -144,60 +132,53 @@ class pie_accumulate(testbase.KcovTestCase): ) def runTest(self): rv, o = self.do( - testbase.kcov + " " + testbase.outbase + "/kcov " + testbase.testbuild + "/pie-test", + self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/pie-test", False, ) assert rv == 0 - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/pie-test/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "argv-dependent.c", 5) == 1 - assert parse_cobertura.hitsPerLine(dom, "argv-dependent.c", 11) == 0 + dom = cobertura.parseFile(self.outbase + "/kcov/pie-test/cobertura.xml") + assert cobertura.hitsPerLine(dom, "argv-dependent.c", 5) == 1 + assert cobertura.hitsPerLine(dom, "argv-dependent.c", 11) == 0 rv, o = self.do( - testbase.kcov + " " + testbase.outbase + "/kcov " + testbase.testbuild + "/pie-test a", + self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/pie-test a", False, ) assert rv == 0 - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/pie-test/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "argv-dependent.c", 5) == 1 - assert parse_cobertura.hitsPerLine(dom, "argv-dependent.c", 11) == 1 + dom = cobertura.parseFile(self.outbase + "/kcov/pie-test/cobertura.xml") + assert cobertura.hitsPerLine(dom, "argv-dependent.c", 5) == 1 + assert cobertura.hitsPerLine(dom, "argv-dependent.c", 11) == 1 class global_ctors(testbase.KcovTestCase): def runTest(self): - noKcovRv, o = self.do(testbase.testbuild + "/global-constructors", False) + noKcovRv, o = self.doCmd(self.testbuild + "/global-constructors") rv, o = self.do( - testbase.kcov - + " " - + testbase.outbase - + "/kcov " - + testbase.testbuild - + "/global-constructors", + self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/global-constructors", False, ) assert rv == noKcovRv - dom = parse_cobertura.parseFile( - testbase.outbase + "/kcov/global-constructors/cobertura.xml" - ) - assert parse_cobertura.hitsPerLine(dom, "test-global-ctors.cc", 4) >= 1 + dom = cobertura.parseFile(self.outbase + "/kcov/global-constructors/cobertura.xml") + assert cobertura.hitsPerLine(dom, "test-global-ctors.cc", 4) >= 1 class daemon_wait_for_last_child(testbase.KcovTestCase): @unittest.skipIf(sys.platform.startswith("darwin"), "Not for OSX, Issue #158") @unittest.skipUnless(platform.machine() in ["x86_64", "i686", "i386"], "Only for x86") def runTest(self): - noKcovRv, o = self.do(testbase.testbuild + "/test_daemon", False) + noKcovRv, o = self.doCmd(self.testbuild + "/test_daemon") rv, o = self.do( - testbase.kcov + " " + testbase.outbase + "/kcov " + testbase.testbuild + "/test_daemon", + self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/test_daemon", False, ) assert rv == 4 assert noKcovRv == 2 - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/test_daemon/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "test-daemon.cc", 31) == 1 + dom = cobertura.parseFile(self.outbase + "/kcov/test_daemon/cobertura.xml") + assert cobertura.hitsPerLine(dom, "test-daemon.cc", 31) == 1 class SignalsBase(testbase.KcovTestCase): @@ -205,13 +186,13 @@ def SignalsBase(): self.m_self = "" def cmpOne(self, sig): - noKcovRv, o = self.do(testbase.testbuild + "/signals " + sig + " " + self.m_self, False) + noKcovRv, o = self.doCmd(self.testbuild + "/signals " + sig + " " + self.m_self) rv, o = self.do( - testbase.kcov + self.kcov + " " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.testbuild + + self.testbuild + "/signals " + sig + " " @@ -220,26 +201,26 @@ def cmpOne(self, sig): ) assert rv == noKcovRv - return parse_cobertura.parseFile(testbase.outbase + "/kcov/signals/cobertura.xml") + return cobertura.parseFile(self.outbase + "/kcov/signals/cobertura.xml") def doTest(self): dom = self.cmpOne("hup") - assert parse_cobertura.hitsPerLine(dom, "test-signals.c", 14) == 1 + assert cobertura.hitsPerLine(dom, "test-signals.c", 14) == 1 dom = self.cmpOne("int") - assert parse_cobertura.hitsPerLine(dom, "test-signals.c", 19) == 1 + assert cobertura.hitsPerLine(dom, "test-signals.c", 19) == 1 dom = self.cmpOne("quit") - assert parse_cobertura.hitsPerLine(dom, "test-signals.c", 24) == 1 + assert cobertura.hitsPerLine(dom, "test-signals.c", 24) == 1 dom = self.cmpOne("bus") - assert parse_cobertura.hitsPerLine(dom, "test-signals.c", 44) == 1 + assert cobertura.hitsPerLine(dom, "test-signals.c", 44) == 1 dom = self.cmpOne("fpe") - assert parse_cobertura.hitsPerLine(dom, "test-signals.c", 49) == 1 + assert cobertura.hitsPerLine(dom, "test-signals.c", 49) == 1 dom = self.cmpOne("term") - assert parse_cobertura.hitsPerLine(dom, "test-signals.c", 84) == 1 + assert cobertura.hitsPerLine(dom, "test-signals.c", 84) == 1 class signals(SignalsBase): @@ -259,23 +240,13 @@ class signals_crash(testbase.KcovTestCase): @unittest.skipIf(sys.platform.startswith("darwin"), "Not for OSX (macho-parser for now)") def runTest(self): rv, o = self.do( - testbase.kcov - + " " - + testbase.outbase - + "/kcov " - + testbase.testbuild - + "/signals segv self", + self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/signals segv self", False, ) assert b"kcov: Process exited with signal 11" in o rv, o = self.do( - testbase.kcov - + " " - + testbase.outbase - + "/kcov " - + testbase.testbuild - + "/signals abrt self", + self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/signals abrt self", False, ) assert b"kcov: Process exited with signal 6" in o @@ -285,13 +256,13 @@ class collect_and_report_only(testbase.KcovTestCase): # Cannot work with combined Engine / Parser @unittest.skipIf(sys.platform.startswith("darwin"), "Not for OSX") def runTest(self): - noKcovRv, o = self.do(testbase.testbuild + "/main-tests ", False) + noKcovRv, o = self.doCmd(self.testbuild + "/main-tests ") rv, o = self.do( - testbase.kcov + self.kcov + " --collect-only " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.testbuild + + self.testbuild + "/main-tests", False, ) @@ -299,43 +270,40 @@ def runTest(self): assert rv == noKcovRv try: - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/main-tests/cobertura.xml") + dom = cobertura.parseFile(self.outbase + "/kcov/main-tests/cobertura.xml") self.fail("File unexpectedly found") except: # Exception is expected here pass rv, o = self.do( - testbase.kcov + self.kcov + " --report-only " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.testbuild + + self.testbuild + "/main-tests", False, ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/main-tests/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "main.cc", 9) == 1 + dom = cobertura.parseFile(self.outbase + "/kcov/main-tests/cobertura.xml") + assert cobertura.hitsPerLine(dom, "main.cc", 9) == 1 class setpgid_kill(testbase.KcovTestCase): def runTest(self): - noKcovRv, o = self.do( - testbase.sources - + "/tests/setpgid-kill/test-script.sh " - + testbase.testbuild - + "/setpgid-kill", - False, + noKcovRv, o = self.doCmd( + self.sources + "/tests/setpgid-kill/test-script.sh " + self.testbuild + "/setpgid-kill" ) assert b"SUCCESS" in o + rv, o = self.do( - testbase.sources + self.sources + "/tests/setpgid-kill/test-script.sh " - + testbase.kcov + + self.kcov + " " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.testbuild + + self.testbuild + "/setpgid-kill", False, ) @@ -346,211 +314,167 @@ class attach_process_with_threads(testbase.KcovTestCase): @unittest.skipIf(sys.platform.startswith("darwin"), "Not for OSX") def runTest(self): rv, o = self.do( - testbase.sources + self.sources + "/tests/daemon/test-script.sh " - + testbase.kcov + + self.kcov + " " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.testbuild + + self.testbuild + "/issue31", False, ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/issue31/cobertura.xml") + dom = cobertura.parseFile(self.outbase + "/kcov/issue31/cobertura.xml") self.skipTest("Fickle test, ignoring") - assert parse_cobertura.hitsPerLine(dom, "test-issue31.cc", 28) >= 1 - assert parse_cobertura.hitsPerLine(dom, "test-issue31.cc", 11) >= 1 - assert parse_cobertura.hitsPerLine(dom, "test-issue31.cc", 9) == 0 + assert cobertura.hitsPerLine(dom, "test-issue31.cc", 28) >= 1 + assert cobertura.hitsPerLine(dom, "test-issue31.cc", 11) >= 1 + assert cobertura.hitsPerLine(dom, "test-issue31.cc", 9) == 0 class attach_process_with_threads_creates_threads(testbase.KcovTestCase): @unittest.skipIf(sys.platform.startswith("darwin"), "Not for OSX") def runTest(self): rv, o = self.do( - testbase.sources + self.sources + "/tests/daemon/test-script.sh " - + testbase.kcov + + self.kcov + " " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.testbuild + + self.testbuild + "/thread-test", False, ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/thread-test/cobertura.xml") + dom = cobertura.parseFile(self.outbase + "/kcov/thread-test/cobertura.xml") self.skipTest("Fickle test, ignoring") - assert parse_cobertura.hitsPerLine(dom, "thread-main.c", 21) >= 1 - assert parse_cobertura.hitsPerLine(dom, "thread-main.c", 9) >= 1 + assert cobertura.hitsPerLine(dom, "thread-main.c", 21) >= 1 + assert cobertura.hitsPerLine(dom, "thread-main.c", 9) >= 1 class merge_same_file_in_multiple_binaries(testbase.KcovTestCase): def runTest(self): rv, o = self.do( - testbase.kcov + " " + testbase.outbase + "/kcov " + testbase.testbuild + "/multi_1", + self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/multi_1", False, ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/multi_1/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "main_1.c", 10) == 0 - assert parse_cobertura.hitsPerLine(dom, "file.c", 3) == 0 + dom = cobertura.parseFile(self.outbase + "/kcov/multi_1/cobertura.xml") + assert cobertura.hitsPerLine(dom, "main_1.c", 10) == 0 + assert cobertura.hitsPerLine(dom, "file.c", 3) == 0 rv, o = self.do( - testbase.kcov + " " + testbase.outbase + "/kcov " + testbase.testbuild + "/multi_2", + self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/multi_2", False, ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/kcov-merged/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "main_2.c", 9) == 1 - assert parse_cobertura.hitsPerLine(dom, "file.c", 3) == 0 - assert parse_cobertura.hitsPerLine(dom, "file.c", 8) == 0 + dom = cobertura.parseFile(self.outbase + "/kcov/kcov-merged/cobertura.xml") + assert cobertura.hitsPerLine(dom, "main_2.c", 9) == 1 + assert cobertura.hitsPerLine(dom, "file.c", 3) == 0 + assert cobertura.hitsPerLine(dom, "file.c", 8) == 0 rv, o = self.do( - testbase.kcov + " " + testbase.outbase + "/kcov " + testbase.testbuild + "/multi_2 1", + self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/multi_2 1", False, ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/kcov-merged/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "file.c", 3) == 0 - assert parse_cobertura.hitsPerLine(dom, "file.c", 8) == 1 + dom = cobertura.parseFile(self.outbase + "/kcov/kcov-merged/cobertura.xml") + assert cobertura.hitsPerLine(dom, "file.c", 3) == 0 + assert cobertura.hitsPerLine(dom, "file.c", 8) == 1 class debuglink(testbase.KcovTestCase): @unittest.skipIf(sys.platform.startswith("darwin"), "Not for OSX") def runTest(self): - os.system(f"rm -rf {(testbase.outbase)}/.debug") - os.system(f"cp {testbase.testbuild}/main-tests {testbase.testbuild}/main-tests-debug-file") + os.system(f"rm -rf {(self.outbase)}/.debug") + os.system(f"cp {self.testbuild}/main-tests {self.testbuild}/main-tests-debug-file") os.system( - f"objcopy --only-keep-debug {testbase.testbuild}/main-tests-debug-file {testbase.testbuild}/main-tests-debug-file.debug" + f"objcopy --only-keep-debug {self.testbuild}/main-tests-debug-file {self.testbuild}/main-tests-debug-file.debug" ) os.system( - f"cp {testbase.testbuild}/main-tests-debug-file.debug {testbase.testbuild}/main-tests-debug-file1.debug" + f"cp {self.testbuild}/main-tests-debug-file.debug {self.testbuild}/main-tests-debug-file1.debug" ) os.system( - f"cp {testbase.testbuild}/main-tests-debug-file.debug {testbase.testbuild}/main-tests-debug-file12.debug" + f"cp {self.testbuild}/main-tests-debug-file.debug {self.testbuild}/main-tests-debug-file12.debug" ) os.system( - f"cp {testbase.testbuild}/main-tests-debug-file.debug {testbase.testbuild}/main-tests-debug-file123.debug" + f"cp {self.testbuild}/main-tests-debug-file.debug {self.testbuild}/main-tests-debug-file123.debug" ) os.system( - f"cp {testbase.testbuild}/main-tests-debug-file {testbase.testbuild}/main-tests-debug-file1" + f"cp {self.testbuild}/main-tests-debug-file {self.testbuild}/main-tests-debug-file1" ) os.system( - f"cp {testbase.testbuild}/main-tests-debug-file {testbase.testbuild}/main-tests-debug-file2" + f"cp {self.testbuild}/main-tests-debug-file {self.testbuild}/main-tests-debug-file2" ) os.system( - f"cp {testbase.testbuild}/main-tests-debug-file {testbase.testbuild}/main-tests-debug-file3" + f"cp {self.testbuild}/main-tests-debug-file {self.testbuild}/main-tests-debug-file3" ) - os.system(f"strip -g {(testbase.testbuild)}/main-tests-debug-file") - os.system(f"strip -g {(testbase.testbuild)}/main-tests-debug-file1") - os.system(f"strip -g {(testbase.testbuild)}/main-tests-debug-file2") - os.system(f"strip -g {(testbase.testbuild)}/main-tests-debug-file3") + os.system(f"strip -g {(self.testbuild)}/main-tests-debug-file") + os.system(f"strip -g {(self.testbuild)}/main-tests-debug-file1") + os.system(f"strip -g {(self.testbuild)}/main-tests-debug-file2") + os.system(f"strip -g {(self.testbuild)}/main-tests-debug-file3") os.system( - f"objcopy --add-gnu-debuglink={testbase.testbuild}/main-tests-debug-file.debug {testbase.testbuild}/main-tests-debug-file" + f"objcopy --add-gnu-debuglink={self.testbuild}/main-tests-debug-file.debug {self.testbuild}/main-tests-debug-file" ) os.system( - f"objcopy --add-gnu-debuglink={testbase.testbuild}/main-tests-debug-file1.debug {testbase.testbuild}/main-tests-debug-file1" + f"objcopy --add-gnu-debuglink={self.testbuild}/main-tests-debug-file1.debug {self.testbuild}/main-tests-debug-file1" ) os.system( - f"objcopy --add-gnu-debuglink={testbase.testbuild}/main-tests-debug-file12.debug {testbase.testbuild}/main-tests-debug-file2" + f"objcopy --add-gnu-debuglink={self.testbuild}/main-tests-debug-file12.debug {self.testbuild}/main-tests-debug-file2" ) os.system( - f"objcopy --add-gnu-debuglink={testbase.testbuild}/main-tests-debug-file123.debug {testbase.testbuild}/main-tests-debug-file3" + f"objcopy --add-gnu-debuglink={self.testbuild}/main-tests-debug-file123.debug {self.testbuild}/main-tests-debug-file3" ) - noKcovRv, o = self.do(testbase.testbuild + "/main-tests-debug-file", False) + noKcovRv, o = self.doCmd(self.testbuild + "/main-tests-debug-file") rv, o = self.do( - testbase.kcov - + " " - + testbase.outbase - + "/kcov " - + testbase.testbuild - + "/main-tests-debug-file", + self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/main-tests-debug-file", False, ) assert rv == noKcovRv - dom = parse_cobertura.parseFile( - testbase.outbase + "/kcov/main-tests-debug-file/cobertura.xml" - ) - assert parse_cobertura.hitsPerLine(dom, "main.cc", 9) == 1 + dom = cobertura.parseFile(self.outbase + "/kcov/main-tests-debug-file/cobertura.xml") + assert cobertura.hitsPerLine(dom, "main.cc", 9) == 1 # Check alignment rv, o = self.do( - testbase.kcov - + " " - + testbase.outbase - + "/kcov " - + testbase.testbuild - + "/main-tests-debug-file1", + self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/main-tests-debug-file1", False, ) - dom = parse_cobertura.parseFile( - testbase.outbase + "/kcov/main-tests-debug-file1/cobertura.xml" - ) - assert parse_cobertura.hitsPerLine(dom, "main.cc", 9) == 1 + dom = cobertura.parseFile(self.outbase + "/kcov/main-tests-debug-file1/cobertura.xml") + assert cobertura.hitsPerLine(dom, "main.cc", 9) == 1 rv, o = self.do( - testbase.kcov - + " " - + testbase.outbase - + "/kcov " - + testbase.testbuild - + "/main-tests-debug-file2", + self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/main-tests-debug-file2", False, ) - dom = parse_cobertura.parseFile( - testbase.outbase + "/kcov/main-tests-debug-file2/cobertura.xml" - ) - assert parse_cobertura.hitsPerLine(dom, "main.cc", 9) == 1 + dom = cobertura.parseFile(self.outbase + "/kcov/main-tests-debug-file2/cobertura.xml") + assert cobertura.hitsPerLine(dom, "main.cc", 9) == 1 rv, o = self.do( - testbase.kcov - + " " - + testbase.outbase - + "/kcov " - + testbase.testbuild - + "/main-tests-debug-file3", + self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/main-tests-debug-file3", False, ) - dom = parse_cobertura.parseFile( - testbase.outbase + "/kcov/main-tests-debug-file3/cobertura.xml" - ) - assert parse_cobertura.hitsPerLine(dom, "main.cc", 9) == 1 + dom = cobertura.parseFile(self.outbase + "/kcov/main-tests-debug-file3/cobertura.xml") + assert cobertura.hitsPerLine(dom, "main.cc", 9) == 1 # Look in .debug - os.system(f"rm -rf {(testbase.outbase)}/kcov") - os.system(f"mkdir -p {(testbase.testbuild)}/.debug") - os.system( - f"mv {testbase.testbuild}/main-tests-debug-file.debug {testbase.testbuild}/.debug" - ) + os.system(f"rm -rf {(self.outbase)}/kcov") + os.system(f"mkdir -p {(self.testbuild)}/.debug") + os.system(f"mv {self.testbuild}/main-tests-debug-file.debug {self.testbuild}/.debug") rv, o = self.do( - testbase.kcov - + " " - + testbase.outbase - + "/kcov " - + testbase.testbuild - + "/main-tests-debug-file", + self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/main-tests-debug-file", False, ) - dom = parse_cobertura.parseFile( - testbase.outbase + "/kcov/main-tests-debug-file/cobertura.xml" - ) - assert parse_cobertura.hitsPerLine(dom, "main.cc", 9) == 1 + dom = cobertura.parseFile(self.outbase + "/kcov/main-tests-debug-file/cobertura.xml") + assert cobertura.hitsPerLine(dom, "main.cc", 9) == 1 - os.system(f"rm -rf {(testbase.outbase)}/kcov") - os.system(f"echo 'abc' >> {(testbase.testbuild)}/.debug/main-tests-debug-file.debug") + os.system(f"rm -rf {(self.outbase)}/kcov") + os.system(f"echo 'abc' >> {(self.testbuild)}/.debug/main-tests-debug-file.debug") rv, o = self.do( - testbase.kcov - + " " - + testbase.outbase - + "/kcov " - + testbase.testbuild - + "/main-tests-debug-file", + self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/main-tests-debug-file", False, ) - dom = parse_cobertura.parseFile( - testbase.outbase + "/kcov/main-tests-debug-file/cobertura.xml" - ) - assert parse_cobertura.hitsPerLine(dom, "main.cc", 9) is None + dom = cobertura.parseFile(self.outbase + "/kcov/main-tests-debug-file/cobertura.xml") + assert cobertura.hitsPerLine(dom, "main.cc", 9) is None # Todo: Look in /usr/lib/debug as well @@ -559,118 +483,119 @@ def runTest(self): class collect_no_source(testbase.KcovTestCase): @unittest.expectedFailure def runTest(self): - os.system(f"cp {testbase.sources}/tests/short-file.c {testbase.testbuild}/main.cc") - os.system(f"gcc -g -o {testbase.testbuild}/main-collect-only {testbase.testbuild}/main.cc") - os.system(f"mv {testbase.testbuild}/main.cc {testbase.testbuild}/tmp-main.cc") + os.system(f"cp {self.sources}/tests/short-file.c {self.testbuild}/main.cc") + os.system(f"gcc -g -o {self.testbuild}/main-collect-only {self.testbuild}/main.cc") + os.system(f"mv {self.testbuild}/main.cc {self.testbuild}/tmp-main.cc") rv, o = self.do( - testbase.kcov + self.kcov + " --collect-only " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.testbuild + + self.testbuild + "/main-collect-only", False, ) - os.system(f"mv {testbase.testbuild}/tmp-main.cc {testbase.testbuild}/main.cc") + os.system(f"mv {self.testbuild}/tmp-main.cc {self.testbuild}/main.cc") rv, o = self.do( - testbase.kcov + self.kcov + " --report-only " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.testbuild + + self.testbuild + "/main-collect-only" ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/main-collect-only/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "main.cc", 1) == 1 + dom = cobertura.parseFile(self.outbase + "/kcov/main-collect-only/cobertura.xml") + assert cobertura.hitsPerLine(dom, "main.cc", 1) == 1 class dlopen(testbase.KcovTestCase): @unittest.expectedFailure def runTest(self): - noKcovRv, o = self.do(testbase.testbuild + "/dlopen", False) + noKcovRv, o = self.doCmd(self.testbuild + "/dlopen") rv, o = self.do( - testbase.kcov + " " + testbase.outbase + "/kcov " + testbase.testbuild + "/dlopen", + self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/dlopen", False, ) assert noKcovRv == rv - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/dlopen/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "dlopen.cc", 11) == 1 - assert parse_cobertura.hitsPerLine(dom, "dlopen.cc", 12) == 0 - assert parse_cobertura.hitsPerLine(dom, "solib.c", 5) == 1 - assert parse_cobertura.hitsPerLine(dom, "solib.c", 12) == 0 + dom = cobertura.parseFile(self.outbase + "/kcov/dlopen/cobertura.xml") + assert cobertura.hitsPerLine(dom, "dlopen.cc", 11) == 1 + assert cobertura.hitsPerLine(dom, "dlopen.cc", 12) == 0 + assert cobertura.hitsPerLine(dom, "solib.c", 5) == 1 + assert cobertura.hitsPerLine(dom, "solib.c", 12) == 0 class dlopen_in_ignored_source_file(testbase.KcovTestCase): @unittest.expectedFailure def runTest(self): rv, o = self.do( - testbase.kcov + self.kcov + " --exclude-pattern=dlopen.cc " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.testbuild + + self.testbuild + "/dlopen", False, ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/dlopen/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "dlopen-main.cc", 10) == 1 - assert parse_cobertura.hitsPerLine(dom, "solib.c", 5) == 1 - assert parse_cobertura.hitsPerLine(dom, "solib.c", 12) == 0 + dom = cobertura.parseFile(self.outbase + "/kcov/dlopen/cobertura.xml") + assert cobertura.hitsPerLine(dom, "dlopen-main.cc", 10) == 1 + assert cobertura.hitsPerLine(dom, "solib.c", 5) == 1 + assert cobertura.hitsPerLine(dom, "solib.c", 12) == 0 class daemon_no_wait_for_last_child(testbase.KcovTestCase): @unittest.skipIf(sys.platform.startswith("darwin"), "Not for OSX") @unittest.expectedFailure def runTest(self): - noKcovRv, o = self.do(testbase.testbuild + "/test_daemon", False) + noKcovRv, o = self.doCmd(self.testbuild + "/test_daemon") rv, o = self.do( - testbase.kcov + self.kcov + " --output-interval=1 --exit-first-process " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.testbuild + + self.testbuild + "/test_daemon", False, ) assert noKcovRv == rv + time.sleep(2) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/test_daemon/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "test-daemon.cc", 31) == 0 + dom = cobertura.parseFile(self.outbase + "/kcov/test_daemon/cobertura.xml") + assert cobertura.hitsPerLine(dom, "test-daemon.cc", 31) == 0 time.sleep(5) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/test_daemon/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "test-daemon.cc", 31) == 1 + dom = cobertura.parseFile(self.outbase + "/kcov/test_daemon/cobertura.xml") + assert cobertura.hitsPerLine(dom, "test-daemon.cc", 31) == 1 class address_sanitizer_coverage(testbase.KcovTestCase): @unittest.skipIf(sys.platform.startswith("darwin"), "Not for OSX") @unittest.expectedFailure def runTest(self): - if not os.path.isfile(testbase.testbuild + "/sanitizer-coverage"): - print("Clang-only") + if not os.path.isfile(self.testbuild + "/sanitizer-coverage"): + self.write_message("Clang-only") assert False rv, o = self.do( - testbase.kcov + self.kcov + " --clang " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.testbuild + + self.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 + dom = cobertura.parseFile(self.outbase + "/kcov/sanitizer-coverage/cobertura.xml") + assert cobertura.hitsPerLine(dom, "sanitizer-coverage.c", 5) == 1 + assert cobertura.hitsPerLine(dom, "sanitizer-coverage.c", 7) == 1 + assert 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 cobertura.hitsPerLine(dom, "sanitizer-coverage.c", 16) == 1 + assert 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 + assert cobertura.hitsPerLine(dom, "sanitizer-coverage.c", 22) == 0 + assert cobertura.hitsPerLine(dom, "sanitizer-coverage.c", 25) == 0 diff --git a/tests/tools/compiled_basic.py b/tests/tools/compiled_basic.py index 3dc3aa1d..849129a1 100644 --- a/tests/tools/compiled_basic.py +++ b/tests/tools/compiled_basic.py @@ -1,7 +1,7 @@ import sys import unittest -import parse_cobertura +import cobertura import testbase @@ -11,113 +11,95 @@ class shared_library(testbase.KcovTestCase): "Not for OSX (does not work with the mach-engine for now)", ) def runTest(self): - noKcovRv, o = self.do(testbase.testbuild + "/shared_library_test", False) + noKcovRv, o = self.doCmd(self.testbuild + "/shared_library_test") rv, o = self.do( - testbase.kcov - + " " - + testbase.outbase - + "/kcov " - + testbase.testbuild - + "/shared_library_test", + self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/shared_library_test", False, ) assert rv == noKcovRv - dom = parse_cobertura.parseFile( - testbase.outbase + "/kcov/shared_library_test/cobertura.xml" - ) - assert parse_cobertura.hitsPerLine(dom, "main.c", 9) >= 1 - assert parse_cobertura.hitsPerLine(dom, "solib.c", 5) == 1 + dom = cobertura.parseFile(self.outbase + "/kcov/shared_library_test/cobertura.xml") + assert cobertura.hitsPerLine(dom, "main.c", 9) >= 1 + assert cobertura.hitsPerLine(dom, "solib.c", 5) == 1 class shared_library_skip(testbase.KcovTestCase): @unittest.skipIf(sys.platform.startswith("darwin"), "Not for OSX, Issue #157") def runTest(self): rv, o = self.do( - testbase.kcov + self.kcov + " --skip-solibs " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.testbuild + + self.testbuild + "/shared_library_test", False, ) self.skipTest("Fickle test, ignoring") assert rv == 0 - dom = parse_cobertura.parseFile( - testbase.outbase + "/kcov/shared_library_test/cobertura.xml" - ) - assert parse_cobertura.hitsPerLine(dom, "main.c", 9) == 1 - assert parse_cobertura.hitsPerLine(dom, "solib.c", 5) is None + dom = cobertura.parseFile(self.outbase + "/kcov/shared_library_test/cobertura.xml") + assert cobertura.hitsPerLine(dom, "main.c", 9) == 1 + assert cobertura.hitsPerLine(dom, "solib.c", 5) is None class shared_library_filter_out(testbase.KcovTestCase): @unittest.skipIf(sys.platform.startswith("darwin"), "Not for OSX, Issue #157") def runTest(self): rv, o = self.do( - testbase.kcov + self.kcov + " --exclude-pattern=solib " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.testbuild + + self.testbuild + "/shared_library_test", False, ) assert rv == 0 - dom = parse_cobertura.parseFile( - testbase.outbase + "/kcov/shared_library_test/cobertura.xml" - ) - assert parse_cobertura.hitsPerLine(dom, "main.c", 9) == 1 - assert parse_cobertura.hitsPerLine(dom, "solib.c", 5) is None + dom = cobertura.parseFile(self.outbase + "/kcov/shared_library_test/cobertura.xml") + assert cobertura.hitsPerLine(dom, "main.c", 9) == 1 + assert cobertura.hitsPerLine(dom, "solib.c", 5) is None class shared_library_accumulate(testbase.KcovTestCase): @unittest.skipIf(sys.platform.startswith("darwin"), "Not for OSX, Issue #157") def runTest(self): rv, o = self.do( - testbase.kcov - + " " - + testbase.outbase - + "/kcov " - + testbase.testbuild - + "/shared_library_test 5", + self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/shared_library_test 5", False, ) assert rv == 0 - dom = parse_cobertura.parseFile( - testbase.outbase + "/kcov/shared_library_test/cobertura.xml" - ) - assert parse_cobertura.hitsPerLine(dom, "main.c", 9) == 1 - assert parse_cobertura.hitsPerLine(dom, "solib.c", 5) == 1 - assert parse_cobertura.hitsPerLine(dom, "solib.c", 10) == 1 + dom = cobertura.parseFile(self.outbase + "/kcov/shared_library_test/cobertura.xml") + assert cobertura.hitsPerLine(dom, "main.c", 9) == 1 + assert cobertura.hitsPerLine(dom, "solib.c", 5) == 1 + assert cobertura.hitsPerLine(dom, "solib.c", 10) == 1 class MainTestBase(testbase.KcovTestCase): def doTest(self, verify): - noKcovRv, o = self.do(testbase.testbuild + "/main-tests", False) + noKcovRv, o = self.doCmd(self.testbuild + "/main-tests") rv, o = self.do( - testbase.kcov + self.kcov + " " + verify + " " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.testbuild + + self.testbuild + "/main-tests 5", False, ) assert rv == noKcovRv - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/main-tests/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "main.cc", 9) == 1 - assert parse_cobertura.hitsPerLine(dom, "main.cc", 14) is None - assert parse_cobertura.hitsPerLine(dom, "main.cc", 18) >= 1 - assert parse_cobertura.hitsPerLine(dom, "main.cc", 25) == 1 - assert parse_cobertura.hitsPerLine(dom, "file.c", 6) >= 1 - assert parse_cobertura.hitsPerLine(dom, "file2.c", 7) == 0 + dom = cobertura.parseFile(self.outbase + "/kcov/main-tests/cobertura.xml") + assert cobertura.hitsPerLine(dom, "main.cc", 9) == 1 + assert cobertura.hitsPerLine(dom, "main.cc", 14) is None + assert cobertura.hitsPerLine(dom, "main.cc", 18) >= 1 + assert cobertura.hitsPerLine(dom, "main.cc", 25) == 1 + assert cobertura.hitsPerLine(dom, "file.c", 6) >= 1 + assert cobertura.hitsPerLine(dom, "file2.c", 7) == 0 class main_test(MainTestBase): diff --git a/tests/tools/filter.py b/tests/tools/filter.py index 623ad681..1ceed3fa 100644 --- a/tests/tools/filter.py +++ b/tests/tools/filter.py @@ -1,81 +1,81 @@ -import parse_cobertura +import cobertura import testbase class include_exclude_pattern(testbase.KcovTestCase): def runTest(self): rv, o = self.do( - testbase.kcov + self.kcov + " --bash-dont-parse-binary-dir --exclude-pattern=first-dir " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.sources + + self.sources + "/tests/bash/shell-main" ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/shell-main/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "shell-main", 29) >= 1 - assert parse_cobertura.hitsPerLine(dom, "c.sh", 3) is None + dom = cobertura.parseFile(self.outbase + "/kcov/shell-main/cobertura.xml") + assert cobertura.hitsPerLine(dom, "shell-main", 29) >= 1 + assert cobertura.hitsPerLine(dom, "c.sh", 3) is None rv, o = self.do( - testbase.kcov + self.kcov + " --include-pattern=first-dir " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.sources + + self.sources + "/tests/bash/shell-main" ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/shell-main/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "shell-main", 29) is None - assert parse_cobertura.hitsPerLine(dom, "c.sh", 3) >= 1 + dom = cobertura.parseFile(self.outbase + "/kcov/shell-main/cobertura.xml") + assert cobertura.hitsPerLine(dom, "shell-main", 29) is None + assert cobertura.hitsPerLine(dom, "c.sh", 3) >= 1 rv, o = self.do( - testbase.kcov + self.kcov + " --include-pattern=first-dir --exclude-pattern=c.sh " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.sources + + self.sources + "/tests/bash/shell-main" ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/shell-main/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "shell-main", 29) is None - assert parse_cobertura.hitsPerLine(dom, "c.sh", 3) is None - assert parse_cobertura.hitsPerLine(dom, "b.sh", 3) >= 1 + dom = cobertura.parseFile(self.outbase + "/kcov/shell-main/cobertura.xml") + assert cobertura.hitsPerLine(dom, "shell-main", 29) is None + assert cobertura.hitsPerLine(dom, "c.sh", 3) is None + assert cobertura.hitsPerLine(dom, "b.sh", 3) >= 1 class include_path(testbase.KcovTestCase): def runTest(self): rv, o = self.do( - testbase.kcov + self.kcov + " --bash-dont-parse-binary-dir --include-path=" - + testbase.sources + + self.sources + "/tests/bash/first-dir " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.sources + + self.sources + "/tests/bash/shell-main" ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/shell-main/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "shell-main", 29) is None - assert parse_cobertura.hitsPerLine(dom, "c.sh", 3) >= 1 - assert parse_cobertura.hitsPerLine(dom, "b.sh", 3) >= 1 + dom = cobertura.parseFile(self.outbase + "/kcov/shell-main/cobertura.xml") + assert cobertura.hitsPerLine(dom, "shell-main", 29) is None + assert cobertura.hitsPerLine(dom, "c.sh", 3) >= 1 + assert cobertura.hitsPerLine(dom, "b.sh", 3) >= 1 class include_path_and_exclude_pattern(testbase.KcovTestCase): def runTest(self): rv, o = self.do( - testbase.kcov + self.kcov + " --bash-dont-parse-binary-dir --include-path=" - + testbase.sources + + self.sources + "/tests/bash/first-dir --exclude-pattern=b.sh " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.sources + + self.sources + "/tests/bash/shell-main" ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/shell-main/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "shell-main", 29) is None - assert parse_cobertura.hitsPerLine(dom, "c.sh", 3) >= 1 - assert parse_cobertura.hitsPerLine(dom, "b.sh", 3) is None + dom = cobertura.parseFile(self.outbase + "/kcov/shell-main/cobertura.xml") + assert cobertura.hitsPerLine(dom, "shell-main", 29) is None + assert cobertura.hitsPerLine(dom, "c.sh", 3) >= 1 + assert cobertura.hitsPerLine(dom, "b.sh", 3) is None diff --git a/tests/tools/python.py b/tests/tools/python.py index bf31abb4..969e584c 100644 --- a/tests/tools/python.py +++ b/tests/tools/python.py @@ -1,19 +1,14 @@ import unittest -import parse_cobertura +import cobertura import testbase class python_exit_status(testbase.KcovTestCase): def runTest(self): - noKcovRv, o = self.do(testbase.sources + "/tests/python/main 5") + noKcovRv, o = self.doCmd(self.sources + "/tests/python/main 5") rv, o = self.do( - testbase.kcov - + " " - + testbase.outbase - + "/kcov " - + testbase.sources - + "/tests/python/main 5" + self.kcov + " " + self.outbase + "/kcov " + self.sources + "/tests/python/main 5" ) assert rv == noKcovRv @@ -22,11 +17,11 @@ def runTest(self): class python_can_set_illegal_parser(testbase.KcovTestCase): def runTest(self): rv, o = self.do( - testbase.kcov + self.kcov + " --python-parser=python7 " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.sources + + self.sources + "/tests/python/main 5" ) @@ -36,11 +31,11 @@ def runTest(self): class python_can_set_legal_parser(testbase.KcovTestCase): def runTest(self): rv, o = self.do( - testbase.kcov + self.kcov + " --python-parser=python3 " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.sources + + self.sources + "/tests/python/main 5" ) @@ -50,11 +45,11 @@ def runTest(self): class python2_can_set_legal_parser(testbase.KcovTestCase): def runTest(self): rv, o = self.do( - testbase.kcov + self.kcov + " --python-parser=python2 " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.sources + + self.sources + "/tests/python/main 5" ) @@ -64,11 +59,11 @@ def runTest(self): class python_issue_368_can_handle_symlink_target(testbase.KcovTestCase): def runTest(self): rv, o = self.do( - testbase.kcov + self.kcov + " --python-parser=python3 " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.sources + + self.sources + "/tests/python/link_main 5 --foo" ) @@ -78,47 +73,47 @@ def runTest(self): class python_unittest(testbase.KcovTestCase): def runTest(self): rv, o = self.do( - testbase.kcov + self.kcov + " " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.sources + + self.sources + "/tests/python/unittest/testdriver" ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/testdriver/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "testdriver", 14) == 1 + dom = cobertura.parseFile(self.outbase + "/kcov/testdriver/cobertura.xml") + assert cobertura.hitsPerLine(dom, "testdriver", 14) == 1 class PythonBase(testbase.KcovTestCase): def doTest(self, extra): rv, o = self.do( - testbase.kcov + self.kcov + " " + extra + " " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.sources + + self.sources + "/tests/python/main 5" ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/main/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "main", 10) == 2 - assert parse_cobertura.hitsPerLine(dom, "main", 17) == 0 - assert parse_cobertura.hitsPerLine(dom, "main", 22) is None - assert parse_cobertura.hitsPerLine(dom, "second.py", 2) == 1 - assert parse_cobertura.hitsPerLine(dom, "second.py", 4) is None - assert parse_cobertura.hitsPerLine(dom, "second.py", 11) is None - assert parse_cobertura.hitsPerLine(dom, "second.py", 31) == 0 - assert parse_cobertura.hitsPerLine(dom, "second.py", 38) == 1 - assert parse_cobertura.hitsPerLine(dom, "second.py", 39) == 0 - assert parse_cobertura.hitsPerLine(dom, "second.py", 40) is None - assert parse_cobertura.hitsPerLine(dom, "second.py", 41) == 1 - assert parse_cobertura.hitsPerLine(dom, "second.py", 56) is None - assert parse_cobertura.hitsPerLine(dom, "second.py", 60) is None - assert parse_cobertura.hitsPerLine(dom, "second.py", 65) is None - assert parse_cobertura.hitsPerLine(dom, "second.py", 77) is None + dom = cobertura.parseFile(self.outbase + "/kcov/main/cobertura.xml") + assert cobertura.hitsPerLine(dom, "main", 10) == 2 + assert cobertura.hitsPerLine(dom, "main", 17) == 0 + assert cobertura.hitsPerLine(dom, "main", 22) is None + assert cobertura.hitsPerLine(dom, "second.py", 2) == 1 + assert cobertura.hitsPerLine(dom, "second.py", 4) is None + assert cobertura.hitsPerLine(dom, "second.py", 11) is None + assert cobertura.hitsPerLine(dom, "second.py", 31) == 0 + assert cobertura.hitsPerLine(dom, "second.py", 38) == 1 + assert cobertura.hitsPerLine(dom, "second.py", 39) == 0 + assert cobertura.hitsPerLine(dom, "second.py", 40) is None + assert cobertura.hitsPerLine(dom, "second.py", 41) == 1 + assert cobertura.hitsPerLine(dom, "second.py", 56) is None + assert cobertura.hitsPerLine(dom, "second.py", 60) is None + assert cobertura.hitsPerLine(dom, "second.py", 65) is None + assert cobertura.hitsPerLine(dom, "second.py", 77) is None class python_coverage(PythonBase): @@ -129,29 +124,19 @@ def runTestTest(self): class python_accumulate_data(testbase.KcovTestCase): def runTest(self): rv, o = self.do( - testbase.kcov - + " " - + testbase.outbase - + "/kcov " - + testbase.sources - + "/tests/python/main 5" + self.kcov + " " + self.outbase + "/kcov " + self.sources + "/tests/python/main 5" ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/main/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "main", 16) == 0 - assert parse_cobertura.hitsPerLine(dom, "main", 19) == 1 + dom = cobertura.parseFile(self.outbase + "/kcov/main/cobertura.xml") + assert cobertura.hitsPerLine(dom, "main", 16) == 0 + assert cobertura.hitsPerLine(dom, "main", 19) == 1 rv, o = self.do( - testbase.kcov - + " " - + testbase.outbase - + "/kcov " - + testbase.sources - + "/tests/python/main" + self.kcov + " " + self.outbase + "/kcov " + self.sources + "/tests/python/main" ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/main/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "main", 16) == 1 - assert parse_cobertura.hitsPerLine(dom, "main", 19) == 1 + dom = cobertura.parseFile(self.outbase + "/kcov/main/cobertura.xml") + assert cobertura.hitsPerLine(dom, "main", 16) == 1 + assert cobertura.hitsPerLine(dom, "main", 19) == 1 class python3_coverage(PythonBase): @@ -167,28 +152,23 @@ def runTest(self): class python_tricky_single_line_string_assignment(testbase.KcovTestCase): def runTest(self): rv, o = self.do( - testbase.kcov - + " " - + testbase.outbase - + "/kcov " - + testbase.sources - + "/tests/python/main 5" + self.kcov + " " + self.outbase + "/kcov " + self.sources + "/tests/python/main 5" ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/main/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "second.py", 34) == 2 + dom = cobertura.parseFile(self.outbase + "/kcov/main/cobertura.xml") + assert cobertura.hitsPerLine(dom, "second.py", 34) == 2 class python_select_parser(testbase.KcovTestCase): def disabledTest(self): rv, o = self.do( - testbase.kcov + self.kcov + " --python-parser=" - + testbase.sources + + self.sources + "/tests/tools/dummy-python.sh " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.sources + + self.sources + "/tests/python/main 5" ) @@ -199,14 +179,9 @@ class python_tricky_single_dict_assignment(testbase.KcovTestCase): @unittest.expectedFailure def runTest(self): rv, o = self.do( - testbase.kcov - + " " - + testbase.outbase - + "/kcov " - + testbase.sources - + "/tests/python/main 5" + self.kcov + " " + self.outbase + "/kcov " + self.sources + "/tests/python/main 5" ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/main/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "second.py", 57) == 1 - assert parse_cobertura.hitsPerLine(dom, "second.py", 61) == 1 + dom = cobertura.parseFile(self.outbase + "/kcov/main/cobertura.xml") + assert cobertura.hitsPerLine(dom, "second.py", 57) == 1 + assert cobertura.hitsPerLine(dom, "second.py", 61) == 1 diff --git a/tests/tools/system_mode.py b/tests/tools/system_mode.py index 9582afbf..70629919 100644 --- a/tests/tools/system_mode.py +++ b/tests/tools/system_mode.py @@ -3,7 +3,7 @@ import time import unittest -import parse_cobertura +import cobertura import testbase @@ -16,7 +16,7 @@ def writeToPipe(self, str): class system_mode_can_start_and_stop_daemon(SystemModeBase): def runTest(self): - rv, o = self.do(testbase.kcov_system_daemon + " -d", False) + rv, o = self.do(self.kcov_system_daemon + " -d", False) pf = "/tmp/kcov-system.pid" assert os.path.isfile(pf) @@ -31,17 +31,12 @@ def runTest(self): class system_mode_can_instrument_binary(SystemModeBase): def runTest(self): rv, o = self.do( - testbase.kcov - + " --system-record " - + testbase.outbase - + "/kcov " - + testbase.testbuild - + "/" + self.kcov + " --system-record " + self.outbase + "/kcov " + self.testbuild + "/" ) assert rv == 0 - src = testbase.testbuild + "/main-tests" - dst = testbase.outbase + "/kcov/main-tests" + src = self.testbuild + "/main-tests" + dst = self.outbase + "/kcov/main-tests" assert os.path.isfile(src) assert os.path.isfile(dst) @@ -52,24 +47,16 @@ def runTest(self): class system_mode_can_record_and_report_binary(SystemModeBase): @unittest.skipIf(platform.machine() == "i686", "x86_64-only") def runTest(self): - print(platform.machine()) - try: - os.makedirs(testbase.outbase + "/kcov") - except: - pass + self.write_message(platform.machine()) + rv, o = self.do( - testbase.kcov - + " --system-record " - + testbase.outbase - + "/kcov " - + testbase.testbuild - + "/" + self.kcov + " --system-record " + self.outbase + "/kcov " + self.testbuild + "/" ) - rv, o = self.do(testbase.kcov_system_daemon + " -d", False) + rv, o = self.do(self.kcov_system_daemon + " -d", False) - os.environ["LD_LIBRARY_PATH"] = testbase.outbase + "/kcov/lib" - rv, o = self.do(testbase.outbase + "/kcov/main-tests", False) + os.environ["LD_LIBRARY_PATH"] = self.outbase + "/kcov/lib" + rv, o = self.do(self.outbase + "/kcov/main-tests", False) self.skipTest("Fickle test, ignoring") assert rv == 0 @@ -77,11 +64,11 @@ def runTest(self): self.writeToPipe("STOPME") rv, o = self.do( - testbase.kcov + " --system-report " + testbase.outbase + "/kcov-report /tmp/kcov-data" + self.kcov + " --system-report " + self.outbase + "/kcov-report /tmp/kcov-data" ) assert rv == 0 - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov-report/main-tests/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "main.cc", 9) == 1 - assert parse_cobertura.hitsPerLine(dom, "main.cc", 14) is None - assert parse_cobertura.hitsPerLine(dom, "main.cc", 18) >= 1 + dom = cobertura.parseFile(self.outbase + "/kcov-report/main-tests/cobertura.xml") + assert cobertura.hitsPerLine(dom, "main.cc", 9) == 1 + assert cobertura.hitsPerLine(dom, "main.cc", 14) is None + assert cobertura.hitsPerLine(dom, "main.cc", 18) >= 1 diff --git a/tests/tools/testbase.py b/tests/tools/testbase.py index 73e89278..922612e2 100644 --- a/tests/tools/testbase.py +++ b/tests/tools/testbase.py @@ -1,20 +1,24 @@ #!/usr/bin/env python3 +import errno import os import os.path import platform import shutil import subprocess import sys -import threading +import time import unittest +PIPE = subprocess.PIPE + kcov = "" -kcov_system_daemon = "" outbase = "" testbuild = "" sources = "" +default_timeout = 10 * 60 + # Normalize path, also ensuring that it is not empty. def normalize(path): @@ -28,7 +32,6 @@ def configure(k, o, t, s): global kcov, outbase, testbuild, sources, kcov_system_daemon kcov = normalize(k) - kcov_system_daemon = k + "-system-daemon" outbase = normalize(o) testbuild = normalize(t) sources = normalize(s) @@ -38,25 +41,41 @@ def configure(k, o, t, s): class KcovTestCase(unittest.TestCase): def setUp(self): - os.makedirs(outbase + "/" + "kcov") + # Make the configuration values available as class members. + self.kcov = kcov + self.kcov_system_daemon = self.kcov + "-system-daemon" + self.outbase = outbase + self.outdir = self.outbase + "/" + "kcov" + self.testbuild = testbuild + self.sources = sources + + # Intentionally fails if target directory exists. + os.makedirs(self.outdir) def tearDown(self): - shutil.rmtree(outbase + "/" + "kcov") + # Don't ignore errors, since they may be caused by bugs in the test suite. + try: + shutil.rmtree(self.outdir) + except OSError as err: + if err.errno != errno.ENOTEMPTY: + raise + + # See https://github.com/ansible/ansible/issues/34335 as an example. + # Sleeping is necessary to ensure no more files are created. + time.sleep(5) + sys.stderr.write(f"warning: retry rmtree: {err}\n") + shutil.rmtree(self.outdir) def doShell(self, cmdline): - child = subprocess.Popen( - cmdline, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE + term = subprocess.run( + cmdline, shell=True, stdout=PIPE, stderr=PIPE, timeout=default_timeout ) - out, err = child.communicate() - output = out + err - rv = child.returncode + output = term.stdout + term.stderr + rv = term.returncode return rv, output - def do(self, cmdline, kcovKcov=True, timeout=None, kill=False): - output = "" - rv = 0 - + def do(self, cmdline, /, kcovKcov=True, *, timeout=default_timeout): extra = "" if ( kcovKcov @@ -70,25 +89,22 @@ def do(self, cmdline, kcovKcov=True, timeout=None, kill=False): ) cmdline = extra + cmdline - child = subprocess.Popen(cmdline.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE) - timer = None + args = cmdline.split() + term = subprocess.run(args, stdout=PIPE, stderr=PIPE, timeout=timeout) + output = term.stdout + term.stderr + rv = term.returncode - if timeout is not None: + return rv, output - def stopChild(): - print(f"\n didn't finish within {timeout} seconds; killing ...") - if kill: - child.kill() - else: - child.terminate() + def doCmd(self, cmdline): + args = cmdline.split() + term = subprocess.run(args, stdout=PIPE, stderr=PIPE, timeout=default_timeout) + output = term.stdout + term.stderr + rv = term.returncode - timer = threading.Timer(timeout, stopChild) - timer.start() + return rv, output - out, err = child.communicate() - if timer is not None: - timer.cancel() - output = out + err - rv = child.returncode + def write_message(self, msg): + """Add a custom message to the current test status line.""" - return rv, output + sys.stderr.write(msg + " ")