From patchwork Thu Jun 19 13:20:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Burton X-Patchwork-Id: 65296 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id C168BC7115D for ; Thu, 19 Jun 2025 13:20:54 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.14643.1750339251566168974 for ; Thu, 19 Jun 2025 06:20:51 -0700 Authentication-Results: mx.groups.io; dkim=none (message not signed); spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: ross.burton@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id EF3FE113E for ; Thu, 19 Jun 2025 06:20:30 -0700 (PDT) Received: from cesw-amp-gbt-1s-m12830-04.lab.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id A4BF43F58B for ; Thu, 19 Jun 2025 06:20:50 -0700 (PDT) From: Ross Burton To: openembedded-core@lists.openembedded.org Subject: [PATCH v2 1/4] oeqa/utils/command: fast-path get_bb_var() Date: Thu, 19 Jun 2025 14:20:42 +0100 Message-ID: <20250619132045.1521932-1-ross.burton@arm.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Thu, 19 Jun 2025 13:20:54 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/219077 get_bb_var() currently end up calling 'bitbake -e' and parsing the whole output. However if postconfig isn't set then we can speed this up by just calling bitbake-getvar. The complication with failing bitbake-getvar calls is because we need to be careful to return None instead of the empty string when the variable doesn't exist. Signed-off-by: Ross Burton --- meta/lib/oeqa/utils/commands.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/meta/lib/oeqa/utils/commands.py b/meta/lib/oeqa/utils/commands.py index 2a47f90e327..b60a6e6c389 100644 --- a/meta/lib/oeqa/utils/commands.py +++ b/meta/lib/oeqa/utils/commands.py @@ -285,7 +285,20 @@ def get_bb_vars(variables=None, target=None, postconfig=None): return values def get_bb_var(var, target=None, postconfig=None): - return get_bb_vars([var], target, postconfig)[var] + if postconfig: + return bitbake("-e %s" % target or "", postconfig=postconfig).output + else: + # Fast-path for the non-postconfig case + cmd = ["bitbake-getvar", "--quiet", "--value", var] + if target: + cmd.extend(["--recipe", target]) + try: + return subprocess.run(cmd, check=True, text=True, stdout=subprocess.PIPE).stdout.strip() + except subprocess.CalledProcessError as e: + # We need to return None not the empty string if the variable hasn't been set. + if e.returncode == 1: + return None + raise def get_test_layer(bblayers=None): if bblayers is None: From patchwork Thu Jun 19 13:20:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Burton X-Patchwork-Id: 65294 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0A5BC7115A for ; Thu, 19 Jun 2025 13:20:54 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.14644.1750339252055456608 for ; Thu, 19 Jun 2025 06:20:52 -0700 Authentication-Results: mx.groups.io; dkim=none (message not signed); spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: ross.burton@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 980A412FC for ; Thu, 19 Jun 2025 06:20:31 -0700 (PDT) Received: from cesw-amp-gbt-1s-m12830-04.lab.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 4D2E53F58B for ; Thu, 19 Jun 2025 06:20:51 -0700 (PDT) From: Ross Burton To: openembedded-core@lists.openembedded.org Subject: [PATCH v2 2/4] scripts/test-remote-image: remove useless postconfig arguments Date: Thu, 19 Jun 2025 14:20:43 +0100 Message-ID: <20250619132045.1521932-2-ross.burton@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250619132045.1521932-1-ross.burton@arm.com> References: <20250619132045.1521932-1-ross.burton@arm.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Thu, 19 Jun 2025 13:20:54 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/219078 I can't see a reason for this script to need to use postconfig files to bounce a variable assignment through another, so remove them. Signed-off-by: Ross Burton --- scripts/test-remote-image | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/scripts/test-remote-image b/scripts/test-remote-image index d209d228544..1d018992b07 100755 --- a/scripts/test-remote-image +++ b/scripts/test-remote-image @@ -152,8 +152,7 @@ class AutoTargetProfile(BaseTargetProfile): return controller def set_kernel_file(self): - postconfig = "QA_GET_MACHINE = \"${MACHINE}\"" - machine = get_bb_var('QA_GET_MACHINE', postconfig=postconfig) + machine = get_bb_var('MACHINE') self.kernel_file = self.kernel_type + '-' + machine + '.bin' def set_rootfs_file(self): @@ -215,13 +214,11 @@ class PublicAB(BaseRepoProfile): def get_repo_path(self): path = '/machines/' - postconfig = "QA_GET_MACHINE = \"${MACHINE}\"" - machine = get_bb_var('QA_GET_MACHINE', postconfig=postconfig) + machine = get_bb_var('MACHINE') if 'qemu' in machine: path += 'qemu/' - postconfig = "QA_GET_DISTRO = \"${DISTRO}\"" - distro = get_bb_var('QA_GET_DISTRO', postconfig=postconfig) + distro = get_bb_var('DISTRO') path += distro.replace('poky', machine) + '/' return path From patchwork Thu Jun 19 13:20:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Burton X-Patchwork-Id: 65295 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB7B8C7115B for ; Thu, 19 Jun 2025 13:20:54 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.14862.1750339252627408180 for ; Thu, 19 Jun 2025 06:20:52 -0700 Authentication-Results: mx.groups.io; dkim=none (message not signed); spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: ross.burton@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3E257113E for ; Thu, 19 Jun 2025 06:20:32 -0700 (PDT) Received: from cesw-amp-gbt-1s-m12830-04.lab.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E93173F58B for ; Thu, 19 Jun 2025 06:20:51 -0700 (PDT) From: Ross Burton To: openembedded-core@lists.openembedded.org Subject: [PATCH v2 3/4] oeqa/selftest/esdk: remove postconfig argument Date: Thu, 19 Jun 2025 14:20:44 +0100 Message-ID: <20250619132045.1521932-3-ross.burton@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250619132045.1521932-1-ross.burton@arm.com> References: <20250619132045.1521932-1-ross.burton@arm.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Thu, 19 Jun 2025 13:20:54 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/219079 Discovered when looking for users of get_bb_var()'s postconfig argument, this wrapper around runCmd() has a postconfig argument that has odd behaviour: it _appends_ the new configuration to local.conf instead of having them used for this specific run (unlike the other functions in commands.py) None of the eSDK tests use this functionality, so remove it. Future test cases that need to write further configuration should do so directly. Signed-off-by: Ross Burton --- meta/lib/oeqa/selftest/cases/esdk.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/meta/lib/oeqa/selftest/cases/esdk.py b/meta/lib/oeqa/selftest/cases/esdk.py index 9f5de2cde7f..7a5fe00a082 100644 --- a/meta/lib/oeqa/selftest/cases/esdk.py +++ b/meta/lib/oeqa/selftest/cases/esdk.py @@ -27,11 +27,7 @@ class oeSDKExtSelfTest(OESelftestTestCase): return glob.glob(pattern)[0] @staticmethod - def run_esdk_cmd(env_eSDK, tmpdir_eSDKQA, cmd, postconfig=None, **options): - if postconfig: - esdk_conf_file = os.path.join(tmpdir_eSDKQA, 'conf', 'local.conf') - with open(esdk_conf_file, 'a+') as f: - f.write(postconfig) + def run_esdk_cmd(env_eSDK, tmpdir_eSDKQA, cmd, **options): if not options: options = {} if not 'shell' in options: From patchwork Thu Jun 19 13:20:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Burton X-Patchwork-Id: 65297 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id CEC50C7115C for ; Thu, 19 Jun 2025 13:20:54 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.14645.1750339253328364228 for ; Thu, 19 Jun 2025 06:20:53 -0700 Authentication-Results: mx.groups.io; dkim=none (message not signed); spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: ross.burton@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DAD2E113E for ; Thu, 19 Jun 2025 06:20:32 -0700 (PDT) Received: from cesw-amp-gbt-1s-m12830-04.lab.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 916683F58B for ; Thu, 19 Jun 2025 06:20:52 -0700 (PDT) From: Ross Burton To: openembedded-core@lists.openembedded.org Subject: [PATCH v2 4/4] oeqa/selftest: add new test for toolchain switching Date: Thu, 19 Jun 2025 14:20:45 +0100 Message-ID: <20250619132045.1521932-4-ross.burton@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250619132045.1521932-1-ross.burton@arm.com> References: <20250619132045.1521932-1-ross.burton@arm.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Thu, 19 Jun 2025 13:20:54 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/219080 Add a basic test for the toolchain switching code: set the toolchain to GCC by default but Clang for a specific recipe, and verify that two recipes are built with the expected compiler. This works because before we strip the installed binaries there is a .comment segment that contains the list of toolchains used. Signed-off-by: Ross Burton --- meta/lib/oeqa/selftest/cases/toolchain.py | 71 +++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 meta/lib/oeqa/selftest/cases/toolchain.py diff --git a/meta/lib/oeqa/selftest/cases/toolchain.py b/meta/lib/oeqa/selftest/cases/toolchain.py new file mode 100644 index 00000000000..b4b280d0375 --- /dev/null +++ b/meta/lib/oeqa/selftest/cases/toolchain.py @@ -0,0 +1,71 @@ +# +# Copyright OpenEmbedded Contributors +# +# SPDX-License-Identifier: MIT +# + +import shutil +import subprocess +import tempfile +from types import SimpleNamespace + +import oe.path +from oeqa.selftest.case import OESelftestTestCase +from oeqa.utils.commands import bitbake, get_bb_var, get_bb_vars + +class ToolchainTests(OESelftestTestCase): + + def test_toolchain_switching(self): + """ + Test that a configuration that uses GCC by default but clang for one + specific recipe does infact do that. + """ + + def extract_comment(objcopy, filename): + """ + Using the specified `objcopy`, return the .comment segment from + `filename` as a bytes(). + """ + with tempfile.NamedTemporaryFile(prefix="comment-") as f: + cmd = [objcopy, "--dump-section", ".comment=" + f.name, filename] + subprocess.run(cmd, check=True) + # clang's objcopy writes to a temporary file and renames, so we need to re-open. + with open(f.name, "rb") as f2: + return f2.read() + + def check_recipe(recipe, filename, override, comment_present, comment_absent=None): + """ + Check that `filename` in `recipe`'s bindir contains `comment`, and + the overrides contain `override`. + """ + d = SimpleNamespace(**get_bb_vars(("D", "bindir", "OBJCOPY", "OVERRIDES", "PATH"), target=recipe)) + + self.assertIn(override, d.OVERRIDES) + + binary = oe.path.join(d.D, d.bindir, filename) + + objcopy = shutil.which(d.OBJCOPY, path=d.PATH) + self.assertIsNotNone(objcopy) + + comment = extract_comment(objcopy, binary) + self.assertIn(comment_present, comment) + if comment_absent: + self.assertNotIn(comment_absent, comment) + + + # GCC by default, clang for selftest-hello. + self.write_config(""" +TOOLCHAIN = "gcc" +TOOLCHAIN:pn-selftest-hello = "clang" + """) + + # Force these recipes to re-install so we can extract the .comments from + # the install directory, as they're stripped out of the final packages. + bitbake("m4 selftest-hello -C install") + + # m4 should be built with GCC and only GCC + check_recipe("m4", "m4", "toolchain-gcc", b"GCC: (GNU)", b"clang") + + # helloworld should be built with clang. We can't assert that GCC is not + # present as it will be linked against glibc which is built with GCC. + check_recipe("selftest-hello", "helloworld", "toolchain-clang", b"clang version")