blob: 01c38c24e6bfaa4d039ea4f581c7b864afa0515e [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002# Copyright (C) 2016 Intel Corporation
Brad Bishopc342db32019-05-15 21:57:59 -04003#
4# SPDX-License-Identifier: MIT
5#
Brad Bishop6e60e8b2018-02-01 10:27:11 -05006
7import os
8import sys
9import glob
10import re
11
Brad Bishopf86d0552018-12-04 14:18:15 -080012from oeqa.core.context import OETestContext, OETestContextExecutor
Brad Bishop6e60e8b2018-02-01 10:27:11 -050013
Brad Bishopf86d0552018-12-04 14:18:15 -080014class OESDKTestContext(OETestContext):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050015 sdk_files_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "files")
16
17 def __init__(self, td=None, logger=None, sdk_dir=None, sdk_env=None,
18 target_pkg_manifest=None, host_pkg_manifest=None):
19 super(OESDKTestContext, self).__init__(td, logger)
20
21 self.sdk_dir = sdk_dir
22 self.sdk_env = sdk_env
23 self.target_pkg_manifest = target_pkg_manifest
24 self.host_pkg_manifest = host_pkg_manifest
25
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080026 def _hasPackage(self, manifest, pkg, regex=False):
27 if regex:
28 # do regex match
29 pat = re.compile(pkg)
30 for p in manifest.keys():
31 if pat.search(p):
32 return True
33 else:
34 # do exact match
35 if pkg in manifest.keys():
Brad Bishop6e60e8b2018-02-01 10:27:11 -050036 return True
37 return False
38
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080039 def hasHostPackage(self, pkg, regex=False):
40 return self._hasPackage(self.host_pkg_manifest, pkg, regex=regex)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050041
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080042 def hasTargetPackage(self, pkg, multilib=False, regex=False):
43 if multilib:
44 # match multilib according to sdk_env
45 mls = self.td.get('MULTILIB_VARIANTS', '').split()
46 for ml in mls:
47 if ('ml'+ml) in self.sdk_env:
48 pkg = ml + '-' + pkg
49 return self._hasPackage(self.target_pkg_manifest, pkg, regex=regex)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050050
51class OESDKTestContextExecutor(OETestContextExecutor):
52 _context_class = OESDKTestContext
53
54 name = 'sdk'
55 help = 'sdk test component'
56 description = 'executes sdk tests'
57
58 default_cases = [os.path.join(os.path.abspath(os.path.dirname(__file__)),
59 'cases')]
60 default_test_data = None
61
62 def register_commands(self, logger, subparsers):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050063 super(OESDKTestContextExecutor, self).register_commands(logger, subparsers)
64
65 sdk_group = self.parser.add_argument_group('sdk options')
66 sdk_group.add_argument('--sdk-env', action='store',
67 help='sdk environment')
68 sdk_group.add_argument('--target-manifest', action='store',
69 help='sdk target manifest')
70 sdk_group.add_argument('--host-manifest', action='store',
71 help='sdk host manifest')
72
73 sdk_dgroup = self.parser.add_argument_group('sdk display options')
74 sdk_dgroup.add_argument('--list-sdk-env', action='store_true',
75 default=False, help='sdk list available environment')
76
77 # XXX this option is required but argparse_oe has a bug handling
78 # required options, seems that don't keep track of already parsed
79 # options
80 sdk_rgroup = self.parser.add_argument_group('sdk required options')
81 sdk_rgroup.add_argument('--sdk-dir', required=False, action='store',
82 help='sdk installed directory')
83
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080084 self.parser.add_argument('-j', '--num-processes', dest='processes', action='store',
85 type=int, help="number of processes to execute in parallel with")
86
Brad Bishop6e60e8b2018-02-01 10:27:11 -050087 @staticmethod
88 def _load_manifest(manifest):
89 pkg_manifest = {}
90 if manifest:
91 with open(manifest) as f:
92 for line in f:
93 (pkg, arch, version) = line.strip().split()
94 pkg_manifest[pkg] = (version, arch)
95
96 return pkg_manifest
97
98 def _process_args(self, logger, args):
99 super(OESDKTestContextExecutor, self)._process_args(logger, args)
100
101 self.tc_kwargs['init']['sdk_dir'] = args.sdk_dir
102 self.tc_kwargs['init']['sdk_env'] = self.sdk_env
103 self.tc_kwargs['init']['target_pkg_manifest'] = \
104 OESDKTestContextExecutor._load_manifest(args.target_manifest)
105 self.tc_kwargs['init']['host_pkg_manifest'] = \
106 OESDKTestContextExecutor._load_manifest(args.host_manifest)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800107 self.tc_kwargs['run']['processes'] = args.processes
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500108
109 @staticmethod
110 def _get_sdk_environs(sdk_dir):
111 sdk_env = {}
112
113 environ_pattern = sdk_dir + '/environment-setup-*'
114 full_sdk_env = glob.glob(sdk_dir + '/environment-setup-*')
115 for env in full_sdk_env:
116 m = re.search('environment-setup-(.*)', env)
117 if m:
118 sdk_env[m.group(1)] = env
119
120 return sdk_env
121
122 def _display_sdk_envs(self, log, args, sdk_envs):
123 log("Available SDK environments at directory %s:" \
124 % args.sdk_dir)
125 log("")
126 for env in sdk_envs:
127 log(env)
128
129 def run(self, logger, args):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500130 import argparse_oe
131
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500132 if not args.sdk_dir:
133 raise argparse_oe.ArgumentUsageError("No SDK directory "\
134 "specified please do, --sdk-dir SDK_DIR", self.name)
135
136 sdk_envs = OESDKTestContextExecutor._get_sdk_environs(args.sdk_dir)
137 if not sdk_envs:
138 raise argparse_oe.ArgumentUsageError("No available SDK "\
Andrew Geissler82c905d2020-04-13 13:39:40 -0500139 "environments found at %s" % args.sdk_dir, self.name)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500140
141 if args.list_sdk_env:
142 self._display_sdk_envs(logger.info, args, sdk_envs)
143 sys.exit(0)
144
145 if not args.sdk_env in sdk_envs:
146 self._display_sdk_envs(logger.error, args, sdk_envs)
147 raise argparse_oe.ArgumentUsageError("No valid SDK "\
148 "environment (%s) specified" % args.sdk_env, self.name)
149
150 self.sdk_env = sdk_envs[args.sdk_env]
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500151 return super(OESDKTestContextExecutor, self).run(logger, args)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500152
153_executor_class = OESDKTestContextExecutor