Skip to content
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
24 changes: 19 additions & 5 deletions easybuild/framework/easyblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -4668,14 +4668,28 @@ def test_cases_step(self):
test_cmd = os.path.join(source_path, self.name, test)
if os.path.exists(test_cmd):
break
if not os.path.exists(test_cmd):
raise EasyBuildError(f"Test specifies invalid path: {test_cmd}")

else:
test_cmd = test
if not os.path.exists(test_cmd):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving this check changes the logic: if test was a relative command, we now require that it specified an existing path, but that wasn't the case before.

This seems to lead to trouble with PyTorch (when forcing test_cases step to run when using --module-only):

Test specifies non-existing path: PyTorch-check-cpp-extension.py

I don't think we should be requiring that the file exists if it's a relative path?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be the case before. Previously it did not require the path to exist if it was absolute as the check was only in the else-branch which seemed wrong

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue was unrelated: The PyTorch easyblock has special handling to use obtain_file in the fetch_step resolving this path.
When skipping that step the file will not be found.

Fix for that in #5162

raise EasyBuildError(f"Test specifies non-existing path: {test_cmd}")

if os.path.isfile(test_cmd):
original_perms = os.lstat(test_cmd).st_mode
if original_perms & stat.S_IEXEC:
original_perms = None
else:
adjust_permissions(test_cmd, stat.S_IEXEC, add=True, recursive=False)
else:
original_perms = None
try:
self.log.debug(f"Running test {test_cmd}")
run_shell_cmd(test_cmd)
except EasyBuildError as err:
except RunShellCmdError:
raise # Let that propagate which will report more information
except Exception as err:
raise EasyBuildError(f"Running test {test_cmd} failed: {err}")
finally:
if original_perms is not None:
adjust_permissions(test_cmd, original_perms, relative=False)

def update_config_template_run_step(self):
"""Update the the easyconfig template dictionary with easyconfig.TEMPLATE_NAMES_EASYBLOCK_RUN_STEP names"""
Expand Down
2 changes: 1 addition & 1 deletion easybuild/tools/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
"""


class RunShellCmdError(BaseException):
class RunShellCmdError(Exception):

def __init__(self, cmd_result, caller_info, *args, **kwargs):
"""Constructor for RunShellCmdError."""
Expand Down
68 changes: 66 additions & 2 deletions test/framework/easyblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import os
import re
import shutil
import stat
import sys
import tempfile
import textwrap
Expand All @@ -52,10 +53,11 @@
from easybuild.tools import LooseVersion, config
from easybuild.tools.build_log import EasyBuildError
from easybuild.tools.config import get_module_syntax, update_build_option
from easybuild.tools.filetools import change_dir, copy_dir, copy_file, mkdir, read_file, remove_dir, remove_file
from easybuild.tools.filetools import symlink, verify_checksum, write_file
from easybuild.tools.filetools import adjust_permissions, change_dir, copy_dir, copy_file, mkdir, read_file
from easybuild.tools.filetools import remove_dir, remove_file, symlink, verify_checksum, write_file
from easybuild.tools.module_generator import module_generator
from easybuild.tools.modules import EnvironmentModules, Lmod, reset_module_caches
from easybuild.tools.run import RunShellCmdError
from easybuild.tools.version import get_git_revision, this_is_easybuild


Expand Down Expand Up @@ -1271,6 +1273,68 @@ def test_handle_iterate_opts(self):
self.assertEqual(eb.cfg.iterating, False)
self.assertEqual(eb.cfg['configopts'], ["--opt1 --anotheropt", "--opt2", "--opt3 --optbis"])

def test_test_cases_step(self):
"""Test test_cases_step"""
self.contents = '\n'.join([
'easyblock = "ConfigureMake"',
'name = "pi"',
'version = "3.14"',
'homepage = "http://example.com"',
'description = "test easyconfig"',
"toolchain = {'name': 'gompi', 'version': '2018a'}",
])
self.writeEC()
eb = EasyBlock(EasyConfig(self.eb_file))
eb.cfg['tests'] = ['does-not-exist']
self.assertRaisesRegex(EasyBuildError, 'non-existing path: does-not-exist', eb.test_cases_step)
eb.cfg['tests'] = ['/abs/path/does-not-exist']
self.assertRaisesRegex(EasyBuildError, 'non-existing path: /abs/path/does-not-exist', eb.test_cases_step)

mock_test_bin = os.path.join(self.test_prefix, 'pi', 'test_me')
os.environ['PATH'] += f':{os.path.dirname(mock_test_bin)}'
write_file(mock_test_bin, "#!/bin/bash\necho 'Test case success'")

adjust_permissions(mock_test_bin, stat.S_IXUSR)
eb.cfg['tests'] = [os.path.basename(mock_test_bin)]
fn = os.path.basename(mock_test_bin)
self.assertRaisesRegex(EasyBuildError, f'non-existing path: {fn}', eb.test_cases_step)

init_config(args=[f"--sourcepath={self.test_prefix}"])
write_file(eb.logfile, '')
eb.test_cases_step()
self.assertIn('Test case success', read_file(eb.logfile))

# Also works with non-executable file
perms = stat.S_IREAD
adjust_permissions(mock_test_bin, perms, relative=False)
eb.cfg['tests'] = [os.path.basename(mock_test_bin)]
write_file(eb.logfile, '')
eb.test_cases_step()
self.assertEqual(stat.S_IMODE(os.lstat(mock_test_bin).st_mode), perms) # Permissions unchanged
self.assertIn('Test case success', read_file(eb.logfile))

# Similar for absolute paths
eb.cfg['tests'] = [mock_test_bin]
write_file(eb.logfile, '')
eb.test_cases_step()
self.assertIn('Test case success', read_file(eb.logfile))

# Detect failure
mock_test_bin_fail = mock_test_bin + "_fail"
write_file(mock_test_bin_fail, "#!/bin/bash\necho 'Test case failure' && exit 1")
eb.cfg['tests'] = [mock_test_bin_fail]
write_file(eb.logfile, '')
self.assertRaisesRegex(RunShellCmdError, f"'{os.path.basename(mock_test_bin_fail)}' failed", eb.test_cases_step)
self.assertIn('Test case failure', read_file(eb.logfile))

# Multiple tests
eb.cfg['tests'] = [mock_test_bin, mock_test_bin_fail]
write_file(eb.logfile, '')
self.assertRaisesRegex(RunShellCmdError, f"'{os.path.basename(mock_test_bin_fail)}' failed", eb.test_cases_step)
log_txt = read_file(eb.logfile)
self.assertIn('Test case success', log_txt)
self.assertIn('Test case failure', log_txt)

def test_post_processing_step(self):
"""Test post_processing_step and deprecated post_install_step."""
init_config(build_options={'silent': True})
Expand Down
Loading