Patrick Williams | 7784c42 | 2022-11-17 07:29:11 -0600 | [diff] [blame] | 1 | # |
| 2 | # Copyright OpenEmbedded Contributors |
| 3 | # |
| 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
| 6 | import os |
| 7 | import subprocess |
| 8 | import tempfile |
| 9 | import shutil |
| 10 | |
| 11 | from oeqa.selftest.case import OESelftestTestCase |
Andrew Geissler | fc113ea | 2023-03-31 09:59:46 -0500 | [diff] [blame] | 12 | from oeqa.utils.commands import bitbake, get_bb_var, get_bb_vars, runCmd |
Patrick Williams | 7784c42 | 2022-11-17 07:29:11 -0600 | [diff] [blame] | 13 | |
| 14 | |
| 15 | class Minidebuginfo(OESelftestTestCase): |
| 16 | def test_minidebuginfo(self): |
| 17 | target_sys = get_bb_var("TARGET_SYS") |
| 18 | binutils = "binutils-cross-{}".format(get_bb_var("TARGET_ARCH")) |
| 19 | |
Andrew Geissler | fc113ea | 2023-03-31 09:59:46 -0500 | [diff] [blame] | 20 | image = 'core-image-minimal' |
| 21 | bb_vars = get_bb_vars(['DEPLOY_DIR_IMAGE', 'IMAGE_LINK_NAME', 'READELF'], image) |
| 22 | |
Patrick Williams | 7784c42 | 2022-11-17 07:29:11 -0600 | [diff] [blame] | 23 | self.write_config(""" |
Patrick Williams | 169d7bc | 2024-01-05 11:33:25 -0600 | [diff] [blame] | 24 | DISTRO_FEATURES:append = " minidebuginfo" |
Patrick Williams | 7784c42 | 2022-11-17 07:29:11 -0600 | [diff] [blame] | 25 | IMAGE_FSTYPES = "tar.bz2" |
| 26 | """) |
Andrew Geissler | fc113ea | 2023-03-31 09:59:46 -0500 | [diff] [blame] | 27 | bitbake("{} {}:do_addto_recipe_sysroot".format(image, binutils)) |
Patrick Williams | 7784c42 | 2022-11-17 07:29:11 -0600 | [diff] [blame] | 28 | |
Patrick Williams | 7784c42 | 2022-11-17 07:29:11 -0600 | [diff] [blame] | 29 | native_sysroot = get_bb_var("RECIPE_SYSROOT_NATIVE", binutils) |
Patrick Williams | 7784c42 | 2022-11-17 07:29:11 -0600 | [diff] [blame] | 30 | |
| 31 | # confirm that executables and shared libraries contain an ELF section |
| 32 | # ".gnu_debugdata" which stores minidebuginfo. |
| 33 | with tempfile.TemporaryDirectory(prefix = "unpackfs-") as unpackedfs: |
Andrew Geissler | fc113ea | 2023-03-31 09:59:46 -0500 | [diff] [blame] | 34 | filename = os.path.join(bb_vars['DEPLOY_DIR_IMAGE'], "{}.tar.bz2".format(bb_vars['IMAGE_LINK_NAME'])) |
Patrick Williams | 7784c42 | 2022-11-17 07:29:11 -0600 | [diff] [blame] | 35 | shutil.unpack_archive(filename, unpackedfs) |
| 36 | |
Andrew Geissler | fc113ea | 2023-03-31 09:59:46 -0500 | [diff] [blame] | 37 | r = runCmd([bb_vars['READELF'], "-W", "-S", os.path.join(unpackedfs, "bin", "busybox")], |
Patrick Williams | 7784c42 | 2022-11-17 07:29:11 -0600 | [diff] [blame] | 38 | native_sysroot = native_sysroot, target_sys = target_sys) |
| 39 | self.assertIn(".gnu_debugdata", r.output) |
| 40 | |
Andrew Geissler | fc113ea | 2023-03-31 09:59:46 -0500 | [diff] [blame] | 41 | r = runCmd([bb_vars['READELF'], "-W", "-S", os.path.join(unpackedfs, "lib", "libc.so.6")], |
Patrick Williams | 7784c42 | 2022-11-17 07:29:11 -0600 | [diff] [blame] | 42 | native_sysroot = native_sysroot, target_sys = target_sys) |
| 43 | self.assertIn(".gnu_debugdata", r.output) |
| 44 | |