From 65512fe6180756b446d4fc296a974c1495936443 Mon Sep 17 00:00:00 2001 From: Alex Domingo Date: Wed, 18 Dec 2024 10:59:28 +0100 Subject: [PATCH 1/2] run sanity checks on empty temp directory --- easybuild/framework/easyblock.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/easybuild/framework/easyblock.py b/easybuild/framework/easyblock.py index b6baf5d55e..41c47335b9 100644 --- a/easybuild/framework/easyblock.py +++ b/easybuild/framework/easyblock.py @@ -3739,16 +3739,16 @@ def xs2str(xs): if self.toolchain.mpi_family() and self.toolchain.mpi_family() in toolchain.OPENMPI: env.setvar('OMPI_MCA_rmaps_base_oversubscribe', '1') - # change to install directory (better environment for running tests) - if os.path.isdir(self.installdir): - change_dir(self.installdir) + # run sanity checks from an empty temp directory + # using the build or installation directory can produce false positives and polute them with files + sanity_work_dir = tempfile.mkdtemp(prefix='eb-saniy-check-') # run sanity check commands for cmd in commands: trace_msg(f"running command '{cmd}' ...") - res = run_shell_cmd(cmd, fail_on_error=False, hidden=True) + res = run_shell_cmd(cmd, work_dir=sanity_work_dir, fail_on_error=False, hidden=True) if res.exit_code != EasyBuildExit.SUCCESS: fail_msg = f"sanity check command {cmd} failed with exit code {res.exit_code} (output: {res.output})" self.sanity_check_fail_msgs.append(fail_msg) @@ -3802,8 +3802,8 @@ def xs2str(xs): "Sanity check failed: " + '\n'.join(self.sanity_check_fail_msgs), exit_code=EasyBuildExit.FAIL_SANITY_CHECK, ) - else: - self.log.debug("Sanity check passed!") + + self.log.debug("Sanity check passed!") def _set_module_as_default(self, fake=False): """ From 2389fc6d73e7a4969d71a6ee7a62516828758868 Mon Sep 17 00:00:00 2001 From: Kenneth Hoste Date: Wed, 18 Dec 2024 11:41:03 +0100 Subject: [PATCH 2/2] enhance test_toy_sanity_check_commands to check on working directory for sanity check commands --- easybuild/framework/easyblock.py | 4 ++-- test/framework/toy_build.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/easybuild/framework/easyblock.py b/easybuild/framework/easyblock.py index 41c47335b9..fb215ffb21 100644 --- a/easybuild/framework/easyblock.py +++ b/easybuild/framework/easyblock.py @@ -3741,14 +3741,14 @@ def xs2str(xs): # run sanity checks from an empty temp directory # using the build or installation directory can produce false positives and polute them with files - sanity_work_dir = tempfile.mkdtemp(prefix='eb-saniy-check-') + sanity_check_work_dir = tempfile.mkdtemp(prefix='eb-sanity-check-') # run sanity check commands for cmd in commands: trace_msg(f"running command '{cmd}' ...") - res = run_shell_cmd(cmd, work_dir=sanity_work_dir, fail_on_error=False, hidden=True) + res = run_shell_cmd(cmd, work_dir=sanity_check_work_dir, fail_on_error=False, hidden=True) if res.exit_code != EasyBuildExit.SUCCESS: fail_msg = f"sanity check command {cmd} failed with exit code {res.exit_code} (output: {res.output})" self.sanity_check_fail_msgs.append(fail_msg) diff --git a/test/framework/toy_build.py b/test/framework/toy_build.py index b386ba550a..f218d40519 100644 --- a/test/framework/toy_build.py +++ b/test/framework/toy_build.py @@ -2373,6 +2373,8 @@ def test_toy_sanity_check_commands(self): test_easyconfigs = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'easyconfigs', 'test_ecs') toy_ec_txt = read_file(os.path.join(test_easyconfigs, 't', 'toy', 'toy-0.0.eb')) + out_file = os.path.join(self.test_prefix, 'out.txt') + toy_ec_txt = '\n'.join([ toy_ec_txt, "toolchain = {'name': 'foss', 'version': '2018a'}", @@ -2388,6 +2390,8 @@ def test_toy_sanity_check_commands(self): " True,", # test command to make sure that '-h' is not passed to commands specified as string ('env -h' fails) " 'env'," + # print current working directory, should *not* be software install directory, but empty dir + f" '(pwd && ls | wc -l) > {out_file}',", "]", ]) @@ -2412,6 +2416,13 @@ def test_toy_sanity_check_commands(self): self.assertExists(toy_modfile) + # check contents of output file created by sanity check commands + self.assertExists(out_file) + out_txt = read_file(out_file) + # working dir for sanity check command should be an empty custom temporary directory + regex = re.compile('^.*/eb-[^/]+/eb-sanity-check-[^/]+\n[ ]*0$') + self.assertTrue(regex.match(out_txt), f"Pattern '{regex.pattern}' should match in: {out_txt}") + def test_sanity_check_paths_lib64(self): """Test whether fallback in sanity check for lib64/ equivalents of library files works.""" test_ecs_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'easyconfigs')