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

Subscribers

People subscribed via source and target branches