[libvirt PATCH 312/351] meson: tests: add file access test setup

Peter Krempa pkrempa at redhat.com
Tue Jul 28 12:56:45 UTC 2020


On Thu, Jul 16, 2020 at 11:59:08 +0200, Pavel Hrdina wrote:
> 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 at redhat.com>
> ---
>  Makefile.am                  |  3 ---
>  scripts/check-file-access.py | 24 +++++++++++++++++++-----
>  tests/Makefile.am            | 12 ------------
>  tests/meson.build            |  8 ++++++++
>  tests/virtestmock.c          |  2 +-
>  5 files changed, 28 insertions(+), 21 deletions(-)
> 
> diff --git a/Makefile.am b/Makefile.am
> index 363c5cf66fd..d05a0c1a85a 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 aa120cafacf..f0e98f4b652 100755
> --- a/scripts/check-file-access.py
> +++ b/scripts/check-file-access.py
> @@ -21,15 +21,27 @@
>  #
>  #
>  
> +import os
> +import random
>  import re
> +import string
>  import sys
>  
> -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]
> +filename = ''.join(random.choice(string.ascii_letters) for _ in range(16))

Umm, python doesn't have a 'mkostemp' equivalent? This seems a bit
fishy.


> +access_file = os.path.join(abs_builddir, 'file-access-{0}.txt'.format(filename))
> +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 not os.is_file(access_file):
> +    sys.exit(ret)
>  
>  known_actions = ["open", "fopen", "access", "stat", "lstat", "connect"]
>  
> @@ -120,6 +132,8 @@ for file in files:
>              print(": %s" % file["testname"], end="")
>          print("")
>  
> +os.remove(access_file)

Wouldn't it make sense to keep this file on failure?

> +
>  if err:
>      sys.exit(1)
>  sys.exit(0)




More information about the libvir-list mailing list