Skip to content

Commit

Permalink
Merge branch 'use_mixin_class' of github.com:casparvl/test-suite into…
Browse files Browse the repository at this point in the history
… use_mixin_class
  • Loading branch information
Caspar van Leeuwen committed Oct 9, 2024
2 parents 38ffee1 + 2f6b33a commit 7e66d57
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
34 changes: 20 additions & 14 deletions eessi/testsuite/eessi_mixin.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
from reframe.core.builtins import variable, parameter, run_after
from reframe.core.exceptions import ReframeSyntaxError
from reframe.core.builtins import parameter, run_after
from reframe.core.exceptions import ReframeFatalError
from reframe.core.pipeline import RegressionMixin
from reframe.utility.sanity import make_performance_function

from eessi.testsuite import hooks
from eessi.testsuite.constants import DEVICE_TYPES, SCALES, COMPUTE_UNIT

from eessi.testsuite import __version__ as EESSI_TESTSUITE_VERSION


# Hooks from the Mixin class seem to be executed _before_ those of the child class
# Thus, if the Mixin class needs self.X to be defined in after setup, the child class would have to define it before
Expand All @@ -34,19 +32,23 @@ class EESSI_Mixin(RegressionMixin):
"""

# Current version of the EESSI test suite
eessi_testsuite_version = variable(str, value=EESSI_TESTSUITE_VERSION)

measure_memory_usage = False
# valid_prog_environs = ['default']
# valid_systems = ['*']
# time_limit = '30m'
scale = parameter(SCALES.keys())

# Note that the error for an empty parameter is a bit unclear for ReFrame 4.6.2, but that will hopefully improve
# see https://github.com/reframe-hpc/reframe/issues/3254
# If that improves: uncomment the following to force the user to set module_name
# module_name = parameter()

def __init_subclass__(cls, **kwargs):
" set default values for built-in ReFrame attributes "
super().__init_subclass__(**kwargs)
cls.valid_prog_environs = ['default']
cls.valid_systems = ['*']
if not cls.time_limit:
cls.time_limit = '1h'

# Helper function to validate if an attribute is present it item_dict.
# If not, print it's current name, value, and the valid_values
def validate_item_in_dict(self, item, item_dict, check_keys=False):
Expand All @@ -62,9 +64,11 @@ def validate_item_in_dict(self, item, item_dict, check_keys=False):

value = getattr(self, item)
if value not in valid_items:
valid_items_str = (', '.join("'" + item + "'" for item in valid_items))
msg = "The variable '%s' had value '%s', but the only valid values are %s" % (item, value, valid_items_str)
raise ReframeSyntaxError(msg)
if len(valid_items) == 1:
msg = f"The variable '{item}' has value {value}, but the only valid value is {valid_items[0]}"
else:
msg = f"The variable '{item}' has value {value}, but the only valid values are {valid_items}"
raise ReframeFatalError(msg)

# We have to make sure that these gets set in any test that inherits
# device_type = variable(str)
Expand All @@ -80,12 +84,14 @@ def validate_init(self):
if not hasattr(self, var):
msg = "The variable '%s' should be defined in any test class that inherits" % var
msg += " from EESSI_Mixin in the init phase (or earlier), but it wasn't"
raise ReframeSyntaxError(msg)
raise ReframeFatalError(msg)

# Check that the value for these variables is valid,
# i.e. exists in their respective dict from eessi.testsuite.constants
self.validate_item_in_dict('device_type', DEVICE_TYPES)
self.validate_item_in_dict('scale', SCALES, check_keys=True)
self.validate_item_in_dict('valid_systems', {'valid_systems': ['*']})
self.validate_item_in_dict('valid_prog_environs', {'valid_prog_environs': ['default']})

@run_after('init')
def run_after_init(self):
Expand Down Expand Up @@ -117,7 +123,7 @@ def validate_setup(self):
if not hasattr(self, var):
msg = "The variable '%s' should be defined in any test class that inherits" % var
msg += " from EESSI_Mixin in the setup phase (or earlier), but it wasn't"
raise ReframeSyntaxError(msg)
raise ReframeFatalError(msg)

# Check if mem_func was defined to compute the required memory per node as function of the number of
# tasks per node
Expand All @@ -126,7 +132,7 @@ def validate_setup(self):
msg += " from EESSI_Mixin in the setup phase (or earlier), but it wasn't. Note that this function"
msg += " can use self.num_tasks_per_node, as it will be called after that attribute"
msg += " has been set."
raise ReframeSyntaxError(msg)
raise ReframeFatalError(msg)

# Check that the value for these variables is valid
# i.e. exists in their respective dict from eessi.testsuite.constants
Expand Down
3 changes: 0 additions & 3 deletions eessi/testsuite/tests/apps/lammps/lammps.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@


class EESSI_LAMMPS_base(rfm.RunOnlyRegressionTest, EESSI_Mixin):
valid_prog_environs = ['default']
valid_systems = ['*']
time_limit = '30m'

device_type = parameter([DEVICE_TYPES[CPU], DEVICE_TYPES[GPU]])

# Parameterize over all modules that start with LAMMPS
Expand Down

0 comments on commit 7e66d57

Please sign in to comment.