diff options
Diffstat (limited to 'lib/oeqa/sdkmingw/case.py')
-rw-r--r-- | lib/oeqa/sdkmingw/case.py | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/lib/oeqa/sdkmingw/case.py b/lib/oeqa/sdkmingw/case.py new file mode 100644 index 0000000..169c143 --- /dev/null +++ b/lib/oeqa/sdkmingw/case.py | |||
@@ -0,0 +1,87 @@ | |||
1 | # Copyright 2018 by Garmin Ltd. or its subsidiaries | ||
2 | # Released under the MIT license (see COPYING.MIT) | ||
3 | |||
4 | import subprocess | ||
5 | import os | ||
6 | import tempfile | ||
7 | import shutil | ||
8 | import bb | ||
9 | |||
10 | from oeqa.core.utils.path import remove_safe | ||
11 | from oeqa.sdk.case import OESDKTestCase | ||
12 | |||
13 | from oeqa.utils.subprocesstweak import errors_have_output | ||
14 | errors_have_output() | ||
15 | |||
16 | class OESDKMinGWTestCase(OESDKTestCase): | ||
17 | def setUp(self): | ||
18 | super().setUp() | ||
19 | |||
20 | self.test_dir = tempfile.mkdtemp(prefix=self.__class__.__name__ + '-', dir=self.tc.sdk_dir) | ||
21 | self.addCleanup(lambda: bb.utils.prunedir(self.test_dir)) | ||
22 | |||
23 | self.wine_test_dir = self.tc.wine_path(self.test_dir) | ||
24 | |||
25 | def copyTestFile(self, src, dest=None): | ||
26 | dest_path = dest or os.path.join(self.test_dir, os.path.basename(src)) | ||
27 | shutil.copyfile(src, dest_path) | ||
28 | self.addCleanup(lambda: remove_safe(dest_path)) | ||
29 | |||
30 | def fetch(self, url, destdir=None, dl_dir=None, archive=None): | ||
31 | if not destdir: | ||
32 | destdir = self.test_dir | ||
33 | |||
34 | if not dl_dir: | ||
35 | dl_dir = self.td.get('DL_DIR', None) | ||
36 | |||
37 | if not archive: | ||
38 | from urllib.parse import urlparse | ||
39 | archive = os.path.basename(urlparse(url).path) | ||
40 | |||
41 | if dl_dir: | ||
42 | tarball = os.path.join(dl_dir, archive) | ||
43 | if os.path.exists(tarball): | ||
44 | return tarball | ||
45 | |||
46 | tarball = os.path.join(destdir, archive) | ||
47 | subprocess.check_output(["wget", "-O", tarball, url]) | ||
48 | return tarball | ||
49 | |||
50 | |||
51 | def _run(self, cmd): | ||
52 | import shlex | ||
53 | |||
54 | def strip_quotes(s): | ||
55 | if s[0] == '"' and s[-1] == '"': | ||
56 | return s[1:-1] | ||
57 | return s | ||
58 | |||
59 | command = ['wine', 'cmd', '/c', self.tc.wine_sdk_env, '>', 'NUL', '&&', 'cd', self.wine_test_dir, '&&'] | ||
60 | |||
61 | # Perform some massaging so that commands can be written naturally in | ||
62 | # test cases. shlex.split() in Non-posix mode gets us most of the way | ||
63 | # there, but it leaves the quotes around a quoted argument, so we | ||
64 | # remove them manually. | ||
65 | command.extend(strip_quotes(s) for s in shlex.split(cmd, posix=False)) | ||
66 | |||
67 | return subprocess.check_output(command, env=self.tc.get_wine_env(), | ||
68 | stderr=subprocess.STDOUT, universal_newlines=True) | ||
69 | |||
70 | def assertIsTargetElf(self, path): | ||
71 | import oe.qa | ||
72 | import oe.elf | ||
73 | |||
74 | elf = oe.qa.ELFFile(path) | ||
75 | elf.open() | ||
76 | |||
77 | if not getattr(self, 'target_os', None): | ||
78 | output = self._run("echo %OECORE_TARGET_OS%:%OECORE_TARGET_ARCH%") | ||
79 | self.target_os, self.target_arch = output.strip().split(":") | ||
80 | |||
81 | machine_data = oe.elf.machine_dict(None)[self.target_os][self.target_arch] | ||
82 | (machine, osabi, abiversion, endian, bits) = machine_data | ||
83 | |||
84 | self.assertEqual(machine, elf.machine()) | ||
85 | self.assertEqual(bits, elf.abiSize()) | ||
86 | self.assertEqual(endian, elf.isLittleEndian()) | ||
87 | |||