@@ -43,26 +43,32 @@ print_test_result() {
4343# $1 - path to dist config file
4444# $2 - path to dist config.local file (or empty)
4545# $3 - path to output script
46+ # $4 - path to variant config file (or empty)
4647run_build_preseed_flow () {
4748 local config_file=" $1 "
4849 local config_local_file=" $2 "
4950 local output_script=" $3 "
51+ local variant_config_file=" $4 "
5052
5153 # Run in a subshell to avoid polluting the test environment
5254 (
5355 # Unset BASE_BOARD to start clean
5456 unset BASE_BOARD
5557
56- # Mimic src/build lines 14-17: source config, then config.local
58+ # Mimic src/build pre-seed: config, then variant , then config.local
5759 if [ -f " ${config_file} " ]; then
5860 source " ${config_file} "
5961 fi
62+ if [ -n " ${variant_config_file} " ] && [ -f " ${variant_config_file} " ]; then
63+ source " ${variant_config_file} "
64+ fi
6065 if [ -n " ${config_local_file} " ] && [ -f " ${config_local_file} " ]; then
6166 source " ${config_local_file} "
6267 fi
6368
64- # Mimic the heredoc bash -c check
69+ # Mimic the heredoc bash -c check (config < variant < config.local)
6570 BASE_BOARD_FROM_CONFIG=$( bash -c " source \" ${config_file} \" >/dev/null 2>&1; \
71+ [ -n \" ${variant_config_file} \" ] && [ -f \" ${variant_config_file} \" ] && source \" ${variant_config_file} \" >/dev/null 2>&1; \
6672 [ -n \" ${config_local_file} \" ] && [ -f \" ${config_local_file} \" ] && source \" ${config_local_file} \" >/dev/null 2>&1; \
6773 echo \$ BASE_BOARD" )
6874 if [ -n " $BASE_BOARD_FROM_CONFIG " ]; then
@@ -215,15 +221,135 @@ CONF
215221 rm -rf " ${tmpdir} "
216222}
217223
224+ # Test 5: Variant sets BASE_BOARD=raspberrypiarm64, no config.local → BASE_ARCH=arm64
225+ test_variant_sets_arm64 () {
226+ local test_name=" Variant sets BASE_BOARD=raspberrypiarm64, no config.local"
227+ print_test_header " $test_name "
228+ (( test_count++ ))
229+
230+ local tmpdir=$( mktemp -d)
231+ local config_file=" ${tmpdir} /config"
232+ local variant_config_file=" ${tmpdir} /variant_config"
233+ local output_script=" ${tmpdir} /board_config.sh"
234+
235+ # Dist config does NOT set BASE_BOARD
236+ cat > " ${config_file} " << 'CONF '
237+ export SOME_OTHER_VAR="hello"
238+ CONF
239+
240+ # Variant config sets arm64 board
241+ cat > " ${variant_config_file} " << 'CONF '
242+ export BASE_BOARD=raspberrypiarm64
243+ CONF
244+
245+ run_build_preseed_flow " ${config_file} " " " " ${output_script} " " ${variant_config_file} "
246+
247+ local is_passed=false
248+ if [ -f " ${output_script} " ] && grep -q ' BASE_ARCH="arm64"' " ${output_script} " ; then
249+ is_passed=true
250+ (( tests_passed++ ))
251+ fi
252+
253+ echo " Generated board config:"
254+ [ -f " ${output_script} " ] && cat " ${output_script} " || echo " (file not created)"
255+ print_test_result " $test_name " " $is_passed " " Expected BASE_ARCH=\" arm64\" from variant"
256+ $is_passed || failed_tests+=(" $test_name " )
257+
258+ rm -rf " ${tmpdir} "
259+ }
260+
261+ # Test 6: config.local overrides variant's BASE_BOARD
262+ test_config_local_overrides_variant () {
263+ local test_name=" config.local BASE_BOARD overrides variant BASE_BOARD"
264+ print_test_header " $test_name "
265+ (( test_count++ ))
266+
267+ local tmpdir=$( mktemp -d)
268+ local config_file=" ${tmpdir} /config"
269+ local config_local_file=" ${tmpdir} /config.local"
270+ local variant_config_file=" ${tmpdir} /variant_config"
271+ local output_script=" ${tmpdir} /board_config.sh"
272+
273+ # Dist config does NOT set BASE_BOARD
274+ cat > " ${config_file} " << 'CONF '
275+ export SOME_OTHER_VAR="hello"
276+ CONF
277+
278+ # Variant sets armhf
279+ cat > " ${variant_config_file} " << 'CONF '
280+ export BASE_BOARD=raspberrypiarmhf
281+ CONF
282+
283+ # config.local overrides to arm64
284+ cat > " ${config_local_file} " << 'CONF '
285+ export BASE_BOARD=raspberrypiarm64
286+ CONF
287+
288+ run_build_preseed_flow " ${config_file} " " ${config_local_file} " " ${output_script} " " ${variant_config_file} "
289+
290+ local is_passed=false
291+ if [ -f " ${output_script} " ] && grep -q ' BASE_ARCH="arm64"' " ${output_script} " ; then
292+ is_passed=true
293+ (( tests_passed++ ))
294+ fi
295+
296+ echo " Generated board config:"
297+ [ -f " ${output_script} " ] && cat " ${output_script} " || echo " (file not created)"
298+ print_test_result " $test_name " " $is_passed " " Expected BASE_ARCH=\" arm64\" (config.local should win over variant)"
299+ $is_passed || failed_tests+=(" $test_name " )
300+
301+ rm -rf " ${tmpdir} "
302+ }
303+
304+ # Test 7: Variant overrides dist config's BASE_BOARD
305+ test_variant_overrides_config () {
306+ local test_name=" Variant BASE_BOARD overrides dist config BASE_BOARD"
307+ print_test_header " $test_name "
308+ (( test_count++ ))
309+
310+ local tmpdir=$( mktemp -d)
311+ local config_file=" ${tmpdir} /config"
312+ local variant_config_file=" ${tmpdir} /variant_config"
313+ local output_script=" ${tmpdir} /board_config.sh"
314+
315+ # Dist config sets armhf
316+ cat > " ${config_file} " << 'CONF '
317+ export BASE_BOARD=raspberrypiarmhf
318+ CONF
319+
320+ # Variant overrides to arm64
321+ cat > " ${variant_config_file} " << 'CONF '
322+ export BASE_BOARD=raspberrypiarm64
323+ CONF
324+
325+ run_build_preseed_flow " ${config_file} " " " " ${output_script} " " ${variant_config_file} "
326+
327+ local is_passed=false
328+ if [ -f " ${output_script} " ] && grep -q ' BASE_ARCH="arm64"' " ${output_script} " ; then
329+ is_passed=true
330+ (( tests_passed++ ))
331+ fi
332+
333+ echo " Generated board config:"
334+ [ -f " ${output_script} " ] && cat " ${output_script} " || echo " (file not created)"
335+ print_test_result " $test_name " " $is_passed " " Expected BASE_ARCH=\" arm64\" (variant should win over dist config)"
336+ $is_passed || failed_tests+=(" $test_name " )
337+
338+ rm -rf " ${tmpdir} "
339+ }
340+
218341# Run all tests
219342run_tests () {
220- echo -e " ${BLUE} Running config.local BASE_BOARD Tests${NC} "
221- echo " ═══════════════════════════════════════"
343+ echo -e " ${BLUE} Running config.local and Variant BASE_BOARD Tests${NC} "
344+ echo " ═══════════════════════════════════════════════════ "
222345
223346 test_no_config_local_defaults_to_armhf
224347 test_config_local_sets_arm64
225348 test_config_local_overrides_config
226349 test_config_sets_board_no_local
350+ test_variant_sets_arm64
351+ test_config_local_overrides_variant
352+ test_variant_overrides_config
227353
228354 # Print summary
229355 echo
0 commit comments