Skip to content

Commit 8104bf0

Browse files
ddissharaldh
authored andcommittedNov 24, 2021
ci(TEST-63-DRACUT-CPIO): kernel extraction tests for dracut-cpio
dracut-cpio already carries a bunch of unit tests covering compression and GNU cpio extraction. The purpose of these tests is to exercise the dracut.sh --enhanced-cpio code-paths as well as kernel cpio archive extraction. Signed-off-by: David Disseldorp <ddiss@suse.de>
1 parent afe4a6d commit 8104bf0

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed
 

‎test/TEST-63-DRACUT-CPIO/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-include ../Makefile.testdir

‎test/TEST-63-DRACUT-CPIO/test.sh

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
33+
"$basedir"/dracut.sh -l --drivers "" \
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 \
42+
-watchdog i6300esb -watchdog-action poweroff \
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

0 commit comments

Comments
 (0)
Please sign in to comment.