blob: adc4166fd2d93d5c8bff2e847f0b73d7ac62b967 [file] [log] [blame]
Brad Bishop6e60e8b2018-02-01 10:27:11 -05001# Copyright (C) 2016 Intel Corporation
2# Released under the MIT license (see COPYING.MIT)
3
4import os
5import sys
6import glob
7import re
8
Brad Bishopf86d0552018-12-04 14:18:15 -08009from oeqa.core.context import OETestContext, OETestContextExecutor
Brad Bishop6e60e8b2018-02-01 10:27:11 -050010
Brad Bishopf86d0552018-12-04 14:18:15 -080011class OESDKTestContext(OETestContext):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050012 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
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080023 def _hasPackage(self, manifest, pkg, regex=False):
24 if regex:
25 # do regex match
26 pat = re.compile(pkg)
27 for p in manifest.keys():
28 if pat.search(p):
29 return True
30 else:
31 # do exact match
32 if pkg in manifest.keys():
Brad Bishop6e60e8b2018-02-01 10:27:11 -050033 return True
34 return False
35
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080036 def hasHostPackage(self, pkg, regex=False):
37 return self._hasPackage(self.host_pkg_manifest, pkg, regex=regex)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050038
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080039 def hasTargetPackage(self, pkg, multilib=False, regex=False):
40 if multilib:
41 # match multilib according to sdk_env
42 mls = self.td.get('MULTILIB_VARIANTS', '').split()
43 for ml in mls:
44 if ('ml'+ml) in self.sdk_env:
45 pkg = ml + '-' + pkg
46 return self._hasPackage(self.target_pkg_manifest, pkg, regex=regex)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050047
48class OESDKTestContextExecutor(OETestContextExecutor):
49 _context_class = OESDKTestContext
50
51 name = 'sdk'
52 help = 'sdk test component'
53 description = 'executes sdk tests'
54
55 default_cases = [os.path.join(os.path.abspath(os.path.dirname(__file__)),
56 'cases')]
57 default_test_data = None
58
59 def register_commands(self, logger, subparsers):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050060 super(OESDKTestContextExecutor, self).register_commands(logger, subparsers)
61
62 sdk_group = self.parser.add_argument_group('sdk options')
63 sdk_group.add_argument('--sdk-env', action='store',
64 help='sdk environment')
65 sdk_group.add_argument('--target-manifest', action='store',
66 help='sdk target manifest')
67 sdk_group.add_argument('--host-manifest', action='store',
68 help='sdk host manifest')
69
70 sdk_dgroup = self.parser.add_argument_group('sdk display options')
71 sdk_dgroup.add_argument('--list-sdk-env', action='store_true',
72 default=False, help='sdk list available environment')
73
74 # XXX this option is required but argparse_oe has a bug handling
75 # required options, seems that don't keep track of already parsed
76 # options
77 sdk_rgroup = self.parser.add_argument_group('sdk required options')
78 sdk_rgroup.add_argument('--sdk-dir', required=False, action='store',
79 help='sdk installed directory')
80
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080081 self.parser.add_argument('-j', '--num-processes', dest='processes', action='store',
82 type=int, help="number of processes to execute in parallel with")
83
Brad Bishop6e60e8b2018-02-01 10:27:11 -050084 @staticmethod
85 def _load_manifest(manifest):
86 pkg_manifest = {}
87 if manifest:
88 with open(manifest) as f:
89 for line in f:
90 (pkg, arch, version) = line.strip().split()
91 pkg_manifest[pkg] = (version, arch)
92
93 return pkg_manifest
94
95 def _process_args(self, logger, args):
96 super(OESDKTestContextExecutor, self)._process_args(logger, args)
97
98 self.tc_kwargs['init']['sdk_dir'] = args.sdk_dir
99 self.tc_kwargs['init']['sdk_env'] = self.sdk_env
100 self.tc_kwargs['init']['target_pkg_manifest'] = \
101 OESDKTestContextExecutor._load_manifest(args.target_manifest)
102 self.tc_kwargs['init']['host_pkg_manifest'] = \
103 OESDKTestContextExecutor._load_manifest(args.host_manifest)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800104 self.tc_kwargs['run']['processes'] = args.processes
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500105
106 @staticmethod
107 def _get_sdk_environs(sdk_dir):
108 sdk_env = {}
109
110 environ_pattern = sdk_dir + '/environment-setup-*'
111 full_sdk_env = glob.glob(sdk_dir + '/environment-setup-*')
112 for env in full_sdk_env:
113 m = re.search('environment-setup-(.*)', env)
114 if m:
115 sdk_env[m.group(1)] = env
116
117 return sdk_env
118
119 def _display_sdk_envs(self, log, args, sdk_envs):
120 log("Available SDK environments at directory %s:" \
121 % args.sdk_dir)
122 log("")
123 for env in sdk_envs:
124 log(env)
125
126 def run(self, logger, args):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500127 import argparse_oe
128
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500129 if not args.sdk_dir:
130 raise argparse_oe.ArgumentUsageError("No SDK directory "\
131 "specified please do, --sdk-dir SDK_DIR", self.name)
132
133 sdk_envs = OESDKTestContextExecutor._get_sdk_environs(args.sdk_dir)
134 if not sdk_envs:
135 raise argparse_oe.ArgumentUsageError("No available SDK "\
136 "enviroments found at %s" % args.sdk_dir, self.name)
137
138 if args.list_sdk_env:
139 self._display_sdk_envs(logger.info, args, sdk_envs)
140 sys.exit(0)
141
142 if not args.sdk_env in sdk_envs:
143 self._display_sdk_envs(logger.error, args, sdk_envs)
144 raise argparse_oe.ArgumentUsageError("No valid SDK "\
145 "environment (%s) specified" % args.sdk_env, self.name)
146
147 self.sdk_env = sdk_envs[args.sdk_env]
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500148 return super(OESDKTestContextExecutor, self).run(logger, args)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500149
150_executor_class = OESDKTestContextExecutor