diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eeadc75a..5bcce3b1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,6 +45,7 @@ jobs: distro: ubuntu22.04 run: | .github/workflows/generic-build.sh ${{ matrix.arch }} + .github/workflows/ci-run-tests.sh --no-ptrace build-osx: name: Build OSX executable (macos-latest) diff --git a/tests/tools/libkcov/main.py b/tests/tools/libkcov/main.py index 39408fd5..0eeedd41 100644 --- a/tests/tools/libkcov/main.py +++ b/tests/tools/libkcov/main.py @@ -90,7 +90,7 @@ def to_fnmatch(pattern): return pattern -def addTests(config, patterns): +def addTests(config, args, patterns): """Add all the kcov test modules. Discovery is not possible, since some modules need to be excluded, @@ -100,20 +100,25 @@ def addTests(config, patterns): test_loader = TestLoader(config, patterns) test_loader.add_tests_from_module("test_basic") - test_loader.add_tests_from_module("test_compiled_basic") + if not args.no_ptrace: + 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 not args.no_ptrace: + 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") + if not args.no_ptrace: + test_loader.add_tests_from_module("test_system_mode") - test_loader.add_tests_from_module("test_accumulate") + if not args.no_ptrace: + 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") + if not args.no_ptrace: + test_loader.add_tests_from_module("test_python") return test_loader.tests @@ -189,6 +194,14 @@ def parse_args(): help="Randomize the execution order of tests", ) + parser.add_argument( + "--no-ptrace", + dest="no_ptrace", + action="store_true", + help="Don't run tests which require ptrace", + ) + + # TODO: The --duration argument was added in 3.12. # kcov test runner custom options @@ -205,7 +218,7 @@ def main(): # Loads and configure tests config = Config(args.kcov, args.outbase, args.binaries, args.sources) - tests = addTests(config, args.patterns) + tests = addTests(config, args, args.patterns) if args.shuffle: random.shuffle(tests) diff --git a/tests/tools/test_bash.py b/tests/tools/test_bash.py index 394f3fda..6a522ee8 100644 --- a/tests/tools/test_bash.py +++ b/tests/tools/test_bash.py @@ -419,6 +419,7 @@ def runTest(self): # Issue #224 class bash_can_find_non_executed_scripts(libkcov.TestCase): + @unittest.skipUnless(platform.machine() in ["x86_64", "i686", "i386"], "Only for x86") def runTest(self): rv, o = self.do( self.kcov @@ -436,6 +437,7 @@ def runTest(self): class bash_can_find_non_executed_scripts_manually(libkcov.TestCase): + @unittest.skipUnless(platform.machine() in ["x86_64", "i686", "i386"], "Only for x86") def runTest(self): rv, o = self.do( self.kcov @@ -492,6 +494,7 @@ def runTest(self): class bash_drain_stdout_without_return(libkcov.TestCase): + @unittest.skipUnless(platform.machine() in ["x86_64", "i686", "i386"], "Only for x86") @unittest.skipIf(sys.platform.startswith("darwin"), "Not for OSX") def runTest(self): rv, o = self.do( diff --git a/tests/tools/test_basic.py b/tests/tools/test_basic.py index 064020aa..dbc2ef5e 100644 --- a/tests/tools/test_basic.py +++ b/tests/tools/test_basic.py @@ -33,15 +33,3 @@ def runTest(self): dom = cobertura.parseFile(self.outbase + "/kcov/main/cobertura.xml") assert cobertura.hitsPerLine(dom, "second.py", 34) == 2 assert noKcovRv, rv - - -# Issue #414 -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. - # See https://www.kernel.org/doc/Documentation/security/Yama.txt - executable = self.sources + "/tests/python/short-test.py" - rv, o = self.do(self.kcov + " echo " + executable) - - assert rv == 0 diff --git a/tests/tools/test_compiled.py b/tests/tools/test_compiled.py index 3006c349..b8ee7262 100644 --- a/tests/tools/test_compiled.py +++ b/tests/tools/test_compiled.py @@ -572,3 +572,15 @@ def runTest(self): assert cobertura.hitsPerLine(dom, "sanitizer-coverage.c", 22) == 0 assert cobertura.hitsPerLine(dom, "sanitizer-coverage.c", 25) == 0 + + +# Issue #414 +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. + # See https://www.kernel.org/doc/Documentation/security/Yama.txt + executable = self.sources + "/tests/python/short-test.py" + rv, o = self.do(self.kcov + " echo " + executable) + + assert rv == 0