Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run sanity checks commands from an empty temporary directory (rather than the software install directory) #4723

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions easybuild/framework/easyblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_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, 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)
Expand Down Expand Up @@ -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):
"""
Expand Down
11 changes: 11 additions & 0 deletions test/framework/toy_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'}",
Expand All @@ -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}',",
"]",
])

Expand All @@ -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')
Expand Down
Loading