summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/core
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib/oeqa/core')
-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