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