[2/2] testsuite: check Isar image for reproducability.

Message ID 20221129175814.16355-3-ubely@ilbers.de
State RFC
Headers show
Series check Isar image for reproducability | expand

Commit Message

Uladzimir Bely Nov. 29, 2022, 5:58 p.m. UTC
This test uses 'diffoscope'[1] tool to check the difference between
two consecutive builds and copy the differeneces in html format.

[1] https://diffoscope.org/

Signed-off-by: Uladzimir Bely <ubely@ilbers.de>
---
 testsuite/cibase.py | 44 ++++++++++++++++++++++++++++++++++++++++++++
 testsuite/citest.py | 18 ++++++++++++++++++
 2 files changed, 62 insertions(+)

Patch

diff --git a/testsuite/cibase.py b/testsuite/cibase.py
index 6239b4de..8a6d4c6e 100755
--- a/testsuite/cibase.py
+++ b/testsuite/cibase.py
@@ -2,6 +2,7 @@ 
 
 import glob
 import os
+import subprocess
 import re
 import tempfile
 import time
@@ -55,6 +56,49 @@  class CIBaseTest(CIBuilder):
             # Try to build with changed configuration with no cleanup
             self.bitbake(targets, **kwargs)
 
+    def perform_reproducable_test(self, targets, **kwargs):
+        def get_bitbake_var(output, var):
+            ret = ''
+            for line in output.splitlines():
+                if line.startswith(var + '='):
+                    ret = line.split('"')[1]
+            return ret
+
+        self.configure(**kwargs)
+
+        self.log.info('Starting first build...')
+        self.bitbake(targets, **kwargs)
+
+        self.move_in_build_dir('tmp', 'tmp1')
+        self.delete_from_build_dir('sstate-cache')
+        self.delete_from_build_dir('ccache')
+
+        self.log.info('Starting second build...')
+        self.bitbake(targets, **kwargs)
+        self.bitbake(targets, **kwargs)
+
+        self.move_in_build_dir('tmp', 'tmp2')
+        self.delete_from_build_dir('sstate-cache')
+        self.delete_from_build_dir('ccache')
+
+        for target in targets:
+            output = subprocess.check_output(['bitbake', '-e', target]).decode()
+
+            machine=get_bitbake_var(output, 'MACHINE')
+            distro=get_bitbake_var(output, 'DISTRO')
+
+            cmdline = ['diffoscope']
+            cmdline.extend(['--html-dir', 'diffoscope_out'])
+            cmdline.extend(['tmp1/deploy/images/' + machine + '/isar-image-base-' + distro + '-' + machine + '.tar.gz'])
+            cmdline.extend(['tmp2/deploy/images/' + machine + '/isar-image-base-' + distro + '-' + machine + '.tar.gz'])
+
+            print(cmdline)
+
+            p1 = subprocess.call(cmdline)
+
+            if p1.returncode:
+                self.fail('Image is not reproducable')
+
     def perform_ccache_test(self, targets, **kwargs):
         def ccache_stats(dir, field):
             # Look ccache source's 'src/core/Statistic.hpp' for field meanings
diff --git a/testsuite/citest.py b/testsuite/citest.py
index 2dc78015..aa63e848 100755
--- a/testsuite/citest.py
+++ b/testsuite/citest.py
@@ -48,6 +48,24 @@  class ReproTest(CIBaseTest):
         finally:
             self.move_in_build_dir('tmp', 'tmp_repro_unsigned')
 
+class ReproducableTest(CIBaseTest):
+
+    """
+    Test cached base repository
+
+    :avocado: tags=reproducable
+    """
+    def test_reproducable(self):
+        targets = [
+            'mc:qemuamd64-bullseye:isar-image-base'
+                  ]
+
+        self.init()
+        try:
+            self.perform_reproducable_test(targets)
+        except:
+            self.cancel('KFAIL')
+
 class CcacheTest(CIBaseTest):
 
     """