]>
Commit | Line | Data |
---|---|---|
8104bf0e DD |
1 | #!/bin/bash |
2 | # This file is part of dracut. | |
3 | # SPDX-License-Identifier: GPL-2.0-or-later | |
4 | ||
5 | # shellcheck disable=SC2034 | |
6 | TEST_DESCRIPTION="kernel cpio extraction tests for dracut-cpio" | |
7 | # see dracut-cpio source for unit tests | |
8 | ||
9 | test_check() { | |
10 | if ! [[ -x $basedir/dracut-cpio ]]; then | |
11 | echo "Test needs dracut-cpio... Skipping" | |
12 | return 1 | |
13 | fi | |
14 | } | |
15 | ||
16 | test_dracut_cpio() { | |
17 | local tdir="${CPIO_TESTDIR}/${1}" | |
18 | shift | |
19 | # --enhanced-cpio tells dracut to use dracut-cpio instead of GNU cpio | |
20 | local dracut_cpio_params=("--enhanced-cpio" "$@") | |
21 | ||
22 | mkdir -p "$tdir" | |
23 | ||
24 | # VM script to print sentinel on boot | |
25 | # write to kmsg so that sysrq messages don't race with console output | |
26 | cat > "$tdir/init.sh" << EOF | |
27 | echo "Image with ${dracut_cpio_params[*]} booted successfully" > /dev/kmsg | |
28 | echo 1 > /proc/sys/kernel/sysrq | |
29 | echo o > /proc/sysrq-trigger | |
30 | sleep 20 | |
31 | EOF | |
32 | ||
f9939d0e | 33 | "$DRACUT" -l --drivers "" \ |
8104bf0e DD |
34 | "${dracut_cpio_params[@]}" \ |
35 | --modules "bash base" \ | |
36 | --include "$tdir/init.sh" /lib/dracut/hooks/emergency/00-init.sh \ | |
37 | --no-hostonly --no-hostonly-cmdline \ | |
38 | "$tdir/initramfs" \ | |
39 | || return 1 | |
40 | ||
41 | "$testdir"/run-qemu \ | |
9f6b4e53 | 42 | -device i6300esb -watchdog-action poweroff \ |
8104bf0e DD |
43 | -daemonize -pidfile "$tdir/vm.pid" \ |
44 | -serial "file:$tdir/console.out" \ | |
45 | -append "panic=1 oops=panic softlockup_panic=1 loglevel=7 console=ttyS0 rd.shell=1" \ | |
46 | -initrd "$tdir/initramfs" || return 1 | |
47 | ||
48 | timeout=120 | |
49 | while [[ -f $tdir/vm.pid ]] \ | |
50 | && ps -p "$(head -n1 "$tdir/vm.pid")" > /dev/null; do | |
51 | echo "$timeout - awaiting VM shutdown" | |
52 | sleep 1 | |
53 | [[ $((timeout--)) -le 0 ]] && return 1 | |
54 | done | |
55 | ||
56 | cat "$tdir/console.out" | |
57 | grep -q "Image with ${dracut_cpio_params[*]} booted successfully" \ | |
58 | "$tdir/console.out" | |
59 | } | |
60 | ||
61 | test_run() { | |
62 | set -x | |
63 | ||
64 | # dracut-cpio is typically used with compression and strip disabled, to | |
65 | # increase the chance of (reflink) extent sharing. | |
66 | test_dracut_cpio "simple" "--no-compress" "--nostrip" || return 1 | |
67 | # dracut-cpio should still work fine with compression and stripping enabled | |
68 | test_dracut_cpio "compress" "--gzip" "--nostrip" || return 1 | |
69 | test_dracut_cpio "strip" "--gzip" "--strip" || return 1 | |
70 | } | |
71 | ||
72 | test_setup() { | |
73 | CPIO_TESTDIR=$(mktemp --directory -p "$TESTDIR" cpio-test.XXXXXXXXXX) \ | |
74 | || return 1 | |
75 | export CPIO_TESTDIR | |
76 | return 0 | |
77 | } | |
78 | ||
79 | test_cleanup() { | |
80 | [ -d "$CPIO_TESTDIR" ] && rm -rf "$CPIO_TESTDIR" | |
81 | return 0 | |
82 | } | |
83 | ||
84 | # shellcheck disable=SC1090 | |
85 | . "$testdir"/test-functions |