diff mbox series

[v3,2/2] selftest: wic: add test for zerorize option of empty plugin

Message ID 1be229689f4c8a3227efe23b3d8cb9b80ac646d5.1701176186.git.lukas.funke@weidmueller.com
State Accepted, archived
Commit 6c6b236b34b35d0e2c020e0f9c447ac35adf8faf
Headers show
Series wic: extend empty plugin with options to write zeros to partiton | expand

Commit Message

Lukas Funke Nov. 28, 2023, 1:52 p.m. UTC
From: Lukas Funke <lukas.funke@weidmueller.com>

Add test for empty plugin which tests whether the plugin creates
partitions with actual data which is 'zero'.

Signed-off-by: Lukas Funke <lukas.funke@weidmueller.com>
---
 meta/lib/oeqa/selftest/cases/wic.py | 36 +++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
diff mbox series

Patch

diff --git a/meta/lib/oeqa/selftest/cases/wic.py b/meta/lib/oeqa/selftest/cases/wic.py
index b4866bcb32..9672f3fae4 100644
--- a/meta/lib/oeqa/selftest/cases/wic.py
+++ b/meta/lib/oeqa/selftest/cases/wic.py
@@ -1391,6 +1391,42 @@  class Wic2(WicTestCase):
         result = runCmd("%s/usr/sbin/sfdisk --part-label %s 3" % (sysroot, image_path))
         self.assertEqual('ext-space', result.output)
 
+    def test_empty_zeroize_plugin(self):
+        img = 'core-image-minimal'
+        expected_size = [ 1024*1024,    # 1M
+                          512*1024,     # 512K
+                          2*1024*1024]  # 2M
+        # Check combination of sourceparams
+        with NamedTemporaryFile("w", suffix=".wks") as wks:
+            wks.writelines(
+                ['part empty --source empty --sourceparams="fill" --ondisk sda --fixed-size 1M\n',
+                 'part empty --source empty --sourceparams="size=512K" --ondisk sda --size 1M --align 1024\n',
+                 'part empty --source empty --sourceparams="size=2048k,bs=512K" --ondisk sda --size 4M --align 1024\n'
+                 ])
+            wks.flush()
+            cmd = "wic create %s -e %s -o %s" % (wks.name, img, self.resultdir)
+            runCmd(cmd)
+            wksname = os.path.splitext(os.path.basename(wks.name))[0]
+            wicout = glob(os.path.join(self.resultdir, "%s-*direct" % wksname))
+            # Skip the complete image and just look at the single partitions
+            for idx, value in enumerate(wicout[1:]):
+                self.logger.info(wicout[idx])
+                # Check if partitions are actually zeroized
+                with open(wicout[idx], mode="rb") as fd:
+                    ba = bytearray(fd.read())
+                    for b in ba:
+                        self.assertEqual(b, 0)
+                self.assertEqual(expected_size[idx], os.path.getsize(wicout[idx]))
+
+        # Check inconsistancy check between "fill" and "--size" parameter
+        with NamedTemporaryFile("w", suffix=".wks") as wks:
+            wks.writelines(['part empty --source empty --sourceparams="fill" --ondisk sda --size 1M\n'])
+            wks.flush()
+            cmd = "wic create %s -e %s -o %s" % (wks.name, img, self.resultdir)
+            result = runCmd(cmd, ignore_status=True)
+            self.assertIn("Source parameter 'fill' only works with the '--fixed-size' option, exiting.", result.output)
+            self.assertNotEqual(0, result.status)
+
 class ModifyTests(WicTestCase):
     def test_wic_ls(self):
         """Test listing image content using 'wic ls'"""