summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/core/context.py
diff options
context:
space:
mode:
authorAníbal Limón <anibal.limon@linux.intel.com>2016-11-09 11:50:46 -0600
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-01-23 12:05:18 +0000
commit94cb20f20d1607702ff6668eeab81a39d0239bcb (patch)
treee010bb7e70ad315861a2f7b0534555b5c071579f /meta/lib/oeqa/core/context.py
parent90f4325dd5f24fa6e79764286a70e87bfa37a673 (diff)
downloadpoky-94cb20f20d1607702ff6668eeab81a39d0239bcb.tar.gz
oeqa/core/context: Add support of OETestContextExecutor
The OETestContextExecutor class supports to use oe-test for run core test component also is a base class for the other test components (runtime, sdk, selftest). Te principal functionality is to support cmdline parsing and execution of OETestContext, the test components could extend the common options to provide specific ones. The common options between test components are test data file, output log and test cases path's to scan. Also it initializes the logger to be passed to the whole OEQA framework. [YOCTO #10230] (From OE-Core rev: 039deafa5f2c8fab31b8373b39f8bc219377b893) Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com> Signed-off-by: Mariano Lopez <mariano.lopez@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oeqa/core/context.py')
-rw-r--r--meta/lib/oeqa/core/context.py85
1 files changed, 85 insertions, 0 deletions
diff --git a/meta/lib/oeqa/core/context.py b/meta/lib/oeqa/core/context.py
index cbab2f8f5f..ba6ccf8e79 100644
--- a/meta/lib/oeqa/core/context.py
+++ b/meta/lib/oeqa/core/context.py
@@ -146,3 +146,88 @@ class OETestContext(object):
146 else: 146 else:
147 self.logger.info("RESULTS - %s - Testcase %s: %s" % (case.id(), 147 self.logger.info("RESULTS - %s - Testcase %s: %s" % (case.id(),
148 oeid, 'PASSED')) 148 oeid, 'PASSED'))
149
150class OETestContextExecutor(object):
151 _context_class = OETestContext
152
153 name = 'core'
154 help = 'core test component example'
155 description = 'executes core test suite example'
156
157 default_cases = [os.path.join(os.path.abspath(os.path.dirname(__file__)),
158 'cases/example')]
159 default_test_data = os.path.join(default_cases[0], 'data.json')
160
161 def register_commands(self, logger, subparsers):
162 self.parser = subparsers.add_parser(self.name, help=self.help,
163 description=self.description, group='components')
164
165 self.default_output_log = '%s-results-%s.log' % (self.name,
166 time.strftime("%Y%m%d%H%M%S"))
167 self.parser.add_argument('--output-log', action='store',
168 default=self.default_output_log,
169 help="results output log, default: %s" % self.default_output_log)
170
171 if self.default_test_data:
172 self.parser.add_argument('--test-data-file', action='store',
173 default=self.default_test_data,
174 help="data file to load, default: %s" % self.default_test_data)
175 else:
176 self.parser.add_argument('--test-data-file', action='store',
177 help="data file to load")
178
179 if self.default_cases:
180 self.parser.add_argument('CASES_PATHS', action='store',
181 default=self.default_cases, nargs='*',
182 help="paths to directories with test cases, default: %s"\
183 % self.default_cases)
184 else:
185 self.parser.add_argument('CASES_PATHS', action='store',
186 nargs='+', help="paths to directories with test cases")
187
188 self.parser.set_defaults(func=self.run)
189
190 def _setup_logger(self, logger, args):
191 formatter = logging.Formatter('%(asctime)s - ' + self.name + \
192 ' - %(levelname)s - %(message)s')
193 sh = logger.handlers[0]
194 sh.setFormatter(formatter)
195 fh = logging.FileHandler(args.output_log)
196 fh.setFormatter(formatter)
197 logger.addHandler(fh)
198
199 return logger
200
201 def _process_args(self, logger, args):
202 self.tc_kwargs = {}
203 self.tc_kwargs['init'] = {}
204 self.tc_kwargs['load'] = {}
205 self.tc_kwargs['run'] = {}
206
207 self.tc_kwargs['init']['logger'] = self._setup_logger(logger, args)
208 if args.test_data_file:
209 self.tc_kwargs['init']['td'] = json.load(
210 open(args.test_data_file, "r"))
211 else:
212 self.tc_kwargs['init']['td'] = {}
213
214 self.module_paths = args.CASES_PATHS
215
216 def run(self, logger, args):
217 self._process_args(logger, args)
218
219 self.tc = self._context_class(**self.tc_kwargs['init'])
220 self.tc.loadTests(self.module_paths, **self.tc_kwargs['load'])
221 rc = self.tc.runTests(**self.tc_kwargs['run'])
222 self.tc.logSummary(rc, self.name)
223 self.tc.logDetails()
224
225 output_link = os.path.join(os.path.dirname(args.output_log),
226 "%s-results.log" % self.name)
227 if os.path.exists(output_link):
228 os.remove(output_link)
229 os.symlink(args.output_log, output_link)
230
231 return rc
232
233_executor_class = OETestContextExecutor