From 7b62e636134574fa126292504e57873e3de2a897 Mon Sep 17 00:00:00 2001 From: Manlio Perillo Date: Sat, 30 Mar 2024 17:21:21 +0100 Subject: [PATCH 1/9] tests: use subprocess.run to run child process The current, old API, is not only inconvenient (using a thread and a timer to implement timeouts) but it is also incorrect since the child process is not waited. Use subprocess.run for both `doShell` and `do`. Note that for the `do` method, this is a behavior change, since a child process is always terminated by kill. Add a default timeout, set to 10 min. After this change the test `system_mode_can_record_and_report_binary` fails. This will be addressed in the next commit. --- tests/tools/bash_linux_only.py | 1 - tests/tools/testbase.py | 43 ++++++++++------------------------ 2 files changed, 13 insertions(+), 31 deletions(-) diff --git a/tests/tools/bash_linux_only.py b/tests/tools/bash_linux_only.py index 056f0258..7b037b0a 100644 --- a/tests/tools/bash_linux_only.py +++ b/tests/tools/bash_linux_only.py @@ -29,7 +29,6 @@ def runTest(self): + "/tests/bash/background-child.sh", kcovKcov=False, timeout=3.0, - kill=True, ) self.assertEqual(0, rv, "kcov exited unsuccessfully") dom = parse_cobertura.parseFile( diff --git a/tests/tools/testbase.py b/tests/tools/testbase.py index 73e89278..8e350bc0 100644 --- a/tests/tools/testbase.py +++ b/tests/tools/testbase.py @@ -6,15 +6,18 @@ import shutil import subprocess import sys -import threading 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): @@ -44,19 +47,15 @@ def tearDown(self): shutil.rmtree(outbase + "/" + "kcov") 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 +69,9 @@ 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 - - if timeout is not None: - - def stopChild(): - print(f"\n didn't finish within {timeout} seconds; killing ...") - if kill: - child.kill() - else: - child.terminate() - - timer = threading.Timer(timeout, stopChild) - timer.start() - - out, err = child.communicate() - if timer is not None: - timer.cancel() - output = out + err - rv = child.returncode + args = cmdline.split() + term = subprocess.run(args, stdout=PIPE, stderr=PIPE, timeout=timeout) + output = term.stdout + term.stderr + rv = term.returncode return rv, output From 142810e766cfa5211ee907ceb8c4c35e37319a59 Mon Sep 17 00:00:00 2001 From: Manlio Perillo Date: Sat, 30 Mar 2024 18:06:15 +0100 Subject: [PATCH 2/9] tests: make shutil.rmtree more robust In some rare case, shutil.rmtree from KcovTestCase.tearDown may fail, in case a child process continue to write additionally files. I can reproduce the behavior consistentily by setting default_timeout to 1 second. Update the tearDown method to retry rmtree in case of a ENOTEMPTY error, waiting 5 seconds to ensure that the offending child process terminates. --- tests/tools/testbase.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/tests/tools/testbase.py b/tests/tools/testbase.py index 8e350bc0..334c716d 100644 --- a/tests/tools/testbase.py +++ b/tests/tools/testbase.py @@ -1,11 +1,13 @@ #!/usr/bin/env python3 +import errno import os import os.path import platform import shutil import subprocess import sys +import time import unittest PIPE = subprocess.PIPE @@ -41,10 +43,24 @@ def configure(k, o, t, s): class KcovTestCase(unittest.TestCase): def setUp(self): - os.makedirs(outbase + "/" + "kcov") + self.outdir = outbase + "/" + "kcov" + + # 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): term = subprocess.run( From 904697e8df5163f4ad96b28e0544ac1b39c00aa0 Mon Sep 17 00:00:00 2001 From: Manlio Perillo Date: Sun, 31 Mar 2024 16:24:50 +0200 Subject: [PATCH 3/9] tests: improve custom messages in a test case A few tests use print to show a custom message, but the problem is that this will break the test status line. Add the KcovTestCase.write_message method, so that the message is showed correctly in the test status line. --- tests/tools/compiled.py | 2 +- tests/tools/system_mode.py | 2 +- tests/tools/testbase.py | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/tools/compiled.py b/tests/tools/compiled.py index 6c0900d9..0b9318d0 100644 --- a/tests/tools/compiled.py +++ b/tests/tools/compiled.py @@ -652,7 +652,7 @@ class address_sanitizer_coverage(testbase.KcovTestCase): @unittest.expectedFailure def runTest(self): if not os.path.isfile(testbase.testbuild + "/sanitizer-coverage"): - print("Clang-only") + self.write_message("Clang-only") assert False rv, o = self.do( testbase.kcov diff --git a/tests/tools/system_mode.py b/tests/tools/system_mode.py index 9582afbf..63212d78 100644 --- a/tests/tools/system_mode.py +++ b/tests/tools/system_mode.py @@ -52,7 +52,7 @@ 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()) + self.write_message(platform.machine()) try: os.makedirs(testbase.outbase + "/kcov") except: diff --git a/tests/tools/testbase.py b/tests/tools/testbase.py index 334c716d..342cc1ef 100644 --- a/tests/tools/testbase.py +++ b/tests/tools/testbase.py @@ -91,3 +91,8 @@ def do(self, cmdline, kcovKcov=True, timeout=default_timeout): rv = term.returncode return rv, output + + def write_message(self, msg): + """Add a custom message to the current test status line.""" + + sys.stderr.write(msg + " ") From c62f6f00c87a0cc8cb20b331b7fa7f0c61dd40ed Mon Sep 17 00:00:00 2001 From: Manlio Perillo Date: Sun, 31 Mar 2024 16:56:48 +0200 Subject: [PATCH 4/9] tests: rename the parse_cobertura module to cobertura The old name is long and not concise. As an example: parse_cobertura.parseFile(path) parse_cobertura.parse(data) --- tests/tools/accumulate.py | 56 ++-- tests/tools/bash.py | 266 +++++++++--------- tests/tools/bash_linux_only.py | 22 +- tests/tools/basic.py | 6 +- .../{parse_cobertura.py => cobertura.py} | 0 tests/tools/compiled.py | 196 ++++++------- tests/tools/compiled_basic.py | 50 ++-- tests/tools/filter.py | 38 +-- tests/tools/python.py | 60 ++-- tests/tools/system_mode.py | 10 +- 10 files changed, 337 insertions(+), 367 deletions(-) rename tests/tools/{parse_cobertura.py => cobertura.py} (100%) diff --git a/tests/tools/accumulate.py b/tests/tools/accumulate.py index 9326d4ab..3c2d8721 100644 --- a/tests/tools/accumulate.py +++ b/tests/tools/accumulate.py @@ -1,4 +1,4 @@ -import parse_cobertura +import cobertura import testbase @@ -13,10 +13,10 @@ def runTest(self): + "/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(testbase.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 @@ -26,10 +26,10 @@ def runTest(self): + testbase.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(testbase.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): @@ -43,10 +43,10 @@ def runTest(self): + "/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(testbase.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 @@ -56,10 +56,10 @@ def runTest(self): + testbase.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(testbase.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): @@ -81,9 +81,9 @@ def runTest(self): + "/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(testbase.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): @@ -114,9 +114,9 @@ def runTest(self): + testbase.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(testbase.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): @@ -166,12 +166,10 @@ def runTest(self): + testbase.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(testbase.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): diff --git a/tests/tools/bash.py b/tests/tools/bash.py index 80ac1a61..6cf8e88b 100644 --- a/tests/tools/bash.py +++ b/tests/tools/bash.py @@ -3,7 +3,7 @@ import sys import unittest -import parse_cobertura +import cobertura import testbase @@ -19,7 +19,7 @@ def doTest(self, args): + args ) - return parse_cobertura.parseFile(testbase.outbase + "/kcov/shell-main/cobertura.xml") + return cobertura.parseFile(testbase.outbase + "/kcov/shell-main/cobertura.xml") class bash_coverage(testbase.KcovTestCase): @@ -33,21 +33,21 @@ def runTest(self): + "/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 + dom = cobertura.parseFile(testbase.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 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 + 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 @@ -64,10 +64,10 @@ def runTest(self): + "/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(testbase.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): @@ -81,46 +81,46 @@ def runTest(self): + "/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(testbase.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): @@ -137,8 +137,8 @@ def runTest(self): False, ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/trap.sh/cobertura.xml") - assert parse_cobertura.hitsPerLine(dom, "trap.sh", 5) == 1 + dom = cobertura.parseFile(testbase.outbase + "/kcov/trap.sh/cobertura.xml") + assert cobertura.hitsPerLine(dom, "trap.sh", 5) == 1 class bash_accumulate_data(testbase.KcovTestCase): @@ -152,9 +152,9 @@ def runTest(self): + "/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(testbase.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 + " " @@ -164,9 +164,9 @@ def runTest(self): + "/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(testbase.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): @@ -180,19 +180,19 @@ def runTest(self): 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 + dom = cobertura.parseFile(testbase.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" ) - 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(testbase.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): @@ -206,9 +206,9 @@ def runTest(self): + "/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(testbase.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 + " " @@ -218,9 +218,9 @@ def runTest(self): + "/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(testbase.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 + " " @@ -230,11 +230,11 @@ def runTest(self): + "/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(testbase.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): @@ -248,11 +248,11 @@ def runTest(self): + "/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(testbase.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): @@ -267,8 +267,8 @@ def runTest(self): ) 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(testbase.outbase + "/kcov/multiline-alias.sh/cobertura.xml") + assert cobertura.hitsPerLine(dom, "multiline-alias.sh", 6) == 1 class bash_multiline_backslashes(testbase.KcovTestCase): @@ -297,10 +297,10 @@ def runTest(self): ) assert b"echo called test_alias" not in o - dom = parse_cobertura.parseFile( + dom = cobertura.parseFile( testbase.outbase + "/kcov/no-executed-statements.sh/cobertura.xml" ) - assert parse_cobertura.hitsPerLine(dom, "no-executed-statements.sh", 4) == 0 + assert cobertura.hitsPerLine(dom, "no-executed-statements.sh", 4) == 0 class bash_stderr_redirection(testbase.KcovTestCase): @@ -337,12 +337,12 @@ def runTest(self): + "/tests/bash/dollar-var-replacements.sh" ) - dom = parse_cobertura.parseFile( + dom = 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 + 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 @@ -356,9 +356,9 @@ def runTest(self): + testbase.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(testbase.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 @@ -372,8 +372,8 @@ def runTest(self): + testbase.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(testbase.outbase + "/kcov/shell-main/cobertura.xml") + assert cobertura.hitsPerLine(dom, "shell-main", 180) == 1 class bash_subshell(testbase.KcovTestCase): @@ -386,10 +386,10 @@ def runTest(self): + testbase.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(testbase.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): @@ -406,9 +406,9 @@ def runTest(self): 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(testbase.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): @@ -437,33 +437,33 @@ def runTest(self): + testbase.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 + dom = cobertura.parseFile(testbase.outbase + "/kcov/other.sh/cobertura.xml") + assert cobertura.hitsPerLine(dom, "other.sh", 22) is None + assert 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 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 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 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 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 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 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 + 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 @@ -478,10 +478,10 @@ def runTest(self): + "/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(testbase.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): @@ -497,10 +497,10 @@ def runTest(self): + "/tests/bash/first-dir/a.sh 5" ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/a.sh/cobertura.xml") + dom = cobertura.parseFile(testbase.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): @@ -514,11 +514,11 @@ def runTest(self): + "/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(testbase.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): @@ -532,14 +532,12 @@ def runTest(self): + "/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(testbase.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): @@ -555,10 +553,8 @@ def runTest(self): timeout=5.0, ) self.assertEqual(0, rv, "kcov exited unsuccessfully") - dom = parse_cobertura.parseFile( + dom = 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) - ) + 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 7b037b0a..aeac1bbd 100644 --- a/tests/tools/bash_linux_only.py +++ b/tests/tools/bash_linux_only.py @@ -1,4 +1,4 @@ -import parse_cobertura +import cobertura import testbase @@ -13,8 +13,8 @@ def runTest(self): + "/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(testbase.outbase + "/kcov/shell-main/cobertura.xml") + assert cobertura.hitsPerLine(dom, "sh-shebang.sh", 4) == 1 class bash_exit_before_child(testbase.KcovTestCase): @@ -31,12 +31,10 @@ def runTest(self): timeout=3.0, ) 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(testbase.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): @@ -50,6 +48,6 @@ def runTest(self): + "/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(testbase.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..bffb747b 100644 --- a/tests/tools/basic.py +++ b/tests/tools/basic.py @@ -1,7 +1,7 @@ import os import unittest -import parse_cobertura +import cobertura import testbase @@ -35,8 +35,8 @@ def runTest(self): noKcovRv, o = self.do(testbase.sources + "/tests/python/main 5") rv, o = self.do(testbase.kcov + " " + testbase.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(testbase.outbase + "/kcov/main/cobertura.xml") + assert cobertura.hitsPerLine(dom, "second.py", 34) == 2 assert noKcovRv, rv 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 0b9318d0..fbdf7072 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 @@ -39,10 +39,10 @@ def runTest(self): ) 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(testbase.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): @@ -54,12 +54,12 @@ def doTest(self, binary): ) 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(testbase.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): @@ -87,9 +87,9 @@ def runTest(self): ) 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(testbase.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): @@ -120,8 +120,8 @@ def runTest(self): ) 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(testbase.outbase + "/kcov/pie/cobertura.xml") + assert cobertura.hitsPerLine(dom, "pie.c", 5) == 1 class pie_argv_basic(testbase.KcovTestCase): @@ -132,9 +132,9 @@ def runTest(self): ) 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(testbase.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): @@ -149,9 +149,9 @@ def runTest(self): ) 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(testbase.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", @@ -159,9 +159,9 @@ def runTest(self): ) 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(testbase.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): @@ -178,10 +178,8 @@ def runTest(self): ) 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(testbase.outbase + "/kcov/global-constructors/cobertura.xml") + assert cobertura.hitsPerLine(dom, "test-global-ctors.cc", 4) >= 1 class daemon_wait_for_last_child(testbase.KcovTestCase): @@ -196,8 +194,8 @@ def runTest(self): 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(testbase.outbase + "/kcov/test_daemon/cobertura.xml") + assert cobertura.hitsPerLine(dom, "test-daemon.cc", 31) == 1 class SignalsBase(testbase.KcovTestCase): @@ -220,26 +218,26 @@ def cmpOne(self, sig): ) assert rv == noKcovRv - return parse_cobertura.parseFile(testbase.outbase + "/kcov/signals/cobertura.xml") + return cobertura.parseFile(testbase.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): @@ -299,7 +297,7 @@ def runTest(self): assert rv == noKcovRv try: - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/main-tests/cobertura.xml") + dom = cobertura.parseFile(testbase.outbase + "/kcov/main-tests/cobertura.xml") self.fail("File unexpectedly found") except: # Exception is expected here @@ -314,8 +312,8 @@ def runTest(self): + "/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(testbase.outbase + "/kcov/main-tests/cobertura.xml") + assert cobertura.hitsPerLine(dom, "main.cc", 9) == 1 class setpgid_kill(testbase.KcovTestCase): @@ -356,11 +354,11 @@ def runTest(self): + "/issue31", False, ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/issue31/cobertura.xml") + dom = cobertura.parseFile(testbase.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): @@ -377,10 +375,10 @@ def runTest(self): + "/thread-test", False, ) - dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/thread-test/cobertura.xml") + dom = cobertura.parseFile(testbase.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): @@ -389,26 +387,26 @@ def runTest(self): testbase.kcov + " " + testbase.outbase + "/kcov " + testbase.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(testbase.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", 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(testbase.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", 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(testbase.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): @@ -466,10 +464,8 @@ def runTest(self): ) 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(testbase.outbase + "/kcov/main-tests-debug-file/cobertura.xml") + assert cobertura.hitsPerLine(dom, "main.cc", 9) == 1 # Check alignment rv, o = self.do( @@ -481,10 +477,8 @@ def runTest(self): + "/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(testbase.outbase + "/kcov/main-tests-debug-file1/cobertura.xml") + assert cobertura.hitsPerLine(dom, "main.cc", 9) == 1 rv, o = self.do( testbase.kcov @@ -495,10 +489,8 @@ def runTest(self): + "/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(testbase.outbase + "/kcov/main-tests-debug-file2/cobertura.xml") + assert cobertura.hitsPerLine(dom, "main.cc", 9) == 1 rv, o = self.do( testbase.kcov @@ -509,10 +501,8 @@ def runTest(self): + "/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(testbase.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") @@ -530,10 +520,8 @@ def runTest(self): + "/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(testbase.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") @@ -547,10 +535,8 @@ def runTest(self): + "/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(testbase.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 @@ -583,8 +569,8 @@ def runTest(self): + "/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(testbase.outbase + "/kcov/main-collect-only/cobertura.xml") + assert cobertura.hitsPerLine(dom, "main.cc", 1) == 1 class dlopen(testbase.KcovTestCase): @@ -597,11 +583,11 @@ def runTest(self): ) 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(testbase.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): @@ -616,10 +602,10 @@ def runTest(self): + "/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(testbase.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): @@ -639,12 +625,12 @@ def runTest(self): 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(testbase.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(testbase.outbase + "/kcov/test_daemon/cobertura.xml") + assert cobertura.hitsPerLine(dom, "test-daemon.cc", 31) == 1 class address_sanitizer_coverage(testbase.KcovTestCase): @@ -664,13 +650,13 @@ def runTest(self): 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(testbase.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..3e046b91 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 @@ -23,11 +23,9 @@ def runTest(self): ) 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(testbase.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): @@ -45,11 +43,9 @@ def runTest(self): 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(testbase.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): @@ -66,11 +62,9 @@ def runTest(self): ) 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(testbase.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): @@ -87,12 +81,10 @@ def runTest(self): ) 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(testbase.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): @@ -111,13 +103,13 @@ def doTest(self, verify): ) 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(testbase.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..35144941 100644 --- a/tests/tools/filter.py +++ b/tests/tools/filter.py @@ -1,4 +1,4 @@ -import parse_cobertura +import cobertura import testbase @@ -13,9 +13,9 @@ def runTest(self): + "/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(testbase.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 @@ -25,9 +25,9 @@ def runTest(self): + testbase.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(testbase.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 @@ -37,10 +37,10 @@ def runTest(self): + testbase.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(testbase.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): @@ -56,10 +56,10 @@ def runTest(self): + "/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(testbase.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): @@ -75,7 +75,7 @@ def runTest(self): + "/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(testbase.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..aafd84c8 100644 --- a/tests/tools/python.py +++ b/tests/tools/python.py @@ -1,6 +1,6 @@ import unittest -import parse_cobertura +import cobertura import testbase @@ -86,8 +86,8 @@ def runTest(self): + "/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(testbase.outbase + "/kcov/testdriver/cobertura.xml") + assert cobertura.hitsPerLine(dom, "testdriver", 14) == 1 class PythonBase(testbase.KcovTestCase): @@ -103,22 +103,22 @@ def doTest(self, extra): + "/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(testbase.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): @@ -137,9 +137,9 @@ def runTest(self): + "/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(testbase.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 + " " @@ -149,9 +149,9 @@ def runTest(self): + "/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(testbase.outbase + "/kcov/main/cobertura.xml") + assert cobertura.hitsPerLine(dom, "main", 16) == 1 + assert cobertura.hitsPerLine(dom, "main", 19) == 1 class python3_coverage(PythonBase): @@ -175,8 +175,8 @@ def runTest(self): + "/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(testbase.outbase + "/kcov/main/cobertura.xml") + assert cobertura.hitsPerLine(dom, "second.py", 34) == 2 class python_select_parser(testbase.KcovTestCase): @@ -207,6 +207,6 @@ def runTest(self): + "/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(testbase.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 63212d78..511498a9 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 @@ -81,7 +81,7 @@ def runTest(self): ) 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(testbase.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 From ad6df5b0d96cd8ae4a4bf965645fec75e84a3446 Mon Sep 17 00:00:00 2001 From: Manlio Perillo Date: Sun, 31 Mar 2024 19:29:42 +0200 Subject: [PATCH 5/9] tests: remove unnecessary creation of outdir The system_mode_can_record_and_report_binary test tries to create the outdir directory, but it is already created by TestCase.setUp. --- tests/tools/system_mode.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/tools/system_mode.py b/tests/tools/system_mode.py index 511498a9..dd838ec0 100644 --- a/tests/tools/system_mode.py +++ b/tests/tools/system_mode.py @@ -53,10 +53,7 @@ class system_mode_can_record_and_report_binary(SystemModeBase): @unittest.skipIf(platform.machine() == "i686", "x86_64-only") def runTest(self): self.write_message(platform.machine()) - try: - os.makedirs(testbase.outbase + "/kcov") - except: - pass + rv, o = self.do( testbase.kcov + " --system-record " From d2403a7b921586a7c466784a571f89b1c1105ea3 Mon Sep 17 00:00:00 2001 From: Manlio Perillo Date: Mon, 1 Apr 2024 09:59:43 +0200 Subject: [PATCH 6/9] tests: use consistent naming convention in test cases All the test case names use the snake case convention, except the basic module that uses the camel case convention. Make naming convention consistent. --- tests/tools/basic.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/tools/basic.py b/tests/tools/basic.py index bffb747b..92cf70a4 100644 --- a/tests/tools/basic.py +++ b/tests/tools/basic.py @@ -5,7 +5,7 @@ import testbase -class TooFewArguments(testbase.KcovTestCase): +class too_few_arguments(testbase.KcovTestCase): def runTest(self): rv, output = self.do(testbase.kcov + " " + testbase.outbase + "/kcov") @@ -13,7 +13,7 @@ def runTest(self): assert rv == 1 -class WrongArguments(testbase.KcovTestCase): +class wrong_arguments(testbase.KcovTestCase): def runTest(self): rv, output = self.do( testbase.kcov @@ -28,7 +28,7 @@ def runTest(self): 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" @@ -41,7 +41,7 @@ def runTest(self): # 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. From ac9bc0cf9c03140331e89b4cb2d531d34fc5e943 Mon Sep 17 00:00:00 2001 From: Manlio Perillo Date: Mon, 1 Apr 2024 11:09:36 +0200 Subject: [PATCH 7/9] tests: make configuration values KcovTestCase members Update the testcase.KcovTestCase.setUp method to add the configuration values as class members instead of globals. These global variables are still needed, but are hidden from the test modules. Remove the global kcov_system_daemon variable, since it is no longer necessary. Update all the test cases and reformat the code with `ruff format`. --- tests/tools/accumulate.py | 127 +++++-------- tests/tools/bash.py | 251 +++++++++++--------------- tests/tools/bash_linux_only.py | 24 +-- tests/tools/basic.py | 21 +-- tests/tools/compiled.py | 318 +++++++++++++-------------------- tests/tools/compiled_basic.py | 46 ++--- tests/tools/filter.py | 44 ++--- tests/tools/python.py | 93 ++++------ tests/tools/system_mode.py | 30 ++-- tests/tools/testbase.py | 10 +- 10 files changed, 386 insertions(+), 578 deletions(-) diff --git a/tests/tools/accumulate.py b/tests/tools/accumulate.py index 3c2d8721..cec2681d 100644 --- a/tests/tools/accumulate.py +++ b/tests/tools/accumulate.py @@ -5,28 +5,18 @@ 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 = cobertura.parseFile(testbase.outbase + "/kcov/main/cobertura.xml") + 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 = cobertura.parseFile(testbase.outbase + "/kcov/main/cobertura.xml") + 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 @@ -35,28 +25,23 @@ def runTest(self): 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 = cobertura.parseFile(testbase.outbase + "/kcov/main/cobertura.xml") + 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 = cobertura.parseFile(testbase.outbase + "/kcov/main/cobertura.xml") + 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 @@ -65,23 +50,13 @@ def runTest(self): 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 = cobertura.parseFile(testbase.outbase + "/kcov/kcov-merged/cobertura.xml") + 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 @@ -89,32 +64,27 @@ def runTest(self): 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 = cobertura.parseFile(testbase.outbase + "/kcov/merged/kcov-merged/cobertura.xml") + 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 @@ -122,51 +92,46 @@ def runTest(self): 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 = cobertura.parseFile(testbase.outbase + "/kcov/merged2/kcov-merged/cobertura.xml") + 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 @@ -175,23 +140,23 @@ def runTest(self): 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 6cf8e88b..1af6b516 100644 --- a/tests/tools/bash.py +++ b/tests/tools/bash.py @@ -10,30 +10,25 @@ 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 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 = cobertura.parseFile(testbase.outbase + "/kcov/shell-main/cobertura.xml") + 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 @@ -56,15 +51,15 @@ 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 = cobertura.parseFile(testbase.outbase + "/kcov/shell-main/cobertura.xml") + 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 @@ -73,15 +68,10 @@ def runTest(self): 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 = cobertura.parseFile(testbase.outbase + "/kcov/short-test.sh/cobertura.xml") + dom = cobertura.parseFile(self.outbase + "/kcov/short-test.sh/cobertura.xml") assert cobertura.hitsPerLine(dom, "short-test.sh", 5) == 11 @@ -126,45 +116,45 @@ def runTest(self): 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 = cobertura.parseFile(testbase.outbase + "/kcov/trap.sh/cobertura.xml") + 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 = cobertura.parseFile(testbase.outbase + "/kcov/unitundertest.sh/cobertura.xml") + 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 = cobertura.parseFile(testbase.outbase + "/kcov/unitundertest.sh/cobertura.xml") + 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 @@ -174,22 +164,18 @@ 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" - ) + 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(testbase.outbase + "/kcov/shell-main/cobertura.xml") + 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 = cobertura.parseFile(testbase.outbase + "/kcov/shell-main/cobertura.xml") + 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 @@ -198,39 +184,39 @@ def runTest(self): 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 = cobertura.parseFile(testbase.outbase + "/kcov/unitundertest.sh/cobertura.xml") + 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 = cobertura.parseFile(testbase.outbase + "/kcov/unitundertest.sh/cobertura.xml") + 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 = cobertura.parseFile(testbase.outbase + "/kcov/unitundertest.sh/cobertura.xml") + 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 @@ -240,15 +226,10 @@ def runTest(self): 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 = cobertura.parseFile(testbase.outbase + "/kcov/shell-main/cobertura.xml") + 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 @@ -258,27 +239,27 @@ def runTest(self): 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 = cobertura.parseFile(testbase.outbase + "/kcov/multiline-alias.sh/cobertura.xml") + 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 = cobertura.parseFile( - testbase.outbase + "/kcov/no-executed-statements.sh/cobertura.xml" - ) + 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,17 +308,15 @@ 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 = cobertura.parseFile( - testbase.outbase + "/kcov/dollar-var-replacements.sh/cobertura.xml" - ) + 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 @@ -349,14 +326,9 @@ def runTest(self): 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 = cobertura.parseFile(testbase.outbase + "/kcov/shell-main/cobertura.xml") + 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 @@ -365,28 +337,18 @@ def runTest(self): 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 = cobertura.parseFile(testbase.outbase + "/kcov/shell-main/cobertura.xml") + 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 = cobertura.parseFile(testbase.outbase + "/kcov/subshell.sh/cobertura.xml") + 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)) @@ -396,31 +358,20 @@ 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 = cobertura.parseFile(testbase.outbase + "/kcov/" + script + "/cobertura.xml") + 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.do(self.sources + "/tests/bash/shell-main 5", False) 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,14 +381,14 @@ 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 = cobertura.parseFile(testbase.outbase + "/kcov/other.sh/cobertura.xml") + 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 @@ -470,15 +421,15 @@ def runTest(self): 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 = cobertura.parseFile(testbase.outbase + "/kcov/a.sh/cobertura.xml") + dom = cobertura.parseFile(self.outbase + "/kcov/a.sh/cobertura.xml") assert cobertura.hitsPerLine(dom, "a.sh", 5) == 1 # Not executed assert cobertura.hitsPerLine(dom, "c.sh", 3) == 0 @@ -487,17 +438,17 @@ def runTest(self): 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 = cobertura.parseFile(testbase.outbase + "/kcov/a.sh/cobertura.xml") + dom = cobertura.parseFile(self.outbase + "/kcov/a.sh/cobertura.xml") # Not executed assert cobertura.hitsPerLine(dom, "c.sh", 3) == 0 assert cobertura.hitsPerLine(dom, "other.sh", 3) == 0 @@ -506,15 +457,15 @@ def runTest(self): 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 = cobertura.parseFile(testbase.outbase + "/kcov/a.sh/cobertura.xml") + dom = cobertura.parseFile(self.outbase + "/kcov/a.sh/cobertura.xml") assert cobertura.hitsPerLine(dom, "a.sh", 5) == 1 # Not included in report assert cobertura.hitsPerLine(dom, "c.sh", 3) is None @@ -524,15 +475,15 @@ def runTest(self): 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 = cobertura.parseFile(testbase.outbase + "/kcov/function-with-spaces.sh/cobertura.xml") + 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 @@ -544,17 +495,17 @@ 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 = cobertura.parseFile( - testbase.outbase + "/kcov/long-output-without-return.sh/cobertura.xml" + 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 aeac1bbd..3fe9963f 100644 --- a/tests/tools/bash_linux_only.py +++ b/tests/tools/bash_linux_only.py @@ -5,15 +5,15 @@ 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 = cobertura.parseFile(testbase.outbase + "/kcov/shell-main/cobertura.xml") + dom = cobertura.parseFile(self.outbase + "/kcov/shell-main/cobertura.xml") assert cobertura.hitsPerLine(dom, "sh-shebang.sh", 4) == 1 @@ -21,17 +21,17 @@ 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, ) self.assertEqual(0, rv, "kcov exited unsuccessfully") - dom = cobertura.parseFile(testbase.outbase + "/kcov/background-child.sh/cobertura.xml") + 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)) @@ -40,14 +40,14 @@ def runTest(self): 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 = cobertura.parseFile(testbase.outbase + "/kcov/sh-shebang.sh/cobertura.xml") + 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 92cf70a4..9a2bbca7 100644 --- a/tests/tools/basic.py +++ b/tests/tools/basic.py @@ -7,7 +7,7 @@ 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 @@ -16,12 +16,7 @@ def runTest(self): 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 @@ -31,11 +26,11 @@ def runTest(self): 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 = cobertura.parseFile(testbase.outbase + "/kcov/main/cobertura.xml") + dom = cobertura.parseFile(self.outbase + "/kcov/main/cobertura.xml") assert cobertura.hitsPerLine(dom, "second.py", 34) == 2 assert noKcovRv, rv @@ -46,7 +41,7 @@ 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/compiled.py b/tests/tools/compiled.py index fbdf7072..ff0803c4 100644 --- a/tests/tools/compiled.py +++ b/tests/tools/compiled.py @@ -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,19 +22,14 @@ 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.do(self.testbuild + "/fork_no_wait", False) 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 = cobertura.parseFile(testbase.outbase + "/kcov/fork_no_wait/cobertura.xml") + 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 @@ -47,14 +37,14 @@ def runTest(self): class ForkBase(testbase.KcovTestCase): def doTest(self, binary): - noKcovRv, o = self.do(testbase.testbuild + "/" + binary, False) + noKcovRv, o = self.do(self.testbuild + "/" + binary, False) 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 = cobertura.parseFile(testbase.outbase + "/kcov/" + binary + "/cobertura.xml") + 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 @@ -83,11 +73,11 @@ 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 = cobertura.parseFile(testbase.outbase + "/kcov/vfork/cobertura.xml") + 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 @@ -95,9 +85,9 @@ def runTest(self): 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.do(self.testbuild + "/test_popen", False) 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,31 +98,29 @@ 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.do(self.testbuild + "/pie", False) + rv, o = self.do(self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/pie", False) assert rv == noKcovRv - dom = cobertura.parseFile(testbase.outbase + "/kcov/pie/cobertura.xml") + 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 = cobertura.parseFile(testbase.outbase + "/kcov/pie-test/cobertura.xml") + 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 @@ -144,41 +132,36 @@ 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 = cobertura.parseFile(testbase.outbase + "/kcov/pie-test/cobertura.xml") + 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 = cobertura.parseFile(testbase.outbase + "/kcov/pie-test/cobertura.xml") + 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.do(self.testbuild + "/global-constructors", False) 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 = cobertura.parseFile(testbase.outbase + "/kcov/global-constructors/cobertura.xml") + dom = cobertura.parseFile(self.outbase + "/kcov/global-constructors/cobertura.xml") assert cobertura.hitsPerLine(dom, "test-global-ctors.cc", 4) >= 1 @@ -186,15 +169,15 @@ 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.do(self.testbuild + "/test_daemon", False) 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 = cobertura.parseFile(testbase.outbase + "/kcov/test_daemon/cobertura.xml") + dom = cobertura.parseFile(self.outbase + "/kcov/test_daemon/cobertura.xml") assert cobertura.hitsPerLine(dom, "test-daemon.cc", 31) == 1 @@ -203,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.do(self.testbuild + "/signals " + sig + " " + self.m_self, False) rv, o = self.do( - testbase.kcov + self.kcov + " " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.testbuild + + self.testbuild + "/signals " + sig + " " @@ -218,7 +201,7 @@ def cmpOne(self, sig): ) assert rv == noKcovRv - return cobertura.parseFile(testbase.outbase + "/kcov/signals/cobertura.xml") + return cobertura.parseFile(self.outbase + "/kcov/signals/cobertura.xml") def doTest(self): dom = self.cmpOne("hup") @@ -257,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 @@ -283,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.do(self.testbuild + "/main-tests ", False) rv, o = self.do( - testbase.kcov + self.kcov + " --collect-only " - + testbase.outbase + + self.outbase + "/kcov " - + testbase.testbuild + + self.testbuild + "/main-tests", False, ) @@ -297,43 +270,40 @@ def runTest(self): assert rv == noKcovRv try: - dom = 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 = cobertura.parseFile(testbase.outbase + "/kcov/main-tests/cobertura.xml") + 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", + self.sources + "/tests/setpgid-kill/test-script.sh " + self.testbuild + "/setpgid-kill", False, ) 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, ) @@ -344,17 +314,17 @@ 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 = cobertura.parseFile(testbase.outbase + "/kcov/issue31/cobertura.xml") + dom = cobertura.parseFile(self.outbase + "/kcov/issue31/cobertura.xml") self.skipTest("Fickle test, ignoring") assert cobertura.hitsPerLine(dom, "test-issue31.cc", 28) >= 1 assert cobertura.hitsPerLine(dom, "test-issue31.cc", 11) >= 1 @@ -365,17 +335,17 @@ 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 = 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 cobertura.hitsPerLine(dom, "thread-main.c", 21) >= 1 assert cobertura.hitsPerLine(dom, "thread-main.c", 9) >= 1 @@ -384,27 +354,27 @@ def runTest(self): 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 = cobertura.parseFile(testbase.outbase + "/kcov/multi_1/cobertura.xml") + 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 = cobertura.parseFile(testbase.outbase + "/kcov/kcov-merged/cobertura.xml") + 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 = cobertura.parseFile(testbase.outbase + "/kcov/kcov-merged/cobertura.xml") + 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 @@ -412,130 +382,98 @@ def runTest(self): 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.do(self.testbuild + "/main-tests-debug-file", False) 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 = cobertura.parseFile(testbase.outbase + "/kcov/main-tests-debug-file/cobertura.xml") + 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 = cobertura.parseFile(testbase.outbase + "/kcov/main-tests-debug-file1/cobertura.xml") + 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 = cobertura.parseFile(testbase.outbase + "/kcov/main-tests-debug-file2/cobertura.xml") + 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 = cobertura.parseFile(testbase.outbase + "/kcov/main-tests-debug-file3/cobertura.xml") + 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 = cobertura.parseFile(testbase.outbase + "/kcov/main-tests-debug-file/cobertura.xml") + 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 = cobertura.parseFile(testbase.outbase + "/kcov/main-tests-debug-file/cobertura.xml") + dom = cobertura.parseFile(self.outbase + "/kcov/main-tests-debug-file/cobertura.xml") assert cobertura.hitsPerLine(dom, "main.cc", 9) is None @@ -545,45 +483,45 @@ 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 = cobertura.parseFile(testbase.outbase + "/kcov/main-collect-only/cobertura.xml") + 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.do(self.testbuild + "/dlopen", False) 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 = cobertura.parseFile(testbase.outbase + "/kcov/dlopen/cobertura.xml") + 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 @@ -594,15 +532,15 @@ 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 = cobertura.parseFile(testbase.outbase + "/kcov/dlopen/cobertura.xml") + 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 @@ -612,24 +550,24 @@ 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.do(self.testbuild + "/test_daemon", False) 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 = cobertura.parseFile(testbase.outbase + "/kcov/test_daemon/cobertura.xml") + dom = cobertura.parseFile(self.outbase + "/kcov/test_daemon/cobertura.xml") assert cobertura.hitsPerLine(dom, "test-daemon.cc", 31) == 0 time.sleep(5) - dom = cobertura.parseFile(testbase.outbase + "/kcov/test_daemon/cobertura.xml") + dom = cobertura.parseFile(self.outbase + "/kcov/test_daemon/cobertura.xml") assert cobertura.hitsPerLine(dom, "test-daemon.cc", 31) == 1 @@ -637,20 +575,20 @@ 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"): + 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 = cobertura.parseFile(testbase.outbase + "/kcov/sanitizer-coverage/cobertura.xml") + 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 diff --git a/tests/tools/compiled_basic.py b/tests/tools/compiled_basic.py index 3e046b91..081bd735 100644 --- a/tests/tools/compiled_basic.py +++ b/tests/tools/compiled_basic.py @@ -11,19 +11,14 @@ 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.do(self.testbuild + "/shared_library_test", False) 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 = cobertura.parseFile(testbase.outbase + "/kcov/shared_library_test/cobertura.xml") + 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 @@ -32,18 +27,18 @@ 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 = cobertura.parseFile(testbase.outbase + "/kcov/shared_library_test/cobertura.xml") + 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 @@ -52,17 +47,17 @@ 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 = cobertura.parseFile(testbase.outbase + "/kcov/shared_library_test/cobertura.xml") + 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 @@ -71,17 +66,12 @@ 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 = cobertura.parseFile(testbase.outbase + "/kcov/shared_library_test/cobertura.xml") + 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 @@ -89,21 +79,21 @@ def runTest(self): class MainTestBase(testbase.KcovTestCase): def doTest(self, verify): - noKcovRv, o = self.do(testbase.testbuild + "/main-tests", False) + noKcovRv, o = self.do(self.testbuild + "/main-tests", False) 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 = cobertura.parseFile(testbase.outbase + "/kcov/main-tests/cobertura.xml") + 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 diff --git a/tests/tools/filter.py b/tests/tools/filter.py index 35144941..1ceed3fa 100644 --- a/tests/tools/filter.py +++ b/tests/tools/filter.py @@ -5,39 +5,39 @@ 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 = cobertura.parseFile(testbase.outbase + "/kcov/shell-main/cobertura.xml") + 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 = cobertura.parseFile(testbase.outbase + "/kcov/shell-main/cobertura.xml") + 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 = cobertura.parseFile(testbase.outbase + "/kcov/shell-main/cobertura.xml") + 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 @@ -46,17 +46,17 @@ def runTest(self): 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 = cobertura.parseFile(testbase.outbase + "/kcov/shell-main/cobertura.xml") + 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 @@ -65,17 +65,17 @@ def runTest(self): 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 = cobertura.parseFile(testbase.outbase + "/kcov/shell-main/cobertura.xml") + 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 aafd84c8..c08caad9 100644 --- a/tests/tools/python.py +++ b/tests/tools/python.py @@ -6,14 +6,9 @@ class python_exit_status(testbase.KcovTestCase): def runTest(self): - noKcovRv, o = self.do(testbase.sources + "/tests/python/main 5") + noKcovRv, o = self.do(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,32 +73,32 @@ 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 = cobertura.parseFile(testbase.outbase + "/kcov/testdriver/cobertura.xml") + 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 = cobertura.parseFile(testbase.outbase + "/kcov/main/cobertura.xml") + 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 @@ -129,27 +124,17 @@ 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 = cobertura.parseFile(testbase.outbase + "/kcov/main/cobertura.xml") + 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 = cobertura.parseFile(testbase.outbase + "/kcov/main/cobertura.xml") + dom = cobertura.parseFile(self.outbase + "/kcov/main/cobertura.xml") assert cobertura.hitsPerLine(dom, "main", 16) == 1 assert cobertura.hitsPerLine(dom, "main", 19) == 1 @@ -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 = cobertura.parseFile(testbase.outbase + "/kcov/main/cobertura.xml") + 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 = cobertura.parseFile(testbase.outbase + "/kcov/main/cobertura.xml") + 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 dd838ec0..70629919 100644 --- a/tests/tools/system_mode.py +++ b/tests/tools/system_mode.py @@ -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) @@ -55,18 +50,13 @@ def runTest(self): 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 @@ -74,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 = cobertura.parseFile(testbase.outbase + "/kcov-report/main-tests/cobertura.xml") + 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 342cc1ef..7e31fba4 100644 --- a/tests/tools/testbase.py +++ b/tests/tools/testbase.py @@ -13,7 +13,6 @@ PIPE = subprocess.PIPE kcov = "" -kcov_system_daemon = "" outbase = "" testbuild = "" sources = "" @@ -33,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) @@ -43,7 +41,13 @@ def configure(k, o, t, s): class KcovTestCase(unittest.TestCase): def setUp(self): - self.outdir = 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) From 846292594e977b599ad5037d35861ea5b47aa8a1 Mon Sep 17 00:00:00 2001 From: Manlio Perillo Date: Mon, 1 Apr 2024 12:37:22 +0200 Subject: [PATCH 8/9] tests: add testbase.KcovTestCase.doCmd method The new function is meant to be used when running a child process that does not run kcov, both directly or indirectly. The method call usually returns noKcovRv, instead of rv. The reason for this change is to make these calls easier to detect, also avoiding having to set the kcovKcov parameter to False. --- tests/tools/bash.py | 2 +- tests/tools/compiled.py | 29 +++++++++++++++-------------- tests/tools/compiled_basic.py | 4 ++-- tests/tools/python.py | 2 +- tests/tools/testbase.py | 8 ++++++++ 5 files changed, 27 insertions(+), 18 deletions(-) diff --git a/tests/tools/bash.py b/tests/tools/bash.py index 1af6b516..9cd44024 100644 --- a/tests/tools/bash.py +++ b/tests/tools/bash.py @@ -369,7 +369,7 @@ def runTest(self): class bash_exit_status(testbase.KcovTestCase): def runTest(self): - noKcovRv, o = self.do(self.sources + "/tests/bash/shell-main 5", False) + noKcovRv, o = self.doCmd(self.sources + "/tests/bash/shell-main 5") rv, o = self.do( self.kcov + " " + self.outbase + "/kcov " + self.sources + "/tests/bash/shell-main 5" ) diff --git a/tests/tools/compiled.py b/tests/tools/compiled.py index ff0803c4..ca52d098 100644 --- a/tests/tools/compiled.py +++ b/tests/tools/compiled.py @@ -22,7 +22,7 @@ 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(self.testbuild + "/fork_no_wait", False) + noKcovRv, o = self.doCmd(self.testbuild + "/fork_no_wait") rv, o = self.do( self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/fork_no_wait", False, @@ -37,7 +37,7 @@ def runTest(self): class ForkBase(testbase.KcovTestCase): def doTest(self, binary): - noKcovRv, o = self.do(self.testbuild + "/" + binary, False) + noKcovRv, o = self.doCmd(self.testbuild + "/" + binary) rv, o = self.do( self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/" + binary, False, @@ -85,7 +85,7 @@ def runTest(self): class popen_test(testbase.KcovTestCase): @unittest.skipUnless(platform.machine() in ["x86_64", "i686", "i386"], "Only for x86") def runTest(self): - noKcovRv, o = self.do(self.testbuild + "/test_popen", False) + noKcovRv, o = self.doCmd(self.testbuild + "/test_popen") rv, o = self.do( self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/test_popen", False, @@ -104,7 +104,7 @@ def runTest(self): class Pie(testbase.KcovTestCase): def runTest(self): - noKcovRv, o = self.do(self.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 @@ -154,7 +154,7 @@ def runTest(self): class global_ctors(testbase.KcovTestCase): def runTest(self): - noKcovRv, o = self.do(self.testbuild + "/global-constructors", False) + noKcovRv, o = self.doCmd(self.testbuild + "/global-constructors") rv, o = self.do( self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/global-constructors", False, @@ -169,7 +169,7 @@ 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(self.testbuild + "/test_daemon", False) + noKcovRv, o = self.doCmd(self.testbuild + "/test_daemon") rv, o = self.do( self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/test_daemon", False, @@ -186,7 +186,7 @@ def SignalsBase(): self.m_self = "" def cmpOne(self, sig): - noKcovRv, o = self.do(self.testbuild + "/signals " + sig + " " + self.m_self, False) + noKcovRv, o = self.doCmd(self.testbuild + "/signals " + sig + " " + self.m_self) rv, o = self.do( self.kcov + " " @@ -256,7 +256,7 @@ 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(self.testbuild + "/main-tests ", False) + noKcovRv, o = self.doCmd(self.testbuild + "/main-tests ") rv, o = self.do( self.kcov + " --collect-only " @@ -291,11 +291,11 @@ def runTest(self): class setpgid_kill(testbase.KcovTestCase): def runTest(self): - noKcovRv, o = self.do( - self.sources + "/tests/setpgid-kill/test-script.sh " + self.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( self.sources + "/tests/setpgid-kill/test-script.sh " @@ -422,7 +422,7 @@ def runTest(self): f"objcopy --add-gnu-debuglink={self.testbuild}/main-tests-debug-file123.debug {self.testbuild}/main-tests-debug-file3" ) - noKcovRv, o = self.do(self.testbuild + "/main-tests-debug-file", False) + noKcovRv, o = self.doCmd(self.testbuild + "/main-tests-debug-file") rv, o = self.do( self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/main-tests-debug-file", False, @@ -514,7 +514,7 @@ def runTest(self): class dlopen(testbase.KcovTestCase): @unittest.expectedFailure def runTest(self): - noKcovRv, o = self.do(self.testbuild + "/dlopen", False) + noKcovRv, o = self.doCmd(self.testbuild + "/dlopen") rv, o = self.do( self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/dlopen", False, @@ -550,7 +550,7 @@ 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(self.testbuild + "/test_daemon", False) + noKcovRv, o = self.doCmd(self.testbuild + "/test_daemon") rv, o = self.do( self.kcov + " --output-interval=1 --exit-first-process " @@ -562,6 +562,7 @@ def runTest(self): ) assert noKcovRv == rv + time.sleep(2) dom = cobertura.parseFile(self.outbase + "/kcov/test_daemon/cobertura.xml") assert cobertura.hitsPerLine(dom, "test-daemon.cc", 31) == 0 diff --git a/tests/tools/compiled_basic.py b/tests/tools/compiled_basic.py index 081bd735..849129a1 100644 --- a/tests/tools/compiled_basic.py +++ b/tests/tools/compiled_basic.py @@ -11,7 +11,7 @@ class shared_library(testbase.KcovTestCase): "Not for OSX (does not work with the mach-engine for now)", ) def runTest(self): - noKcovRv, o = self.do(self.testbuild + "/shared_library_test", False) + noKcovRv, o = self.doCmd(self.testbuild + "/shared_library_test") rv, o = self.do( self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/shared_library_test", False, @@ -79,7 +79,7 @@ def runTest(self): class MainTestBase(testbase.KcovTestCase): def doTest(self, verify): - noKcovRv, o = self.do(self.testbuild + "/main-tests", False) + noKcovRv, o = self.doCmd(self.testbuild + "/main-tests") rv, o = self.do( self.kcov + " " diff --git a/tests/tools/python.py b/tests/tools/python.py index c08caad9..969e584c 100644 --- a/tests/tools/python.py +++ b/tests/tools/python.py @@ -6,7 +6,7 @@ class python_exit_status(testbase.KcovTestCase): def runTest(self): - noKcovRv, o = self.do(self.sources + "/tests/python/main 5") + noKcovRv, o = self.doCmd(self.sources + "/tests/python/main 5") rv, o = self.do( self.kcov + " " + self.outbase + "/kcov " + self.sources + "/tests/python/main 5" ) diff --git a/tests/tools/testbase.py b/tests/tools/testbase.py index 7e31fba4..6c48eb74 100644 --- a/tests/tools/testbase.py +++ b/tests/tools/testbase.py @@ -96,6 +96,14 @@ def do(self, cmdline, kcovKcov=True, timeout=default_timeout): return rv, output + 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 + + return rv, output + def write_message(self, msg): """Add a custom message to the current test status line.""" From 9794dd09aedac5f3212ec06e7a341a737932b3c5 Mon Sep 17 00:00:00 2001 From: Manlio Perillo Date: Mon, 1 Apr 2024 16:10:24 +0200 Subject: [PATCH 9/9] tests: make calls to KcovTestCase.do more strict Update the KcovTestCase.do method signature, so that kcovKcov is both a positional or keyword parameter, and the timeout is a keyword only parameter. I was planning to make kcovKcov a positional only parameter, but the `bash_linux_only.bash_exit_before_child` test used it as a keyword parameter. This change codifies the current usage. --- tests/tools/testbase.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tools/testbase.py b/tests/tools/testbase.py index 6c48eb74..922612e2 100644 --- a/tests/tools/testbase.py +++ b/tests/tools/testbase.py @@ -75,7 +75,7 @@ def doShell(self, cmdline): return rv, output - def do(self, cmdline, kcovKcov=True, timeout=default_timeout): + def do(self, cmdline, /, kcovKcov=True, *, timeout=default_timeout): extra = "" if ( kcovKcov