blob: ebb03af9eb0af116bd5516d19e36bedfd86de363 [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002# Copyright (C) 2016 Intel Corporation
Brad Bishopc342db32019-05-15 21:57:59 -04003#
4# SPDX-License-Identifier: MIT
5#
Brad Bishop6e60e8b2018-02-01 10:27:11 -05006
Brad Bishop19323692019-04-05 15:28:33 -04007import os
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008import subprocess
9
10from oeqa.core.case import OETestCase
11
12class OESDKTestCase(OETestCase):
13 def _run(self, cmd):
14 return subprocess.check_output(". %s > /dev/null; %s;" % \
Brad Bishopc342db32019-05-15 21:57:59 -040015 (self.tc.sdk_env, cmd), shell=True, executable="/bin/bash",
Brad Bishop6e60e8b2018-02-01 10:27:11 -050016 stderr=subprocess.STDOUT, universal_newlines=True)
Brad Bishop19323692019-04-05 15:28:33 -040017
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())