From: Adriaan Schmidt <adriaan.schmidt@siemens.com>
To: <isar-users@googlegroups.com>
Cc: Adriaan Schmidt <adriaan.schmidt@siemens.com>
Subject: [PATCH v2 2/3] sstate: add test case
Date: Tue, 22 Feb 2022 10:06:27 +0100 [thread overview]
Message-ID: <20220222090628.2174022-3-adriaan.schmidt@siemens.com> (raw)
In-Reply-To: <20220222090628.2174022-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 | 90 ++++++++++++++++++++++++++++++
2 files changed, 104 insertions(+)
diff --git a/testsuite/build_test/build_test.py b/testsuite/build_test/build_test.py
index ec1bb311..e0eea1bd 100644
--- a/testsuite/build_test/build_test.py
+++ b/testsuite/build_test/build_test.py
@@ -230,3 +230,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 49d34de1..dbf4d3a3 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
@@ -77,3 +78,92 @@ 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)
+
+ # Save contents of image deploy dir
+ expected_files = set(glob.glob(f'{self.build_dir}/tmp/deploy/images/*/*'))
+
+ # 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_install_setscene', '!do_rootfs_install']),
+ check_executed_tasks('isar-image-base-*-wic-img',
+ ['do_rootfs_install_setscene', '!do_rootfs_install'])
+ ]):
+ self.fail("Failed rebuild image")
+
+ # Verify content of image deploy dir
+ deployed_files = set(glob.glob(f'{self.build_dir}/tmp/deploy/images/*/*'))
+ if not deployed_files == expected_files:
+ if len(expected_files - deployed_files) > 0:
+ self.log.error(f"{target}: files missing from deploy dir after rebuild with sstate cache:"
+ f"{expected_files - deployed_files}")
+ if len(deployed_files - expected_files) > 0:
+ self.log.error(f"{target}: additional files in deploy dir after rebuild with sstate cache:"
+ f"{deployed_files - expected_files}")
+ 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_install_setscene', '!do_rootfs_install']),
+ 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_install_setscene', '!do_rootfs_install'])
+ ]):
+ self.fail("Failed rebuild package and image")
--
2.30.2
next prev parent reply other threads:[~2022-02-22 9:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-22 9:06 [PATCH v2 0/3] Sstate-cache follow-up Adriaan Schmidt
2022-02-22 9:06 ` [PATCH v2 1/3] testsuite: refactor Adriaan Schmidt
2022-02-22 9:06 ` Adriaan Schmidt [this message]
2022-02-22 9:06 ` [PATCH v2 3/3] doc: add sstate to user manual Adriaan Schmidt
2022-02-28 15:30 ` [PATCH v2 0/3] Sstate-cache follow-up 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=20220222090628.2174022-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