aboutsummaryrefslogtreecommitdiffstats
path: root/lib/oeqa/sdkmingw/context.py
blob: 5319223a6cabb2eef944f466449b4543f4b49e27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# Copyright (C) 2018 by Garmin Ltd. or its subsidiaries
# Released under the MIT license (see COPYING.MIT)
import os
import subprocess

from oeqa.sdk.context import OESDKTestContext, OESDKTestContextExecutor

from oeqa.utils.subprocesstweak import errors_have_output
errors_have_output()

class OESDKMinGWTestContext(OESDKTestContext):
    sdk_files_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "files")

    def __init__(self, td=None, logger=None, sdk_dir=None, sdk_env=None, wine_prefix=None,
            wine_arch=None, wine_devices={}, target_pkg_manifest=None, host_pkg_manifest=None):
        super(OESDKMinGWTestContext, self).__init__(td, logger, sdk_dir, sdk_env, target_pkg_manifest, host_pkg_manifest)
        self.wine_prefix = wine_prefix
        self.wine_arch = wine_arch
        # Create the wine environment
        subprocess.check_output(["wine", "cmd", "/c", "echo 1"], env=self.get_wine_env())

        device_dir  = "%s/dosdevices" % wine_prefix
        bb.utils.mkdirhier(device_dir)
        for device, path in wine_devices.items():
            device_path = "%s/%s" % (device_dir, device)
            os.symlink(os.path.relpath(path, device_dir), device_path)

        self.wine_sdk_dir = self.wine_path(sdk_dir)
        self.wine_sdk_env = self.wine_path(sdk_env)

    def get_wine_env(self):
        env = os.environ.copy()

        # Turn off all Wine debug logging so it doesn't interfere with command output
        env['WINEDEBUG'] = '-all'

        env['WINEPREFIX'] = self.wine_prefix
        env['WINEARCH'] = self.wine_arch

        # Convenience variables to make test cases easier to write
        env['SDK_DIR'] = getattr(self, 'wine_sdk_dir', '')

        return env

    def wine_path(self, p):
        """
        Converts a host POSIX path to a path in Wine
        """
        o = subprocess.check_output(['wine', 'winepath', '-w', p], env=self.get_wine_env())
        return o.decode('utf-8').rstrip()


class OESDKMinGWTestContextExecutor(OESDKTestContextExecutor):
    _context_class = OESDKMinGWTestContext

    name = 'sdk-mingw'
    help = 'MinGW sdk test component'
    description = 'executes MinGW sdk tests'

    default_cases = [os.path.join(os.path.abspath(os.path.dirname(__file__)),
            'cases')]

    def register_commands(self, logger, subparsers):
        super(OESDKMinGWTestContextExecutor, self).register_commands(logger, subparsers)

        wine_group  = self.parser.add_argument_group('wine options')
        wine_group.add_argument('--wine-prefix', action='store',
            help='Wine prefix (bottle). Default is $SDK_DIR/.wine')
        wine_group.add_argument('--wine-arch', action='store', choices=('win32', 'win64'),
            default='win64', help='Wine architecture. Defaults to %(default)s')

    def _process_args(self, logger, args):
        super(OESDKMinGWTestContextExecutor, self)._process_args(logger, args)
        self.tc_kwargs['init']['wine_prefix'] = args.wine_prefix or os.path.join(args.sdk_dir, '.wine')
        self.tc_kwargs['init']['wine_arch'] = args.wine_arch

_executor_class = OESDKMinGWTestContextExecutor