1# 2# Copyright OpenEmbedded Contributors 3# 4# SPDX-License-Identifier: MIT 5# 6 7from oeqa.runtime.case import OERuntimeTestCase 8from oeqa.core.decorator.depends import OETestDepends 9from oeqa.core.decorator.data import skipIfNotInDataVar 10from oeqa.runtime.decorator.package import OEHasPackage 11 12import subprocess 13 14class MultilibTest(OERuntimeTestCase): 15 16 def archtest(self, binary, arch): 17 """ 18 Check that ``binary`` has the ELF class ``arch`` (e.g. ELF32/ELF64). 19 """ 20 21 dest = "{}/test_binary".format(self.td.get('T', '')) 22 self.target.copyFrom(binary, dest) 23 output = subprocess.check_output("readelf -h {}".format(dest), shell=True).decode() 24 os.remove(dest) 25 26 l = [l.split()[1] for l in output.split('\n') if "Class:" in l] 27 if l: 28 theclass = l[0] 29 else: 30 self.fail('Cannot parse readelf. Output:\n%s' % output) 31 32 msg = "%s isn't %s (is %s)" % (binary, arch, theclass) 33 self.assertEqual(theclass, arch, msg=msg) 34 35 @skipIfNotInDataVar('MULTILIBS', 'multilib:lib32', 36 "This isn't a multilib:lib32 image") 37 @OETestDepends(['ssh.SSHTest.test_ssh']) 38 @OEHasPackage(['lib32-libc6']) 39 def test_check_multilib_libc(self): 40 """ 41 Check that a multilib image has both 32-bit and 64-bit libc in. 42 """ 43 self.archtest("/lib/libc.so.6", "ELF32") 44 self.archtest("/lib64/libc.so.6", "ELF64") 45 46 @OETestDepends(['multilib.MultilibTest.test_check_multilib_libc']) 47 @OEHasPackage(['lib32-connman']) 48 def test_file_connman(self): 49 self.archtest("/usr/sbin/connmand", "ELF32") 50