mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-08-04 12:22:35 +03:00
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>
This commit is contained in:
@ -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_file = sys.argv[1]
|
||||
permitted_file = sys.argv[2]
|
||||
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
|
||||
|
||||
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)
|
||||
|
Reference in New Issue
Block a user