diff options
author | Aníbal Limón <limon.anibal@gmail.com> | 2016-01-30 11:05:15 -0600 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-02-10 16:06:22 +0000 |
commit | b588b80d667052f2864d529793bf7db155b29f90 (patch) | |
tree | 2e5e5cb0b2f2d98a9afc66fae53868684b3f2ef6 | |
parent | 59791d1f49591354c31c652af6c7c482461a878c (diff) | |
download | poky-b588b80d667052f2864d529793bf7db155b29f90.tar.gz |
testimage/testsdk: Modularize TestContext.
Move anonymous duplicated class TestContext from testimage/testsdk to
oeqa/oetest now we have two new classes ImageTestContext and
SDKTestContext with common code in TestContext class.
(From OE-Core rev: 593f2fdf6ee94c5f91761a669048da3598cbe3fa)
Signed-off-by: Aníbal Limón <limon.anibal@gmail.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | meta/classes/testimage.bbclass | 40 | ||||
-rw-r--r-- | meta/classes/testsdk.bbclass | 29 | ||||
-rw-r--r-- | meta/lib/oeqa/oetest.py | 63 |
3 files changed, 69 insertions, 63 deletions
diff --git a/meta/classes/testimage.bbclass b/meta/classes/testimage.bbclass index 6eea3f8a27..bdd6c9de6f 100644 --- a/meta/classes/testimage.bbclass +++ b/meta/classes/testimage.bbclass | |||
@@ -195,7 +195,8 @@ def testimage_main(d): | |||
195 | import oeqa.runtime | 195 | import oeqa.runtime |
196 | import time | 196 | import time |
197 | import signal | 197 | import signal |
198 | from oeqa.oetest import loadTests, runTests, get_test_suites, get_tests_list | 198 | from oeqa.oetest import loadTests, runTests, \ |
199 | get_test_suites, get_tests_list, ImageTestContext | ||
199 | from oeqa.targetcontrol import get_target_controller | 200 | from oeqa.targetcontrol import get_target_controller |
200 | from oeqa.utils.dump import get_host_dumper | 201 | from oeqa.utils.dump import get_host_dumper |
201 | 202 | ||
@@ -212,48 +213,14 @@ def testimage_main(d): | |||
212 | testslist = get_tests_list(get_test_suites(d), d.getVar("BBPATH", True).split(':')) | 213 | testslist = get_tests_list(get_test_suites(d), d.getVar("BBPATH", True).split(':')) |
213 | testsrequired = [t for t in d.getVar("TEST_SUITES", True).split() if t != "auto"] | 214 | testsrequired = [t for t in d.getVar("TEST_SUITES", True).split() if t != "auto"] |
214 | 215 | ||
215 | tagexp = d.getVar("TEST_SUITES_TAGS", True) | ||
216 | |||
217 | # we need the host dumper in test context | 216 | # we need the host dumper in test context |
218 | host_dumper = get_host_dumper(d) | 217 | host_dumper = get_host_dumper(d) |
219 | 218 | ||
220 | # the robot dance | 219 | # the robot dance |
221 | target = get_target_controller(d) | 220 | target = get_target_controller(d) |
222 | 221 | ||
223 | class TestContext(object): | ||
224 | def __init__(self): | ||
225 | self.d = d | ||
226 | self.testslist = testslist | ||
227 | self.tagexp = tagexp | ||
228 | self.testsrequired = testsrequired | ||
229 | self.filesdir = os.path.join(os.path.dirname(os.path.abspath(oeqa.runtime.__file__)),"files") | ||
230 | self.target = target | ||
231 | self.host_dumper = host_dumper | ||
232 | self.imagefeatures = d.getVar("IMAGE_FEATURES", True).split() | ||
233 | self.distrofeatures = d.getVar("DISTRO_FEATURES", True).split() | ||
234 | manifest = os.path.join(d.getVar("DEPLOY_DIR_IMAGE", True), d.getVar("IMAGE_LINK_NAME", True) + ".manifest") | ||
235 | nomanifest = d.getVar("IMAGE_NO_MANIFEST", True) | ||
236 | |||
237 | self.sigterm = False | ||
238 | self.origsigtermhandler = signal.getsignal(signal.SIGTERM) | ||
239 | signal.signal(signal.SIGTERM, self.sigterm_exception) | ||
240 | |||
241 | if nomanifest is None or nomanifest != "1": | ||
242 | try: | ||
243 | with open(manifest) as f: | ||
244 | self.pkgmanifest = f.read() | ||
245 | except IOError as e: | ||
246 | bb.fatal("No package manifest file found. Did you build the image?\n%s" % e) | ||
247 | else: | ||
248 | self.pkgmanifest = "" | ||
249 | |||
250 | def sigterm_exception(self, signum, stackframe): | ||
251 | bb.warn("TestImage received SIGTERM, shutting down...") | ||
252 | self.sigterm = True | ||
253 | self.target.stop() | ||
254 | |||
255 | # test context | 222 | # test context |
256 | tc = TestContext() | 223 | tc = ImageTestContext(d, testslist, testsrequired, target, host_dumper) |
257 | 224 | ||
258 | # this is a dummy load of tests | 225 | # this is a dummy load of tests |
259 | # we are doing that to find compile errors in the tests themselves | 226 | # we are doing that to find compile errors in the tests themselves |
@@ -264,7 +231,6 @@ def testimage_main(d): | |||
264 | import traceback | 231 | import traceback |
265 | bb.fatal("Loading tests failed:\n%s" % traceback.format_exc()) | 232 | bb.fatal("Loading tests failed:\n%s" % traceback.format_exc()) |
266 | 233 | ||
267 | |||
268 | if export: | 234 | if export: |
269 | signal.signal(signal.SIGTERM, tc.origsigtermhandler) | 235 | signal.signal(signal.SIGTERM, tc.origsigtermhandler) |
270 | tc.origsigtermhandler = None | 236 | tc.origsigtermhandler = None |
diff --git a/meta/classes/testsdk.bbclass b/meta/classes/testsdk.bbclass index 104c7a15f4..06e7a77398 100644 --- a/meta/classes/testsdk.bbclass +++ b/meta/classes/testsdk.bbclass | |||
@@ -13,7 +13,8 @@ def testsdk_main(d): | |||
13 | import oeqa.sdk | 13 | import oeqa.sdk |
14 | import time | 14 | import time |
15 | import subprocess | 15 | import subprocess |
16 | from oeqa.oetest import loadTests, runTests, get_test_suites, get_tests_list | 16 | from oeqa.oetest import loadTests, runTests, \ |
17 | get_test_suites, get_tests_list, SDKTestContext | ||
17 | 18 | ||
18 | pn = d.getVar("PN", True) | 19 | pn = d.getVar("PN", True) |
19 | bb.utils.mkdirhier(d.getVar("TEST_LOG_DIR", True)) | 20 | bb.utils.mkdirhier(d.getVar("TEST_LOG_DIR", True)) |
@@ -28,29 +29,6 @@ def testsdk_main(d): | |||
28 | if not os.path.exists(tcname): | 29 | if not os.path.exists(tcname): |
29 | bb.fatal("The toolchain is not built. Build it before running the tests: 'bitbake <image> -c populate_sdk' .") | 30 | bb.fatal("The toolchain is not built. Build it before running the tests: 'bitbake <image> -c populate_sdk' .") |
30 | 31 | ||
31 | class TestContext(object): | ||
32 | def __init__(self): | ||
33 | self.d = d | ||
34 | self.testslist = testslist | ||
35 | self.testsrequired = testsrequired | ||
36 | self.filesdir = os.path.join(os.path.dirname(os.path.abspath(oeqa.runtime.__file__)),"files") | ||
37 | self.sdktestdir = sdktestdir | ||
38 | self.sdkenv = sdkenv | ||
39 | self.imagefeatures = d.getVar("IMAGE_FEATURES", True).split() | ||
40 | self.distrofeatures = d.getVar("DISTRO_FEATURES", True).split() | ||
41 | manifest = d.getVar("SDK_TARGET_MANIFEST", True) | ||
42 | try: | ||
43 | with open(manifest) as f: | ||
44 | self.pkgmanifest = f.read() | ||
45 | except IOError as e: | ||
46 | bb.fatal("No package manifest file found. Did you build the sdk image?\n%s" % e) | ||
47 | hostmanifest = d.getVar("SDK_HOST_MANIFEST", True) | ||
48 | try: | ||
49 | with open(hostmanifest) as f: | ||
50 | self.hostpkgmanifest = f.read() | ||
51 | except IOError as e: | ||
52 | bb.fatal("No host package manifest file found. Did you build the sdk image?\n%s" % e) | ||
53 | |||
54 | sdktestdir = d.expand("${WORKDIR}/testimage-sdk/") | 32 | sdktestdir = d.expand("${WORKDIR}/testimage-sdk/") |
55 | bb.utils.remove(sdktestdir, True) | 33 | bb.utils.remove(sdktestdir, True) |
56 | bb.utils.mkdirhier(sdktestdir) | 34 | bb.utils.mkdirhier(sdktestdir) |
@@ -63,8 +41,7 @@ def testsdk_main(d): | |||
63 | targets = glob.glob(d.expand(sdktestdir + "/tc/environment-setup-*")) | 41 | targets = glob.glob(d.expand(sdktestdir + "/tc/environment-setup-*")) |
64 | for sdkenv in targets: | 42 | for sdkenv in targets: |
65 | bb.plain("Testing %s" % sdkenv) | 43 | bb.plain("Testing %s" % sdkenv) |
66 | # test context | 44 | tc = SDKTestContext(d, testslist, testsrequired, sdktestdir, sdkenv) |
67 | tc = TestContext() | ||
68 | 45 | ||
69 | # this is a dummy load of tests | 46 | # this is a dummy load of tests |
70 | # we are doing that to find compile errors in the tests themselves | 47 | # we are doing that to find compile errors in the tests themselves |
diff --git a/meta/lib/oeqa/oetest.py b/meta/lib/oeqa/oetest.py index 6470129180..9951a6f40e 100644 --- a/meta/lib/oeqa/oetest.py +++ b/meta/lib/oeqa/oetest.py | |||
@@ -11,11 +11,14 @@ import os, re, mmap | |||
11 | import unittest | 11 | import unittest |
12 | import inspect | 12 | import inspect |
13 | import subprocess | 13 | import subprocess |
14 | import signal | ||
14 | try: | 15 | try: |
15 | import bb | 16 | import bb |
16 | except ImportError: | 17 | except ImportError: |
17 | pass | 18 | pass |
18 | import logging | 19 | import logging |
20 | |||
21 | import oeqa.runtime | ||
19 | from oeqa.utils.decorators import LogResults, gettag, getResults | 22 | from oeqa.utils.decorators import LogResults, gettag, getResults |
20 | 23 | ||
21 | logger = logging.getLogger("BitBake") | 24 | logger = logging.getLogger("BitBake") |
@@ -326,3 +329,63 @@ def get_tests_list(testsuites, bbpath, type="runtime"): | |||
326 | add_auto_list(testpath) | 329 | add_auto_list(testpath) |
327 | 330 | ||
328 | return testslist | 331 | return testslist |
332 | |||
333 | class TestContext(object): | ||
334 | def __init__(self, d, testslist, testsrequired): | ||
335 | self.d = d | ||
336 | self.testslist = testslist | ||
337 | self.testsrequired = testsrequired | ||
338 | |||
339 | self.filesdir = os.path.join(os.path.dirname(os.path.abspath( | ||
340 | oeqa.runtime.__file__)), "files") | ||
341 | self.imagefeatures = d.getVar("IMAGE_FEATURES", True).split() | ||
342 | self.distrofeatures = d.getVar("DISTRO_FEATURES", True).split() | ||
343 | |||
344 | class ImageTestContext(TestContext): | ||
345 | def __init__(self, d, testslist, testsrequired, target, host_dumper): | ||
346 | super(ImageTestContext, self).__init__(d, testslist, testsrequired) | ||
347 | |||
348 | self.tagexp = d.getVar("TEST_SUITES_TAGS", True) | ||
349 | |||
350 | self.target = target | ||
351 | self.host_dumper = host_dumper | ||
352 | |||
353 | manifest = os.path.join(d.getVar("DEPLOY_DIR_IMAGE", True), | ||
354 | d.getVar("IMAGE_LINK_NAME", True) + ".manifest") | ||
355 | nomanifest = d.getVar("IMAGE_NO_MANIFEST", True) | ||
356 | if nomanifest is None or nomanifest != "1": | ||
357 | try: | ||
358 | with open(manifest) as f: | ||
359 | self.pkgmanifest = f.read() | ||
360 | except IOError as e: | ||
361 | bb.fatal("No package manifest file found. Did you build the image?\n%s" % e) | ||
362 | else: | ||
363 | self.pkgmanifest = "" | ||
364 | |||
365 | self.sigterm = False | ||
366 | self.origsigtermhandler = signal.getsignal(signal.SIGTERM) | ||
367 | signal.signal(signal.SIGTERM, self._sigterm_exception) | ||
368 | |||
369 | def _sigterm_exception(self, signum, stackframe): | ||
370 | bb.warn("TestImage received SIGTERM, shutting down...") | ||
371 | self.sigterm = True | ||
372 | self.target.stop() | ||
373 | |||
374 | class SDKTestContext(TestContext): | ||
375 | def __init__(self, d, testslist, testsrequired, sdktestdir, sdkenv): | ||
376 | super(SDKTestContext, self).__init__(d, testslist, testsrequired) | ||
377 | |||
378 | self.sdktestdir = sdktestdir | ||
379 | self.sdkenv = sdkenv | ||
380 | |||
381 | try: | ||
382 | with open(d.getVar("SDK_TARGET_MANIFEST", True)) as f: | ||
383 | self.pkgmanifest = f.read() | ||
384 | except IOError as e: | ||
385 | bb.fatal("No package manifest file found. Did you build the sdk image?\n%s" % e) | ||
386 | |||
387 | try: | ||
388 | with open(d.getVar("SDK_HOST_MANIFEST", True)) as f: | ||
389 | self.hostpkgmanifest = f.read() | ||
390 | except IOError as e: | ||
391 | bb.fatal("No host package manifest file found. Did you build the sdk image?\n%s" % e) | ||