From 8d24c9de22ca30ceecf630643ce06e706415b273 Mon Sep 17 00:00:00 2001 From: Patrick Bellasi Date: Thu, 15 Dec 2016 12:28:55 +0000 Subject: [PATCH] wlgen/rtapp: fix loading of custom JSON When 'kind=custom' the 'params' parameter must be used to specify the full path of a JSON file to be used for the rt-app confiuration. This feature is currently broken because we anticipate in the rtapp::conf() method some checks required only by the "profile" kind. This patch fixes this issue and improve some sanity checks on the values of the specified parameters. Signed-off-by: Patrick Bellasi --- libs/wlgen/wlgen/rta.py | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/libs/wlgen/wlgen/rta.py b/libs/wlgen/wlgen/rta.py index e779e8345..ceaa8b6fc 100644 --- a/libs/wlgen/wlgen/rta.py +++ b/libs/wlgen/wlgen/rta.py @@ -256,15 +256,26 @@ class RTA(Workload): def _confCustom(self): + rtapp_conf = self.params['custom'] + + # Sanity check params being a valid file path + if not isinstance(rtapp_conf, str) or \ + not os.path.isfile(rtapp_conf): + self._log.debug('Checking for %s', rtapp_conf) + raise ValueError('value specified for \'params\' is not ' + 'a valid rt-app JSON configuration file') + if self.duration is None: raise ValueError('Workload duration not specified') target_cpu = self.getTargetCpu(self.loadref) calibration = self.getCalibrationConf(target_cpu) + self._log.info('Loading custom configuration:') + self._log.info(' %s', rtapp_conf) self.json = '{0:s}_{1:02d}.json'.format(self.name, self.exc_id) ofile = open(self.json, 'w') - ifile = open(self.params['custom'], 'r') + ifile = open(rtapp_conf, 'r') replacements = { '__DURATION__' : str(self.duration), '__PVALUE__' : str(calibration), @@ -283,6 +294,15 @@ class RTA(Workload): def _confProfile(self): + # Sanity check for task names + for task in self.params.keys(): + if len(task) > 15: + # rt-app uses pthread_setname_np(3) which limits the task name + # to 16 characters including the terminal '\0'. + msg = ('Task name "{}" too long, please configure your tasks ' + 'with names shorter than 16 characters').format(task) + raise ValueError(msg) + # Task configuration target_cpu = self.getTargetCpu(self.loadref) self.rta_profile = { @@ -462,12 +482,12 @@ class RTA(Workload): The rt-app based workload allows to define different classes of workloads. The classes supported so far are detailed hereafter. - Periodic workloads - ------------------ - - Custom workloads ---------------- + When 'kind' is 'custom' the tasks generated by this workload are the + ones defined in a provided rt-app JSON configuration file. + In this case the 'params' parameter must be used to specify the + complete path of the rt-app JSON configuration file to use. Profile based workloads @@ -491,14 +511,6 @@ class RTA(Workload): """ - for task in params.keys(): - if len(task) > 15: - # rt-app uses pthread_setname_np(3) which limits the task name - # to 16 characters including the terminal '\0'. - msg = ('Task name "{}" too long, please configure your tasks ' - 'with names shorter than 16 characters').format(task) - raise ValueError(msg) - if not sched: sched = {'policy' : 'OTHER'} -- GitLab