Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1 | # Copyright (C) 2016 Intel Corporation |
| 2 | # Released under the MIT license (see COPYING.MIT) |
| 3 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 4 | import os |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 5 | import subprocess |
| 6 | |
| 7 | from oeqa.core.case import OETestCase |
| 8 | |
| 9 | class OESDKTestCase(OETestCase): |
| 10 | def _run(self, cmd): |
| 11 | return subprocess.check_output(". %s > /dev/null; %s;" % \ |
| 12 | (self.tc.sdk_env, cmd), shell=True, |
| 13 | stderr=subprocess.STDOUT, universal_newlines=True) |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 14 | |
| 15 | def fetch(self, workdir, dl_dir, url, archive=None): |
| 16 | if not archive: |
| 17 | from urllib.parse import urlparse |
| 18 | archive = os.path.basename(urlparse(url).path) |
| 19 | |
| 20 | if dl_dir: |
| 21 | tarball = os.path.join(dl_dir, archive) |
| 22 | if os.path.exists(tarball): |
| 23 | return tarball |
| 24 | |
| 25 | tarball = os.path.join(workdir, archive) |
| 26 | subprocess.check_output(["wget", "-O", tarball, url]) |
| 27 | return tarball |
| 28 | |
| 29 | def check_elf(self, path, target_os=None, target_arch=None): |
| 30 | """ |
| 31 | Verify that the ELF binary $path matches the specified target |
| 32 | OS/architecture, or if not specified the currently configured MACHINE's |
| 33 | OS/architecture. |
| 34 | """ |
| 35 | import oe.qa, oe.elf |
| 36 | |
| 37 | if not target_os or not target_arch: |
| 38 | output = self._run("echo $OECORE_TARGET_OS:$OECORE_TARGET_ARCH") |
| 39 | target_os, target_arch = output.strip().split(":") |
| 40 | |
| 41 | machine_data = oe.elf.machine_dict(None)[target_os][target_arch] |
| 42 | (machine, osabi, abiversion, endian, bits) = machine_data |
| 43 | |
| 44 | elf = oe.qa.ELFFile(path) |
| 45 | elf.open() |
| 46 | |
| 47 | self.assertEqual(machine, elf.machine(), |
| 48 | "Binary was %s but expected %s" % |
| 49 | (oe.qa.elf_machine_to_string(elf.machine()), oe.qa.elf_machine_to_string(machine))) |
| 50 | self.assertEqual(bits, elf.abiSize()) |
| 51 | self.assertEqual(endian, elf.isLittleEndian()) |