1c342db35SBrad Bishop# 2eb8dc403SDave Cobbley# Copyright (C) 2016 Intel Corporation 3c342db35SBrad Bishop# 4c342db35SBrad Bishop# SPDX-License-Identifier: MIT 5c342db35SBrad Bishop# 6eb8dc403SDave Cobbley 719323693SBrad Bishopimport os 8eb8dc403SDave Cobbleyimport subprocess 9eb8dc403SDave Cobbley 10eb8dc403SDave Cobbleyfrom oeqa.core.case import OETestCase 11eb8dc403SDave Cobbley 12eb8dc403SDave Cobbleyclass OESDKTestCase(OETestCase): 13eb8dc403SDave Cobbley def _run(self, cmd): 14eb8dc403SDave Cobbley return subprocess.check_output(". %s > /dev/null; %s;" % \ 15c342db35SBrad Bishop (self.tc.sdk_env, cmd), shell=True, executable="/bin/bash", 16eb8dc403SDave Cobbley stderr=subprocess.STDOUT, universal_newlines=True) 1719323693SBrad Bishop 1819323693SBrad Bishop def fetch(self, workdir, dl_dir, url, archive=None): 1919323693SBrad Bishop if not archive: 2019323693SBrad Bishop from urllib.parse import urlparse 2119323693SBrad Bishop archive = os.path.basename(urlparse(url).path) 2219323693SBrad Bishop 2319323693SBrad Bishop if dl_dir: 2419323693SBrad Bishop tarball = os.path.join(dl_dir, archive) 2519323693SBrad Bishop if os.path.exists(tarball): 2619323693SBrad Bishop return tarball 2719323693SBrad Bishop 2819323693SBrad Bishop tarball = os.path.join(workdir, archive) 29*c9f7865aSAndrew Geissler subprocess.check_output(["wget", "-O", tarball, url], stderr=subprocess.STDOUT) 3019323693SBrad Bishop return tarball 3119323693SBrad Bishop 3219323693SBrad Bishop def check_elf(self, path, target_os=None, target_arch=None): 3319323693SBrad Bishop """ 3419323693SBrad Bishop Verify that the ELF binary $path matches the specified target 3519323693SBrad Bishop OS/architecture, or if not specified the currently configured MACHINE's 3619323693SBrad Bishop OS/architecture. 3719323693SBrad Bishop """ 3819323693SBrad Bishop import oe.qa, oe.elf 3919323693SBrad Bishop 4019323693SBrad Bishop if not target_os or not target_arch: 4119323693SBrad Bishop output = self._run("echo $OECORE_TARGET_OS:$OECORE_TARGET_ARCH") 4219323693SBrad Bishop target_os, target_arch = output.strip().split(":") 4319323693SBrad Bishop 4419323693SBrad Bishop machine_data = oe.elf.machine_dict(None)[target_os][target_arch] 4519323693SBrad Bishop (machine, osabi, abiversion, endian, bits) = machine_data 4619323693SBrad Bishop 4719323693SBrad Bishop elf = oe.qa.ELFFile(path) 4819323693SBrad Bishop elf.open() 4919323693SBrad Bishop 5019323693SBrad Bishop self.assertEqual(machine, elf.machine(), 5119323693SBrad Bishop "Binary was %s but expected %s" % 5219323693SBrad Bishop (oe.qa.elf_machine_to_string(elf.machine()), oe.qa.elf_machine_to_string(machine))) 5319323693SBrad Bishop self.assertEqual(bits, elf.abiSize()) 5419323693SBrad Bishop self.assertEqual(endian, elf.isLittleEndian()) 55