blob: d8611c8b3087433b4d2f53ed6ba2616d237167a3 [file] [log] [blame]
Brad Bishop6e60e8b2018-02-01 10:27:11 -05001# Copyright (C) 2016 Intel Corporation
2# Released under the MIT license (see COPYING.MIT)
3
Brad Bishop19323692019-04-05 15:28:33 -04004import os
Brad Bishop6e60e8b2018-02-01 10:27:11 -05005import subprocess
6
7from oeqa.core.case import OETestCase
8
9class 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 Bishop19323692019-04-05 15:28:33 -040014
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())