From df15a12bbd7f5b9cdc798c3a4a952f1d0c50a46d Mon Sep 17 00:00:00 2001 From: Patrick Bellasi Date: Fri, 26 Feb 2016 14:38:01 +0000 Subject: [PATCH 1/3] libs/utils/test: fix multiple run of the executor Tests executions and data collection is driven by the Executor module which should be executed just one time to run all the experiments required by the following tests. The current implementation of LisaTest creates the Executor object and run its from within the ctor method of the base class. This ctor is called by nosetests before each test runs. This imply that we currently run data collection multiple times. This patch fixes this issue by switching to the usage of the setUpClass class method, which is granted to be called just one time by nosetest. This mehod is used in each test to call the LisaTest::_init() method which is now the one in charge to initialized and execute tests. Signed-off-by: Patrick Bellasi --- libs/utils/test.py | 10 ++++++---- tests/eas/rfc.py | 5 +++-- tests/sfreq/smoke_test.py | 5 +++-- tests/stune/smoke_test_ramp.py | 5 +++-- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/libs/utils/test.py b/libs/utils/test.py index f616d2ada..8366bdb09 100644 --- a/libs/utils/test.py +++ b/libs/utils/test.py @@ -25,7 +25,8 @@ from executor import Executor class LisaTest(unittest.TestCase): """A base class for LISA defined tests""" - def __init__(self, conf_file, *args, **kwargs): + @classmethod + def _init(self, conf_file, *args, **kwargs): """ Base class to run LISA test experiments """ @@ -36,7 +37,6 @@ class LisaTest(unittest.TestCase): self.logger.setLevel(kwargs['loglevel']) kwargs.pop('loglevel') - self.conf_file = conf_file self.logger.info("%14s - Using configuration:", "LisaTest") @@ -50,10 +50,9 @@ class LisaTest(unittest.TestCase): self.logger.debug("%14s - Checking tests configuration...", "LisaTest") self._checkConf() - super(LisaTest, self).__init__(*args, **kwargs) - self._runExperiments() + @classmethod def _runExperiments(self): """ Default experiments execution engine @@ -75,6 +74,7 @@ class LisaTest(unittest.TestCase): # Execute post-experiments code defined by the test self._experimentsFinalize() + @classmethod def _checkConf(self): """ Check for mandatory configuration options @@ -88,11 +88,13 @@ class LisaTest(unittest.TestCase): assert self.conf['wloads'], \ "Configuration file with empty set of workloads ('wloads' attribute)" + @classmethod def _experimentsInit(self): """ Code executed before running the experiments """ + @classmethod def _experimentsFinalize(self): """ Code executed after running the experiments diff --git a/tests/eas/rfc.py b/tests/eas/rfc.py index 9a8ceab0a..84d99a0f7 100644 --- a/tests/eas/rfc.py +++ b/tests/eas/rfc.py @@ -26,8 +26,9 @@ TESTS_CONF = os.path.join(TESTS_DIRECTORY, "rfc.config") class RFC(LisaTest): """Tests for the Energy-Aware Scheduler""" - def __init__(self, *args, **kwargs): - super(RFC, self).__init__(TESTS_CONF, *args, **kwargs) + @classmethod + def setUpClass(cls, *args, **kwargs): + super(RFC, cls)._init(TESTS_CONF, args, kwargs) def test_energy_regression(self): """Check that there is not regression on energy""" diff --git a/tests/sfreq/smoke_test.py b/tests/sfreq/smoke_test.py index 02531df6e..a6cc83cce 100644 --- a/tests/sfreq/smoke_test.py +++ b/tests/sfreq/smoke_test.py @@ -26,8 +26,9 @@ TESTS_CONF = os.path.join(TESTS_DIRECTORY, "smoke_test.config") class SFreq(LisaTest): """Tests for SchedFreq framework""" - def __init__(self, *args, **kwargs): - super(SFreq, self).__init__(TESTS_CONF, *args, **kwargs) + @classmethod + def setUpClass(cls, *args, **kwargs): + super(SFreq, cls)._init(TESTS_CONF, *args, **kwargs) def test_regression(self): """Check that there is not regression on energy""" diff --git a/tests/stune/smoke_test_ramp.py b/tests/stune/smoke_test_ramp.py index e7a9d9eb3..62385612d 100644 --- a/tests/stune/smoke_test_ramp.py +++ b/tests/stune/smoke_test_ramp.py @@ -29,8 +29,9 @@ TESTS_CONF = os.path.join(TESTS_DIRECTORY, "smoke_test_ramp.config") class STune(LisaTest): """Tests for SchedTune framework""" - def __init__(self, *args, **kwargs): - super(STune, self).__init__(TESTS_CONF, *args, **kwargs) + @classmethod + def setUpClass(cls, *args, **kwargs): + super(STune, cls)._init(TESTS_CONF, *args, **kwargs) def test_boosted_utilization_signal(self): """The boosted utilization signal is appropriately boosted -- GitLab From 19af1b636016d16cda1b117fb6393b86f35e2274 Mon Sep 17 00:00:00 2001 From: Patrick Bellasi Date: Fri, 26 Feb 2016 14:39:38 +0000 Subject: [PATCH 2/3] libs/utils/test: use cls instead of self for class methods Signed-off-by: Patrick Bellasi --- libs/utils/test.py | 60 +++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/libs/utils/test.py b/libs/utils/test.py index 8366bdb09..a0c101f53 100644 --- a/libs/utils/test.py +++ b/libs/utils/test.py @@ -26,76 +26,76 @@ class LisaTest(unittest.TestCase): """A base class for LISA defined tests""" @classmethod - def _init(self, conf_file, *args, **kwargs): + def _init(cls, conf_file, *args, **kwargs): """ Base class to run LISA test experiments """ - self.logger = logging.getLogger('test') - self.logger.setLevel(logging.INFO) + cls.logger = logging.getLogger('test') + cls.logger.setLevel(logging.INFO) if 'loglevel' in kwargs: - self.logger.setLevel(kwargs['loglevel']) + cls.logger.setLevel(kwargs['loglevel']) kwargs.pop('loglevel') - self.conf_file = conf_file - self.logger.info("%14s - Using configuration:", + cls.conf_file = conf_file + cls.logger.info("%14s - Using configuration:", "LisaTest") - self.logger.info("%14s - %s", - "LisaTest", self.conf_file) + cls.logger.info("%14s - %s", + "LisaTest", cls.conf_file) - self.logger.debug("%14s - Load test specific configuration...", "LisaTest") - json_conf = JsonConf(self.conf_file) - self.conf = json_conf.load() + cls.logger.debug("%14s - Load test specific configuration...", "LisaTest") + json_conf = JsonConf(cls.conf_file) + cls.conf = json_conf.load() - self.logger.debug("%14s - Checking tests configuration...", "LisaTest") - self._checkConf() + cls.logger.debug("%14s - Checking tests configuration...", "LisaTest") + cls._checkConf() - self._runExperiments() + cls._runExperiments() @classmethod - def _runExperiments(self): + def _runExperiments(cls): """ Default experiments execution engine """ - self.logger.info("%14s - Setup tests execution engine...", "LisaTest") - self.executor = Executor(tests_conf = self.conf_file) + cls.logger.info("%14s - Setup tests execution engine...", "LisaTest") + cls.executor = Executor(tests_conf = cls.conf_file); # Alias executor objects to make less verbose tests code - self.te = self.executor.te - self.target = self.executor.target + cls.te = cls.executor.te + cls.target = cls.executor.target # Execute pre-experiments code defined by the test - self._experimentsInit() + cls._experimentsInit() - self.logger.info("%14s - Experiments execution...", "LisaTest") - self.executor.run() + cls.logger.info("%14s - Experiments execution...", "LisaTest") + cls.executor.run() # Execute post-experiments code defined by the test - self._experimentsFinalize() + cls._experimentsFinalize() @classmethod - def _checkConf(self): + def _checkConf(cls): """ Check for mandatory configuration options """ - assert 'confs' in self.conf, \ + assert 'confs' in cls.conf, \ "Configuration file missing target configurations ('confs' attribute)" - assert self.conf['confs'], \ + assert cls.conf['confs'], \ "Configuration file with empty set of target configurations ('confs' attribute)" - assert 'wloads' in self.conf, \ + assert 'wloads' in cls.conf, \ "Configuration file missing workload configurations ('wloads' attribute)" - assert self.conf['wloads'], \ + assert cls.conf['wloads'], \ "Configuration file with empty set of workloads ('wloads' attribute)" @classmethod - def _experimentsInit(self): + def _experimentsInit(cls): """ Code executed before running the experiments """ @classmethod - def _experimentsFinalize(self): + def _experimentsFinalize(cls): """ Code executed after running the experiments """ -- GitLab From 293aba12c7b69a2e9ba7808e7869c4692725b559 Mon Sep 17 00:00:00 2001 From: Patrick Bellasi Date: Fri, 26 Feb 2016 14:40:49 +0000 Subject: [PATCH 3/3] libs/utils/executor: add footer line after a test complete This allows to better distinguish the end of the last iteration of a workload execution from the configuration of the next workload. Signed-off-by: Patrick Bellasi --- libs/utils/executor.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libs/utils/executor.py b/libs/utils/executor.py index 1f7a4c11e..103c459cc 100644 --- a/libs/utils/executor.py +++ b/libs/utils/executor.py @@ -545,6 +545,8 @@ class Executor(): logging.info(r'%14s - %s', 'Executor', stats_file.replace(self.te.res_dir, '')) + self._print_footer('Executor') + ################################################################################ # Utility Functions ################################################################################ @@ -564,6 +566,11 @@ class Executor(): logging.info(FMT_TITLE) logging.info(r'%14s - %s', tag, message) + def _print_footer(self, tag, message=None): + if message: + logging.info(r'%14s - %s', tag, message) + logging.info(FMT_FOOTER) + ################################################################################ # Globals @@ -582,5 +589,6 @@ TGT_RUN_DIR = 'run_dir' FMT_SECTION = r'{:#<80}'.format('') FMT_HEADER = r'{:=<80}'.format('') FMT_TITLE = r'{:~<80}'.format('') +FMT_FOOTER = r'{:-<80}'.format('') # vim :set tabstop=4 shiftwidth=4 expandtab -- GitLab