public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: Anton Mikanovich <amikan@ilbers.de>
To: isar-users@googlegroups.com
Cc: Anton Mikanovich <amikan@ilbers.de>
Subject: [PATCH 4/6] CI: Add essential packages rebuild test case
Date: Fri, 21 Feb 2025 17:48:41 +0200	[thread overview]
Message-ID: <20250221154843.515037-5-amikan@ilbers.de> (raw)
In-Reply-To: <20250221154843.515037-1-amikan@ilbers.de>

Rebuilding of essential packages (already present in sbuild chroot) was
not covered with CI before. Add a testcase for such a fuctionality.

This test case also covers f62de679 change already merged.

Signed-off-by: Anton Mikanovich <amikan@ilbers.de>
---
 testsuite/cibase.py    | 101 +++++++++++++++++++++++++++++++++++++++++
 testsuite/cibuilder.py |   4 ++
 testsuite/citest.py    |  25 +++++++++-
 3 files changed, 129 insertions(+), 1 deletion(-)

diff --git a/testsuite/cibase.py b/testsuite/cibase.py
index 075535b1..c692719a 100755
--- a/testsuite/cibase.py
+++ b/testsuite/cibase.py
@@ -1,4 +1,10 @@
 #!/usr/bin/env python3
+#
+# This software is a part of ISAR.
+# Copyright (C) 2022-2025 ilbers GmbH
+# Copyright (C) 2022-2024 Siemens AG
+#
+# SPDX-License-Identifier: MIT
 
 import glob
 import os
@@ -359,3 +365,98 @@ class CIBaseTest(CIBuilder):
                         self.fail("Source packages are equal")
         finally:
             self.cleanup_tmp_layer(tmp_layer_dir)
+
+
+class CIEssentialTest(CIBaseTest):
+    def init(self, pkg='sed', dep='enable-fsck', **kwargs):
+        self.__pkg = pkg
+        self.__dep = dep
+        self.__flag = 'isar'
+        super().init(**kwargs)
+
+    def perform_build_test(self, targets, **kwargs):
+        package_targets = []
+        dependant_targets = []
+        localapt_targets = []
+        cleanup_targets = []
+        rootfs_dirs = {}
+        work_dirs = {}
+        for target in targets:
+            package_target = target.split(':', 3)
+            dependant_target = package_target.copy()
+            cleanup_target = package_target.copy()
+
+            package_target[-1] = self.__pkg
+            dependant_target[-1] = self.__dep
+            cleanup_target[-1] = 'sbuild-chroot-target:do_cleansstate'
+
+            package_targets.append(':'.join(package_target))
+            dep_str = ':'.join(dependant_target)
+            dependant_targets.append(dep_str)
+            localapt_targets.append(dep_str + ':do_local_isarapt')
+            cleanup_targets.append(':'.join(cleanup_target))
+
+            rootfs_dirs[target] = CIUtils.getVars(
+                'IMAGE_ROOTFS', target=target
+            )
+
+            work_dirs[dep_str] = CIUtils.getVars('WORKDIR', target=dep_str)
+
+        self.configure(essentials=self.__pkg, **kwargs)
+
+        cmd = (
+            "%e dpkg-query -f='\${Version}' -W "
+            f"{self.__pkg} > ${{WORKDIR}}/ci_vercheck"
+        )
+        sbuildclass_file = self.set_sbuild_hook(cmd)
+
+        try:
+            # Build local isar-apt copy
+            self.bitbake(localapt_targets, **kwargs)
+
+            # Build package for target
+            self.bitbake(package_targets, **kwargs)
+
+            # Cleanup existing sbuild chroot
+            self.bitbake(cleanup_targets, **kwargs)
+
+            # Build other package
+            self.bitbake(dependant_targets, **kwargs)
+
+            # Ensure updated build dep used
+            for target in dependant_targets:
+                check_path = os.path.join(work_dirs[target], 'ci_vercheck')
+                with open(check_path) as f:
+                    ver = f.read()
+                if self.__flag not in ver:
+                    self.fail(
+                        f"Package {self.__pkg} of version {ver} used for "
+                        f"building don't have {self.__flag} flag"
+                    )
+        finally:
+            self.restorefile(sbuildclass_file)
+
+        # Change rootfs bbclass and rebuild
+        layerdir_core = CIUtils.getVars('LAYERDIR_core')
+        rfsclass_file = os.path.join(layerdir_core, 'classes/rootfs.bbclass')
+        self.backupfile(rfsclass_file)
+        try:
+            with open(rfsclass_file, 'a') as file:
+                file.write('python do_rootfs_install:append() {\n\n}')
+
+            # Build again package for target
+            self.bitbake(package_targets, **kwargs)
+        finally:
+            self.restorefile(rfsclass_file)
+
+        # Build full image after all
+        self.bitbake(targets, **kwargs)
+
+        # Ensure target rootfs use non-updated package
+        for target in targets:
+            ver = self.get_pkg_ver(rootfs_dirs[target], self.__pkg)
+            if self.__flag in ver:
+                self.fail(
+                    f"Package {self.__pkg} of version {ver} used for "
+                    f"installing have {self.__flag} flag, but shouldn't"
+                )
diff --git a/testsuite/cibuilder.py b/testsuite/cibuilder.py
index d335dbe8..5aa64e31 100755
--- a/testsuite/cibuilder.py
+++ b/testsuite/cibuilder.py
@@ -109,6 +109,7 @@ class CIBuilder(Test):
         source_date_epoch=None,
         use_apt_snapshot=False,
         image_install=None,
+        essentials=None,
         **kwargs,
     ):
         # write configuration file and set bitbake_args
@@ -155,6 +156,7 @@ class CIBuilder(Test):
             f"  sstate_dir = {sstate_dir}\n"
             f"  ccache_dir = {ccache_dir}\n"
             f"  image_install = {image_install}\n"
+            f"  essentials = {essentials}\n"
             f"==================================================="
         )
 
@@ -216,6 +218,8 @@ class CIBuilder(Test):
                 f.write('IMAGE_INSTALL = "%s"\n' % image_install)
             if fail_on_cleanup == '1':
                 f.write('ISAR_FAIL_ON_CLEANUP = "1"\n')
+            if essentials:
+                f.write('ISAR_REBUILD_ESSENTIAL_PKGS = "%s"\n' % essentials)
 
         # include ci_build.conf in local.conf
         with open(self.build_dir + '/conf/local.conf', 'r+') as f:
diff --git a/testsuite/citest.py b/testsuite/citest.py
index ee965278..9e2c1b43 100755
--- a/testsuite/citest.py
+++ b/testsuite/citest.py
@@ -1,9 +1,15 @@
 #!/usr/bin/env python3
+#
+# This software is a part of ISAR.
+# Copyright (C) 2022-2025 ilbers GmbH
+# Copyright (C) 2022-2025 Siemens AG
+#
+# SPDX-License-Identifier: MIT
 
 from avocado import skipUnless
 from avocado.core import exceptions
 from avocado.utils import path
-from cibase import CIBaseTest
+from cibase import CIBaseTest, CIEssentialTest
 from utils import CIUtils
 
 UMOCI_AVAILABLE = True
@@ -400,6 +406,23 @@ class SstateTest(CIBaseTest):
         self.perform_sstate_test(image_target, package_target)
 
 
+class EssentialTest(CIEssentialTest):
+
+    """
+    Essential packages rebuild test
+
+    :avocado: tags=essential,full
+    """
+
+    def test_essential(self):
+        targets = [
+            'mc:qemuamd64-bookworm:isar-image-base',
+        ]
+
+        self.init(pkg="sed", dep="enable-fsck")
+        self.perform_build_test(targets)
+
+
 class SingleTest(CIBaseTest):
 
     """
-- 
2.34.1

-- 
You received this message because you are subscribed to the Google Groups "isar-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/isar-users/20250221154843.515037-5-amikan%40ilbers.de.

  parent reply	other threads:[~2025-02-21 15:49 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-21 15:48 [PATCH 0/6] Fix essentials rebuild and cover with CI Anton Mikanovich
2025-02-21 15:48 ` [PATCH 1/6] CI: Add API for checking package version in rootfs Anton Mikanovich
2025-02-21 15:48 ` [PATCH 2/6] CI: Add API for sbuild hook insertion Anton Mikanovich
2025-02-21 15:48 ` [PATCH 3/6] CI: Add sed as essential rebuild test package Anton Mikanovich
2025-02-21 15:48 ` Anton Mikanovich [this message]
2025-02-21 15:48 ` [PATCH 5/6] CI: Fix getVars API on fast recalling Anton Mikanovich
2025-02-21 15:48 ` [PATCH 6/6] meta: Do not update isar-apt during sbuild chroot prepare Anton Mikanovich
2025-02-21 16:34   ` 'Jan Kiszka' via isar-users
2025-03-03 10:13     ` Anton Mikanovich
2025-03-03 14:32       ` 'Jan Kiszka' via isar-users
2025-03-03 15:16         ` Anton Mikanovich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250221154843.515037-5-amikan@ilbers.de \
    --to=amikan@ilbers.de \
    --cc=isar-users@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox