diff mbox series

[2/2] testimage: Set nostamp for do_write_image_test_data

Message ID 20230613095148.1269420-2-peter.hoyes@arm.com
State Superseded
Headers show
Series [1/2] rootfs-postcommands,testimage: Move testdata generation to own task | expand

Commit Message

Peter Hoyes June 13, 2023, 9:51 a.m. UTC
From: Peter Hoyes <Peter.Hoyes@arm.com>

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 <Peter.Hoyes@arm.com>
---
 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

Comments

Richard Purdie June 13, 2023, 11:29 a.m. UTC | #1
On Tue, 2023-06-13 at 10:51 +0100, Peter Hoyes wrote:
> From: Peter Hoyes <Peter.Hoyes@arm.com>
> 
> 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 <Peter.Hoyes@arm.com>
> ---
>  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

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
diff mbox series

Patch

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')