Skip to contentSkip to conversation

rootfs-postcommands,testimage: Move testdata generation to own task

PATCH In review Peter Hoyes 2 participants 3 messages Jun 13, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 rootfs-postcommands,testimage: Move testdata generation to own task

From: Peter Hoyes <[email protected]>

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

---
 .../rootfs-postcommands.bbclass               | 23 -------------------
 meta/classes-recipe/testimage.bbclass         | 21 +++++++++++++++++
 2 files changed, 21 insertions(+), 23 deletions(-)
meta/classes-recipe/rootfs-postcommands.bbclass +0 -23
index 690fa976aa..ad7e7ccd8b 100644
@@ -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")
meta/classes-recipe/testimage.bbclass +21 -0
index b48cd96575..b23340420f 100644
@@ -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
Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/2 testimage: Set nostamp for do_write_image_test_data

From: Peter Hoyes <[email protected]>

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.

---
 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
meta/classes-recipe/testimage.bbclass +1 -0
index b23340420f..67f7f3629e 100644
@@ -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
 
meta/lib/oeqa/selftest/cases/testimage.py new file +26 -0
new file mode 100644
index 0000000000..3ba9184821
@@ -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')
Signature · 1 line
2.34.1
#2 lore raw

Re: [OE-core] [PATCH 2/2] testimage: Set nostamp for do_write_image_test_data

Quoted 24 lines · Peter Hoyes

From: Peter Hoyes <[email protected]>

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.

---
 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
meta/classes-recipe/testimage.bbclass +0 -0
index b23340420f..67f7f3629e 100644

meta/classes-recipe/testimage.bbclass python do_write_image_test_data() { · line 123

Quoted 6 lines
meta/classes-recipe/testimage.bbclass +1 -0
@@ -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

I'm torn on this. What this means is that all other tasks depending on do_image_complete will now also rerun. I suspect that will cause a cascade of selftest failures as they aren't written to expect that.

I know there was an alternative patch of injecting all the values into the checksum, I suspect that suffers the same issue as we'd need to filter it a bit to stop things like TIME changing it. We can't need *everything* there!

What we really need to do is filter the list of variables being written out to some set of what is really needed rather than everything.

Cheers,

Richard