public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: Adriaan Schmidt <adriaan.schmidt@siemens.com>
To: <isar-users@googlegroups.com>
Cc: Adriaan Schmidt <adriaan.schmidt@siemens.com>
Subject: [PATCH 2/3] sstate: add test case
Date: Thu, 23 Dec 2021 12:33:59 +0100	[thread overview]
Message-ID: <20211223113400.1123555-3-adriaan.schmidt@siemens.com> (raw)
In-Reply-To: <20211223113400.1123555-1-adriaan.schmidt@siemens.com>

The test populates an sstate cache, and then (after removing tmp/)
rebuilds certain recipes. Bitbake task_order logs are examined
to confirm that rebuilds used arifacts from the cache.

Signed-off-by: Adriaan Schmidt <adriaan.schmidt@siemens.com>
---
 testsuite/build_test/build_test.py | 14 ++++++
 testsuite/build_test/cibase.py     | 76 ++++++++++++++++++++++++++++++
 2 files changed, 90 insertions(+)

diff --git a/testsuite/build_test/build_test.py b/testsuite/build_test/build_test.py
index d343a78..65ff6e5 100644
--- a/testsuite/build_test/build_test.py
+++ b/testsuite/build_test/build_test.py
@@ -210,3 +210,17 @@ class ContainerSdkTest(CIBaseTest):
 
         self.init()
         self.perform_build_test(targets, bitbake_cmd='do_populate_sdk', container=True)
+
+class SstateTest(CIBaseTest):
+
+    """
+    Test builds with artifacts taken from sstate cache
+
+    :avocado: tags=sstate,fast,full
+    """
+    def test_sstate(self):
+        image_target = 'mc:qemuamd64-bullseye:isar-image-base'
+        package_target = 'mc:qemuamd64-bullseye:hello'
+
+        self.init('build-sstate')
+        self.perform_sstate_test(image_target, package_target)
diff --git a/testsuite/build_test/cibase.py b/testsuite/build_test/cibase.py
index 842ceaa..ae03aa7 100644
--- a/testsuite/build_test/cibase.py
+++ b/testsuite/build_test/cibase.py
@@ -1,5 +1,6 @@
 #!/usr/bin/env python3
 
+import glob
 import os
 import re
 import tempfile
@@ -86,3 +87,78 @@ class CIBaseTest(CIBuilder):
         # Cleanup
         self.delete_from_build_dir('tmp')
         self.delete_from_build_dir('ccache')
+
+    def perform_sstate_test(self, image_target, package_target, **kwargs):
+        def check_executed_tasks(target, expected):
+            taskorder_file = glob.glob(f'{self.build_dir}/tmp/work/*/{target}/*/temp/log.task_order')
+            try:
+                with open(taskorder_file[0], 'r') as f:
+                    tasks = [l.split()[0] for l in f.readlines()]
+            except (FileNotFoundError, IndexError):
+                tasks = []
+            if expected is None:
+                # require that no tasks were executed
+                return len(tasks) == 0
+            for e in expected:
+                should_run = True
+                if e.startswith('!'):
+                    should_run = False
+                    e = e[1:]
+                if should_run != (e in tasks):
+                    self.log.error(f"{target}: executed tasks {str(tasks)} did not match expected {str(expected)}")
+                    return False
+            return True
+
+        self.configure(sstate=True, **kwargs)
+
+        # Cleanup sstate and tmp before test
+        self.delete_from_build_dir('sstate-cache')
+        self.delete_from_build_dir('tmp')
+
+        # Populate cache
+        self.bitbake(image_target, **kwargs)
+
+        # Rebuild image
+        self.delete_from_build_dir('tmp')
+        self.bitbake(image_target, **kwargs)
+        if not all([
+                check_executed_tasks('isar-bootstrap-target',
+                    ['do_bootstrap_setscene', '!do_bootstrap']),
+                check_executed_tasks('buildchroot-target',
+                    ['do_rootfs_setscene', '!do_rootfs']),
+                check_executed_tasks('isar-image-base-*-wic-img',
+                    ['do_rootfs_setscene', '!do_rootfs'])
+            ]):
+            self.fail("Failed rebuild image")
+
+        # Rebuild single package
+        self.delete_from_build_dir('tmp')
+        self.bitbake(package_target, **kwargs)
+        if not all([
+                check_executed_tasks('isar-bootstrap-target',
+                    ['do_bootstrap_setscene']),
+                check_executed_tasks('buildchroot-target',
+                    ['!do_buildchroot_deploy']),
+                check_executed_tasks('hello',
+                    ['do_dpkg_build_setscene', 'do_deploy_deb', '!do_dpkg_build'])
+            ]):
+            self.fail("Failed rebuild single package")
+
+        # Rebuild package and image
+        self.delete_from_build_dir('tmp')
+        process.run(f'find {self.build_dir}/sstate-cache/ -name sstate:hello:* -delete')
+        self.bitbake(image_target, **kwargs)
+        if not all([
+                check_executed_tasks('isar-bootstrap-target',
+                    ['do_bootstrap_setscene', '!do_bootstrap']),
+                check_executed_tasks('buildchroot-target',
+                    ['do_rootfs_setscene', '!do_rootfs']),
+                check_executed_tasks('hello',
+                    ['do_fetch', 'do_dpkg_build']),
+                # TODO: if we actually make a change to hello, then we could test
+                #       that do_rootfs is executed. currently, hello is rebuilt,
+                #       but its sstate sig/hash does not change.
+                check_executed_tasks('isar-image-base-*-wic-img',
+                    ['do_rootfs_setscene', '!do_rootfs'])
+            ]):
+            self.fail("Failed rebuild package and image")
-- 
2.30.2


  parent reply	other threads:[~2021-12-23 11:34 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-23 11:33 [PATCH 0/3] Sstate-cache follow-up Adriaan Schmidt
2021-12-23 11:33 ` [PATCH 1/3] testsuite: refactor Adriaan Schmidt
2021-12-23 11:33 ` Adriaan Schmidt [this message]
2021-12-23 11:34 ` [PATCH 3/3] doc: add sstate to user manual Adriaan Schmidt
2022-01-04 15:47 ` [PATCH 0/3] Sstate-cache follow-up Jan Kiszka
2022-01-07  8:18   ` Schmidt, Adriaan
2022-02-22  6:24 ` 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=20211223113400.1123555-3-adriaan.schmidt@siemens.com \
    --to=adriaan.schmidt@siemens.com \
    --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