Skip to content

Commit ddd96d7

Browse files
committed
tests: integration tests for %include and multi-disk
Add check-include-multidisk covering various %include and multi-disk scenarios. Call as part of integration tests (integration make target). Signed-off-by: Loïc Minier <loic.minier@oss.qualcomm.com>
1 parent abe746b commit ddd96d7

2 files changed

Lines changed: 165 additions & 0 deletions

File tree

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ lint:
3535
integration: all
3636
# make sure generated output has created expected files
3737
tests/integration/check-missing-files platforms/*/*/*.xml
38+
# test %include and multi-disk features
39+
tests/integration/check-include-multidisk
3840

3941
check: lint integration
4042

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
#!/bin/sh
2+
# Copyright (c) 2026 Qualcomm Innovation Center, Inc. All rights reserved.
3+
# SPDX-License-Identifier: BSD-3-Clause-Clear
4+
5+
# Test %include directive and multi-disk support in gen_partition.py
6+
7+
set -eu
8+
9+
TOPDIR="$(cd "$(dirname "$0")/../.." && pwd)"
10+
GEN="${TOPDIR}/gen_partition.py"
11+
TMPDIR="$(mktemp -d)"
12+
trap 'rm -rf "${TMPDIR}"' EXIT
13+
14+
errors=0
15+
fail() { echo "FAIL: $1" >&2; errors=$((errors + 1)); }
16+
pass() { echo "PASS: $1"; }
17+
18+
##########################################################################
19+
# Test 1: basic %include resolves correctly
20+
##########################################################################
21+
cat > "${TMPDIR}/disk.conf.inc" <<'EOF'
22+
--disk --type=emmc --size=1073741824 --sector-size-in-bytes=512
23+
EOF
24+
cat > "${TMPDIR}/parts.conf.inc" <<'EOF'
25+
--partition --name=boot --size=4096KB --type-guid=20117F86-E985-4357-B9EE-374BC1D8487D
26+
EOF
27+
cat > "${TMPDIR}/main.conf" <<'EOF'
28+
%include disk.conf.inc
29+
%include parts.conf.inc
30+
EOF
31+
32+
"${GEN}" -i "${TMPDIR}/main.conf" -o "${TMPDIR}/out1.xml" 2>&1
33+
if grep -q 'label="boot"' "${TMPDIR}/out1.xml"; then
34+
pass "basic %include"
35+
else
36+
fail "basic %include: partition not found in output"
37+
fi
38+
39+
##########################################################################
40+
# Test 2: nested %include
41+
##########################################################################
42+
mkdir -p "${TMPDIR}/sub"
43+
cat > "${TMPDIR}/sub/nested.conf.inc" <<'EOF'
44+
--partition --name=rootfs --size=8192KB --type-guid=B921B045-1DF0-41C3-AF44-4C6F280D3FAE
45+
EOF
46+
cat > "${TMPDIR}/outer.conf.inc" <<'EOF'
47+
%include sub/nested.conf.inc
48+
EOF
49+
cat > "${TMPDIR}/nest.conf" <<'EOF'
50+
%include disk.conf.inc
51+
%include outer.conf.inc
52+
EOF
53+
54+
"${GEN}" -i "${TMPDIR}/nest.conf" -o "${TMPDIR}/out2.xml" 2>&1
55+
if grep -q 'label="rootfs"' "${TMPDIR}/out2.xml"; then
56+
pass "nested %include"
57+
else
58+
fail "nested %include: partition not found in output"
59+
fi
60+
61+
##########################################################################
62+
# Test 3: circular %include detection
63+
##########################################################################
64+
cat > "${TMPDIR}/a.conf" <<EOF
65+
%include b.conf
66+
EOF
67+
cat > "${TMPDIR}/b.conf" <<EOF
68+
--disk --type=emmc --size=1073741824 --sector-size-in-bytes=512
69+
%include a.conf
70+
EOF
71+
72+
if "${GEN}" -i "${TMPDIR}/a.conf" -o "${TMPDIR}/circular.xml" 2>&1; then
73+
fail "circular %include: should have failed"
74+
else
75+
pass "circular %include detected"
76+
fi
77+
78+
##########################################################################
79+
# Test 4: multi-disk generates indexed output files
80+
##########################################################################
81+
cat > "${TMPDIR}/multi.conf" <<'EOF'
82+
--disk --type=spinor --size=67108864 --sector-size-in-bytes=4096
83+
--partition --name=xbl --size=1024KB --type-guid=DEA0BA2C-CBDD-4805-B4F9-F428251C3E98
84+
--disk --type=nvme --size=68719476736 --sector-size-in-bytes=512
85+
--partition --name=efi --size=524288KB --type-guid=C12A7328-F81F-11D2-BA4B-00A0C93EC93B
86+
EOF
87+
88+
"${GEN}" -i "${TMPDIR}/multi.conf" -o "${TMPDIR}/multi-out.xml" 2>&1
89+
if [ -f "${TMPDIR}/multi-out0.xml" ] && \
90+
[ -f "${TMPDIR}/multi-out1.xml" ]; then
91+
pass "multi-disk indexed output files"
92+
else
93+
fail "multi-disk: expected multi-out0.xml and multi-out1.xml"
94+
fi
95+
96+
if grep -q 'label="xbl"' "${TMPDIR}/multi-out0.xml" && \
97+
grep -q 'label="efi"' "${TMPDIR}/multi-out1.xml"; then
98+
pass "multi-disk partition placement"
99+
else
100+
fail "multi-disk: partitions in wrong XML"
101+
fi
102+
103+
##########################################################################
104+
# Test 5: single-disk with -o writes directly (no index)
105+
##########################################################################
106+
cat > "${TMPDIR}/single.conf" <<'EOF'
107+
--disk --type=ufs --size=76841669632 --sector-size-in-bytes=4096
108+
--partition --name=boot --size=4096KB --type-guid=20117F86-E985-4357-B9EE-374BC1D8487D
109+
EOF
110+
111+
"${GEN}" -i "${TMPDIR}/single.conf" -o "${TMPDIR}/single-out.xml" 2>&1
112+
if [ -f "${TMPDIR}/single-out.xml" ]; then
113+
pass "single-disk -o mode"
114+
else
115+
fail "single-disk -o: partitions.xml not written"
116+
fi
117+
118+
##########################################################################
119+
# Test 6: missing %include file gives an error
120+
##########################################################################
121+
cat > "${TMPDIR}/missing.conf" <<'EOF'
122+
%include nonexistent.conf.inc
123+
EOF
124+
125+
if "${GEN}" -i "${TMPDIR}/missing.conf" -o "${TMPDIR}/missing.xml" 2>&1; then
126+
fail "missing %include: should have failed"
127+
else
128+
pass "missing %include detected"
129+
fi
130+
131+
##########################################################################
132+
# Test 7: %include with multi-disk
133+
##########################################################################
134+
cat > "${TMPDIR}/spinor.conf.inc" <<'EOF'
135+
--disk --type=spinor --size=67108864 --sector-size-in-bytes=4096
136+
--partition --name=fw --size=1024KB --type-guid=DEA0BA2C-CBDD-4805-B4F9-F428251C3E98
137+
EOF
138+
cat > "${TMPDIR}/nvme.conf.inc" <<'EOF'
139+
--disk --type=nvme --size=68719476736 --sector-size-in-bytes=512
140+
--partition --name=efi --size=524288KB --type-guid=C12A7328-F81F-11D2-BA4B-00A0C93EC93B
141+
EOF
142+
cat > "${TMPDIR}/combo.conf" <<'EOF'
143+
%include spinor.conf.inc
144+
%include nvme.conf.inc
145+
EOF
146+
147+
"${GEN}" -i "${TMPDIR}/combo.conf" -o "${TMPDIR}/combo.xml" 2>&1
148+
if [ -f "${TMPDIR}/combo0.xml" ] && \
149+
[ -f "${TMPDIR}/combo1.xml" ]; then
150+
pass "%include with multi-disk"
151+
else
152+
fail "%include with multi-disk: expected combo0.xml and combo1.xml"
153+
fi
154+
155+
##########################################################################
156+
# Summary
157+
##########################################################################
158+
if [ "${errors}" -ne 0 ]; then
159+
echo "${errors} test(s) failed" >&2
160+
exit 1
161+
fi
162+
echo "All tests passed"
163+
exit 0

0 commit comments

Comments
 (0)