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 |
| 12 | from oeqa.utils.commands import bitbake, get_bb_var, runCmd |
| 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 | |
| 20 | self.write_config(""" |
| 21 | PACKAGE_MINIDEBUGINFO = "1" |
| 22 | IMAGE_FSTYPES = "tar.bz2" |
| 23 | """) |
| 24 | bitbake("core-image-minimal {}:do_addto_recipe_sysroot".format(binutils)) |
| 25 | |
| 26 | deploy_dir = get_bb_var("DEPLOY_DIR_IMAGE") |
| 27 | native_sysroot = get_bb_var("RECIPE_SYSROOT_NATIVE", binutils) |
| 28 | readelf = get_bb_var("READELF", "core-image-minimal") |
| 29 | |
| 30 | # confirm that executables and shared libraries contain an ELF section |
| 31 | # ".gnu_debugdata" which stores minidebuginfo. |
| 32 | with tempfile.TemporaryDirectory(prefix = "unpackfs-") as unpackedfs: |
| 33 | filename = os.path.join(deploy_dir, "core-image-minimal-{}.tar.bz2".format(self.td["MACHINE"])) |
| 34 | shutil.unpack_archive(filename, unpackedfs) |
| 35 | |
| 36 | r = runCmd([readelf, "-W", "-S", os.path.join(unpackedfs, "bin", "busybox")], |
| 37 | native_sysroot = native_sysroot, target_sys = target_sys) |
| 38 | self.assertIn(".gnu_debugdata", r.output) |
| 39 | |
| 40 | r = runCmd([readelf, "-W", "-S", os.path.join(unpackedfs, "lib", "libc.so.6")], |
| 41 | native_sysroot = native_sysroot, target_sys = target_sys) |
| 42 | self.assertIn(".gnu_debugdata", r.output) |
| 43 | |