summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorPavel Hrdina <phrdina@redhat.com>2020-07-28 14:29:32 +0200
committerPavel Hrdina <phrdina@redhat.com>2020-08-03 09:27:06 +0200
commit9d406981165221e6f1a40e6cf3f7e3653855c872 (patch)
tree93b2e70707500e0d60ecb0f39cee860afd7b7d9a /scripts
parent59cafec0a43809d540a8202b769a8de428287d5e (diff)
downloadlibvirt-9d406981165221e6f1a40e6cf3f7e3653855c872.tar.gz
meson: tests: add file access test setup
We need to modify check-file-access.py to be usable as wrapper for libvirt tests. This way we can run the tests using this command: meson test --setup access which will run all tests using check-file-access.py as a wrapper. With autotools all file access are written into single file for all tests and compared once the whole test suite is done. With Meson we will compare the file access after every single test because it is used as wrapper now. That requires writing the file access into separate files for every single test as they are executed in parallel. Since the wrapper is used for all tests in Meson including tests outside of tests directory we have to check for presence of the output file. We should also cleanup after ourselves. Signed-off-by: Pavel Hrdina <phrdina@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Neal Gompa <ngompa13@gmail.com>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/check-file-access.py28
1 files changed, 22 insertions, 6 deletions
diff --git a/scripts/check-file-access.py b/scripts/check-file-access.py
index aa120cafac..2636eb4f96 100755
--- a/scripts/check-file-access.py
+++ b/scripts/check-file-access.py
@@ -21,22 +21,36 @@
#
#
+import os
import re
import sys
+import tempfile
-if len(sys.argv) != 3:
- print("syntax: %s ACCESS-FILE PERMITTED-ACCESS-FILE")
- sys.exit(1)
+abs_builddir = os.environ.get('abs_builddir', '')
+abs_srcdir = os.environ.get('abs_srcdir', '')
+
+access_fd, access_file = tempfile.mkstemp(dir=abs_builddir,
+ prefix='file-access-',
+ suffix='.txt')
+permitted_file = os.path.join(abs_srcdir, 'permitted_file_access.txt')
+
+os.environ['VIR_TEST_FILE_ACCESS_OUTPUT'] = access_file
-access_file = sys.argv[1]
-permitted_file = sys.argv[2]
+test = ' '.join(sys.argv[1:])
+
+ret = os.system(test)
+
+if ret != 0 or os.read(access_fd, 10) == b'':
+ os.close(access_fd)
+ os.remove(access_file)
+ sys.exit(ret)
known_actions = ["open", "fopen", "access", "stat", "lstat", "connect"]
files = []
permitted = []
-with open(access_file, "r") as fh:
+with os.fdopen(access_fd, "r") as fh:
for line in fh:
line = line.rstrip("\n")
@@ -120,6 +134,8 @@ for file in files:
print(": %s" % file["testname"], end="")
print("")
+os.remove(access_file)
+
if err:
sys.exit(1)
sys.exit(0)