From: Gilles DAVID Date: Wed, 24 Apr 2024 12:31:56 +0000 (+0200) Subject: Support new env variable for tests : SALOME_TESTS_PATH and SALOME_TESTS_DIRECTORY X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=951b66a6f225464b3019c60e9dafd99ef67d9b7a;p=modules%2Fkernel.git Support new env variable for tests : SALOME_TESTS_PATH and SALOME_TESTS_DIRECTORY SALOME_TESTS_PATH is a list of path separated with a ";" or ":" If given, a new CtestTestfile.cmake file is created in SALOME_TESTS_DIRECTORY. If SALOME_TESTS_DIRECTORY is not provided, a temporary directory is created instead. The temporary directory is deleted after the tests execution. If SALOME_TESTS_PATH is not provided, the previous behaviour is kept (run tests in ABSOLUTE_APPLI_PATH/bin/salome/test). --- diff --git a/bin/runTests.py b/bin/runTests.py index d1d5656c3..36e62aa98 100644 --- a/bin/runTests.py +++ b/bin/runTests.py @@ -18,18 +18,22 @@ # import os -import sys -import select +from pathlib import Path +import re +import shutil import subprocess +import sys +import tempfile + def __configureTests(args=None, exe=None): - if args is None: - args = [] - if exe: - usage = "Usage: %s [options]"%exe - else: - usage = "Usage: %prog [options]" - epilog = """\n + if args is None: + args = [] + if exe: + usage = "Usage: %s [options]" % exe + else: + usage = "Usage: %prog [options]" + epilog = """\n Run tests of SALOME components provided with application.\n Principal options are: -h,--help @@ -61,30 +65,57 @@ Principal options are: For complete description of available options, pleaser refer to ctest documentation.\n """ - if not args: - return [] + if not args: + return [] + + if args[0] in ["-h", "--help"]: + print(usage + epilog) + sys.exit(0) + + return args - if args[0] in ["-h", "--help"]: - print(usage + epilog) - sys.exit(0) - return args # # tests must be in ${ABSOLUTE_APPLI_PATH}/${__testSubDir}/ __testSubDir = "bin/salome/test" -def runTests(args, exe=None): - args = __configureTests(args, exe) - appliPath = os.getenv("ABSOLUTE_APPLI_PATH") - if not appliPath: - raise SalomeContextException("Unable to find application path. Please check that the variable ABSOLUTE_APPLI_PATH is set.") +def runTests(args, exe=None): + args = __configureTests(args, exe) + test_path_list = [] + salome_tests_path = os.getenv("SALOME_TESTS_PATH") + if salome_tests_path: + salome_tests_path_list = re.split("[:;]", salome_tests_path) + test_path_list += [ + Path(p) for p in salome_tests_path_list if Path(p) not in test_path_list + ] + salome_tests_path = ( + os.getenv("SALOME_TESTS_DIRECTORY") or tempfile.NamedTemporaryFile().name + ) + ctest_directory = Path(salome_tests_path) + ctest_directory.mkdir(exist_ok=True) + ctest_test_file = ctest_directory / "CTestTestfile.cmake" + content = "" + for test_path in test_path_list: + content += f'SUBDIRS("{test_path}")\n' + ctest_test_file.write_text(content) + command = ["ctest"] + args + ret = subprocess.check_call(command, cwd=ctest_directory) + if not os.getenv("SALOME_TESTS_DIRECTORY"): + shutil.rmtree(ctest_directory) + return ret + else: + appliPath = os.getenv("ABSOLUTE_APPLI_PATH") + if not appliPath: + from salomeContext import SalomeContextException - testPath = os.path.join(appliPath, __testSubDir) + raise SalomeContextException( + "Unable to find application path. Please check that the variable ABSOLUTE_APPLI_PATH is set." + ) + testPath = os.path.join(appliPath, __testSubDir) - command = ["ctest"] + args - p = subprocess.Popen(command, cwd=testPath) - p.communicate() - return p.returncode -# + command = ["ctest"] + args + p = subprocess.Popen(command, cwd=testPath) + p.communicate() + return p.returncode diff --git a/bin/salomeContext.py b/bin/salomeContext.py index d59f2cad6..5fe4126f8 100755 --- a/bin/salomeContext.py +++ b/bin/salomeContext.py @@ -201,6 +201,7 @@ class SalomeContext: """Unset environment variable""" def unsetVariable(self, name): if name in os.environ: + self.getLogger().debug("Unset environment variable: %s", name) del os.environ[name] # @@ -212,6 +213,7 @@ class SalomeContext: value = os.path.expandvars(value) # expand environment variables self.getLogger().debug("Add to %s: %s", name, value) env = os.getenv(name, None) + self.getLogger().debug("Prepend to environment variable: %s : %s", name, value) if env is None: os.environ[name] = value else: @@ -225,6 +227,7 @@ class SalomeContext: value = os.path.expandvars(value) # expand environment variables env = os.getenv(name, None) + self.getLogger().debug("Append to environment variable: %s : %s", name, value) if env is None: os.environ[name] = value else: