Merge ~jocave/plainbox-provider-checkbox:dtb-mismatch-test into plainbox-provider-checkbox:master

Proposed by Jonathan Cave
Status: Merged
Approved by: Jonathan Cave
Approved revision: b498e8123e714b43339549a25485bfbabd7ac44f
Merged at revision: 32733a488fd63ce97ec1a60b0a2231051b170dd1
Proposed branch: ~jocave/plainbox-provider-checkbox:dtb-mismatch-test
Merge into: plainbox-provider-checkbox:master
Diff against target: 116 lines (+92/-0)
3 files modified
bin/booted_dtb_tests.py (+72/-0)
units/kernel-snap/jobs.pxu (+19/-0)
units/kernel-snap/test-plan.pxu (+1/-0)
Reviewer Review Type Date Requested Status
Maciej Kisielewski Approve
Review via email: mp+407622@code.launchpad.net

Description of the change

Create a new test to run on UC18 that checks that the DTB files supplied in the kernel snap are correctly extracted to the boot directory and everything is in sync.

I've tested that it correctly fails on current RPi devices running UC18, but I'm unsure whether there are other devices that use u-boot where this might fail.

To post a comment you must log in.
Revision history for this message
Maciej Kisielewski (kissiel) wrote :

Looks good modulo some nitpicking below.
One cool thing that could be done in this script is to introduce a partially filled print that always does file=sys.stderr, flush=True. (functools.partial goodies)

review: Approve
Revision history for this message
Jonathan Cave (jocave) wrote :

Tidied up as per comments, squashed, and re-pushed

Revision history for this message
Maciej Kisielewski (kissiel) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/bin/booted_dtb_tests.py b/bin/booted_dtb_tests.py
0new file mode 1007550new file mode 100755
index 0000000..9ebe2e4
--- /dev/null
+++ b/bin/booted_dtb_tests.py
@@ -0,0 +1,72 @@
1#!/usr/bin/env python3
2#
3# This file is part of Checkbox.
4#
5# Copyright 2021 Canonical Ltd.
6# Written by:
7# Jonathan Cave <jonathan.cave@canonical.com>
8#
9# Checkbox is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License version 3,
11# as published by the Free Software Foundation.
12#
13# Checkbox is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with Checkbox. If not, see <http://www.gnu.org/licenses/>.
20
21import filecmp
22import sys
23from os import walk
24from os.path import join, relpath
25
26from checkbox_support.snap_utils.system import get_kernel_snap
27
28
29if len(sys.argv) != 2:
30 raise SystemExit('ERROR: please specify the bootloader')
31
32dtb_dir = '/var/lib/snapd/hostfs/boot/{}'.format(sys.argv[1])
33print('Bootloader DTB location: {}'.format(dtb_dir))
34
35kernel = get_kernel_snap()
36if kernel is None:
37 raise SystemExit('ERROR: failed to get kernel snap')
38snap_dtbs = '/snap/{}/current/dtbs'.format(kernel)
39print('Kernel snap DTB location: {}'.format(
40 snap_dtbs), end='\n\n', flush=True)
41
42snap_files = []
43for (dirpath, dirs, files) in walk(snap_dtbs):
44 if dirpath == snap_dtbs:
45 snap_files.extend(files)
46 else:
47 snap_files.extend([join(relpath(dirpath, snap_dtbs), f)
48 for f in files])
49
50match, mismatch, errors = filecmp.cmpfiles(
51 snap_dtbs, dtb_dir, snap_files, shallow=True)
52
53if match:
54 print('{} matching DTB files found'.format(
55 len(match)), end='\n\n', flush=True)
56
57if mismatch:
58 print('FAIL: DTB files shipped in kernel snap with mismatched versions'
59 ' in bootloader dir:', file=sys.stderr)
60 for f in mismatch:
61 print(f, file=sys.stderr)
62 print('', file=sys.stderr, flush=True)
63
64if errors:
65 print('FAIL: DTB files shipped in kernel snap which could not be'
66 ' found in bootloader dir:', file=sys.stderr)
67 for f in errors:
68 print(f, file=sys.stderr)
69 print('', file=sys.stderr, flush=True)
70
71if mismatch or errors:
72 raise SystemExit('Comparison failed')
diff --git a/units/kernel-snap/jobs.pxu b/units/kernel-snap/jobs.pxu
index 950d1a6..b03d6a8 100644
--- a/units/kernel-snap/jobs.pxu
+++ b/units/kernel-snap/jobs.pxu
@@ -33,3 +33,22 @@ imports:
33 from com.canonical.certification import ubuntu_core_features33 from com.canonical.certification import ubuntu_core_features
34requires:34requires:
35 ubuntu_core_features.force_kernel_extraction == 'True'35 ubuntu_core_features.force_kernel_extraction == 'True'
36
37unit: template
38template-resource: bootloader
39template-filter: bootloader.name == 'uboot'
40id: kernel-snap/booted-dtbs-match-current-{name}
41requires:
42 lsb.description == 'Ubuntu Core 18'
43 snap.name == 'snapd' and int(snap.revision) >= 11841
44category_id: kernel-snap
45_summary: The dtbs in the bootloader match those in current kernel snap
46_description:
47 Since snapd version 2.50 DTB files can be distributed in the kernel snap and
48 the extracted in to the boot partition. This checks that if the DTBs are in
49 sync.
50plugin: shell
51user: root
52estimated_duration: 2.0
53command:
54 booted_dtb_tests.py {name}
diff --git a/units/kernel-snap/test-plan.pxu b/units/kernel-snap/test-plan.pxu
index ffaa5d1..585bd01 100644
--- a/units/kernel-snap/test-plan.pxu
+++ b/units/kernel-snap/test-plan.pxu
@@ -14,6 +14,7 @@ _name: Automated Kernel Snap tests
14_description: Automated Kernel Snap tests for Ubuntu Core devices14_description: Automated Kernel Snap tests for Ubuntu Core devices
15include:15include:
16 kernel-snap/booted-kernel-matches-current-.*16 kernel-snap/booted-kernel-matches-current-.*
17 kernel-snap/booted-dtbs-match-current-.*
17bootstrap_include:18bootstrap_include:
18 bootloader19 bootloader
1920

Subscribers

People subscribed via source and target branches