blob: f7171260e741432d5843b14ddc6f794a0f0ae620 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# Copyright (C) 2013 Intel Corporation
2#
3# Released under the MIT license (see COPYING.MIT)
4
5# Main unittest module used by testimage.bbclass
6# This provides the oeRuntimeTest base class which is inherited by all tests in meta/lib/oeqa/runtime.
7
8# It also has some helper functions and it's responsible for actually starting the tests
9
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050010import os, re, mmap, sys
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011import unittest
12import inspect
13import subprocess
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050014import signal
Patrick Williamsc0f7c042017-02-23 20:41:17 -060015import shutil
16import functools
Patrick Williamsf1e5d692016-03-30 15:21:19 -050017try:
18 import bb
19except ImportError:
20 pass
21import logging
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050022
23import oeqa.runtime
24# Exported test doesn't require sdkext
25try:
26 import oeqa.sdkext
27except ImportError:
28 pass
Patrick Williamsf1e5d692016-03-30 15:21:19 -050029from oeqa.utils.decorators import LogResults, gettag, getResults
30
31logger = logging.getLogger("BitBake")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050032
33def getVar(obj):
34 #extend form dict, if a variable didn't exists, need find it in testcase
35 class VarDict(dict):
36 def __getitem__(self, key):
37 return gettag(obj, key)
38 return VarDict()
39
40def checkTags(tc, tagexp):
41 return eval(tagexp, None, getVar(tc))
42
Patrick Williamsc124f4f2015-09-15 14:41:29 -050043def filterByTagExp(testsuite, tagexp):
44 if not tagexp:
45 return testsuite
46 caseList = []
47 for each in testsuite:
48 if not isinstance(each, unittest.BaseTestSuite):
49 if checkTags(each, tagexp):
50 caseList.append(each)
51 else:
52 caseList.append(filterByTagExp(each, tagexp))
53 return testsuite.__class__(caseList)
54
Patrick Williamsc124f4f2015-09-15 14:41:29 -050055@LogResults
56class oeTest(unittest.TestCase):
57
Patrick Williamsc0f7c042017-02-23 20:41:17 -060058 pscmd = "ps"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050059 longMessage = True
60
61 @classmethod
62 def hasPackage(self, pkg):
Patrick Williamsc0f7c042017-02-23 20:41:17 -060063 """
64 True if the full package name exists in the manifest, False otherwise.
65 """
66 return pkg in oeTest.tc.pkgmanifest
67
68 @classmethod
69 def hasPackageMatch(self, match):
70 """
71 True if match exists in the manifest as a regular expression substring,
72 False otherwise.
73 """
74 for s in oeTest.tc.pkgmanifest:
75 if re.match(match, s):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050076 return True
77 return False
78
79 @classmethod
80 def hasFeature(self,feature):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050081 if feature in oeTest.tc.imagefeatures or \
82 feature in oeTest.tc.distrofeatures:
83 return True
84 else:
85 return False
86
87class oeRuntimeTest(oeTest):
88 def __init__(self, methodName='runTest'):
89 self.target = oeRuntimeTest.tc.target
90 super(oeRuntimeTest, self).__init__(methodName)
91
92 def setUp(self):
Patrick Williamsc0f7c042017-02-23 20:41:17 -060093 # Install packages in the DUT
94 self.tc.install_uninstall_packages(self.id())
95
Patrick Williamsc124f4f2015-09-15 14:41:29 -050096 # Check if test needs to run
97 if self.tc.sigterm:
98 self.fail("Got SIGTERM")
99 elif (type(self.target).__name__ == "QemuTarget"):
100 self.assertTrue(self.target.check(), msg = "Qemu not running?")
101
Patrick Williamsd7e96312015-09-22 08:09:05 -0500102 self.setUpLocal()
103
104 # a setup method before tests but after the class instantiation
105 def setUpLocal(self):
106 pass
107
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500108 def tearDown(self):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500109 # Uninstall packages in the DUT
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600110 self.tc.install_uninstall_packages(self.id(), False)
111
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500112 res = getResults()
113 # If a test fails or there is an exception dump
114 # for QemuTarget only
115 if (type(self.target).__name__ == "QemuTarget" and
116 (self.id() in res.getErrorList() or
117 self.id() in res.getFailList())):
118 self.tc.host_dumper.create_dir(self._testMethodName)
119 self.tc.host_dumper.dump_host()
120 self.target.target_dumper.dump_target(
121 self.tc.host_dumper.dump_dir)
122 print ("%s dump data stored in %s" % (self._testMethodName,
123 self.tc.host_dumper.dump_dir))
124
125 self.tearDownLocal()
126
127 # Method to be run after tearDown and implemented by child classes
128 def tearDownLocal(self):
129 pass
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500130
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500131def getmodule(pos=2):
132 # stack returns a list of tuples containg frame information
133 # First element of the list the is current frame, caller is 1
134 frameinfo = inspect.stack()[pos]
135 modname = inspect.getmodulename(frameinfo[1])
136 #modname = inspect.getmodule(frameinfo[0]).__name__
137 return modname
138
139def skipModule(reason, pos=2):
140 modname = getmodule(pos)
141 if modname not in oeTest.tc.testsrequired:
142 raise unittest.SkipTest("%s: %s" % (modname, reason))
143 else:
144 raise Exception("\nTest %s wants to be skipped.\nReason is: %s" \
145 "\nTest was required in TEST_SUITES, so either the condition for skipping is wrong" \
146 "\nor the image really doesn't have the required feature/package when it should." % (modname, reason))
147
148def skipModuleIf(cond, reason):
149
150 if cond:
151 skipModule(reason, 3)
152
153def skipModuleUnless(cond, reason):
154
155 if not cond:
156 skipModule(reason, 3)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500157
158_buffer_logger = ""
159def custom_verbose(msg, *args, **kwargs):
160 global _buffer_logger
161 if msg[-1] != "\n":
162 _buffer_logger += msg
163 else:
164 _buffer_logger += msg
165 try:
166 bb.plain(_buffer_logger.rstrip("\n"), *args, **kwargs)
167 except NameError:
168 logger.info(_buffer_logger.rstrip("\n"), *args, **kwargs)
169 _buffer_logger = ""
170
171class TestContext(object):
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600172 def __init__(self, d, exported=False):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500173 self.d = d
174
175 self.testsuites = self._get_test_suites()
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600176
177 if exported:
178 path = [os.path.dirname(os.path.abspath(__file__))]
179 extrapath = ""
180 else:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500181 path = d.getVar("BBPATH").split(':')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600182 extrapath = "lib/oeqa"
183
184 self.testslist = self._get_tests_list(path, extrapath)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500185 self.testsrequired = self._get_test_suites_required()
186
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600187 self.filesdir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "runtime/files")
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500188 self.corefilesdir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "files")
189 self.imagefeatures = d.getVar("IMAGE_FEATURES").split()
190 self.distrofeatures = d.getVar("DISTRO_FEATURES").split()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500191
192 # get testcase list from specified file
193 # if path is a relative path, then relative to build/conf/
194 def _read_testlist(self, fpath, builddir):
195 if not os.path.isabs(fpath):
196 fpath = os.path.join(builddir, "conf", fpath)
197 if not os.path.exists(fpath):
198 bb.fatal("No such manifest file: ", fpath)
199 tcs = []
200 for line in open(fpath).readlines():
201 line = line.strip()
202 if line and not line.startswith("#"):
203 tcs.append(line)
204 return " ".join(tcs)
205
206 # return test list by type also filter if TEST_SUITES is specified
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600207 def _get_tests_list(self, bbpath, extrapath):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500208 testslist = []
209
210 type = self._get_test_namespace()
211
212 # This relies on lib/ under each directory in BBPATH being added to sys.path
213 # (as done by default in base.bbclass)
214 for testname in self.testsuites:
215 if testname != "auto":
216 if testname.startswith("oeqa."):
217 testslist.append(testname)
218 continue
219 found = False
220 for p in bbpath:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600221 if os.path.exists(os.path.join(p, extrapath, type, testname + ".py")):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500222 testslist.append("oeqa." + type + "." + testname)
223 found = True
224 break
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600225 elif os.path.exists(os.path.join(p, extrapath, type, testname.split(".")[0] + ".py")):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500226 testslist.append("oeqa." + type + "." + testname)
227 found = True
228 break
229 if not found:
230 bb.fatal('Test %s specified in TEST_SUITES could not be found in lib/oeqa/runtime under BBPATH' % testname)
231
232 if "auto" in self.testsuites:
233 def add_auto_list(path):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500234 files = sorted([f for f in os.listdir(path) if f.endswith('.py') and not f.startswith('_')])
235 for f in files:
236 module = 'oeqa.' + type + '.' + f[:-3]
237 if module not in testslist:
238 testslist.append(module)
239
240 for p in bbpath:
241 testpath = os.path.join(p, 'lib', 'oeqa', type)
242 bb.debug(2, 'Searching for tests in %s' % testpath)
243 if os.path.exists(testpath):
244 add_auto_list(testpath)
245
246 return testslist
247
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600248 def getTestModules(self):
249 """
250 Returns all the test modules in the testlist.
251 """
252
253 import pkgutil
254
255 modules = []
256 for test in self.testslist:
257 if re.search("\w+\.\w+\.test_\S+", test):
258 test = '.'.join(t.split('.')[:3])
259 module = pkgutil.get_loader(test)
260 modules.append(module)
261
262 return modules
263
264 def getModulefromID(self, test_id):
265 """
266 Returns the test module based on a test id.
267 """
268
269 module_name = ".".join(test_id.split(".")[:3])
270 modules = self.getTestModules()
271 for module in modules:
272 if module.name == module_name:
273 return module
274
275 return None
276
277 def getTests(self, test):
278 '''Return all individual tests executed when running the suite.'''
279 # Unfortunately unittest does not have an API for this, so we have
280 # to rely on implementation details. This only needs to work
281 # for TestSuite containing TestCase.
282 method = getattr(test, '_testMethodName', None)
283 if method:
284 # leaf case: a TestCase
285 yield test
286 else:
287 # Look into TestSuite.
288 tests = getattr(test, '_tests', [])
289 for t1 in tests:
290 for t2 in self.getTests(t1):
291 yield t2
292
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500293 def loadTests(self):
294 setattr(oeTest, "tc", self)
295
296 testloader = unittest.TestLoader()
297 testloader.sortTestMethodsUsing = None
298 suites = [testloader.loadTestsFromName(name) for name in self.testslist]
299 suites = filterByTagExp(suites, getattr(self, "tagexp", None))
300
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500301 # Determine dependencies between suites by looking for @skipUnlessPassed
302 # method annotations. Suite A depends on suite B if any method in A
303 # depends on a method on B.
304 for suite in suites:
305 suite.dependencies = []
306 suite.depth = 0
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600307 for test in self.getTests(suite):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500308 methodname = getattr(test, '_testMethodName', None)
309 if methodname:
310 method = getattr(test, methodname)
311 depends_on = getattr(method, '_depends_on', None)
312 if depends_on:
313 for dep_suite in suites:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600314 if depends_on in [getattr(t, '_testMethodName', None) for t in self.getTests(dep_suite)]:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500315 if dep_suite not in suite.dependencies and \
316 dep_suite is not suite:
317 suite.dependencies.append(dep_suite)
318 break
319 else:
320 logger.warning("Test %s was declared as @skipUnlessPassed('%s') but that test is either not defined or not active. Will run the test anyway." %
321 (test, depends_on))
322
323 # Use brute-force topological sort to determine ordering. Sort by
324 # depth (higher depth = must run later), with original ordering to
325 # break ties.
326 def set_suite_depth(suite):
327 for dep in suite.dependencies:
328 new_depth = set_suite_depth(dep) + 1
329 if new_depth > suite.depth:
330 suite.depth = new_depth
331 return suite.depth
332
333 for index, suite in enumerate(suites):
334 set_suite_depth(suite)
335 suite.index = index
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600336
337 def cmp(a, b):
338 return (a > b) - (a < b)
339
340 def cmpfunc(a, b):
341 return cmp((a.depth, a.index), (b.depth, b.index))
342
343 suites.sort(key=functools.cmp_to_key(cmpfunc))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500344
345 self.suite = testloader.suiteClass(suites)
346
347 return self.suite
348
349 def runTests(self):
350 logger.info("Test modules %s" % self.testslist)
351 if hasattr(self, "tagexp") and self.tagexp:
352 logger.info("Filter test cases by tags: %s" % self.tagexp)
353 logger.info("Found %s tests" % self.suite.countTestCases())
354 runner = unittest.TextTestRunner(verbosity=2)
355 if 'bb' in sys.modules:
356 runner.stream.write = custom_verbose
357
358 return runner.run(self.suite)
359
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600360class RuntimeTestContext(TestContext):
361 def __init__(self, d, target, exported=False):
362 super(RuntimeTestContext, self).__init__(d, exported)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500363
364 self.target = target
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500365
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600366 self.pkgmanifest = {}
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500367 manifest = os.path.join(d.getVar("DEPLOY_DIR_IMAGE"),
368 d.getVar("IMAGE_LINK_NAME") + ".manifest")
369 nomanifest = d.getVar("IMAGE_NO_MANIFEST")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500370 if nomanifest is None or nomanifest != "1":
371 try:
372 with open(manifest) as f:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600373 for line in f:
374 (pkg, arch, version) = line.strip().split()
375 self.pkgmanifest[pkg] = (version, arch)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500376 except IOError as e:
377 bb.fatal("No package manifest file found. Did you build the image?\n%s" % e)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500378
379 def _get_test_namespace(self):
380 return "runtime"
381
382 def _get_test_suites(self):
383 testsuites = []
384
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500385 manifests = (self.d.getVar("TEST_SUITES_MANIFEST") or '').split()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500386 if manifests:
387 for manifest in manifests:
388 testsuites.extend(self._read_testlist(manifest,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500389 self.d.getVar("TOPDIR")).split())
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500390
391 else:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500392 testsuites = self.d.getVar("TEST_SUITES").split()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500393
394 return testsuites
395
396 def _get_test_suites_required(self):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500397 return [t for t in self.d.getVar("TEST_SUITES").split() if t != "auto"]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500398
399 def loadTests(self):
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600400 super(RuntimeTestContext, self).loadTests()
401 if oeTest.hasPackage("procps"):
402 oeRuntimeTest.pscmd = "ps -ef"
403
404 def extract_packages(self):
405 """
406 Find packages that will be needed during runtime.
407 """
408
409 modules = self.getTestModules()
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500410 bbpaths = self.d.getVar("BBPATH").split(":")
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600411
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500412 shutil.rmtree(self.d.getVar("TEST_EXTRACTED_DIR"))
413 shutil.rmtree(self.d.getVar("TEST_PACKAGED_DIR"))
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600414 for module in modules:
415 json_file = self._getJsonFile(module)
416 if json_file:
417 needed_packages = self._getNeededPackages(json_file)
418 self._perform_package_extraction(needed_packages)
419
420 def _perform_package_extraction(self, needed_packages):
421 """
422 Extract packages that will be needed during runtime.
423 """
424
425 import oe.path
426
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500427 extracted_path = self.d.getVar("TEST_EXTRACTED_DIR")
428 packaged_path = self.d.getVar("TEST_PACKAGED_DIR")
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600429
430 for key,value in needed_packages.items():
431 packages = ()
432 if isinstance(value, dict):
433 packages = (value, )
434 elif isinstance(value, list):
435 packages = value
436 else:
437 bb.fatal("Failed to process needed packages for %s; "
438 "Value must be a dict or list" % key)
439
440 for package in packages:
441 pkg = package["pkg"]
442 rm = package.get("rm", False)
443 extract = package.get("extract", True)
444 if extract:
445 dst_dir = os.path.join(extracted_path, pkg)
446 else:
447 dst_dir = os.path.join(packaged_path)
448
449 # Extract package and copy it to TEST_EXTRACTED_DIR
450 pkg_dir = self._extract_in_tmpdir(pkg)
451 if extract:
452
453 # Same package used for more than one test,
454 # don't need to extract again.
455 if os.path.exists(dst_dir):
456 continue
457 oe.path.copytree(pkg_dir, dst_dir)
458 shutil.rmtree(pkg_dir)
459
460 # Copy package to TEST_PACKAGED_DIR
461 else:
462 self._copy_package(pkg)
463
464 def _getJsonFile(self, module):
465 """
466 Returns the path of the JSON file for a module, empty if doesn't exitst.
467 """
468
469 module_file = module.path
470 json_file = "%s.json" % module_file.rsplit(".", 1)[0]
471 if os.path.isfile(module_file) and os.path.isfile(json_file):
472 return json_file
473 else:
474 return ""
475
476 def _getNeededPackages(self, json_file, test=None):
477 """
478 Returns a dict with needed packages based on a JSON file.
479
480
481 If a test is specified it will return the dict just for that test.
482 """
483
484 import json
485
486 needed_packages = {}
487
488 with open(json_file) as f:
489 test_packages = json.load(f)
490 for key,value in test_packages.items():
491 needed_packages[key] = value
492
493 if test:
494 if test in needed_packages:
495 needed_packages = needed_packages[test]
496 else:
497 needed_packages = {}
498
499 return needed_packages
500
501 def _extract_in_tmpdir(self, pkg):
502 """"
503 Returns path to a temp directory where the package was
504 extracted without dependencies.
505 """
506
507 from oeqa.utils.package_manager import get_package_manager
508
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500509 pkg_path = os.path.join(self.d.getVar("TEST_INSTALL_TMP_DIR"), pkg)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600510 pm = get_package_manager(self.d, pkg_path)
511 extract_dir = pm.extract(pkg)
512 shutil.rmtree(pkg_path)
513
514 return extract_dir
515
516 def _copy_package(self, pkg):
517 """
518 Copy the RPM, DEB or IPK package to dst_dir
519 """
520
521 from oeqa.utils.package_manager import get_package_manager
522
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500523 pkg_path = os.path.join(self.d.getVar("TEST_INSTALL_TMP_DIR"), pkg)
524 dst_dir = self.d.getVar("TEST_PACKAGED_DIR")
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600525 pm = get_package_manager(self.d, pkg_path)
526 pkg_info = pm.package_info(pkg)
527 file_path = pkg_info[pkg]["filepath"]
528 shutil.copy2(file_path, dst_dir)
529 shutil.rmtree(pkg_path)
530
531 def install_uninstall_packages(self, test_id, pkg_dir, install):
532 """
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500533 Check if the test requires a package and Install/Uninstall it in the DUT
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600534 """
535
536 test = test_id.split(".")[4]
537 module = self.getModulefromID(test_id)
538 json = self._getJsonFile(module)
539 if json:
540 needed_packages = self._getNeededPackages(json, test)
541 if needed_packages:
542 self._install_uninstall_packages(needed_packages, pkg_dir, install)
543
544 def _install_uninstall_packages(self, needed_packages, pkg_dir, install=True):
545 """
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500546 Install/Uninstall packages in the DUT without using a package manager
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600547 """
548
549 if isinstance(needed_packages, dict):
550 packages = [needed_packages]
551 elif isinstance(needed_packages, list):
552 packages = needed_packages
553
554 for package in packages:
555 pkg = package["pkg"]
556 rm = package.get("rm", False)
557 extract = package.get("extract", True)
558 src_dir = os.path.join(pkg_dir, pkg)
559
560 # Install package
561 if install and extract:
562 self.target.connection.copy_dir_to(src_dir, "/")
563
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500564 # Uninstall package
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600565 elif not install and rm:
566 self.target.connection.delete_dir_structure(src_dir, "/")
567
568class ImageTestContext(RuntimeTestContext):
569 def __init__(self, d, target, host_dumper):
570 super(ImageTestContext, self).__init__(d, target)
571
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500572 self.tagexp = d.getVar("TEST_SUITES_TAGS")
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600573
574 self.host_dumper = host_dumper
575
576 self.sigterm = False
577 self.origsigtermhandler = signal.getsignal(signal.SIGTERM)
578 signal.signal(signal.SIGTERM, self._sigterm_exception)
579
580 def _sigterm_exception(self, signum, stackframe):
581 bb.warn("TestImage received SIGTERM, shutting down...")
582 self.sigterm = True
583 self.target.stop()
584
585 def install_uninstall_packages(self, test_id, install=True):
586 """
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500587 Check if the test requires a package and Install/Uninstall it in the DUT
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600588 """
589
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500590 pkg_dir = self.d.getVar("TEST_EXTRACTED_DIR")
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600591 super(ImageTestContext, self).install_uninstall_packages(test_id, pkg_dir, install)
592
593class ExportTestContext(RuntimeTestContext):
594 def __init__(self, d, target, exported=False, parsedArgs={}):
595 """
596 This class is used when exporting tests and when are executed outside OE environment.
597
598 parsedArgs can contain the following:
599 - tag: Filter test by tag.
600 """
601 super(ExportTestContext, self).__init__(d, target, exported)
602
603 tag = parsedArgs.get("tag", None)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500604 self.tagexp = tag if tag != None else d.getVar("TEST_SUITES_TAGS")
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600605
606 self.sigterm = None
607
608 def install_uninstall_packages(self, test_id, install=True):
609 """
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500610 Check if the test requires a package and Install/Uninstall it in the DUT
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600611 """
612
613 export_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500614 extracted_dir = self.d.getVar("TEST_EXPORT_EXTRACTED_DIR")
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600615 pkg_dir = os.path.join(export_dir, extracted_dir)
616 super(ExportTestContext, self).install_uninstall_packages(test_id, pkg_dir, install)