Skip to content

817 automatically perform module purge before building tests #834

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

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions lib/pavilion/scriptcomposer.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ def module_change(self, module, sys_vars, config_wrappers):

self.env_change(mod_env)

def module_purge(self) -> None:
"""Add a module purge to the script."""

self._script_lines.extend([
"# Check whether the module command exists",
"if declare -F module; then",
"\tmodule purge",
"fi"
])

def newline(self):
"""Function that just adds a newline to the script lines."""
# This will create a blank line with just a newline.
Expand Down
10 changes: 10 additions & 0 deletions lib/pavilion/test_config/file_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,11 @@ class TestConfigLoader(yc.YamlConfigLoader):
help_text='If True, test will fail if any of its build '
'commands fail, rather than just the last '
'command.'),
yc.StrElem(
'purge_modules', choices=["true", "false", "True", "False"],
default="True",
help_text="Whether or not to perform a module purge "
"before building."),
],
help_text="The test build configuration. This will be "
"used to dynamically generate a build script for "
Expand Down Expand Up @@ -835,6 +840,11 @@ class TestConfigLoader(yc.YamlConfigLoader):
'but may vary. '
'(In particular, the \'raw\' scheduler has a much higher limit.) '
'Tests that use MPI should use this cautiously.'),
yc.StrElem(
'purge_modules', choices=["true", "false", "True", "False"],
default="True",
help_text="Whether or not to perform a module purge "
"before running."),
],
help_text="The test run configuration. This will be used "
"to dynamically generate a run script for the "
Expand Down
9 changes: 9 additions & 0 deletions lib/pavilion/test_run/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,16 @@ def _write_script(self, stype: str, path: Path, config: dict, module_wrappers: d
script.comment('To be built in an allocation.')

script.command(f'echo "(pav) Setting up {stype} environment."')

purge = utils.str_bool(config.get("purge_modules"))

if purge:
script.newline()
script.comment("Start with a fresh environment")
script.module_purge()

modules = config.get('modules', [])

if modules:
script.newline()
script.comment('Perform module related changes to the environment.')
Expand Down
6 changes: 5 additions & 1 deletion lib/pavilion/unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,14 +313,15 @@ def _load_test(self, name: str, platform: str = 'this', host: str = 'this',
del __config_lines

def _quick_test(self, cfg=None, name="quick_test",
build=True, finalize=True):
build=True, finalize=True, purge=True):
"""Create a test run object to work with.
The default is a simple hello world test with the raw scheduler.

:param dict cfg: An optional config dict to create the test from.
:param str name: The name of the test.
:param bool build: Build this test, while we're at it.
:param bool finalize: Finalize this test.
:param bool purge: Perform a module purge before building/running
:rtype: TestRun
"""

Expand All @@ -329,6 +330,9 @@ def _quick_test(self, cfg=None, name="quick_test",

cfg = copy.deepcopy(cfg)

cfg["build"]["purge_modules"] = str(purge)
cfg["run"]["purge_modules"] = str(purge)

loader = TestConfigLoader()
cfg = loader.validate(loader.normalize(cfg))

Expand Down
2 changes: 1 addition & 1 deletion test/tests/log_cmd_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_log_arguments(self):
log_cmd._setup_arguments(parser)

# run a simple test
test = self._quick_test(finalize=False)
test = self._quick_test(finalize=False, purge=False)
raw = schedulers.get_plugin('raw')

raw.schedule_tests(self.pav_cfg, [test])
Expand Down
58 changes: 58 additions & 0 deletions test/tests/mod_wrapper_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,61 @@ def check_test(ctest, expected_lines):
'module swap $old_module gcc/1.2.8',
])

@unittest.skipIf(not has_module_cmd() and find_module_init() is None,
"Could not find a module system.")
def test_run_module_purge(self):
"""Test that a module purge is performed when running tests."""

# Test that a module purge is performed by default
test_cfg = self._quick_test_cfg()
test_cfg['run']['cmds'] = [
'[[ $(module -t list 2>&1) = "No modules loaded" ]] || exit 1',
]
test_cfg['run']['preamble'].append('module load test_mod1 || exit 2')

test = self._quick_test(test_cfg)

run_result = test.run()

self.assertEqual(run_result, 0)

# Check that we can disable purging
test_cfg = self._quick_test_cfg()
test_cfg['run']['cmds'] = [
'[[ $(module -t list 2>&1) = "No modules loaded" ]] || exit 1',
]
test_cfg['run']['preamble'].append('module load test_mod1 || exit 2')
test_cfg["run"]["purge_modules"] = False
test = self._quick_test(test_cfg)
run_result = test.run()

self.assertEqual(run_result, 1)

@unittest.skipIf(not has_module_cmd() and find_module_init() is None,
"Could not find a module system.")
def test_build_module_purge(self):
"""Test that a module purge is performed when building tests."""

# Test that a module purge is performed by default
test_cfg = self._quick_test_cfg()
test_cfg['build']['cmds'] = [
'[[ $(module -t list 2>&1) = "No modules loaded" ]] || exit 1',
]
test_cfg['run']['preamble'].append('module load test_mod1 || exit 2')

test = self._quick_test(test_cfg, build=False)
build_result = test.build()

self.assertEqual(build_result, True)

# Check that we can disable purging
test_cfg = self._quick_test_cfg()
test_cfg['build']['cmds'] = [
'[[ $(module -t list 2>&1) = "No modules loaded" ]] || exit 1',
]
test_cfg['build']['preamble'] = ['module load test_mod1 || exit 2']
test_cfg["build"]["purge_modules"] = False
test = self._quick_test(test_cfg, build=False)
build_result = test.build()

self.assertEqual(build_result, False)
Loading