From eacef7fe3643afab7a419ffdbc7929f2c3d00014 Mon Sep 17 00:00:00 2001 From: Vasileios Karakasis Date: Sat, 13 Nov 2021 21:06:40 +0100 Subject: [PATCH 1/4] Add a utility function to skip tests that have no topology information --- reframe/core/pipeline.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/reframe/core/pipeline.py b/reframe/core/pipeline.py index 8a3e70deeb..920f9ee9f5 100644 --- a/reframe/core/pipeline.py +++ b/reframe/core/pipeline.py @@ -2203,6 +2203,24 @@ def skip_if(self, cond, msg=None): if cond: self.skip(msg) + def skip_if_no_procinfo(self, msg=None): + '''Skip test if no processor topology information is available. + + This method has effect only if called after the ``setup`` stage. + + :arg msg: A message explaining why the test was skipped. + If not specified, a default message will be used. + + .. versionadded:: 3.9.1 + ''' + if not self.current_partition: + return + + proc = self.current_partition.processor + pname = self.current_partition.fullname + self.skip_if(not proc.info, + f'no topology information found for partition {pname!r}') + def __str__(self): return "%s(name='%s', prefix='%s')" % (type(self).__name__, self.name, self.prefix) From 281073a7773d5aff44c12689aab496a84531e0e9 Mon Sep 17 00:00:00 2001 From: Vasileios Karakasis Date: Sat, 13 Nov 2021 21:10:39 +0100 Subject: [PATCH 2/4] Fix PEP8 issues --- reframe/core/pipeline.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/reframe/core/pipeline.py b/reframe/core/pipeline.py index 920f9ee9f5..0e7b3754b5 100644 --- a/reframe/core/pipeline.py +++ b/reframe/core/pipeline.py @@ -2216,10 +2216,10 @@ def skip_if_no_procinfo(self, msg=None): if not self.current_partition: return - proc = self.current_partition.processor - pname = self.current_partition.fullname - self.skip_if(not proc.info, - f'no topology information found for partition {pname!r}') + proc = self.current_partition.processor + pname = self.current_partition.fullname + self.skip_if(not proc.info, + f'no topology information found for partition {pname!r}') def __str__(self): return "%s(name='%s', prefix='%s')" % (type(self).__name__, From eb6769320c1cabc23e589416e25aea141d4588dd Mon Sep 17 00:00:00 2001 From: Vasileios Karakasis Date: Sat, 13 Nov 2021 21:55:57 +0100 Subject: [PATCH 3/4] Add unit test --- unittests/test_pipeline.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/unittests/test_pipeline.py b/unittests/test_pipeline.py index fa5942aa38..74e4515916 100644 --- a/unittests/test_pipeline.py +++ b/unittests/test_pipeline.py @@ -17,7 +17,7 @@ from reframe.core.containers import _STAGEDIR_MOUNT from reframe.core.exceptions import (BuildError, PipelineError, ReframeError, PerformanceError, SanityError, - ReframeSyntaxError) + SkipTestError, ReframeSyntaxError) def _run(test, partition, prgenv): @@ -1455,3 +1455,27 @@ def test_not_configured_container_platform(container_test, local_exec_ctx): with pytest.raises(PipelineError): _run(container_test(platform, 'ubuntu:18.04'), *local_exec_ctx) + + +def test_skip_if_no_topo(HelloTest, local_exec_ctx): + class MyTest(HelloTest): + @run_after('setup') + def access_topo(self): + self.skip_if_no_procinfo() + + class EchoTest(rfm.RunOnlyRegressionTest): + valid_systems = ['*'] + valid_prog_environs = ['*'] + executable = 'echo' + sanity_patterns = sn.assert_true(1) + + @run_before('setup') + def access_topo(self): + self.skip_if_no_procinfo() + + # The test should be skipped, because the auto-detection has not run + with pytest.raises(SkipTestError, match='no topology.*information'): + _run(MyTest(), *local_exec_ctx) + + # This test should run to completion without problems + _run(EchoTest(), *local_exec_ctx) From 01a9aea1abd9c082ca7d08b2b7ddf049db7bab8e Mon Sep 17 00:00:00 2001 From: Vasileios Karakasis Date: Mon, 15 Nov 2021 17:56:18 +0100 Subject: [PATCH 4/4] Address PR comments --- reframe/core/pipeline.py | 6 ++++-- unittests/test_pipeline.py | 12 ++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/reframe/core/pipeline.py b/reframe/core/pipeline.py index 0e7b3754b5..f29f2161b6 100644 --- a/reframe/core/pipeline.py +++ b/reframe/core/pipeline.py @@ -2218,8 +2218,10 @@ def skip_if_no_procinfo(self, msg=None): proc = self.current_partition.processor pname = self.current_partition.fullname - self.skip_if(not proc.info, - f'no topology information found for partition {pname!r}') + if msg is None: + msg = f'no topology information found for partition {pname!r}' + + self.skip_if(not proc.info, msg) def __str__(self): return "%s(name='%s', prefix='%s')" % (type(self).__name__, diff --git a/unittests/test_pipeline.py b/unittests/test_pipeline.py index 74e4515916..f483ecad5c 100644 --- a/unittests/test_pipeline.py +++ b/unittests/test_pipeline.py @@ -1459,9 +1459,11 @@ def test_not_configured_container_platform(container_test, local_exec_ctx): def test_skip_if_no_topo(HelloTest, local_exec_ctx): class MyTest(HelloTest): + skip_message = variable(str, type(None), value=None) + @run_after('setup') def access_topo(self): - self.skip_if_no_procinfo() + self.skip_if_no_procinfo(self.skip_message) class EchoTest(rfm.RunOnlyRegressionTest): valid_systems = ['*'] @@ -1474,8 +1476,14 @@ def access_topo(self): self.skip_if_no_procinfo() # The test should be skipped, because the auto-detection has not run + t = MyTest() with pytest.raises(SkipTestError, match='no topology.*information'): - _run(MyTest(), *local_exec_ctx) + _run(t, *local_exec_ctx) + + # Re-run to test that the custom message is used + t.skip_message = 'custom message' + with pytest.raises(SkipTestError, match='custom message'): + _run(t, *local_exec_ctx) # This test should run to completion without problems _run(EchoTest(), *local_exec_ctx)