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