summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/sdk
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib/oeqa/sdk')
-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
3 files changed, 145 insertions, 0 deletions
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