diff --git a/.github/workflows/ci-run-tests.sh b/.github/workflows/ci-run-tests.sh index df9b1a3d..776fc62d 100755 --- a/.github/workflows/ci-run-tests.sh +++ b/.github/workflows/ci-run-tests.sh @@ -3,7 +3,8 @@ set -euo pipefail run () { - tests/tools/run-tests build/src/kcov /tmp/ build-tests/ "." -v "$@" || exit 64 + export PYTHONPATH=tests/tools + python -m libkcov build/src/kcov /tmp/ build-tests/ "." -v "$@" || exit 64 } run "$@" diff --git a/tests/tools/testbase.py b/tests/tools/libkcov/__init__.py similarity index 76% rename from tests/tools/testbase.py rename to tests/tools/libkcov/__init__.py index 922612e2..fb5b8753 100644 --- a/tests/tools/testbase.py +++ b/tests/tools/libkcov/__init__.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python3 - import errno import os import os.path @@ -12,43 +10,21 @@ PIPE = subprocess.PIPE -kcov = "" -outbase = "" -testbuild = "" -sources = "" - default_timeout = 10 * 60 -# Normalize path, also ensuring that it is not empty. -def normalize(path): - assert len(path) != 0, "path must be not empty" - - path = os.path.normpath(path) - return path - - -def configure(k, o, t, s): - global kcov, outbase, testbuild, sources, kcov_system_daemon +class TestCase(unittest.TestCase): + def __init__(self, kcov, outbase, binaries, sources): + super().__init__() - kcov = normalize(k) - outbase = normalize(o) - testbuild = normalize(t) - sources = normalize(s) - - assert os.path.abspath(outbase) != os.getcwd(), "'outbase' cannot be the current directory" - - -class KcovTestCase(unittest.TestCase): - def setUp(self): - # 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.binaries = binaries self.sources = sources + def setUp(self): # Intentionally fails if target directory exists. os.makedirs(self.outdir) @@ -83,7 +59,7 @@ def do(self, cmdline, /, kcovKcov=True, *, timeout=default_timeout): and platform.machine() in ["x86_64", "i386", "i686"] ): extra = ( - kcov + self.kcov + " --include-pattern=kcov --exclude-pattern=helper.cc,library.cc,html-data-files.cc " + "/tmp/kcov-kcov " ) diff --git a/tests/tools/libkcov/__main__.py b/tests/tools/libkcov/__main__.py new file mode 100644 index 00000000..c510f37e --- /dev/null +++ b/tests/tools/libkcov/__main__.py @@ -0,0 +1,5 @@ +"""Main entry point.""" + +from .main import main + +main() diff --git a/tests/tools/cobertura.py b/tests/tools/libkcov/cobertura.py old mode 100755 new mode 100644 similarity index 67% rename from tests/tools/cobertura.py rename to tests/tools/libkcov/cobertura.py index 7ac97700..3046783e --- a/tests/tools/cobertura.py +++ b/tests/tools/libkcov/cobertura.py @@ -1,10 +1,5 @@ -#!/usr/bin/env python3 - -import sys import xml.dom.minidom -# all these imports are standard on most modern python implementations - def readFile(name): f = open(name, "r") @@ -61,25 +56,3 @@ def hitsPerLine(dom, fileName, lineNr): return hits return None - - -if __name__ == "__main__": - if len(sys.argv) < 4: - print("Usage: lookup-class-line ") - sys.exit(1) - - fileName = sys.argv[2] - line = int(sys.argv[3]) - - data = readFile(sys.argv[1]) - - dom = parse(data) - fileTag = lookupClassName(dom, fileName) - - if fileTag is not None: - hits = lookupHitsByLine(fileTag, line) - if hits is not None: - print(hits) - sys.exit(0) - - print("nocode") diff --git a/tests/tools/libkcov/main.py b/tests/tools/libkcov/main.py new file mode 100644 index 00000000..39408fd5 --- /dev/null +++ b/tests/tools/libkcov/main.py @@ -0,0 +1,234 @@ +"""A custom simplified implementation of the test runner. + +This is necessary, since `unittest.main` does not support correctly how kcov +tests are imported. It will also make it easy to add additional features. + +Most of the test runner code has been copied from the `unittest.main` module. +""" + +import argparse +import importlib +import os +import os.path +import platform +import random +import sys +import unittest +from collections import namedtuple +from fnmatch import fnmatchcase + +# Copied from unittest.main. +_NO_TESTS_EXITCODE = 5 + + +class TestLoader: + """A simplified test loader. + + The implementation assumes that each test case runs only one test method: + `runTest`. + """ + + def __init__(self, config, patterns): + self.tests = [] + self.config = config + self.patterns = patterns + + def add_test_case(self, test_case_class): + if not self.match_test(test_case_class): + return + + cfg = self.config + test = test_case_class(cfg.kcov, cfg.outbase, cfg.binaries, cfg.sources) + self.tests.append(test) + + def add_tests_from_module(self, name): + """Add all test cases from the named module.""" + + module = importlib.import_module(name) + for name in dir(module): + obj = getattr(module, name) + if ( + isinstance(obj, type) + and issubclass(obj, unittest.TestCase) + and obj not in (unittest.TestCase, unittest.FunctionTestCase) + and hasattr(obj, "runTest") + ): + self.add_test_case(obj) + + def match_test(self, test_case_class): + if not self.patterns: + return True + + full_name = f"{test_case_class.__module__}.{test_case_class.__qualname__}" + return any(fnmatchcase(full_name, pattern) for pattern in self.patterns) + + +Config = namedtuple("Config", ["kcov", "outbase", "binaries", "sources"]) + + +def fatal(msg): + sys.stderr.write(f"error: {msg}\n") + sys.stderr.flush() + os._exit(1) + + +def normalized_not_empty(path): + """Normalize path, also ensuring that it is not empty.""" + + if len(path) == 0: + raise ValueError("path must be not empty") + + path = os.path.normpath(path) + return path + + +# Implementation copied from unittest.main. +def to_fnmatch(pattern): + if "*" not in pattern: + pattern = "*%s*" % pattern + + return pattern + + +def addTests(config, patterns): + """Add all the kcov test modules. + + Discovery is not possible, since some modules need to be excluded, + depending on the os and arch. + """ + + test_loader = TestLoader(config, patterns) + + test_loader.add_tests_from_module("test_basic") + test_loader.add_tests_from_module("test_compiled_basic") + + if platform.machine() in ["x86_64", "i386", "i686"]: + test_loader.add_tests_from_module("test_compiled") + if sys.platform.startswith("linux"): + test_loader.add_tests_from_module("test_bash_linux_only") + + if platform.machine() in ["x86_64", "i386", "i686"]: + test_loader.add_tests_from_module("test_system_mode") + + test_loader.add_tests_from_module("test_accumulate") + test_loader.add_tests_from_module("test_bash") + test_loader.add_tests_from_module("test_filter") + test_loader.add_tests_from_module("test_python") + + return test_loader.tests + + +def parse_args(): + parser = argparse.ArgumentParser() + + parser.add_argument("kcov", type=normalized_not_empty) + parser.add_argument("outbase", type=normalized_not_empty) + parser.add_argument("binaries", type=normalized_not_empty) + parser.add_argument("sources", type=normalized_not_empty) + + # Code copied from unittest.main. + parser.add_argument( + "-v", + "--verbose", + dest="verbosity", + action="store_const", + const=2, + help="Verbose output", + ) + parser.add_argument( + "-q", + "--quiet", + dest="verbosity", + action="store_const", + const=0, + help="Quiet output", + ) + parser.add_argument( + "-f", + "--failfast", + dest="failfast", + action="store_true", + help="Stop on first fail or error", + ) + parser.add_argument( + "-b", + "--buffer", + dest="buffer", + action="store_true", + help="Buffer stdout and stderr during tests", + ) + parser.add_argument( + "-c", + "--catch", + dest="catchbreak", + action="store_true", + help="Catch Ctrl-C and display results so far", + ) + parser.add_argument( + "-k", + dest="patterns", + action="append", + type=to_fnmatch, + help="Only run tests which match the given substring", + ) + parser.add_argument( + "--locals", + dest="tb_locals", + action="store_true", + help="Show local variables in tracebacks", + ) + + # TODO: The --duration argument was added in 3.12. + + # kcov test runner options + + parser.add_argument( + "--shuffle", + dest="shuffle", + action="store_true", + help="Randomize the execution order of tests", + ) + + # TODO: The --duration argument was added in 3.12. + + # kcov test runner custom options + + return parser.parse_args() + + +def main(): + # Parse the command line and validate the configuration paths + args = parse_args() + + if os.path.abspath(args.outbase) == os.getcwd(): + fatal("'outbase' cannot be the current directory") + + # Loads and configure tests + config = Config(args.kcov, args.outbase, args.binaries, args.sources) + tests = addTests(config, args.patterns) + + if args.shuffle: + random.shuffle(tests) + + # Run the tests + test_suite = unittest.TestSuite(tests) + + # Code copied from unittest.main. + if args.catchbreak: + unittest.installHandler() + + test_runner = unittest.TextTestRunner( + verbosity=args.verbosity, + failfast=args.failfast, + buffer=args.buffer, + tb_locals=args.tb_locals, + ) + + result = test_runner.run(test_suite) + if True: + if result.testsRun == 0 and len(result.skipped) == 0: + sys.exit(_NO_TESTS_EXITCODE) + elif result.wasSuccessful(): + sys.exit(0) + else: + sys.exit(1) diff --git a/tests/tools/parse_cobertura b/tests/tools/parse_cobertura new file mode 100755 index 00000000..3ff642f1 --- /dev/null +++ b/tests/tools/parse_cobertura @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 + +import sys + +from libkcov import cobertura + +if len(sys.argv) < 4: + print("Usage: lookup-class-line ") + sys.exit(1) + +fileName = sys.argv[2] +line = int(sys.argv[3]) + +data = cobertura.readFile(sys.argv[1]) + +dom = cobertura.parse(data) +fileTag = cobertura.lookupClassName(dom, fileName) + +if fileTag is not None: + hits = cobertura.lookupHitsByLine(fileTag, line) + if hits is not None: + print(hits) + sys.exit(0) + +print("nocode") diff --git a/tests/tools/run-tests b/tests/tools/run-tests deleted file mode 100755 index d8cbfd6a..00000000 --- a/tests/tools/run-tests +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env python3 - -import platform -import sys -import unittest - -import testbase - -# The actual tests -from basic import * -from compiled_basic import * - -if platform.machine() in ["x86_64", "i386", "i686"]: - from compiled import * -if sys.platform.startswith("linux"): - from bash_linux_only import * - - if platform.machine() in ["x86_64", "i386", "i686"]: - from system_mode import * -from accumulate import * -from bash import * -from filter import * -from python import * - -if __name__ == "__main__": - if len(sys.argv) < 5: - print( - "Usage: run-tests " - ) - sys.exit(1) - - testbase.configure(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4]) - - sys.argv = sys.argv[4:] - - unittest.main() diff --git a/tests/tools/accumulate.py b/tests/tools/test_accumulate.py similarity index 93% rename from tests/tools/accumulate.py rename to tests/tools/test_accumulate.py index cec2681d..49305d18 100644 --- a/tests/tools/accumulate.py +++ b/tests/tools/test_accumulate.py @@ -1,8 +1,8 @@ -import cobertura -import testbase +import libkcov +from libkcov import cobertura -class accumulate_data(testbase.KcovTestCase): +class accumulate_data(libkcov.TestCase): def runTest(self): rv, o = self.do( self.kcov + " " + self.outbase + "/kcov " + self.sources + "/tests/python/main" @@ -22,7 +22,7 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "main", 14) == 2 -class dont_accumulate_data_with_clean(testbase.KcovTestCase): +class dont_accumulate_data_with_clean(libkcov.TestCase): def runTest(self): rv, o = self.do( self.kcov + " " + self.outbase + "/kcov " + self.sources + "/tests/python/main" @@ -47,7 +47,7 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "main", 14) == 1 -class merge_basic(testbase.KcovTestCase): +class merge_basic(libkcov.TestCase): def runTest(self): rv, o = self.do( self.kcov + " " + self.outbase + "/kcov " + self.sources + "/tests/python/main 5" @@ -61,7 +61,7 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "shell-main", 4) == 1 -class merge_multiple_output_directories(testbase.KcovTestCase): +class merge_multiple_output_directories(libkcov.TestCase): def runTest(self): rv, o = self.do( self.kcov + " " + self.outbase + "/kcov/first " + self.sources + "/tests/python/main 5" @@ -89,7 +89,7 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "shell-main", 4) == 1 -class merge_merged_output(testbase.KcovTestCase): +class merge_merged_output(libkcov.TestCase): def runTest(self): rv, o = self.do( self.kcov + " " + self.outbase + "/kcov/first " + self.sources + "/tests/python/main 5" @@ -137,7 +137,7 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "dollar-var-replacements.sh", 2) == 1 -class merge_coveralls(testbase.KcovTestCase): +class merge_coveralls(libkcov.TestCase): def runTest(self): rv, o = self.do( self.kcov diff --git a/tests/tools/bash.py b/tests/tools/test_bash.py similarity index 92% rename from tests/tools/bash.py rename to tests/tools/test_bash.py index 9cd44024..394f3fda 100644 --- a/tests/tools/bash.py +++ b/tests/tools/test_bash.py @@ -3,11 +3,11 @@ import sys import unittest -import cobertura -import testbase +import libkcov +from libkcov import cobertura -class BashBase(testbase.KcovTestCase): +class BashBase(libkcov.TestCase): def doTest(self, args): rv, o = self.do( self.kcov @@ -22,7 +22,7 @@ def doTest(self, args): return cobertura.parseFile(self.outbase + "/kcov/shell-main/cobertura.xml") -class bash_coverage(testbase.KcovTestCase): +class bash_coverage(libkcov.TestCase): def runTest(self): rv, o = self.do( self.kcov + " " + self.outbase + "/kcov " + self.sources + "/tests/bash/shell-main" @@ -48,7 +48,7 @@ def runTest(self): # Very limited, will expand once it's working better -class bash_coverage_debug_trap(testbase.KcovTestCase): +class bash_coverage_debug_trap(libkcov.TestCase): def runTest(self): rv, o = self.do( self.kcov @@ -65,7 +65,7 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "shell-main", 22) == 1 -class bash_short_file(testbase.KcovTestCase): +class bash_short_file(libkcov.TestCase): def runTest(self): rv, o = self.do( self.kcov + " " + self.outbase + "/kcov " + self.sources + "/tests/bash/short-test.sh" @@ -113,7 +113,7 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "shell-main", 7) is None -class bash_honor_signal(testbase.KcovTestCase): +class bash_honor_signal(libkcov.TestCase): def runTest(self): rv, o = self.do( self.sources @@ -131,7 +131,7 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "trap.sh", 5) == 1 -class bash_accumulate_data(testbase.KcovTestCase): +class bash_accumulate_data(libkcov.TestCase): def runTest(self): rv, o = self.do( self.kcov @@ -159,7 +159,7 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "unitundertest.sh", 16) == 1 -class bash_accumulate_changed_data(testbase.KcovTestCase): +class bash_accumulate_changed_data(libkcov.TestCase): # Not sure why, but for now... @unittest.skipUnless(platform.machine() in ["x86_64", "i686", "i386"], "Only for x86") def runTest(self): @@ -181,7 +181,7 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "other.sh", 6) == 3 -class bash_merge_data_issue_38(testbase.KcovTestCase): +class bash_merge_data_issue_38(libkcov.TestCase): def runTest(self): rv, o = self.do( self.kcov @@ -223,7 +223,7 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "unitundertest.sh", 36) == 1 -class bash_issue_116_arithmetic_and_heredoc_issue_117_comment_within_string(testbase.KcovTestCase): +class bash_issue_116_arithmetic_and_heredoc_issue_117_comment_within_string(libkcov.TestCase): def runTest(self): rv, o = self.do( self.kcov + " " + self.outbase + "/kcov " + self.sources + "/tests/bash/shell-main" @@ -236,7 +236,7 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "shell-main", 152) == 1 -class bash_multiline_quotes(testbase.KcovTestCase): +class bash_multiline_quotes(libkcov.TestCase): def runTest(self): rv, o = self.do( self.kcov @@ -252,7 +252,7 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "multiline-alias.sh", 6) == 1 -class bash_multiline_backslashes(testbase.KcovTestCase): +class bash_multiline_backslashes(libkcov.TestCase): def runTest(self): rv, o = self.do( self.kcov @@ -266,7 +266,7 @@ def runTest(self): assert b"function_name" not in o -class bash_no_executed_lines(testbase.KcovTestCase): +class bash_no_executed_lines(libkcov.TestCase): def runTest(self): rv, o = self.do( self.kcov @@ -282,7 +282,7 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "no-executed-statements.sh", 4) == 0 -class bash_stderr_redirection(testbase.KcovTestCase): +class bash_stderr_redirection(libkcov.TestCase): def runTest(self): rv, o = self.do( self.kcov @@ -305,7 +305,7 @@ def runTest(self): assert b"kcov" not in o -class bash_dollar_var_replacement(testbase.KcovTestCase): +class bash_dollar_var_replacement(libkcov.TestCase): def runTest(self): rv, o = self.do( self.kcov @@ -323,7 +323,7 @@ def runTest(self): # Issue #152 -class bash_done_eof(testbase.KcovTestCase): +class bash_done_eof(libkcov.TestCase): def runTest(self): rv, o = self.do( self.kcov + " " + self.outbase + "/kcov " + self.sources + "/tests/bash/shell-main 5" @@ -334,7 +334,7 @@ def runTest(self): # Issue #154 -class bash_eof_backtick(testbase.KcovTestCase): +class bash_eof_backtick(libkcov.TestCase): def runTest(self): rv, o = self.do( self.kcov + " " + self.outbase + "/kcov " + self.sources + "/tests/bash/shell-main" @@ -343,7 +343,7 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "shell-main", 180) == 1 -class bash_subshell(testbase.KcovTestCase): +class bash_subshell(libkcov.TestCase): def runTest(self): rv, o = self.do( self.kcov + " " + self.outbase + "/kcov " + self.sources + "/tests/bash/subshell.sh" @@ -354,7 +354,7 @@ def runTest(self): self.assertEqual(0, cobertura.hitsPerLine(dom, "subshell.sh", 8)) -class bash_handle_all_output(testbase.KcovTestCase): +class bash_handle_all_output(libkcov.TestCase): def runTest(self): script = "handle-all-output.sh" rv, o = self.do( @@ -367,7 +367,7 @@ def runTest(self): self.assertEqual(1000, cobertura.hitsPerLine(dom, script, 4)) -class bash_exit_status(testbase.KcovTestCase): +class bash_exit_status(libkcov.TestCase): def runTest(self): noKcovRv, o = self.doCmd(self.sources + "/tests/bash/shell-main 5") rv, o = self.do( @@ -378,7 +378,7 @@ def runTest(self): # Issue 180 -class bash_ignore_uncovered(testbase.KcovTestCase): +class bash_ignore_uncovered(libkcov.TestCase): def runTest(self): rv, o = self.do( self.kcov @@ -418,7 +418,7 @@ def runTest(self): # Issue #224 -class bash_can_find_non_executed_scripts(testbase.KcovTestCase): +class bash_can_find_non_executed_scripts(libkcov.TestCase): def runTest(self): rv, o = self.do( self.kcov @@ -435,7 +435,7 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "c.sh", 3) == 0 -class bash_can_find_non_executed_scripts_manually(testbase.KcovTestCase): +class bash_can_find_non_executed_scripts_manually(libkcov.TestCase): def runTest(self): rv, o = self.do( self.kcov @@ -454,7 +454,7 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "other.sh", 3) == 0 -class bash_can_ignore_non_executed_scripts(testbase.KcovTestCase): +class bash_can_ignore_non_executed_scripts(libkcov.TestCase): def runTest(self): rv, o = self.do( self.kcov @@ -472,7 +472,7 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "other.sh", 3) is None -class bash_can_ignore_function_with_spaces(testbase.KcovTestCase): +class bash_can_ignore_function_with_spaces(libkcov.TestCase): def runTest(self): rv, o = self.do( self.kcov @@ -491,7 +491,7 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "function-with-spaces.sh", 11) == 1 -class bash_drain_stdout_without_return(testbase.KcovTestCase): +class bash_drain_stdout_without_return(libkcov.TestCase): @unittest.skipIf(sys.platform.startswith("darwin"), "Not for OSX") def runTest(self): rv, o = self.do( diff --git a/tests/tools/bash_linux_only.py b/tests/tools/test_bash_linux_only.py similarity index 90% rename from tests/tools/bash_linux_only.py rename to tests/tools/test_bash_linux_only.py index 3fe9963f..d0a46bb6 100644 --- a/tests/tools/bash_linux_only.py +++ b/tests/tools/test_bash_linux_only.py @@ -1,8 +1,8 @@ -import cobertura -import testbase +import libkcov +from libkcov import cobertura -class bash_sh_shebang(testbase.KcovTestCase): +class bash_sh_shebang(libkcov.TestCase): def runTest(self): rv, o = self.do( self.kcov @@ -17,7 +17,7 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "sh-shebang.sh", 4) == 1 -class bash_exit_before_child(testbase.KcovTestCase): +class bash_exit_before_child(libkcov.TestCase): def runTest(self): # kcovKcov shouldn't wait for the background process, so call it with kcovKcov = False rv, o = self.do( @@ -37,7 +37,7 @@ def runTest(self): self.assertEqual(1, cobertura.hitsPerLine(dom, "background-child.sh", 4)) -class bash_ldpreload_multilib(testbase.KcovTestCase): +class bash_ldpreload_multilib(libkcov.TestCase): def runTest(self): rv, o = self.do( self.kcov diff --git a/tests/tools/basic.py b/tests/tools/test_basic.py similarity index 82% rename from tests/tools/basic.py rename to tests/tools/test_basic.py index 9a2bbca7..b8f9d10e 100644 --- a/tests/tools/basic.py +++ b/tests/tools/test_basic.py @@ -1,11 +1,11 @@ import os import unittest -import cobertura -import testbase +import libkcov +from libkcov import cobertura -class too_few_arguments(testbase.KcovTestCase): +class too_few_arguments(libkcov.TestCase): def runTest(self): rv, output = self.do(self.kcov + " " + self.outbase + "/kcov") @@ -13,17 +13,17 @@ def runTest(self): assert rv == 1 -class wrong_arguments(testbase.KcovTestCase): +class wrong_arguments(libkcov.TestCase): def runTest(self): rv, output = self.do( - self.kcov + " --abc=efg " + self.outbase + "/kcov " + self.testbuild + "/tests-stripped" + self.kcov + " --abc=efg " + self.outbase + "/kcov " + self.binaries + "/tests-stripped" ) assert b"kcov: error: Unrecognized option: --abc=efg" in output assert rv == 1 -class lookup_binary_in_path(testbase.KcovTestCase): +class lookup_binary_in_path(libkcov.TestCase): @unittest.expectedFailure def runTest(self): os.environ["PATH"] += self.sources + "/tests/python" @@ -36,7 +36,7 @@ def runTest(self): # Issue #414 -class outdir_is_executable(testbase.KcovTestCase): +class outdir_is_executable(libkcov.TestCase): 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. diff --git a/tests/tools/compiled.py b/tests/tools/test_compiled.py similarity index 68% rename from tests/tools/compiled.py rename to tests/tools/test_compiled.py index ca52d098..5c0599eb 100644 --- a/tests/tools/compiled.py +++ b/tests/tools/test_compiled.py @@ -3,28 +3,28 @@ import sys import unittest -import cobertura -import testbase +import libkcov +from libkcov import cobertura -class illegal_insn(testbase.KcovTestCase): +class illegal_insn(libkcov.TestCase): @unittest.skipIf(sys.platform.startswith("darwin"), "Not for OSX") @unittest.skipUnless(platform.machine() in ["x86_64", "i686", "i386"], "Only for x86") def runTest(self): rv, output = self.do( - self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/illegal-insn", + self.kcov + " " + self.outbase + "/kcov " + self.binaries + "/illegal-insn", False, ) assert rv != 0 assert b"Illegal instructions are" in output -class fork_no_wait(testbase.KcovTestCase): +class fork_no_wait(libkcov.TestCase): @unittest.skipIf(sys.platform.startswith("darwin"), "Not for OSX") def runTest(self): - noKcovRv, o = self.doCmd(self.testbuild + "/fork_no_wait") + noKcovRv, o = self.doCmd(self.binaries + "/fork_no_wait") rv, o = self.do( - self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/fork_no_wait", + self.kcov + " " + self.outbase + "/kcov " + self.binaries + "/fork_no_wait", False, ) assert rv == noKcovRv @@ -35,11 +35,11 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "fork-no-wait.c", 24) >= 1 -class ForkBase(testbase.KcovTestCase): +class ForkBase(libkcov.TestCase): def doTest(self, binary): - noKcovRv, o = self.doCmd(self.testbuild + "/" + binary) + noKcovRv, o = self.doCmd(self.binaries + "/" + binary) rv, o = self.do( - self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/" + binary, + self.kcov + " " + self.outbase + "/kcov " + self.binaries + "/" + binary, False, ) assert rv == noKcovRv @@ -66,15 +66,13 @@ def runTest(self): self.doTest("fork-32") -class vfork(testbase.KcovTestCase): +class vfork(libkcov.TestCase): @unittest.skipIf( sys.platform.startswith("darwin"), "Not for OSX (does not work with the mach-engine for now)", ) def runTest(self): - rv, o = self.do( - self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/vfork", False - ) + rv, o = self.do(self.kcov + " " + self.outbase + "/kcov " + self.binaries + "/vfork", False) assert rv == 0 dom = cobertura.parseFile(self.outbase + "/kcov/vfork/cobertura.xml") @@ -82,12 +80,12 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "vfork.c", 18) >= 1 -class popen_test(testbase.KcovTestCase): +class popen_test(libkcov.TestCase): @unittest.skipUnless(platform.machine() in ["x86_64", "i686", "i386"], "Only for x86") def runTest(self): - noKcovRv, o = self.doCmd(self.testbuild + "/test_popen") + noKcovRv, o = self.doCmd(self.binaries + "/test_popen") rv, o = self.do( - self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/test_popen", + self.kcov + " " + self.outbase + "/kcov " + self.binaries + "/test_popen", False, ) assert rv == noKcovRv @@ -95,27 +93,27 @@ def runTest(self): assert b"popen OK" in o -class short_filename(testbase.KcovTestCase): +class short_filename(libkcov.TestCase): @unittest.expectedFailure def runTest(self): rv, o = self.do(self.kcov + " " + self.outbase + "/kcov ./s", False) assert rv == 99 -class Pie(testbase.KcovTestCase): +class Pie(libkcov.TestCase): def runTest(self): - noKcovRv, o = self.doCmd(self.testbuild + "/pie") - rv, o = self.do(self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/pie", False) + noKcovRv, o = self.doCmd(self.binaries + "/pie") + rv, o = self.do(self.kcov + " " + self.outbase + "/kcov " + self.binaries + "/pie", False) assert rv == noKcovRv dom = cobertura.parseFile(self.outbase + "/kcov/pie/cobertura.xml") assert cobertura.hitsPerLine(dom, "pie.c", 5) == 1 -class pie_argv_basic(testbase.KcovTestCase): +class pie_argv_basic(libkcov.TestCase): def runTest(self): rv, o = self.do( - self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/pie-test", + self.kcov + " " + self.outbase + "/kcov " + self.binaries + "/pie-test", False, ) assert rv == 0 @@ -125,14 +123,14 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "argv-dependent.c", 11) == 0 -class pie_accumulate(testbase.KcovTestCase): +class pie_accumulate(libkcov.TestCase): @unittest.skipIf( sys.platform.startswith("darwin"), "Not for OSX (does not work with the mach-engine for now)", ) def runTest(self): rv, o = self.do( - self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/pie-test", + self.kcov + " " + self.outbase + "/kcov " + self.binaries + "/pie-test", False, ) assert rv == 0 @@ -142,7 +140,7 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "argv-dependent.c", 11) == 0 rv, o = self.do( - self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/pie-test a", + self.kcov + " " + self.outbase + "/kcov " + self.binaries + "/pie-test a", False, ) assert rv == 0 @@ -152,11 +150,11 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "argv-dependent.c", 11) == 1 -class global_ctors(testbase.KcovTestCase): +class global_ctors(libkcov.TestCase): def runTest(self): - noKcovRv, o = self.doCmd(self.testbuild + "/global-constructors") + noKcovRv, o = self.doCmd(self.binaries + "/global-constructors") rv, o = self.do( - self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/global-constructors", + self.kcov + " " + self.outbase + "/kcov " + self.binaries + "/global-constructors", False, ) assert rv == noKcovRv @@ -165,13 +163,13 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "test-global-ctors.cc", 4) >= 1 -class daemon_wait_for_last_child(testbase.KcovTestCase): +class daemon_wait_for_last_child(libkcov.TestCase): @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.doCmd(self.testbuild + "/test_daemon") + noKcovRv, o = self.doCmd(self.binaries + "/test_daemon") rv, o = self.do( - self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/test_daemon", + self.kcov + " " + self.outbase + "/kcov " + self.binaries + "/test_daemon", False, ) assert rv == 4 @@ -181,18 +179,18 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "test-daemon.cc", 31) == 1 -class SignalsBase(testbase.KcovTestCase): +class SignalsBase(libkcov.TestCase): def SignalsBase(): self.m_self = "" def cmpOne(self, sig): - noKcovRv, o = self.doCmd(self.testbuild + "/signals " + sig + " " + self.m_self) + noKcovRv, o = self.doCmd(self.binaries + "/signals " + sig + " " + self.m_self) rv, o = self.do( self.kcov + " " + self.outbase + "/kcov " - + self.testbuild + + self.binaries + "/signals " + sig + " " @@ -236,33 +234,33 @@ def runTest(self): self.doTest() -class signals_crash(testbase.KcovTestCase): +class signals_crash(libkcov.TestCase): @unittest.skipIf(sys.platform.startswith("darwin"), "Not for OSX (macho-parser for now)") def runTest(self): rv, o = self.do( - self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/signals segv self", + self.kcov + " " + self.outbase + "/kcov " + self.binaries + "/signals segv self", False, ) assert b"kcov: Process exited with signal 11" in o rv, o = self.do( - self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/signals abrt self", + self.kcov + " " + self.outbase + "/kcov " + self.binaries + "/signals abrt self", False, ) assert b"kcov: Process exited with signal 6" in o -class collect_and_report_only(testbase.KcovTestCase): +class collect_and_report_only(libkcov.TestCase): # Cannot work with combined Engine / Parser @unittest.skipIf(sys.platform.startswith("darwin"), "Not for OSX") def runTest(self): - noKcovRv, o = self.doCmd(self.testbuild + "/main-tests ") + noKcovRv, o = self.doCmd(self.binaries + "/main-tests ") rv, o = self.do( self.kcov + " --collect-only " + self.outbase + "/kcov " - + self.testbuild + + self.binaries + "/main-tests", False, ) @@ -277,22 +275,17 @@ def runTest(self): pass rv, o = self.do( - self.kcov - + " --report-only " - + self.outbase - + "/kcov " - + self.testbuild - + "/main-tests", + self.kcov + " --report-only " + self.outbase + "/kcov " + self.binaries + "/main-tests", False, ) dom = cobertura.parseFile(self.outbase + "/kcov/main-tests/cobertura.xml") assert cobertura.hitsPerLine(dom, "main.cc", 9) == 1 -class setpgid_kill(testbase.KcovTestCase): +class setpgid_kill(libkcov.TestCase): def runTest(self): noKcovRv, o = self.doCmd( - self.sources + "/tests/setpgid-kill/test-script.sh " + self.testbuild + "/setpgid-kill" + self.sources + "/tests/setpgid-kill/test-script.sh " + self.binaries + "/setpgid-kill" ) assert b"SUCCESS" in o @@ -303,14 +296,14 @@ def runTest(self): + " " + self.outbase + "/kcov " - + self.testbuild + + self.binaries + "/setpgid-kill", False, ) assert b"SUCCESS" in o -class attach_process_with_threads(testbase.KcovTestCase): +class attach_process_with_threads(libkcov.TestCase): @unittest.skipIf(sys.platform.startswith("darwin"), "Not for OSX") def runTest(self): rv, o = self.do( @@ -320,7 +313,7 @@ def runTest(self): + " " + self.outbase + "/kcov " - + self.testbuild + + self.binaries + "/issue31", False, ) @@ -331,7 +324,7 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "test-issue31.cc", 9) == 0 -class attach_process_with_threads_creates_threads(testbase.KcovTestCase): +class attach_process_with_threads_creates_threads(libkcov.TestCase): @unittest.skipIf(sys.platform.startswith("darwin"), "Not for OSX") def runTest(self): rv, o = self.do( @@ -341,7 +334,7 @@ def runTest(self): + " " + self.outbase + "/kcov " - + self.testbuild + + self.binaries + "/thread-test", False, ) @@ -351,10 +344,10 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "thread-main.c", 9) >= 1 -class merge_same_file_in_multiple_binaries(testbase.KcovTestCase): +class merge_same_file_in_multiple_binaries(libkcov.TestCase): def runTest(self): rv, o = self.do( - self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/multi_1", + self.kcov + " " + self.outbase + "/kcov " + self.binaries + "/multi_1", False, ) dom = cobertura.parseFile(self.outbase + "/kcov/multi_1/cobertura.xml") @@ -362,7 +355,7 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "file.c", 3) == 0 rv, o = self.do( - self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/multi_2", + self.kcov + " " + self.outbase + "/kcov " + self.binaries + "/multi_2", False, ) dom = cobertura.parseFile(self.outbase + "/kcov/kcov-merged/cobertura.xml") @@ -371,7 +364,7 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "file.c", 8) == 0 rv, o = self.do( - self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/multi_2 1", + self.kcov + " " + self.outbase + "/kcov " + self.binaries + "/multi_2 1", False, ) dom = cobertura.parseFile(self.outbase + "/kcov/kcov-merged/cobertura.xml") @@ -379,52 +372,52 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "file.c", 8) == 1 -class debuglink(testbase.KcovTestCase): +class debuglink(libkcov.TestCase): @unittest.skipIf(sys.platform.startswith("darwin"), "Not for OSX") def runTest(self): 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"cp {self.binaries}/main-tests {self.binaries}/main-tests-debug-file") os.system( - f"objcopy --only-keep-debug {self.testbuild}/main-tests-debug-file {self.testbuild}/main-tests-debug-file.debug" + f"objcopy --only-keep-debug {self.binaries}/main-tests-debug-file {self.binaries}/main-tests-debug-file.debug" ) os.system( - f"cp {self.testbuild}/main-tests-debug-file.debug {self.testbuild}/main-tests-debug-file1.debug" + f"cp {self.binaries}/main-tests-debug-file.debug {self.binaries}/main-tests-debug-file1.debug" ) os.system( - f"cp {self.testbuild}/main-tests-debug-file.debug {self.testbuild}/main-tests-debug-file12.debug" + f"cp {self.binaries}/main-tests-debug-file.debug {self.binaries}/main-tests-debug-file12.debug" ) os.system( - f"cp {self.testbuild}/main-tests-debug-file.debug {self.testbuild}/main-tests-debug-file123.debug" + f"cp {self.binaries}/main-tests-debug-file.debug {self.binaries}/main-tests-debug-file123.debug" ) os.system( - f"cp {self.testbuild}/main-tests-debug-file {self.testbuild}/main-tests-debug-file1" + f"cp {self.binaries}/main-tests-debug-file {self.binaries}/main-tests-debug-file1" ) os.system( - f"cp {self.testbuild}/main-tests-debug-file {self.testbuild}/main-tests-debug-file2" + f"cp {self.binaries}/main-tests-debug-file {self.binaries}/main-tests-debug-file2" ) os.system( - f"cp {self.testbuild}/main-tests-debug-file {self.testbuild}/main-tests-debug-file3" + f"cp {self.binaries}/main-tests-debug-file {self.binaries}/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"strip -g {(self.binaries)}/main-tests-debug-file") + os.system(f"strip -g {(self.binaries)}/main-tests-debug-file1") + os.system(f"strip -g {(self.binaries)}/main-tests-debug-file2") + os.system(f"strip -g {(self.binaries)}/main-tests-debug-file3") os.system( - f"objcopy --add-gnu-debuglink={self.testbuild}/main-tests-debug-file.debug {self.testbuild}/main-tests-debug-file" + f"objcopy --add-gnu-debuglink={self.binaries}/main-tests-debug-file.debug {self.binaries}/main-tests-debug-file" ) os.system( - f"objcopy --add-gnu-debuglink={self.testbuild}/main-tests-debug-file1.debug {self.testbuild}/main-tests-debug-file1" + f"objcopy --add-gnu-debuglink={self.binaries}/main-tests-debug-file1.debug {self.binaries}/main-tests-debug-file1" ) os.system( - f"objcopy --add-gnu-debuglink={self.testbuild}/main-tests-debug-file12.debug {self.testbuild}/main-tests-debug-file2" + f"objcopy --add-gnu-debuglink={self.binaries}/main-tests-debug-file12.debug {self.binaries}/main-tests-debug-file2" ) os.system( - f"objcopy --add-gnu-debuglink={self.testbuild}/main-tests-debug-file123.debug {self.testbuild}/main-tests-debug-file3" + f"objcopy --add-gnu-debuglink={self.binaries}/main-tests-debug-file123.debug {self.binaries}/main-tests-debug-file3" ) - noKcovRv, o = self.doCmd(self.testbuild + "/main-tests-debug-file") + noKcovRv, o = self.doCmd(self.binaries + "/main-tests-debug-file") rv, o = self.do( - self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/main-tests-debug-file", + self.kcov + " " + self.outbase + "/kcov " + self.binaries + "/main-tests-debug-file", False, ) assert rv == noKcovRv @@ -434,21 +427,21 @@ def runTest(self): # Check alignment rv, o = self.do( - self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/main-tests-debug-file1", + self.kcov + " " + self.outbase + "/kcov " + self.binaries + "/main-tests-debug-file1", False, ) dom = cobertura.parseFile(self.outbase + "/kcov/main-tests-debug-file1/cobertura.xml") assert cobertura.hitsPerLine(dom, "main.cc", 9) == 1 rv, o = self.do( - self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/main-tests-debug-file2", + self.kcov + " " + self.outbase + "/kcov " + self.binaries + "/main-tests-debug-file2", False, ) dom = cobertura.parseFile(self.outbase + "/kcov/main-tests-debug-file2/cobertura.xml") assert cobertura.hitsPerLine(dom, "main.cc", 9) == 1 rv, o = self.do( - self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/main-tests-debug-file3", + self.kcov + " " + self.outbase + "/kcov " + self.binaries + "/main-tests-debug-file3", False, ) dom = cobertura.parseFile(self.outbase + "/kcov/main-tests-debug-file3/cobertura.xml") @@ -456,21 +449,21 @@ def runTest(self): # Look in .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") + os.system(f"mkdir -p {(self.binaries)}/.debug") + os.system(f"mv {self.binaries}/main-tests-debug-file.debug {self.binaries}/.debug") rv, o = self.do( - self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/main-tests-debug-file", + self.kcov + " " + self.outbase + "/kcov " + self.binaries + "/main-tests-debug-file", False, ) 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 {(self.outbase)}/kcov") - os.system(f"echo 'abc' >> {(self.testbuild)}/.debug/main-tests-debug-file.debug") + os.system(f"echo 'abc' >> {(self.binaries)}/.debug/main-tests-debug-file.debug") rv, o = self.do( - self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/main-tests-debug-file", + self.kcov + " " + self.outbase + "/kcov " + self.binaries + "/main-tests-debug-file", False, ) dom = cobertura.parseFile(self.outbase + "/kcov/main-tests-debug-file/cobertura.xml") @@ -480,30 +473,30 @@ def runTest(self): # Todo: Look in /usr/lib/debug as well -class collect_no_source(testbase.KcovTestCase): +class collect_no_source(libkcov.TestCase): @unittest.expectedFailure def runTest(self): - 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") + os.system(f"cp {self.sources}/tests/short-file.c {self.binaries}/main.cc") + os.system(f"gcc -g -o {self.binaries}/main-collect-only {self.binaries}/main.cc") + os.system(f"mv {self.binaries}/main.cc {self.binaries}/tmp-main.cc") rv, o = self.do( self.kcov + " --collect-only " + self.outbase + "/kcov " - + self.testbuild + + self.binaries + "/main-collect-only", False, ) - os.system(f"mv {self.testbuild}/tmp-main.cc {self.testbuild}/main.cc") + os.system(f"mv {self.binaries}/tmp-main.cc {self.binaries}/main.cc") rv, o = self.do( self.kcov + " --report-only " + self.outbase + "/kcov " - + self.testbuild + + self.binaries + "/main-collect-only" ) @@ -511,12 +504,12 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "main.cc", 1) == 1 -class dlopen(testbase.KcovTestCase): +class dlopen(libkcov.TestCase): @unittest.expectedFailure def runTest(self): - noKcovRv, o = self.doCmd(self.testbuild + "/dlopen") + noKcovRv, o = self.doCmd(self.binaries + "/dlopen") rv, o = self.do( - self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/dlopen", + self.kcov + " " + self.outbase + "/kcov " + self.binaries + "/dlopen", False, ) @@ -528,7 +521,7 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "solib.c", 12) == 0 -class dlopen_in_ignored_source_file(testbase.KcovTestCase): +class dlopen_in_ignored_source_file(libkcov.TestCase): @unittest.expectedFailure def runTest(self): rv, o = self.do( @@ -536,7 +529,7 @@ def runTest(self): + " --exclude-pattern=dlopen.cc " + self.outbase + "/kcov " - + self.testbuild + + self.binaries + "/dlopen", False, ) @@ -546,17 +539,17 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "solib.c", 12) == 0 -class daemon_no_wait_for_last_child(testbase.KcovTestCase): +class daemon_no_wait_for_last_child(libkcov.TestCase): @unittest.skipIf(sys.platform.startswith("darwin"), "Not for OSX") @unittest.expectedFailure def runTest(self): - noKcovRv, o = self.doCmd(self.testbuild + "/test_daemon") + noKcovRv, o = self.doCmd(self.binaries + "/test_daemon") rv, o = self.do( self.kcov + " --output-interval=1 --exit-first-process " + self.outbase + "/kcov " - + self.testbuild + + self.binaries + "/test_daemon", False, ) @@ -572,11 +565,11 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "test-daemon.cc", 31) == 1 -class address_sanitizer_coverage(testbase.KcovTestCase): +class address_sanitizer_coverage(libkcov.TestCase): @unittest.skipIf(sys.platform.startswith("darwin"), "Not for OSX") @unittest.expectedFailure def runTest(self): - if not os.path.isfile(self.testbuild + "/sanitizer-coverage"): + if not os.path.isfile(self.binaries + "/sanitizer-coverage"): self.write_message("Clang-only") assert False rv, o = self.do( @@ -584,7 +577,7 @@ def runTest(self): + " --clang " + self.outbase + "/kcov " - + self.testbuild + + self.binaries + "/sanitizer-coverage", False, ) diff --git a/tests/tools/compiled_basic.py b/tests/tools/test_compiled_basic.py similarity index 81% rename from tests/tools/compiled_basic.py rename to tests/tools/test_compiled_basic.py index 849129a1..84f81689 100644 --- a/tests/tools/compiled_basic.py +++ b/tests/tools/test_compiled_basic.py @@ -1,19 +1,19 @@ import sys import unittest -import cobertura -import testbase +import libkcov +from libkcov import cobertura -class shared_library(testbase.KcovTestCase): +class shared_library(libkcov.TestCase): @unittest.skipIf( sys.platform.startswith("darwin"), "Not for OSX (does not work with the mach-engine for now)", ) def runTest(self): - noKcovRv, o = self.doCmd(self.testbuild + "/shared_library_test") + noKcovRv, o = self.doCmd(self.binaries + "/shared_library_test") rv, o = self.do( - self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/shared_library_test", + self.kcov + " " + self.outbase + "/kcov " + self.binaries + "/shared_library_test", False, ) assert rv == noKcovRv @@ -23,7 +23,7 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "solib.c", 5) == 1 -class shared_library_skip(testbase.KcovTestCase): +class shared_library_skip(libkcov.TestCase): @unittest.skipIf(sys.platform.startswith("darwin"), "Not for OSX, Issue #157") def runTest(self): rv, o = self.do( @@ -31,7 +31,7 @@ def runTest(self): + " --skip-solibs " + self.outbase + "/kcov " - + self.testbuild + + self.binaries + "/shared_library_test", False, ) @@ -43,7 +43,7 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "solib.c", 5) is None -class shared_library_filter_out(testbase.KcovTestCase): +class shared_library_filter_out(libkcov.TestCase): @unittest.skipIf(sys.platform.startswith("darwin"), "Not for OSX, Issue #157") def runTest(self): rv, o = self.do( @@ -51,7 +51,7 @@ def runTest(self): + " --exclude-pattern=solib " + self.outbase + "/kcov " - + self.testbuild + + self.binaries + "/shared_library_test", False, ) @@ -62,11 +62,11 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "solib.c", 5) is None -class shared_library_accumulate(testbase.KcovTestCase): +class shared_library_accumulate(libkcov.TestCase): @unittest.skipIf(sys.platform.startswith("darwin"), "Not for OSX, Issue #157") def runTest(self): rv, o = self.do( - self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/shared_library_test 5", + self.kcov + " " + self.outbase + "/kcov " + self.binaries + "/shared_library_test 5", False, ) assert rv == 0 @@ -77,9 +77,9 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "solib.c", 10) == 1 -class MainTestBase(testbase.KcovTestCase): +class MainTestBase(libkcov.TestCase): def doTest(self, verify): - noKcovRv, o = self.doCmd(self.testbuild + "/main-tests") + noKcovRv, o = self.doCmd(self.binaries + "/main-tests") rv, o = self.do( self.kcov + " " @@ -87,7 +87,7 @@ def doTest(self, verify): + " " + self.outbase + "/kcov " - + self.testbuild + + self.binaries + "/main-tests 5", False, ) diff --git a/tests/tools/filter.py b/tests/tools/test_filter.py similarity index 93% rename from tests/tools/filter.py rename to tests/tools/test_filter.py index 1ceed3fa..691fc7c1 100644 --- a/tests/tools/filter.py +++ b/tests/tools/test_filter.py @@ -1,8 +1,8 @@ -import cobertura -import testbase +import libkcov +from libkcov import cobertura -class include_exclude_pattern(testbase.KcovTestCase): +class include_exclude_pattern(libkcov.TestCase): def runTest(self): rv, o = self.do( self.kcov @@ -43,7 +43,7 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "b.sh", 3) >= 1 -class include_path(testbase.KcovTestCase): +class include_path(libkcov.TestCase): def runTest(self): rv, o = self.do( self.kcov @@ -62,7 +62,7 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "b.sh", 3) >= 1 -class include_path_and_exclude_pattern(testbase.KcovTestCase): +class include_path_and_exclude_pattern(libkcov.TestCase): def runTest(self): rv, o = self.do( self.kcov diff --git a/tests/tools/python.py b/tests/tools/test_python.py similarity index 88% rename from tests/tools/python.py rename to tests/tools/test_python.py index 969e584c..ee0a6075 100644 --- a/tests/tools/python.py +++ b/tests/tools/test_python.py @@ -1,10 +1,10 @@ import unittest -import cobertura -import testbase +import libkcov +from libkcov import cobertura -class python_exit_status(testbase.KcovTestCase): +class python_exit_status(libkcov.TestCase): def runTest(self): noKcovRv, o = self.doCmd(self.sources + "/tests/python/main 5") rv, o = self.do( @@ -14,7 +14,7 @@ def runTest(self): assert rv == noKcovRv -class python_can_set_illegal_parser(testbase.KcovTestCase): +class python_can_set_illegal_parser(libkcov.TestCase): def runTest(self): rv, o = self.do( self.kcov @@ -28,7 +28,7 @@ def runTest(self): assert b"Cannot find Python parser 'python7'" in o -class python_can_set_legal_parser(testbase.KcovTestCase): +class python_can_set_legal_parser(libkcov.TestCase): def runTest(self): rv, o = self.do( self.kcov @@ -42,7 +42,7 @@ def runTest(self): assert b"Cannot find Python parser 'python3'" not in o -class python2_can_set_legal_parser(testbase.KcovTestCase): +class python2_can_set_legal_parser(libkcov.TestCase): def runTest(self): rv, o = self.do( self.kcov @@ -56,7 +56,7 @@ def runTest(self): assert b"Cannot find Python parser 'python2'" not in o -class python_issue_368_can_handle_symlink_target(testbase.KcovTestCase): +class python_issue_368_can_handle_symlink_target(libkcov.TestCase): def runTest(self): rv, o = self.do( self.kcov @@ -70,7 +70,7 @@ def runTest(self): assert b"unrecognized option '--foo'" not in o -class python_unittest(testbase.KcovTestCase): +class python_unittest(libkcov.TestCase): def runTest(self): rv, o = self.do( self.kcov @@ -85,7 +85,7 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "testdriver", 14) == 1 -class PythonBase(testbase.KcovTestCase): +class PythonBase(libkcov.TestCase): def doTest(self, extra): rv, o = self.do( self.kcov @@ -121,7 +121,7 @@ def runTestTest(self): self.doTest("") -class python_accumulate_data(testbase.KcovTestCase): +class python_accumulate_data(libkcov.TestCase): def runTest(self): rv, o = self.do( self.kcov + " " + self.outbase + "/kcov " + self.sources + "/tests/python/main 5" @@ -149,7 +149,7 @@ def runTest(self): self.doTest("--python-parser=python2") -class python_tricky_single_line_string_assignment(testbase.KcovTestCase): +class python_tricky_single_line_string_assignment(libkcov.TestCase): def runTest(self): rv, o = self.do( self.kcov + " " + self.outbase + "/kcov " + self.sources + "/tests/python/main 5" @@ -159,7 +159,7 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "second.py", 34) == 2 -class python_select_parser(testbase.KcovTestCase): +class python_select_parser(libkcov.TestCase): def disabledTest(self): rv, o = self.do( self.kcov @@ -175,7 +175,7 @@ def disabledTest(self): assert rv == 99 -class python_tricky_single_dict_assignment(testbase.KcovTestCase): +class python_tricky_single_dict_assignment(libkcov.TestCase): @unittest.expectedFailure def runTest(self): rv, o = self.do( diff --git a/tests/tools/system_mode.py b/tests/tools/test_system_mode.py similarity index 91% rename from tests/tools/system_mode.py rename to tests/tools/test_system_mode.py index 70629919..e417d077 100644 --- a/tests/tools/system_mode.py +++ b/tests/tools/test_system_mode.py @@ -3,11 +3,11 @@ import time import unittest -import cobertura -import testbase +import libkcov +from libkcov import cobertura -class SystemModeBase(testbase.KcovTestCase): +class SystemModeBase(libkcov.TestCase): def writeToPipe(self, str): f = open("/tmp/kcov-system.pipe", "w") f.write(str) @@ -31,11 +31,11 @@ def runTest(self): class system_mode_can_instrument_binary(SystemModeBase): def runTest(self): rv, o = self.do( - self.kcov + " --system-record " + self.outbase + "/kcov " + self.testbuild + "/" + self.kcov + " --system-record " + self.outbase + "/kcov " + self.binaries + "/" ) assert rv == 0 - src = self.testbuild + "/main-tests" + src = self.binaries + "/main-tests" dst = self.outbase + "/kcov/main-tests" assert os.path.isfile(src) @@ -50,7 +50,7 @@ def runTest(self): self.write_message(platform.machine()) rv, o = self.do( - self.kcov + " --system-record " + self.outbase + "/kcov " + self.testbuild + "/" + self.kcov + " --system-record " + self.outbase + "/kcov " + self.binaries + "/" ) rv, o = self.do(self.kcov_system_daemon + " -d", False)