blob: 2919f0793929cfae420fa3d35d2f83784c18b17a [file] [log] [blame]
Patrick Williams7784c422022-11-17 07:29:11 -06001#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6import os
7import subprocess
8import tempfile
9import shutil
10
11from oeqa.selftest.case import OESelftestTestCase
Andrew Geisslerfc113ea2023-03-31 09:59:46 -050012from oeqa.utils.commands import bitbake, get_bb_var, get_bb_vars, runCmd
Patrick Williams7784c422022-11-17 07:29:11 -060013
14
15class 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 Geisslerfc113ea2023-03-31 09:59:46 -050020 image = 'core-image-minimal'
21 bb_vars = get_bb_vars(['DEPLOY_DIR_IMAGE', 'IMAGE_LINK_NAME', 'READELF'], image)
22
Patrick Williams7784c422022-11-17 07:29:11 -060023 self.write_config("""
Patrick Williams169d7bc2024-01-05 11:33:25 -060024DISTRO_FEATURES:append = " minidebuginfo"
Patrick Williams7784c422022-11-17 07:29:11 -060025IMAGE_FSTYPES = "tar.bz2"
26""")
Andrew Geisslerfc113ea2023-03-31 09:59:46 -050027 bitbake("{} {}:do_addto_recipe_sysroot".format(image, binutils))
Patrick Williams7784c422022-11-17 07:29:11 -060028
Patrick Williams7784c422022-11-17 07:29:11 -060029 native_sysroot = get_bb_var("RECIPE_SYSROOT_NATIVE", binutils)
Patrick Williams7784c422022-11-17 07:29:11 -060030
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 Geisslerfc113ea2023-03-31 09:59:46 -050034 filename = os.path.join(bb_vars['DEPLOY_DIR_IMAGE'], "{}.tar.bz2".format(bb_vars['IMAGE_LINK_NAME']))
Patrick Williams7784c422022-11-17 07:29:11 -060035 shutil.unpack_archive(filename, unpackedfs)
36
Andrew Geisslerfc113ea2023-03-31 09:59:46 -050037 r = runCmd([bb_vars['READELF'], "-W", "-S", os.path.join(unpackedfs, "bin", "busybox")],
Patrick Williams7784c422022-11-17 07:29:11 -060038 native_sysroot = native_sysroot, target_sys = target_sys)
39 self.assertIn(".gnu_debugdata", r.output)
40
Andrew Geisslerfc113ea2023-03-31 09:59:46 -050041 r = runCmd([bb_vars['READELF'], "-W", "-S", os.path.join(unpackedfs, "lib", "libc.so.6")],
Patrick Williams7784c422022-11-17 07:29:11 -060042 native_sysroot = native_sysroot, target_sys = target_sys)
43 self.assertIn(".gnu_debugdata", r.output)
44