selftest: Add basic test framework
Now, by execute `make test-run` in tests/, kexec-tools sanity tests
will be performed using VMs. There are currently 3 test cases, for local
kdump, nfs kdump and ssh kdump.
For each test VM, the selftest framework will create a snapshot layer,
do setup as required by the test case, this ensure each test runs in a
clean VM.
This framework will install a custom systemd service that starts when
system have finished booting, and the service will do basic routine
(fetch and set boot counter, etc..), then call the test case which is
installed in /kexec-kdump-test/test.sh in VM.
Each VM will have two serial consoles, one for ordinary console usage,
one for the test communication and log. The test script will watch the
second test console to know the test status.
The test cases are located in tests/scripts/testcases, documents about
the test cases structure will be provided in following commits.
Signed-off-by: Kairui Song <kasong@redhat.com>
Acked-by: Dave Young <dyoung@redhat.com>
2020-07-31 07:34:40 +00:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
BOOT_ARG="test_boot_count"
|
|
|
|
_YELLOW='\033[1;33m'
|
|
|
|
_GREEN='\033[0;32m'
|
|
|
|
_RED='\033[0;31m'
|
|
|
|
_NC='\033[0m' # No Color
|
|
|
|
|
|
|
|
if [ -n "$(cat /proc/cmdline | grep "\bno_test\b")" ]; then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
get_test_boot_count() {
|
|
|
|
local boot_count=$(cat /proc/cmdline | sed -n "s/.*$BOOT_ARG=\([0-9]*\).*/\1/p")
|
|
|
|
|
|
|
|
if [ -z "$boot_count" ]; then
|
|
|
|
boot_count=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo $boot_count
|
|
|
|
}
|
|
|
|
|
|
|
|
test_output() {
|
|
|
|
echo $@ > /dev/ttyS1
|
|
|
|
echo $@ > /dev/ttyS0
|
|
|
|
|
|
|
|
sync
|
|
|
|
}
|
|
|
|
|
|
|
|
test_passed() {
|
|
|
|
echo -e "${_GREEN}TEST PASSED${_NC}" > /dev/ttyS1
|
|
|
|
echo -e "${_GREEN}kexec-kdump-test: TEST PASSED${_NC}" > /dev/ttyS0
|
|
|
|
|
|
|
|
echo $@ > /dev/ttyS1
|
|
|
|
echo $@ > /dev/ttyS0
|
|
|
|
|
|
|
|
sync
|
|
|
|
|
|
|
|
shutdown -h 0
|
|
|
|
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
test_failed() {
|
|
|
|
echo -e "${_RED}TEST FAILED${_NC}" > /dev/ttyS1
|
|
|
|
echo -e "${_RED}kexec-kdump-test: TEST FAILED${_NC}" > /dev/ttyS0
|
|
|
|
|
|
|
|
echo $@ > /dev/ttyS1
|
|
|
|
echo $@ > /dev/ttyS0
|
|
|
|
|
|
|
|
sync
|
|
|
|
|
|
|
|
shutdown -h 0
|
|
|
|
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
test_abort() {
|
|
|
|
echo -e "${_YELLOW}TEST ABORTED${_NC}" > /dev/ttyS1
|
|
|
|
echo -e "${_YELLOW}kexec-kdump-test: TEST ABORTED${_NC}" > /dev/ttyS0
|
|
|
|
|
|
|
|
echo $@ > /dev/ttyS1
|
|
|
|
echo $@ > /dev/ttyS0
|
|
|
|
|
|
|
|
sync
|
|
|
|
|
|
|
|
shutdown -h 0
|
|
|
|
|
|
|
|
exit 2
|
|
|
|
}
|
|
|
|
|
|
|
|
has_valid_vmcore_dir() {
|
|
|
|
local path=$1
|
|
|
|
local vmcore_dir=$path/$(ls -1 $path | tail -n 1)
|
|
|
|
local vmcore="<invalid>"
|
|
|
|
|
2020-11-18 09:15:37 +00:00
|
|
|
test_output "Found a vmcore dir \"$vmcore_dir\":"
|
selftest: Add basic test framework
Now, by execute `make test-run` in tests/, kexec-tools sanity tests
will be performed using VMs. There are currently 3 test cases, for local
kdump, nfs kdump and ssh kdump.
For each test VM, the selftest framework will create a snapshot layer,
do setup as required by the test case, this ensure each test runs in a
clean VM.
This framework will install a custom systemd service that starts when
system have finished booting, and the service will do basic routine
(fetch and set boot counter, etc..), then call the test case which is
installed in /kexec-kdump-test/test.sh in VM.
Each VM will have two serial consoles, one for ordinary console usage,
one for the test communication and log. The test script will watch the
second test console to know the test status.
The test cases are located in tests/scripts/testcases, documents about
the test cases structure will be provided in following commits.
Signed-off-by: Kairui Song <kasong@redhat.com>
Acked-by: Dave Young <dyoung@redhat.com>
2020-07-31 07:34:40 +00:00
|
|
|
# Checking with `crash` is slow and consume a lot of memory/disk,
|
|
|
|
# just do a sanity check by check if log are available.
|
|
|
|
if [ -e $vmcore_dir/vmcore ]; then
|
|
|
|
vmcore=$vmcore_dir/vmcore
|
2020-11-18 09:15:37 +00:00
|
|
|
makedumpfile --dump-dmesg $vmcore $vmcore_dir/vmcore-dmesg.txt.2 || {
|
|
|
|
test_output "Failed to retrive dmesg from vmcore!"
|
|
|
|
return 1
|
|
|
|
}
|
selftest: Add basic test framework
Now, by execute `make test-run` in tests/, kexec-tools sanity tests
will be performed using VMs. There are currently 3 test cases, for local
kdump, nfs kdump and ssh kdump.
For each test VM, the selftest framework will create a snapshot layer,
do setup as required by the test case, this ensure each test runs in a
clean VM.
This framework will install a custom systemd service that starts when
system have finished booting, and the service will do basic routine
(fetch and set boot counter, etc..), then call the test case which is
installed in /kexec-kdump-test/test.sh in VM.
Each VM will have two serial consoles, one for ordinary console usage,
one for the test communication and log. The test script will watch the
second test console to know the test status.
The test cases are located in tests/scripts/testcases, documents about
the test cases structure will be provided in following commits.
Signed-off-by: Kairui Song <kasong@redhat.com>
Acked-by: Dave Young <dyoung@redhat.com>
2020-07-31 07:34:40 +00:00
|
|
|
elif [ -e $vmcore_dir/vmcore.flat ]; then
|
|
|
|
vmcore=$vmcore_dir/vmcore.flat
|
|
|
|
makedumpfile -R $vmcore_dir/vmcore < $vmcore || return 1
|
2020-11-18 09:15:37 +00:00
|
|
|
makedumpfile --dump-dmesg $vmcore_dir/vmcore $vmcore_dir/vmcore-dmesg.txt.2 || {
|
|
|
|
test_output "Failed to retrive dmesg from vmcore!"
|
|
|
|
return 1
|
|
|
|
}
|
selftest: Add basic test framework
Now, by execute `make test-run` in tests/, kexec-tools sanity tests
will be performed using VMs. There are currently 3 test cases, for local
kdump, nfs kdump and ssh kdump.
For each test VM, the selftest framework will create a snapshot layer,
do setup as required by the test case, this ensure each test runs in a
clean VM.
This framework will install a custom systemd service that starts when
system have finished booting, and the service will do basic routine
(fetch and set boot counter, etc..), then call the test case which is
installed in /kexec-kdump-test/test.sh in VM.
Each VM will have two serial consoles, one for ordinary console usage,
one for the test communication and log. The test script will watch the
second test console to know the test status.
The test cases are located in tests/scripts/testcases, documents about
the test cases structure will be provided in following commits.
Signed-off-by: Kairui Song <kasong@redhat.com>
Acked-by: Dave Young <dyoung@redhat.com>
2020-07-31 07:34:40 +00:00
|
|
|
rm $vmcore_dir/vmcore
|
|
|
|
else
|
2020-11-18 09:15:37 +00:00
|
|
|
test_output "The vmcore dir is empty!"
|
selftest: Add basic test framework
Now, by execute `make test-run` in tests/, kexec-tools sanity tests
will be performed using VMs. There are currently 3 test cases, for local
kdump, nfs kdump and ssh kdump.
For each test VM, the selftest framework will create a snapshot layer,
do setup as required by the test case, this ensure each test runs in a
clean VM.
This framework will install a custom systemd service that starts when
system have finished booting, and the service will do basic routine
(fetch and set boot counter, etc..), then call the test case which is
installed in /kexec-kdump-test/test.sh in VM.
Each VM will have two serial consoles, one for ordinary console usage,
one for the test communication and log. The test script will watch the
second test console to know the test status.
The test cases are located in tests/scripts/testcases, documents about
the test cases structure will be provided in following commits.
Signed-off-by: Kairui Song <kasong@redhat.com>
Acked-by: Dave Young <dyoung@redhat.com>
2020-07-31 07:34:40 +00:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
selftest: ignore all spaces when compare the dmesg files
For the log entry that has multiple lines, "makedumpfile --dump-dmesg"
would indent the remaining lines while vmcore-dmesg doesn't. For
example, vmcore-dmesg.txt and vmcore-dmesg.txt.2 are the outputs of
vmcore-dmesg and "makedumpfile --dump-dmesg" respectively,
```
diff -u vmcore-dmesg.txt vmcore-dmesg.txt.2
--- vmcore-dmesg.txt 2021-03-28 22:13:09.986000000 -0400
+++ vmcore-dmesg.txt.2 2021-03-28 22:13:39.920106131 -0400
@@ -397,9 +397,9 @@
[ 1.710742] vc vcsa: hash matches
[ 1.711938] RAS: Correctable Errors collector initialized.
[ 1.713736] Unstable clock detected, switching default tracing clock to "global"
-If you want to keep using the local clock, then add:
- "trace_clock=local"
-on the kernel command line
+ If you want to keep using the local clock, then add:
+ "trace_clock=local"
+ on the kernel command line
[ 1.750539] ata1.01: NODEV after polling detection
[ 1.750973] ata1.00: ATA-7: QEMU HARDDISK, 2.5+, max UDMA/100
[ 1.752885] ata1.00: 8388608 sectors, multi 16: LBA48
```
Quite often, all three tests could fail because of the above difference. So
let's ignore all the spaces. This patch could fix bz1952299 [1].
[1] https://bugzilla.redhat.com/show_bug.cgi?id=1952299
Signed-off-by: Coiby Xu <coxu@redhat.com>
Acked-by: Kairui Song <kasong@redhat.com>
2021-06-07 06:40:53 +00:00
|
|
|
if ! diff -w $vmcore_dir/vmcore-dmesg.txt.2 $vmcore_dir/vmcore-dmesg.txt; then
|
2020-11-18 09:15:37 +00:00
|
|
|
test_output "Dmesg retrived from vmcore is different from dump version!"
|
selftest: Add basic test framework
Now, by execute `make test-run` in tests/, kexec-tools sanity tests
will be performed using VMs. There are currently 3 test cases, for local
kdump, nfs kdump and ssh kdump.
For each test VM, the selftest framework will create a snapshot layer,
do setup as required by the test case, this ensure each test runs in a
clean VM.
This framework will install a custom systemd service that starts when
system have finished booting, and the service will do basic routine
(fetch and set boot counter, etc..), then call the test case which is
installed in /kexec-kdump-test/test.sh in VM.
Each VM will have two serial consoles, one for ordinary console usage,
one for the test communication and log. The test script will watch the
second test console to know the test status.
The test cases are located in tests/scripts/testcases, documents about
the test cases structure will be provided in following commits.
Signed-off-by: Kairui Song <kasong@redhat.com>
Acked-by: Dave Young <dyoung@redhat.com>
2020-07-31 07:34:40 +00:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2020-07-31 07:34:42 +00:00
|
|
|
test_output "VMCORE: $vmcore"
|
|
|
|
test_output "KERNEL VERSION: $(rpm -q kernel-core)"
|
selftest: Add basic test framework
Now, by execute `make test-run` in tests/, kexec-tools sanity tests
will be performed using VMs. There are currently 3 test cases, for local
kdump, nfs kdump and ssh kdump.
For each test VM, the selftest framework will create a snapshot layer,
do setup as required by the test case, this ensure each test runs in a
clean VM.
This framework will install a custom systemd service that starts when
system have finished booting, and the service will do basic routine
(fetch and set boot counter, etc..), then call the test case which is
installed in /kexec-kdump-test/test.sh in VM.
Each VM will have two serial consoles, one for ordinary console usage,
one for the test communication and log. The test script will watch the
second test console to know the test status.
The test cases are located in tests/scripts/testcases, documents about
the test cases structure will be provided in following commits.
Signed-off-by: Kairui Song <kasong@redhat.com>
Acked-by: Dave Young <dyoung@redhat.com>
2020-07-31 07:34:40 +00:00
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOT_COUNT=$(get_test_boot_count)
|
|
|
|
test_output "Kexec-Kdump-Test Boot #$BOOT_COUNT"
|
|
|
|
|
|
|
|
echo 'fedora' | passwd --stdin root
|
|
|
|
|
|
|
|
test_output "Updating kernel cmdline"
|
|
|
|
grubby --update-kernel ALL --args $BOOT_ARG=$(expr $BOOT_COUNT + 1) && sync
|
|
|
|
|
|
|
|
test_output "Executing test hook"
|
|
|
|
source /kexec-kdump-test/test.sh
|
|
|
|
|
|
|
|
on_test;
|
|
|
|
|
|
|
|
test_output "Test exited, system hang for inspect"
|