summaryrefslogtreecommitdiffstats
path: root/meta
diff options
context:
space:
mode:
authorAníbal Limón <anibal.limon@linux.intel.com>2016-10-31 17:24:25 -0600
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-01-23 12:05:19 +0000
commit8a37763ae9e5b8bfa4ed89c2ab8642b8f5bfc287 (patch)
treed4af06c2d2efd97b340aa657959a7abca1af4a1a /meta
parent9a23e0f703ec3ccb99b354102d804eda13543b23 (diff)
downloadpoky-8a37763ae9e5b8bfa4ed89c2ab8642b8f5bfc287.tar.gz
oeqa/sdk: Add case and context modules for the SDK component
Adds case and context modules for SDK based on oetest.py old code. Enables SDK Test component usage with oe-test, the SDK Test component adds command line options for specify sdk installed dir, sdk environment and target/hosts maniftest. [YOCTO #10599] (From OE-Core rev: 19e875dd81c42841666e6db5f6b665b4e1cddfe6) 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')
-rw-r--r--meta/lib/oeqa/oetest.py51
-rw-r--r--meta/lib/oeqa/sdk/__init__.py0
-rw-r--r--meta/lib/oeqa/sdk/case.py12
-rw-r--r--meta/lib/oeqa/sdk/context.py133
4 files changed, 145 insertions, 51 deletions
diff --git a/meta/lib/oeqa/oetest.py b/meta/lib/oeqa/oetest.py
index d1aef967e4..d7c358844f 100644
--- a/meta/lib/oeqa/oetest.py
+++ b/meta/lib/oeqa/oetest.py
@@ -145,20 +145,6 @@ class OETestCalledProcessError(subprocess.CalledProcessError):
145 145
146subprocess.CalledProcessError = OETestCalledProcessError 146subprocess.CalledProcessError = OETestCalledProcessError
147 147
148class oeSDKTest(oeTest):
149 def __init__(self, methodName='runTest'):
150 self.sdktestdir = oeSDKTest.tc.sdktestdir
151 super(oeSDKTest, self).__init__(methodName)
152
153 @classmethod
154 def hasHostPackage(self, pkg):
155 if re.search(pkg, oeTest.tc.hostpkgmanifest):
156 return True
157 return False
158
159 def _run(self, cmd):
160 return subprocess.check_output(". %s > /dev/null; %s;" % (self.tc.sdkenv, cmd), shell=True, stderr=subprocess.STDOUT).decode("utf-8")
161
162class oeSDKExtTest(oeSDKTest): 148class oeSDKExtTest(oeSDKTest):
163 def _run(self, cmd): 149 def _run(self, cmd):
164 # extensible sdk shows a warning if found bitbake in the path 150 # extensible sdk shows a warning if found bitbake in the path
@@ -657,43 +643,6 @@ class ExportTestContext(RuntimeTestContext):
657 pkg_dir = os.path.join(export_dir, extracted_dir) 643 pkg_dir = os.path.join(export_dir, extracted_dir)
658 super(ExportTestContext, self).install_uninstall_packages(test_id, pkg_dir, install) 644 super(ExportTestContext, self).install_uninstall_packages(test_id, pkg_dir, install)
659 645
660class SDKTestContext(TestContext):
661 def __init__(self, d, sdktestdir, sdkenv, tcname, *args):
662 super(SDKTestContext, self).__init__(d)
663
664 self.sdktestdir = sdktestdir
665 self.sdkenv = sdkenv
666 self.tcname = tcname
667
668 if not hasattr(self, 'target_manifest'):
669 self.target_manifest = d.getVar("SDK_TARGET_MANIFEST")
670 try:
671 self.pkgmanifest = {}
672 with open(self.target_manifest) as f:
673 for line in f:
674 (pkg, arch, version) = line.strip().split()
675 self.pkgmanifest[pkg] = (version, arch)
676 except IOError as e:
677 bb.fatal("No package manifest file found. Did you build the sdk image?\n%s" % e)
678
679 if not hasattr(self, 'host_manifest'):
680 self.host_manifest = d.getVar("SDK_HOST_MANIFEST")
681 try:
682 with open(self.host_manifest) as f:
683 self.hostpkgmanifest = f.read()
684 except IOError as e:
685 bb.fatal("No host package manifest file found. Did you build the sdk image?\n%s" % e)
686
687 def _get_test_namespace(self):
688 return "sdk"
689
690 def _get_test_suites(self):
691 return (self.d.getVar("TEST_SUITES_SDK") or "auto").split()
692
693 def _get_test_suites_required(self):
694 return [t for t in (self.d.getVar("TEST_SUITES_SDK") or \
695 "auto").split() if t != "auto"]
696
697class SDKExtTestContext(SDKTestContext): 646class SDKExtTestContext(SDKTestContext):
698 def __init__(self, d, sdktestdir, sdkenv, tcname, *args): 647 def __init__(self, d, sdktestdir, sdkenv, tcname, *args):
699 self.target_manifest = d.getVar("SDK_EXT_TARGET_MANIFEST") 648 self.target_manifest = d.getVar("SDK_EXT_TARGET_MANIFEST")
diff --git a/meta/lib/oeqa/sdk/__init__.py b/meta/lib/oeqa/sdk/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/meta/lib/oeqa/sdk/__init__.py
diff --git a/meta/lib/oeqa/sdk/case.py b/meta/lib/oeqa/sdk/case.py
new file mode 100644
index 0000000000..782db8b523
--- /dev/null
+++ b/meta/lib/oeqa/sdk/case.py
@@ -0,0 +1,12 @@
1# Copyright (C) 2016 Intel Corporation
2# Released under the MIT license (see COPYING.MIT)
3
4import subprocess
5
6from oeqa.core.case import OETestCase
7
8class OESDKTestCase(OETestCase):
9 def _run(self, cmd):
10 return subprocess.check_output(". %s > /dev/null; %s;" % \
11 (self.tc.sdk_env, cmd), shell=True,
12 stderr=subprocess.STDOUT).decode("utf-8")
diff --git a/meta/lib/oeqa/sdk/context.py b/meta/lib/oeqa/sdk/context.py
new file mode 100644
index 0000000000..0189ed851e
--- /dev/null
+++ b/meta/lib/oeqa/sdk/context.py
@@ -0,0 +1,133 @@
1# Copyright (C) 2016 Intel Corporation
2# Released under the MIT license (see COPYING.MIT)
3
4import os
5import sys
6import glob
7import re
8
9from oeqa.core.context import OETestContext, OETestContextExecutor
10
11class OESDKTestContext(OETestContext):
12 sdk_files_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "files")
13
14 def __init__(self, td=None, logger=None, sdk_dir=None, sdk_env=None,
15 target_pkg_manifest=None, host_pkg_manifest=None):
16 super(OESDKTestContext, self).__init__(td, logger)
17
18 self.sdk_dir = sdk_dir
19 self.sdk_env = sdk_env
20 self.target_pkg_manifest = target_pkg_manifest
21 self.host_pkg_manifest = host_pkg_manifest
22
23 def _hasPackage(self, manifest, pkg):
24 for host_pkg in manifest.keys():
25 if re.search(pkg, host_pkg):
26 return True
27 return False
28
29 def hasHostPackage(self, pkg):
30 return self._hasPackage(self.host_pkg_manifest, pkg)
31
32 def hasTargetPackage(self, pkg):
33 return self._hasPackage(self.target_pkg_manifest, pkg)
34
35class OESDKTestContextExecutor(OETestContextExecutor):
36 _context_class = OESDKTestContext
37
38 name = 'sdk'
39 help = 'sdk test component'
40 description = 'executes sdk tests'
41
42 default_cases = [os.path.join(os.path.abspath(os.path.dirname(__file__)),
43 'cases')]
44 default_test_data = None
45
46 def register_commands(self, logger, subparsers):
47 import argparse_oe
48
49 super(OESDKTestContextExecutor, self).register_commands(logger, subparsers)
50
51 sdk_group = self.parser.add_argument_group('sdk options')
52 sdk_group.add_argument('--sdk-env', action='store',
53 help='sdk environment')
54 sdk_group.add_argument('--target-manifest', action='store',
55 help='sdk target manifest')
56 sdk_group.add_argument('--host-manifest', action='store',
57 help='sdk host manifest')
58
59 sdk_dgroup = self.parser.add_argument_group('sdk display options')
60 sdk_dgroup.add_argument('--list-sdk-env', action='store_true',
61 default=False, help='sdk list available environment')
62
63 # XXX this option is required but argparse_oe has a bug handling
64 # required options, seems that don't keep track of already parsed
65 # options
66 sdk_rgroup = self.parser.add_argument_group('sdk required options')
67 sdk_rgroup.add_argument('--sdk-dir', required=False, action='store',
68 help='sdk installed directory')
69
70 @staticmethod
71 def _load_manifest(manifest):
72 pkg_manifest = {}
73 if manifest:
74 with open(manifest) as f:
75 for line in f:
76 (pkg, arch, version) = line.strip().split()
77 pkg_manifest[pkg] = (version, arch)
78
79 return pkg_manifest
80
81 def _process_args(self, logger, args):
82 super(OESDKTestContextExecutor, self)._process_args(logger, args)
83
84 self.tc_kwargs['init']['sdk_dir'] = args.sdk_dir
85 self.tc_kwargs['init']['sdk_env'] = self.sdk_env
86 self.tc_kwargs['init']['target_pkg_manifest'] = \
87 OESDKTestContextExecutor._load_manifest(args.target_manifest)
88 self.tc_kwargs['init']['host_pkg_manifest'] = \
89 OESDKTestContextExecutor._load_manifest(args.host_manifest)
90
91 @staticmethod
92 def _get_sdk_environs(sdk_dir):
93 sdk_env = {}
94
95 environ_pattern = sdk_dir + '/environment-setup-*'
96 full_sdk_env = glob.glob(sdk_dir + '/environment-setup-*')
97 for env in full_sdk_env:
98 m = re.search('environment-setup-(.*)', env)
99 if m:
100 sdk_env[m.group(1)] = env
101
102 return sdk_env
103
104 def _display_sdk_envs(self, log, args, sdk_envs):
105 log("Available SDK environments at directory %s:" \
106 % args.sdk_dir)
107 log("")
108 for env in sdk_envs:
109 log(env)
110
111 def run(self, logger, args):
112 if not args.sdk_dir:
113 raise argparse_oe.ArgumentUsageError("No SDK directory "\
114 "specified please do, --sdk-dir SDK_DIR", self.name)
115
116 sdk_envs = OESDKTestContextExecutor._get_sdk_environs(args.sdk_dir)
117 if not sdk_envs:
118 raise argparse_oe.ArgumentUsageError("No available SDK "\
119 "enviroments found at %s" % args.sdk_dir, self.name)
120
121 if args.list_sdk_env:
122 self._display_sdk_envs(logger.info, args, sdk_envs)
123 sys.exit(0)
124
125 if not args.sdk_env in sdk_envs:
126 self._display_sdk_envs(logger.error, args, sdk_envs)
127 raise argparse_oe.ArgumentUsageError("No valid SDK "\
128 "environment (%s) specified" % args.sdk_env, self.name)
129
130 self.sdk_env = sdk_envs[args.sdk_env]
131 super(OESDKTestContextExecutor, self).run(logger, args)
132
133_executor_class = OESDKTestContextExecutor