diff --git a/Makefile.am b/Makefile.am index 363c5cf66f..d05a0c1a85 100644 --- a/Makefile.am +++ b/Makefile.am @@ -37,9 +37,6 @@ srpm: clean check-local: all tests -check-access: all - @($(MAKE) $(AM_MAKEFLAGS) -C tests check-access) - dist-hook: gen-AUTHORS .PHONY: gen-AUTHORS 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_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) diff --git a/tests/Makefile.am b/tests/Makefile.am index 24ae515a39..04c37ccda2 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -16,17 +16,6 @@ ## License along with this library. If not, see ## . -if WITH_LINUX -check-access: file-access-clean - VIR_TEST_FILE_ACCESS=1 $(MAKE) $(AM_MAKEFLAGS) check - $(RUNUTF8) $(PYTHON) $(top_srcdir)/scripts/check-file-access.py \ - $(abs_builddir)/test_file_access.txt \ - $(abs_srcdir)/permitted_file_access.txt | sort -u - -file-access-clean: - > test_file_access.txt -endif WITH_LINUX - VALGRIND = valgrind --quiet --leak-check=full --trace-children=yes \ --trace-children-skip="*/tools/virsh","*/tests/commandhelper","/usr/bin/*" \ --suppressions=$(abs_srcdir)/.valgrind.supp diff --git a/tests/meson.build b/tests/meson.build index 03ec061ac8..3bbdddc1f7 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -678,3 +678,12 @@ foreach name : test_scripts script = find_program(name) test(name, script, env: tests_env) endforeach + +add_test_setup( + 'access', + env: [ + 'VIR_TEST_FILE_ACCESS=1', + runutf8, + ], + exe_wrapper: [ python3_prog, check_file_access_prog.path() ], +) diff --git a/tests/virtestmock.c b/tests/virtestmock.c index e5dccae2a8..776493f0c5 100644 --- a/tests/virtestmock.c +++ b/tests/virtestmock.c @@ -69,7 +69,7 @@ printFile(const char *file, output = VIR_FILE_ACCESS_DEFAULT; } - if (!(fp = real_fopen(output, "a"))) { + if (!(fp = real_fopen(output, "w"))) { fprintf(stderr, "Unable to open %s: %s\n", output, g_strerror(errno)); abort(); }