]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
meson: tests: add file access test setup
authorPavel Hrdina <phrdina@redhat.com>
Tue, 28 Jul 2020 12:29:32 +0000 (14:29 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Mon, 3 Aug 2020 07:27:06 +0000 (09:27 +0200)
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>
Makefile.am
scripts/check-file-access.py
tests/Makefile.am
tests/meson.build
tests/virtestmock.c

index 363c5cf66fda70e48c580930ca40e893b9f08f7a..d05a0c1a85a856207e8dd4d8499a5806a3a066be 100644 (file)
@@ -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
index aa120cafacfcb1d4377373a2d40f0a636f6562eb..2636eb4f96df74ac41c77518a5ddf46d859cb6a4 100755 (executable)
 #
 #
 
+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)
index 24ae515a3900e80e7b5e84ed9a0308895d0e8af4..04c37ccda2e400373becf6ae3cd5754d9d0c2893 100644 (file)
 ## License along with this library.  If not, see
 ## <http://www.gnu.org/licenses/>.
 
-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
index 03ec061ac8ecf79dba3c6046d350a793072a5640..3bbdddc1f72feae70469aa47ebde007fae0f6b37 100644 (file)
@@ -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() ],
+)
index e5dccae2a87eb7d1d98a0a488ca06a6b98892426..776493f0c5de2ec6b79e455525a9f04522682236 100644 (file)
@@ -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();
     }