diff options
Diffstat (limited to 'lib/oeqa/sdkmingw/context.py')
-rw-r--r-- | lib/oeqa/sdkmingw/context.py | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/lib/oeqa/sdkmingw/context.py b/lib/oeqa/sdkmingw/context.py new file mode 100644 index 0000000..edabcbd --- /dev/null +++ b/lib/oeqa/sdkmingw/context.py | |||
@@ -0,0 +1,69 @@ | |||
1 | # Copyright (C) 2018 by Garmin Ltd. or its subsidiaries | ||
2 | # Released under the MIT license (see COPYING.MIT) | ||
3 | import os | ||
4 | import subprocess | ||
5 | |||
6 | from oeqa.sdk.context import OESDKTestContext, OESDKTestContextExecutor | ||
7 | |||
8 | from oeqa.utils.subprocesstweak import errors_have_output | ||
9 | errors_have_output() | ||
10 | |||
11 | class OESDKMinGWTestContext(OESDKTestContext): | ||
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, wine_prefix=None, | ||
15 | wine_arch=None, target_pkg_manifest=None, host_pkg_manifest=None): | ||
16 | super(OESDKMinGWTestContext, self).__init__(td, logger, sdk_dir, sdk_env, target_pkg_manifest, host_pkg_manifest) | ||
17 | self.wine_prefix = wine_prefix | ||
18 | self.wine_arch = wine_arch | ||
19 | self.wine_sdk_dir = self.wine_path(sdk_dir) | ||
20 | self.wine_sdk_env = self.wine_path(sdk_env) | ||
21 | |||
22 | def get_wine_env(self): | ||
23 | env = os.environ.copy() | ||
24 | |||
25 | # Turn off all Wine debug logging so it doesn't interfere with command output | ||
26 | env['WINEDEBUG'] = '-all' | ||
27 | |||
28 | env['WINEPREFIX'] = self.wine_prefix | ||
29 | env['WINEARCH'] = self.wine_arch | ||
30 | |||
31 | # Convenience variables to make test cases easier to write | ||
32 | env['SDK_DIR'] = getattr(self, 'wine_sdk_dir', '') | ||
33 | |||
34 | return env | ||
35 | |||
36 | def wine_path(self, p): | ||
37 | """ | ||
38 | Converts a host POSIX path to a path in Wine | ||
39 | """ | ||
40 | o = subprocess.check_output(['wine', 'winepath', '-w', p], env=self.get_wine_env()) | ||
41 | return o.decode('utf-8').rstrip() | ||
42 | |||
43 | |||
44 | class OESDKMinGWTestContextExecutor(OESDKTestContextExecutor): | ||
45 | _context_class = OESDKMinGWTestContext | ||
46 | |||
47 | name = 'sdk-mingw' | ||
48 | help = 'MinGW sdk test component' | ||
49 | description = 'executes MinGW sdk tests' | ||
50 | |||
51 | default_cases = [os.path.join(os.path.abspath(os.path.dirname(__file__)), | ||
52 | 'cases')] | ||
53 | |||
54 | def register_commands(self, logger, subparsers): | ||
55 | super(OESDKMinGWTestContextExecutor, self).register_commands(logger, subparsers) | ||
56 | |||
57 | wine_group = self.parser.add_argument_group('wine options') | ||
58 | wine_group.add_argument('--wine-prefix', action='store', | ||
59 | help='Wine prefix (bottle). Default is $SDK_DIR/.wine') | ||
60 | wine_group.add_argument('--wine-arch', action='store', choices=('win32', 'win64'), | ||
61 | default='win64', help='Wine architecture. Defaults to %(default)s') | ||
62 | |||
63 | def _process_args(self, logger, args): | ||
64 | super(OESDKMinGWTestContextExecutor, self)._process_args(logger, args) | ||
65 | self.tc_kwargs['init']['wine_prefix'] = args.wine_prefix or os.path.join(args.sdk_dir, '.wine') | ||
66 | self.tc_kwargs['init']['wine_arch'] = args.wine_arch | ||
67 | |||
68 | _executor_class = OESDKMinGWTestContextExecutor | ||
69 | |||