Debian Codegraph @

test_functions

raw symbols SCIP
1 #!/bin/dash
2
3 # Copyright (C) 2011 Loïc Minier <[email protected]>
4
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301,
18 # USA.
19
20 # Let the function library know that it is called from the testsuite.
21 FK_TESTSUITE_RUNNING="yes"
22
23 . ./testlib
24
25 functions="${FK_CHECKOUT:-$FK_DIR}/functions"
26
27 test_syntax() {
28 sh -n "$functions"
29 }
30 add_test test_syntax
31
32 test_mtdblock() {
33 get_tempfile
34 mock_proc_mtd="$last_tempfile"
35 cat >"$mock_proc_mtd" <<EOF
36 dev: size erasesize name
37 mtd0: 00580000 00020000 "root"
38 mtd1: 00100000 00020000 "kernel"
39 mtd2: 00160000 00020000 "initrd"
40 mtd3: 00020000 00020000 "reset"
41 mtd4: 00800000 00020000 "jffs2"
42 EOF
43 (
44 . "$functions"
45 PROC_MTD="$mock_proc_mtd"
46 root_mtd=$(mtdblock "root")
47 if [ "$root_mtd" != "/dev/mtdblock0" ]; then
48 echo "Expected root mtd to be /dev/mtdblock0 but got $root_mtd" >&2
49 exit 1
50 fi
51 jffs2_mtd=$(mtdblock "jffs2")
52 if [ "$jffs2_mtd" != "/dev/mtdblock4" ]; then
53 echo "Expected jffs2 mtd to be /dev/mtdblock4 but got $jffs2_mtd" >&2
54 exit 1
55 fi
56 )
57 }
58 add_test test_mtdblock
59
60 test_mtdchar() {
61 get_tempfile
62 mock_proc_mtd="$last_tempfile"
63 cat >"$mock_proc_mtd" <<EOF
64 dev: size erasesize name
65 mtd0: 00580000 00020000 "root"
66 mtd1: 00100000 00020000 "kernel"
67 mtd2: 00160000 00020000 "initrd"
68 mtd3: 00020000 00020000 "reset"
69 mtd4: 00800000 00020000 "jffs2"
70 EOF
71 (
72 . "$functions"
73 PROC_MTD="$mock_proc_mtd"
74 root_mtd=$(mtdchar "root")
75 if [ "$root_mtd" != "/dev/mtd0" ]; then
76 echo "Expected root mtd to be /dev/mtd0 but got $root_mtd" >&2
77 exit 1
78 fi
79 jffs2_mtd=$(mtdchar "jffs2")
80 if [ "$jffs2_mtd" != "/dev/mtd4" ]; then
81 echo "Expected jffs2 mtd to be /dev/mtd4 but got $jffs2_mtd" >&2
82 exit 1
83 fi
84 )
85 }
86 add_test test_mtdchar
87
88 test_mtdsize() {
89 get_tempfile
90 mock_proc_mtd="$last_tempfile"
91 cat >"$mock_proc_mtd" <<EOF
92 dev: size erasesize name
93 mtd0: 00580000 00020000 "root"
94 mtd1: 00100000 00020000 "kernel"
95 mtd2: 00160000 00020000 "initrd"
96 mtd3: 00020000 00020000 "reset"
97 mtd4: 00800000 00020000 "jffs2"
98 EOF
99 (
100 . "$functions"
101 PROC_MTD="$mock_proc_mtd"
102 root_size=$(mtdsize "root")
103 if [ "$root_size" != 5767168 ]; then
104 echo "Expected root size of 5767168 but got $root_size" >&2
105 exit 1
106 fi
107 jffs2_size=$(mtdsize "jffs2")
108 if [ "$jffs2_size" != 8388608 ]; then
109 echo "Expected jffs2 size of 8388608 but got $jffs2_size" >&2
110 exit 1
111 fi
112 )
113 }
114 add_test test_mtdsize
115
116 test_check_kflavors() {
117 (
118 . "$functions"
119 if check_kflavors "4.14.0-1-armmp" "armmp-lpae"; then
120 echo "Expected check_kflavors to fail with kernel suffix not in expected flavors, but it succeeded" >&2
121 exit 1
122 fi
123 if ! check_kflavors "4.14.0-1-armmp-lpae" "armmp-lpae"; then
124 echo "Expected check_kflavors to succeed with kernel suffix in expected flavors, but it failed" >&2
125 exit 1
126 fi
127 if check_kflavors "4.14.0-1-armp-lpae+" "armmp"; then
128 echo "Expected check_kflavors to fail with kernel suffix (with additional +) not in expected flavors, but it succeeded" >&2
129 exit 1
130 fi
131 if ! check_kflavors "4.14.0-1-armmp-lpae+" "armmp-lpae"; then
132 echo "Expected check_kflavours to succeed with kernel suffix (with additional +) in expected flavors, but it failed" >&2
133 exit 1
134 fi
135 if ! check_kflavors "4.14.0-1-armmp-lpae" "any"; then
136 echo "Expected check_kflavours to succeed with kernel suffix 'any' in expected flavors, but it failed" >&2
137 exit 1
138 fi
139 )
140 }
141 add_test test_check_kflavors
142
143 test_check_size() {
144 (
145 . "$functions"
146 error() {
147 return 1
148 }
149 if check_mtd_size "MTD" 2 1; then
150 echo "Expected check_mtd_size to fail for too small size, but it succeeded" >&2
151 exit 1
152 fi
153 if ! check_mtd_size "MTD" 1 1; then
154 echo "Expected check_supported to succeed with large enough size, but it failed" >&2
155 exit 1
156 fi
157 )
158 }
159 add_test test_check_size
160
161 test_check_supported() {
162 (
163 . "$functions"
164 if check_supported "Dummy"; then
165 echo "Expected check_supported to fail for non-existent board, but it succeeded" >&2
166 exit 1
167 fi
168 machine="Marvell SheevaPlug Reference Board"
169 if ! check_supported "$machine"; then
170 echo "Expected check_supported to succeed with machine $machine, but it failed" >&2
171 exit 1
172 fi
173 )
174 }
175 add_test test_check_supported
176
177 test_get_cpuinfo_hardware() {
178 get_tempfile
179 mock_proc_cpuinfo="$last_tempfile"
180 cat >"$mock_proc_cpuinfo" <<EOF
181 Processor : Feroceon 88FR131 rev 1 (v5l)
182 BogoMIPS : 1192.75
183 Features : swp half thumb fastmult edsp
184 CPU implementer : 0x56
185 CPU architecture: 5TE
186 CPU variant : 0x2
187 CPU part : 0x131
188 CPU revision : 1
189
190 Hardware : Marvell SheevaPlug Reference Board
191 Revision : 0000
192 Serial : 0000000000000000
193 EOF
194 (
195 . "$functions"
196 PROC_CPUINFO="$mock_proc_cpuinfo"
197 PROC_DTMODEL="/this/must/not/exist"
198 FK_ETC_MACHINE="/this/must/not/exist"
199 get_machine
200 if [ "$machine" != "Marvell SheevaPlug Reference Board" ]; then
201 echo "Expected machine to be Marvell SheevaPlug Reference Board but got $machine" >&2
202 exit 1
203 fi
204 )
205 }
206 add_test test_get_cpuinfo_hardware
207
208 test_get_dt_hardware() {
209 get_tempfile
210 mock_proc_cpuinfo="$last_tempfile"
211 cat >"$mock_proc_cpuinfo" <<EOF
212 Processor : Feroceon 88FR131 rev 1 (v5l)
213 BogoMIPS : 1191.11
214 Features : swp half thumb fastmult edsp
215 CPU implementer : 0x56
216 CPU architecture: 5TE
217 CPU variant : 0x2
218 CPU part : 0x131
219 CPU revision : 1
220
221 Hardware : Marvell Kirkwood (Flattened Device Tree)
222 Revision : 0000
223 Serial : 0000000000000000
224 EOF
225
226 get_tempfile
227 mock_dt_model="$last_tempfile"
228 echo -n "Globalscale Technologies Dreamplug" >"$mock_dt_model"
229
230 (
231 . "$functions"
232 PROC_CPUINFO="$mock_proc_cpuinfo"
233 PROC_DTMODEL="$mock_dt_model"
234 FK_ETC_MACHINE="/this/must/not/exist"
235 get_machine
236 if [ "$machine" != "Globalscale Technologies Dreamplug" ]; then
237 echo "Expected machine to be Globalscale Technologies Dreamplug but got $machine" >&2
238 exit 1
239 fi
240 )
241
242 }
243 add_test test_get_dt_hardware
244
245 test_get_machine() {
246 get_tempfile
247 mock_etc_machine="$last_tempfile"
248 echo "Freescale MX53 LOCO Board" >"$mock_etc_machine"
249
250 get_tempfile
251 mock_proc_cpuinfo="$last_tempfile"
252 cat >"$mock_proc_cpuinfo" <<EOF
253 Processor : Feroceon 88FR131 rev 1 (v5l)
254 BogoMIPS : 1192.75
255 Features : swp half thumb fastmult edsp
256 CPU implementer : 0x56
257 CPU architecture: 5TE
258 CPU variant : 0x2
259 CPU part : 0x131
260 CPU revision : 1
261
262 Hardware : Marvell SheevaPlug Reference Board
263 Revision : 0000
264 Serial : 0000000000000000
265 EOF
266
267 get_tempfile
268 mock_dt_model="$last_tempfile"
269 echo -n "Globalscale Technologies Dreamplug" >"$mock_dt_model"
270 (
271 . "$functions"
272 FK_MACHINE=""
273 PROC_DTMODEL="/this/must/not/exist"
274 FK_ETC_MACHINE="/this/must/not/exist"
275 PROC_CPUINFO="$mock_proc_cpuinfo"
276 if get_machine; then
277 if [ "$machine" != "Marvell SheevaPlug Reference Board" ]; then
278 echo "Expected get_machine to return Marvell SheevaPlug Reference Board but got $machine" >&2
279 exit 1
280 fi
281 else
282 echo "Expected get_machine to succeed with mocked /proc/cpuinfo but it failed" >&2
283 exit 1
284 fi
285 PROC_DTMODEL="$mock_dt_model"
286 if get_machine; then
287 if [ "$machine" != "Globalscale Technologies Dreamplug" ]; then
288 echo "Expected get_machine to return Globalscale Technologies Dreamplug but got $machine" >&2
289 exit 1
290 fi
291 else
292 echo "Expected get_machine to succeed with mocked /proc/dtmodel but it failed" >&2
293 exit 1
294 fi
295 FK_ETC_MACHINE="$mock_etc_machine"
296 if get_machine; then
297 if [ "$machine" != "Freescale MX53 LOCO Board" ]; then
298 echo "Expected get_machine to return Freescale MX53 LOCO Board but got $machine" >&2
299 exit 1
300 fi
301 else
302 echo "Expected get_machine to succeed with mocked /etc/flash-kernel/machine but it failed" >&2
303 exit 1
304 fi
305 FK_MACHINE="Genesi EfikaMX nettop"
306 if get_machine; then
307 if [ "$machine" != "Genesi EfikaMX nettop" ]; then
308 echo "Expected get_machine to return Genesi EfikaMX nettop but got $machine" >&2
309 exit 1
310 fi
311 else
312 echo "Expected get_machine to succeed with valid FK_MACHINE but it failed" >&2
313 exit 1
314 fi
315 FK_MACHINE="none"
316 if get_machine; then
317 if [ -n "$none_machine" ]; then
318 echo "Expected get_machine to return an empty string but got $machine" >&2
319 exit 1
320 fi
321 else
322 echo "Expected get_machine to succeed with FK_MACHINE=\"none\" but it failed" >&2
323 exit 1
324 fi
325 )
326 }
327 add_test test_get_machine
328
329 test_get_kfile_suffix() {
330 (
331 . "$functions"
332 kfile_suffix=$(get_kfile_suffix "/boot/vmlinuz-2.6.32-5-kirkwood")
333 if [ "$kfile_suffix" != "kirkwood" ]; then
334 echo "Expected kernel file suffix to be kirkwood but got $kfile_suffix" >&2
335 exit 1
336 fi
337 kfile_suffix=""
338 kfile_suffix=$(get_kfile_suffix "/boot/vmlinuz-3.10-1-armmp-lpae" "$kfile_suffix")
339 if [ "$kfile_suffix" != "lpae" ]; then
340 echo "Expected kernel file suffix to be lpae but got $kfile_suffix" >&2
341 exit 1
342 fi
343 kfile_suffix=$(get_kfile_suffix "/boot/vmlinuz-3.10-1-armmp-lpae" "$kfile_suffix")
344 if [ "$kfile_suffix" != "armmp-lpae" ]; then
345 echo "Expected kernel file suffix to be armmp-lpae but got $kfile_suffix" >&2
346 exit 1
347 fi
348 kfile_suffix=$(get_kfile_suffix "/boot/vmlinuz-3.10-1-armmp")
349 if [ "$kfile_suffix" != "armmp" ]; then
350 echo "Expected kernel file suffix to be armmp but got $kfile_suffix" >&2
351 exit 1
352 fi
353 )
354 }
355 add_test test_get_kfile_suffix
356
357 test_get_machine_field() {
358 (
359 . "$functions"
360 machine="Marvell SheevaPlug Reference Board"
361 if machine_field="$(get_machine_field "$machine" "Machine")"; then
362 if [ "$machine_field" != "$machine" ]; then
363 echo "Expected Machine field to be $machine but got $machine_field" >&2
364 exit 1
365 fi
366 else
367 echo "Expected get_machine_field to succeed on Machine field but it failed" >&2
368 exit 1
369 fi
370 kflavors="$(get_machine_field "$machine" "Kernel-Flavors")"
371 if [ "$kflavors" != "kirkwood marvell" ]; then
372 echo "Expected Kernel-Flavors field to be 'kirkwood marvell' but got $kflavors" >&2
373 exit 1
374 fi
375 if dummy_field="$(get_machine_field "$machine" "Dummy")"; then
376 echo "Expected get_machine_field to fail on unknown field Dummy but it succeeded" >&2
377 exit 1
378 fi
379 )
380
381 get_tempfile
382 mock_etc_db="$last_tempfile"
383 cat >"$mock_etc_db" <<EOF
384 Machine: Board File Machine A
385 Machine: DT Machine A
386 Machine: DT Machine A v2
387 Kernel-Flavors: machinea
388
389 Machine: Board File Machine B
390 Kernel-Flavors: machineb
391
392 Machine: DT Machine B
393 Kernel-Flavors: machineb-dt
394
395 Machine: Machine C
396 Machine: Machine C
397 Kernel-Flavors: machinec
398 Machine: Invalid
399 Dummy: Dummy
400 EOF
401 (
402 FK_ETC_DB="$mock_etc_db"
403 . "$functions"
404 machine="Board File Machine A"
405 if machine_field="$(get_machine_field "$machine" "Machine")"; then
406 if [ "$machine_field" != "$machine" ]; then
407 echo "Expected Machine field to be $machine but got $machine_field" >&2
408 exit 1
409 fi
410 else
411 echo "Expected get_machine_field to succeed on Machine field but it failed" >&2
412 exit 1
413 fi
414 kflavors=$(get_machine_field "$machine" "Kernel-Flavors")
415 if [ "$kflavors" != "machinea" ]; then
416 echo "Expected Kernel-Flavors field to be machinea but got $kflavors" >&2
417 exit 1
418 fi
419 machine="DT Machine A"
420 kflavors=$(get_machine_field "$machine" "Kernel-Flavors")
421 if [ "$kflavors" != "machinea" ]; then
422 echo "Expected Kernel-Flavors field to be machinea but got $kflavors" >&2
423 exit 1
424 fi
425 if machine_field="$(get_machine_field "$machine" "Machine")"; then
426 if [ "$machine_field" != "$machine" ]; then
427 echo "Expected Machine field to be $machine but got $machine_field" >&2
428 exit 1
429 fi
430 else
431 echo "Expected get_machine_field to succeed on Machine field but it failed" >&2
432 exit 1
433 fi
434 machine="DT Machine A v2"
435 kflavors=$(get_machine_field "$machine" "Kernel-Flavors")
436 if [ "$kflavors" != "machinea" ]; then
437 echo "Expected Kernel-Flavors field to be machinea but got $kflavors" >&2
438 exit 1
439 fi
440 if machine_field="$(get_machine_field "$machine" "Machine")"; then
441 if [ "$machine_field" != "$machine" ]; then
442 echo "Expected Machine field to be $machine but got $machine_field" >&2
443 exit 1
444 fi
445 else
446 echo "Expected get_machine_field to succeed on Machine field but it failed" >&2
447 exit 1
448 fi
449
450 machine="Board File Machine B"
451 kflavors=$(get_machine_field "$machine" "Kernel-Flavors")
452 if [ "$kflavors" != "machineb" ]; then
453 echo "Expected Kernel-Flavors field to be machineb but got $kflavors" >&2
454 exit 1
455 fi
456 if machine_field="$(get_machine_field "$machine" "Machine")"; then
457 if [ "$machine_field" != "$machine" ]; then
458 echo "Expected Machine field to be $machine but got $machine_field" >&2
459 exit 1
460 fi
461 else
462 echo "Expected get_machine_field to succeed on Machine field but it failed" >&2
463 exit 1
464 fi
465
466 machine="DT Machine B"
467 kflavors=$(get_machine_field "$machine" "Kernel-Flavors")
468 if [ "$kflavors" != "machineb-dt" ]; then
469 echo "Expected Kernel-Flavors field to be machineb-dt but got $kflavors" >&2
470 exit 1
471 fi
472 if machine_field="$(get_machine_field "$machine" "Machine")"; then
473 if [ "$machine_field" != "$machine" ]; then
474 echo "Expected Machine field to be $machine but got $machine_field" >&2
475 exit 1
476 fi
477 else
478 echo "Expected get_machine_field to succeed on Machine field but it failed" >&2
479 exit 1
480 fi
481
482 machine="Machine C"
483 kflavors=$(get_machine_field "$machine" "Kernel-Flavors")
484 if [ "$kflavors" != "machinec" ]; then
485 echo "Expected Kernel-Flavors field to be machinec but got $kflavors" >&2
486 exit 1
487 fi
488 if field="$(get_machine_field "$machine" "Dummy" 2>/dev/null)"; then
489 echo "Expected Dummy field to hit syntax error but got $field" >&2
490 exit 1
491 fi
492
493 )
494 }
495 add_test test_get_machine_field
496
497 test_etc_db() {
498 get_tempfile
499 mock_etc_db="$last_tempfile"
500 cat >"$mock_etc_db" <<EOF
501 Machine: Marvell SheevaPlug Reference Board
502 Kernel-Flavors: Dummy
503 EOF
504
505 (
506 FK_ETC_DB="$mock_etc_db"
507 . "$functions"
508 machine="Marvell SheevaPlug Reference Board"
509 kflavors=$(get_machine_field "$machine" "Kernel-Flavors")
510 if [ "$kflavors" != "Dummy" ]; then
511 echo "Expected Kernel-Flavors field to be overridden to Dummy but got $kflavors" >&2
512 exit 1
513 fi
514 kaddress=$(get_machine_field "$machine" "U-Boot-Kernel-Address")
515 if [ "$kaddress" != "0x00008000" ]; then
516 echo "Expected U-Boot-Kernel-Address to be 0x00008000 but got $kaddress" >&2
517 exit 1
518 fi
519 )
520 }
521 add_test test_etc_db
522
523 test_machine_uses_flash() {
524 (
525 . "$functions"
526 if ! machine_uses_flash "Dummy"; then
527 echo "Expected machine_uses_flash to succeed for non-existent board, but it failed" >&2
528 exit 1
529 fi
530 machine="Buffalo Linkstation Mini"
531 if machine_uses_flash "$machine"; then
532 echo "Expected machine_uses_flash to fail for $machine, but it succeeded" >&2
533 exit 1
534 fi
535 machine="Lanner EM7210"
536 if ! machine_uses_flash "$machine"; then
537 echo "Expected machine_uses_flash to succeed for $machine, but it failed" >&2
538 exit 1
539 fi
540 )
541 }
542 add_test test_machine_uses_flash
543
544 test_set_machine_id() {
545 (
546 . "$functions"
547 arm_code="$(set_machine_id 2097 | od -x)"
548 expected="0000000 1c08 e3a0 1031 e381
549 0000010"
550 if [ "$arm_code" != "$expected" ]; then
551 echo "Expected \"$expected\" for machine-id 2097 but got \"$arm_code\"" >&2
552 exit 1
553 fi
554 arm_code="$(set_machine_id "" | od -x)"
555 expected="0000000"
556 if [ "$arm_code" != "$expected" ]; then
557 echo "Expected \"$expected\" for empty machine-id but got \"$arm_code\"" >&2
558 exit 1
559 fi
560 )
561 }
562 add_test test_set_machine_id
563
564 test_mkimage_kernel() {
565 (
566 mkimage() {
567 saved_args="$@"
568 }
569 . "$functions"
570 saved_args=""
571 mkarch="arm"
572 mkimage_kernel "0xdeadbeef" "0xbaddcafe" "desc" "input" "output" 2>/dev/null
573 expected="-A arm -O linux -T kernel -C none -a 0xdeadbeef -e 0xbaddcafe -n desc -d input output"
574 if [ "$expected" != "$saved_args" ]; then
575 echo "Expected mkimage_kernel to be called with \"$expected\" but it was called with \"$saved_args\"" >&2
576 exit 1
577 fi
578 )
579 }
580 add_test test_mkimage_kernel
581
582 test_mkimage_initrd() {
583 (
584 mkimage() {
585 saved_args="$@"
586 }
587 . "$functions"
588 saved_args=""
589 mkarch="arm"
590 mkimage_initrd "0xdeadbeef" "desc" "input" "output" 2>/dev/null
591 expected="-A arm -O linux -T ramdisk -C none -a 0xdeadbeef -e 0xdeadbeef -n desc -d input output"
592 if [ "$expected" != "$saved_args" ]; then
593 echo "Expected mkimage_initrd to be called with \"$expected\" but it was called with \"$saved_args\"" >&2
594 exit 1
595 fi
596 )
597 }
598 add_test test_mkimage_initrd
599
600 test_mkimage_multi() {
601 (
602 mkimage() {
603 saved_args="$@"
604 }
605 . "$functions"
606 saved_args=""
607 mkarch="arm"
608 mkimage_multi "0xdeadbeef" "desc" "kinput" "iinput" "output" 2>/dev/null
609 expected="-A arm -O linux -T multi -C none -a 0xdeadbeef -e 0xdeadbeef -n desc -d kinput:iinput output"
610 if [ "$expected" != "$saved_args" ]; then
611 echo "Expected mkimage_multi to be called with \"$expected\" but it was called with \"$saved_args\"" >&2
612 exit 1
613 fi
614 )
615 }
616 add_test test_mkimage_multi
617
618 test_gen_kernel() {
619 get_tempfile
620 kernel_input="$last_tempfile"
621 echo "foo" >"$kernel_input"
622 get_tempfile
623 kernel_output="$last_tempfile"
624 (
625 . "$functions"
626 gen_kernel "$kernel_input" "$kernel_output" 2097
627 result="$(od -t x1 "$kernel_output")"
628 expected="0000000 08 1c a0 e3 31 10 81 e3 66 6f 6f 0a
629 0000014"
630 if [ "$result" != "$expected" ]; then
631 echo "With machine id 2097, expected \"$expected\" but got \"$result\"" >&2
632 exit 1
633 fi
634 gen_kernel "$kernel_input" "$kernel_output" ""
635 result="$(od -t x1 "$kernel_output")"
636 expected="0000000 66 6f 6f 0a
637 0000004"
638 if [ "$result" != "$expected" ]; then
639 echo "With no machine id, expected \"$expected\" but got \"$result\"" >&2
640 exit 1
641 fi
642 )
643 }
644 add_test test_gen_kernel
645
646 test_flash_initrd() {
647 get_tempfile
648 initrd_input="$last_tempfile"
649 echo "foo" >"$initrd_input"
650 get_tempfile
651 initrd_output="$last_tempfile"
652 (
653 . "$functions"
654 flash_initrd "$initrd_input" "$initrd_output" 3 2>/dev/null
655 result="$(od -t x1 "$initrd_output")"
656 expected="0000000 66 6f 6f 0a 00 00 00
657 0000007"
658 if [ "$result" != "$expected" ]; then
659 echo "With 3 bytes of padding, expected \"$expected\" but got \"$result\"" >&2
660 exit 1
661 fi
662 flash_initrd "$initrd_input" "$initrd_output" 0 2>/dev/null
663 result="$(od -t x1 "$initrd_output")"
664 expected="0000000 66 6f 6f 0a
665 0000004"
666 if [ "$result" != "$expected" ]; then
667 echo "With no padding, expected \"$expected\" but got \"$result\"" >&2
668 exit 1
669 fi
670 )
671 }
672 add_test test_flash_initrd
673
674 test_dtb_append_from() {
675 (
676 . "$functions"
677 dtb_append_from="3.12"
678 kvers=3.11-1-kirkwood
679 if dtb_append_required ; then
680 echo "Kernel $kvers does not need appended DTB, but got true" >&2
681 exit 1
682 fi
683 kvers=3.12-1-kirkwood
684 if ! dtb_append_required ; then
685 echo "Kernel $kvers does need appended DTB, but got false" >&2
686 exit 1
687 fi
688 )
689 }
690 add_test test_dtb_append_from
691
692 test_get_kernel_status() {
693 available="
694 5.15.0-1021-generic /boot/vmlinuz-5.15.0-1021-generic
695 5.15.0-1022-raspi /boot/vmlinuz-5.15.0-1022-raspi
696 5.15.0-1022-raspi-nolpae /boot/vmlinuz-5.15.0-1022-raspi-nolpae
697 5.15.0-1023-raspi /boot/vmlinuz-5.15.0-1023-raspi"
698 (
699 linux_version() {
700 case "$1" in
701 list)
702 if [ "$2" = "--paths" ]; then
703 echo "$available"
704 else
705 echo "$available" | while read -r ver path; do
706 echo "$ver"
707 done
708 fi
709 ;;
710 compare)
711 case "$3" in
712 eq) [ "$2" = "$4" ] ;;
713 ne) [ "$2" != "$4" ] ;;
714 *)
715 echo "Unexpected arg in test-case"
716 exit 1
717 ;;
718 esac
719 ;;
720 esac
721 }
722 dpkg_query() {
723 case "$1" in
724 --search)
725 shift
726 while [ -n "$1" ]; do
727 case "$1" in
728 /boot/vmlinuz-5.15.0-*)
729 echo "linux-image-${1#/boot/vmlinuz-}: $1"
730 ;;
731 *)
732 echo "Unexpected arg in test-case"
733 exit 1
734 ;;
735 esac
736 shift
737 done
738 ;;
739 --show)
740 shift
741 while [ -n "$1" ]; do
742 case "$1" in
743 --showformat)
744 shift
745 ;;
746 linux-image-5.15.0-1022-raspi*)
747 echo -n installed
748 ;;
749 linux-image-5.15.0-1023-*)
750 echo -n triggers-pending
751 ;;
752 linux-image-*)
753 echo -n not-installed
754 ;;
755 *)
756 echo "Unexpected arg in test-case"
757 exit 1
758 ;;
759 esac
760 shift
761 done
762 ;;
763 esac
764 }
765 # Can't define a function with a hyphen in the name but luckily, dash
766 # does permit them in alias names
767 alias dpkg-query=dpkg_query
768 alias linux-version=linux_version
769 . "$functions"
770 if [ "$(get_kernel_status 5.15.0-1022-raspi)" != "installed" ]; then
771 echo "get_kernel_status did not output the expected result" >&2
772 exit 1
773 fi
774 if [ "$(get_kernel_status 5.15.0-1023-raspi)" != "triggers-pending" ]; then
775 echo "get_kernel_status did not output the expected result" >&2
776 exit 1
777 fi
778 if [ "$(get_kernel_status 5.15.0-1021-generic)" != "not-installed" ]; then
779 echo "get_kernel_status did not output the expected result" >&2
780 exit 1
781 fi
782 )
783 }
784 add_test test_get_kernel_status
785
786 test_main
787
788 # vim:syntax=sh