]>
git.ipfire.org Git - thirdparty/dracut.git/blob - test/test-functions
2 PATH
=/usr
/sbin
:/usr
/bin
:/sbin
:/bin
5 # shellcheck disable=SC1090
6 [[ -e .testdir
${TEST_RUN_ID:+-$TEST_RUN_ID} ]] && . .testdir
${TEST_RUN_ID:+-$TEST_RUN_ID}
7 if [[ -z $TESTDIR ]] ||
[[ ! -d $TESTDIR ]]; then
8 TESTDIR
=$
(mktemp
-d -p "/var/tmp" -t dracut-test.XXXXXX
)
10 echo "TESTDIR=\"$TESTDIR\"" > .testdir
${TEST_RUN_ID:+-$TEST_RUN_ID}
13 KVERSION
=${KVERSION-$(uname -r)}
15 [ -z "$USE_NETWORK" ] && USE_NETWORK
="network-legacy"
17 if [[ -z $basedir ]]; then basedir
="$(realpath ../..)"; fi
20 TEST_DRACUT_ARGS
+=" --local --no-hostonly --no-early-microcode --add test --kver $KVERSION"
22 # shellcheck disable=SC2162
23 IFS
=' ' read -a TEST_DRACUT_ARGS_ARRAY
<<< "$TEST_DRACUT_ARGS"
25 "$basedir"/dracut.sh
"$@" \
26 --kernel-cmdline "panic=1 oops=panic softlockup_panic=1 systemd.crash_reboot selinux=0 console=ttyS0,115200n81 $DEBUGFAIL" \
27 "${TEST_DRACUT_ARGS_ARRAY[@]}" ||
return 1
30 command -v test_check
&> /dev
/null || test_check
() {
34 command -v test_cleanup
&> /dev
/null || test_cleanup
() {
38 # terminal sequence to set color to a 'success' color (currently: green)
39 function SETCOLOR_SUCCESS
() { echo -en '\033[0;32m'; }
40 # terminal sequence to set color to a 'failure' color (currently: red)
41 function SETCOLOR_FAILURE
() { echo -en '\033[0;31m'; }
42 # terminal sequence to set color to a 'warning' color (currently: yellow)
43 function SETCOLOR_WARNING
() { echo -en '\033[0;33m'; }
44 # terminal sequence to reset to the default color.
45 function SETCOLOR_NORMAL
() { echo -en '\033[0;39m'; }
47 COLOR_SUCCESS
='\033[0;32m'
48 COLOR_FAILURE
='\033[0;31m'
49 COLOR_WARNING
='\033[0;33m'
50 COLOR_NORMAL
='\033[0;39m'
53 if ((EUID
!= 0)); then
55 echo "Tests must be run as root! Please use 'sudo'."
61 # generate qemu arguments for named raw disks
63 # qemu_add_drive_args <index> <args> <filename> <id-name> [<bootindex>]
65 # index: name of the index variable (set to 0 at start)
66 # args: name of the argument array variable (set to () at start)
67 # filename: filename of the raw disk image
68 # id-name: name of the disk in /dev/disk/by-id -> /dev/disk/by-id/ata-disk_$name
69 # size: optional file size in MiB (0 implies size is not set)
70 # bootindex: optional bootindex number
72 # to be used later with `qemu … "${args[@]}" …`
73 # The <index> variable will be incremented each time the function is called.
75 # can't be easier than this :-/
79 # declare -a disk_args=()
80 # declare -i disk_index=0
81 # qemu_add_drive_args disk_index disk_args "$TESTDIR"/root.ext3 root 0 1
82 # qemu_add_drive_args disk_index disk_args "$TESTDIR"/client.img client
83 # qemu_add_drive_args disk_index disk_args "$TESTDIR"/iscsidisk2.img iscsidisk2
84 # qemu_add_drive_args disk_index disk_args "$TESTDIR"/iscsidisk3.img iscsidisk3
85 # qemu "${disk_args[@]}"
87 qemu_add_drive_args
() {
90 local name
=${4:-$index}
94 if [ "${size}" -ne 0 ]; then
95 dd if=/dev
/zero of
="${file}" bs
=1MiB count
="${size}"
99 -drive "if=none,format=raw,file=${file},id=drive-sata${index}" \
100 -device "ide-hd,bus=ide.${index},drive=drive-sata${index},id=sata${index},${bootindex:+bootindex=$bootindex,}model=disk,serial=${name}" \
103 # shellcheck disable=SC2219
107 test_marker_reset
() {
108 dd if=/dev
/zero of
="$TESTDIR"/marker.img bs
=1MiB count
=1
111 test_marker_check
() {
112 local marker
=${1:-dracut-root-block-success}
113 local file=${2:-marker.img}
115 grep -U --binary-files=binary
-F -m 1 -q "$marker" "$TESTDIR/$file"
123 echo "TEST RUN: $TEST_DESCRIPTION"
124 test_check
&& test_run
129 echo "TEST SETUP: $TEST_DESCRIPTION"
130 test_check
&& test_setup
134 echo "TEST CLEANUP: $TEST_DESCRIPTION"
137 rm -f -- .testdir
${TEST_RUN_ID:+-$TEST_RUN_ID}
142 if ! test_check
2 &> test${TEST_RUN_ID:+-$TEST_RUN_ID}.log
; then
143 echo -e "TEST: $TEST_DESCRIPTION " "$COLOR_WARNING" "[SKIPPED]" "$COLOR_NORMAL"
146 echo -e "TEST: $TEST_DESCRIPTION " "$COLOR_SUCCESS" "[STARTED]" "$COLOR_NORMAL"
148 if [[ $V == "1" ]]; then
151 test_setup
&& test_run
154 if ((ret
!= 0)) && [[ -f "$TESTDIR"/server.log
]]; then
155 mv "$TESTDIR"/server.log .
/server
${TEST_RUN_ID:+-$TEST_RUN_ID}.log
158 rm -f -- .testdir
${TEST_RUN_ID:+-$TEST_RUN_ID}
160 ) < /dev
/null
2>&1 |
tee "test${TEST_RUN_ID:+-$TEST_RUN_ID}.log"
161 elif [[ $V == "2" ]]; then
163 # shellcheck disable=SC2154
165 test_setup
&& test_run
168 if ((ret
!= 0)) && [[ -f "$TESTDIR"/server.log
]]; then
169 mv "$TESTDIR"/server.log .
/server
${TEST_RUN_ID:+-$TEST_RUN_ID}.log
172 rm -f -- .testdir
${TEST_RUN_ID:+-$TEST_RUN_ID}
174 ) < /dev
/null
2>&1 |
"$basedir/logtee" "test${TEST_RUN_ID:+-$TEST_RUN_ID}.log"
177 test_setup
&& test_run
181 rm -f -- .testdir
${TEST_RUN_ID:+-$TEST_RUN_ID}
183 ) < /dev
/null
> test${TEST_RUN_ID:+-$TEST_RUN_ID}.log
2>&1
187 if [ $ret -eq 0 ]; then
188 rm -- test${TEST_RUN_ID:+-$TEST_RUN_ID}.log
189 echo -e "TEST: $TEST_DESCRIPTION " "$COLOR_SUCCESS" "[OK]" "$COLOR_NORMAL"
191 echo -e "TEST: $TEST_DESCRIPTION " "$COLOR_FAILURE" "[FAILED]" "$COLOR_NORMAL"
192 if [ "$V" == "2" ]; then
193 tail -c 1048576 "$(pwd)/server${TEST_RUN_ID:+-$TEST_RUN_ID}.log" "$(pwd)/test${TEST_RUN_ID:+-$TEST_RUN_ID}.log"
194 echo -e "TEST: $TEST_DESCRIPTION " "$COLOR_FAILURE" "[FAILED]" "$COLOR_NORMAL"
196 echo "see $(pwd)/test${TEST_RUN_ID:+-$TEST_RUN_ID}.log"