From 402b735914a9cf84e33bff482848db121853c8f0 Mon Sep 17 00:00:00 2001 From: Manlio Perillo Date: Sun, 17 Mar 2024 09:29:58 +0100 Subject: [PATCH] tests: fix basic.OutDirectoryIsExecutable Commit 4b4cb9c (Merge pull request #426 from perillo/fix-argv-parsing) added a regression test, but the test failed due to ptrace errors on Linux. The "Operation not permitted" error was caused by kcov trying to trace the "/bin/usr/python". The solution is to execute an executable having user permission. Restore the short-test.py executable, and use it instead of python. short-test.py always exits with exit status 0. --- tests/python/short-test.py | 4 ++-- tests/tools/basic.py | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/python/short-test.py b/tests/python/short-test.py index 711ca606..e6e593b4 100755 --- a/tests/python/short-test.py +++ b/tests/python/short-test.py @@ -1,9 +1,9 @@ -#!/usr/bin/python +#!/usr/bin/env python3 import sys def doSomething(): - print 'Hello world' + print('Hello world') if __name__ == '__main__': diff --git a/tests/tools/basic.py b/tests/tools/basic.py index 50772209..33d772d8 100644 --- a/tests/tools/basic.py +++ b/tests/tools/basic.py @@ -31,6 +31,10 @@ def runTest(self): class OutDirectoryIsExecutable(testbase.KcovTestCase): def runTest(self): self.setUp() - rv,o = self.do(testbase.kcov + " echo python -V") + # 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) assert rv == 0