Skip to content

Commit

Permalink
Merge pull request #456 from SimonKagstrom/run-tests-without-ptrace
Browse files Browse the repository at this point in the history
Run tests without ptrace
  • Loading branch information
SimonKagstrom authored Jul 17, 2024
2 parents 6e50ca5 + 3601188 commit c6089dc
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 19 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 20 additions & 7 deletions tests/tools/libkcov/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions tests/tools/test_bash.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand Down
12 changes: 0 additions & 12 deletions tests/tools/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 12 additions & 0 deletions tests/tools/test_compiled.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c6089dc

Please sign in to comment.