From patchwork Tue Jun 13 09:51:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Hoyes X-Patchwork-Id: 25509 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 EB85AC7EE2E for ; Tue, 13 Jun 2023 09:52:25 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.9326.1686649941934246890 for ; Tue, 13 Jun 2023 02:52:22 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: peter.hoyes@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 3E2721FB; Tue, 13 Jun 2023 02:53:06 -0700 (PDT) Received: from e125920.cambridge.arm.com (unknown [10.1.199.64]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C38B43F71E; Tue, 13 Jun 2023 02:52:20 -0700 (PDT) From: Peter Hoyes To: openembedded-core@lists.openembedded.org Cc: Ross.Burton@arm.com, Peter Hoyes Subject: [PATCH 1/2] rootfs-postcommands,testimage: Move testdata generation to own task Date: Tue, 13 Jun 2023 10:51:47 +0100 Message-Id: <20230613095148.1269420-1-peter.hoyes@arm.com> X-Mailer: git-send-email 2.34.1 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 ; Tue, 13 Jun 2023 09:52:25 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/182704 From: Peter Hoyes write_image_test_data is currently a ROOTFS_POSTPROCESS_COMMAND, even though it does not act on the rootfs. Additionally it is only required when running testimage. Promote it to its own task, to decouple it from rootfs generation, and move it to testimage.bbclass Signed-off-by: Peter Hoyes --- .../rootfs-postcommands.bbclass | 23 ------------------- meta/classes-recipe/testimage.bbclass | 21 +++++++++++++++++ 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/meta/classes-recipe/rootfs-postcommands.bbclass b/meta/classes-recipe/rootfs-postcommands.bbclass index 690fa976aa..ad7e7ccd8b 100644 --- a/meta/classes-recipe/rootfs-postcommands.bbclass +++ b/meta/classes-recipe/rootfs-postcommands.bbclass @@ -33,9 +33,6 @@ ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("IMAGE_FEATURES", "read-only # and we don't want to disable such a default that by setting a value here. APPEND:append = '${@bb.utils.contains("IMAGE_FEATURES", "read-only-rootfs", " ro", "", d)}' -# Generates test data file with data store variables expanded in json format -ROOTFS_POSTPROCESS_COMMAND += "write_image_test_data; " - # Write manifest IMAGE_MANIFEST = "${IMGDEPLOYDIR}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.manifest" ROOTFS_POSTUNINSTALL_COMMAND =+ "write_image_manifest ; " @@ -368,26 +365,6 @@ rootfs_sysroot_relativelinks () { sysroot-relativelinks.py ${SDK_OUTPUT}/${SDKTARGETSYSROOT} } -# Generated test data json file -python write_image_test_data() { - from oe.data import export2json - - deploy_dir = d.getVar('IMGDEPLOYDIR') - link_name = d.getVar('IMAGE_LINK_NAME') - testdata_name = os.path.join(deploy_dir, "%s.testdata.json" % d.getVar('IMAGE_NAME')) - - searchString = "%s/"%(d.getVar("TOPDIR")).replace("//","/") - export2json(d, testdata_name, searchString=searchString, replaceString="") - - if os.path.exists(testdata_name) and link_name: - testdata_link = os.path.join(deploy_dir, "%s.testdata.json" % link_name) - if testdata_link != testdata_name: - if os.path.lexists(testdata_link): - os.remove(testdata_link) - os.symlink(os.path.basename(testdata_name), testdata_link) -} -write_image_test_data[vardepsexclude] += "TOPDIR" - # Check for unsatisfied recommendations (RRECOMMENDS) python rootfs_log_check_recommends() { log_path = d.expand("${T}/log.do_rootfs") diff --git a/meta/classes-recipe/testimage.bbclass b/meta/classes-recipe/testimage.bbclass index b48cd96575..b23340420f 100644 --- a/meta/classes-recipe/testimage.bbclass +++ b/meta/classes-recipe/testimage.bbclass @@ -100,6 +100,27 @@ TESTIMAGE_DUMP_DIR ?= "${LOG_DIR}/runtime-hostdump/" TESTIMAGE_UPDATE_VARS ?= "DL_DIR WORKDIR DEPLOY_DIR_IMAGE IMAGE_LINK_NAME" +# Generated test data json file +python do_write_image_test_data() { + from oe.data import export2json + + deploy_dir = d.getVar('IMGDEPLOYDIR') + link_name = d.getVar('IMAGE_LINK_NAME') + testdata_name = os.path.join(deploy_dir, "%s.testdata.json" % d.getVar('IMAGE_NAME')) + + searchString = "%s/"%(d.getVar("TOPDIR")).replace("//","/") + export2json(d, testdata_name, searchString=searchString, replaceString="") + + if os.path.exists(testdata_name) and link_name: + testdata_link = os.path.join(deploy_dir, "%s.testdata.json" % link_name) + if testdata_link != testdata_name: + if os.path.lexists(testdata_link): + os.remove(testdata_link) + os.symlink(os.path.basename(testdata_name), testdata_link) +} +do_write_image_test_data[vardepsexclude] += "TOPDIR" +addtask write_image_test_data after do_rootfs before do_image_complete + testimage_dump_target () { top -bn1 ps From patchwork Tue Jun 13 09:51:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Hoyes X-Patchwork-Id: 25510 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 CF5E9C88CB6 for ; Tue, 13 Jun 2023 09:52:35 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.9441.1686649952881754316 for ; Tue, 13 Jun 2023 02:52:33 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: peter.hoyes@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 65AEA1FB; Tue, 13 Jun 2023 02:53:17 -0700 (PDT) Received: from e125920.cambridge.arm.com (unknown [10.1.199.64]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B8A763F71E; Tue, 13 Jun 2023 02:52:31 -0700 (PDT) From: Peter Hoyes To: openembedded-core@lists.openembedded.org Cc: Ross.Burton@arm.com, Peter Hoyes Subject: [PATCH 2/2] testimage: Set nostamp for do_write_image_test_data Date: Tue, 13 Jun 2023 10:51:48 +0100 Message-Id: <20230613095148.1269420-2-peter.hoyes@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230613095148.1269420-1-peter.hoyes@arm.com> References: <20230613095148.1269420-1-peter.hoyes@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 ; Tue, 13 Jun 2023 09:52:35 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/182705 From: Peter Hoyes The testdata.json file generated as part of the rootfs postprocess commands contains almost all Bitbake variables and is used by OEQA test cases to inspect the build environment. However it is not automatically regenerated, complicating the process of developing OEQA test cases. Set nostamp on the new do_write_image_test_data task so that it always runs. Add a demonstrative OE selftest. Signed-off-by: Peter Hoyes --- meta/classes-recipe/testimage.bbclass | 1 + meta/lib/oeqa/selftest/cases/testimage.py | 26 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 meta/lib/oeqa/selftest/cases/testimage.py diff --git a/meta/classes-recipe/testimage.bbclass b/meta/classes-recipe/testimage.bbclass index b23340420f..67f7f3629e 100644 --- a/meta/classes-recipe/testimage.bbclass +++ b/meta/classes-recipe/testimage.bbclass @@ -118,6 +118,7 @@ python do_write_image_test_data() { os.remove(testdata_link) os.symlink(os.path.basename(testdata_name), testdata_link) } +do_write_image_test_data[nostamp] = "1" do_write_image_test_data[vardepsexclude] += "TOPDIR" addtask write_image_test_data after do_rootfs before do_image_complete diff --git a/meta/lib/oeqa/selftest/cases/testimage.py b/meta/lib/oeqa/selftest/cases/testimage.py new file mode 100644 index 0000000000..3ba9184821 --- /dev/null +++ b/meta/lib/oeqa/selftest/cases/testimage.py @@ -0,0 +1,26 @@ +# +# Copyright OpenEmbedded Contributors +# +# SPDX-License-Identifier: MIT +# + +import json +from oeqa.selftest.case import OESelftestTestCase +from oeqa.utils.commands import bitbake, get_bb_vars + +class TestDataTests(OESelftestTestCase): + def test_regenerate(self): + """ + Test that variables changes are reflected in testdata.json + """ + test_image = "core-image-minimal" + self.write_config('IMAGE_CLASSES += "testimage"\nTEST_VARIABLE = "VALUE1"') + bitbake(test_image) + self.append_config('TEST_VARIABLE = "VALUE2"') + bitbake(test_image) + + vars = get_bb_vars(('DEPLOY_DIR_IMAGE', 'IMAGE_LINK_NAME'), test_image) + testdata_json = "%s/%s.testdata.json" % (vars['DEPLOY_DIR_IMAGE'], vars['IMAGE_LINK_NAME']) + with open(testdata_json, 'r') as tf: + testdata_vars = json.load(tf) + self.assertEqual(testdata_vars['TEST_VARIABLE'], 'VALUE2')