The purpose of crash selftest is to perform quick sanity testing of
new patches, and further more, to work with kexec-tools selftest, in
order to provide complete testing for kdump overall process.
This patch borrowed kexec-tools selftest. Now by running "make live-test"
and "make vmcore-test" in tests/, the selftest will build crash from source,
and execute it by feeding a group of commands to crash, then check the
outputs whether are as expected.
The commands are located in scripts/crash_test.sh, which will be enriched
continuously.
Signed-off-by: Tao Liu <ltao(a)redhat.com>
---
tests/Makefile | 51 ++++++++++++++++++++
tests/README | 26 ++++++++++
tests/scripts/crash_test.sh | 94 +++++++++++++++++++++++++++++++++++++
3 files changed, 171 insertions(+)
create mode 100644 tests/Makefile
create mode 100644 tests/README
create mode 100755 tests/scripts/crash_test.sh
diff --git a/tests/Makefile b/tests/Makefile
new file mode 100644
index 0000000..2a0b251
--- /dev/null
+++ b/tests/Makefile
@@ -0,0 +1,51 @@
+VMCORE ?=
+VMLINUX ?=
+
+TEST_ROOT := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
+BUILD_ROOT := $(TEST_ROOT)/build
+REPO = $(shell realpath $(TEST_ROOT)/../)
+SPEC = crash.spec
+ARCH = $(shell arch)
+TEST_SCRIPT = $(TEST_ROOT)/scripts/crash_test.sh
+
+RPMDEFINE = --define '_sourcedir $(REPO)'\
+ --define '_specdir $(REPO)'\
+ --define '_builddir $(BUILD_ROOT)'\
+ --define '_srcrpmdir $(BUILD_ROOT)'\
+ --define '_rpmdir $(BUILD_ROOT)'
+
+CRASH_SRC = $(filter-out $(REPO)/tests,$(wildcard $(REPO)/*))
+CRASH_NVR = $(shell rpm $(RPMDEFINE) -q --specfile $(REPO)/$(SPEC) 2>/dev/null | grep
-m 1 .)
+CRASH_RPM = $(BUILD_ROOT)/$(ARCH)/$(CRASH_NVR).rpm
+CRASH_BIN = $(BUILD_ROOT)/$(ARCH)/usr/bin/crash
+
+default:
+ @echo "make live-test"
+ @echo "make vmcore-test VMCORE=<file> VMLINUX=<file>"
+ @exit 0
+
+$(CRASH_RPM): $(CRASH_SRC)
+ sh -c "cd .. && fedpkg sources"
+ @echo Rebuilding RPM due to modification of sources: $?
+ rpmbuild $(RPMDEFINE) -ba $(REPO)/$(SPEC)
+
+crash_bin: $(CRASH_RPM)
+ cd $(BUILD_ROOT)/$(ARCH) && rpm2cpio $(CRASH_RPM) | cpio -div
+ touch crash_bin
+
+live-test: crash_bin
+ $(TEST_SCRIPT) $(CRASH_BIN)
+
+vmcore-test: crash_bin
+ifeq ($(strip $(VMCORE)),)
+ @echo "Must provide VMCORE!"
+ @exit 1
+endif
+ifeq ($(strip $(VMLINUX)),)
+ @echo "Must provide VMLINUX!"
+ @exit 1
+endif
+ $(TEST_SCRIPT) $(CRASH_BIN) $(VMCORE) $(VMLINUX)
+
+clean:
+ rm -rf $(TEST_ROOT)/build crash_bin
\ No newline at end of file
diff --git a/tests/README b/tests/README
new file mode 100644
index 0000000..d286cef
--- /dev/null
+++ b/tests/README
@@ -0,0 +1,26 @@
+===============
+Crash Self-test
+===============
+
+
+Introduction
+============
+The self-tests here are useful for quick sanity tests for new patches, and are also
useful for overall kdump process testing when intergrated with kexec-tools.
+
+Basic usage
+===========
+If you want to perform vmcore-testing, you need to get vmcore and vmlinux ready first.
Then you can start vmcore-testing by typing the following command:
+
+`make clean && make vmcore-test VMCORE=<path/to/vmcore>
VMLINUX=<path/to/vmlinux>`
+
+If you want to perform live-testing, you need to install kernel-debuginfo first.
+
+`sudo debuginfo-install -y kernel-debuginfo-$(uname -r)`
+
+Then start live-testing by typing the following command:
+
+`make clean && make live-test`
+
+Test Cases
+==========
+Currently the testing commands are located in tests/scripts/crash_test.sh. A cmd_list
array is piped to crash, then check the output of crash whether is expected.
\ No newline at end of file
diff --git a/tests/scripts/crash_test.sh b/tests/scripts/crash_test.sh
new file mode 100755
index 0000000..d09e0ea
--- /dev/null
+++ b/tests/scripts/crash_test.sh
@@ -0,0 +1,94 @@
+#!/bin/sh
+
+crash=$1
+vmcore=$2
+vmlinux=$3
+
+cmd_list=(
+ "p linux_banner"
+ "rd -a linux_banner | head -1"
+ "sym schedule"
+ "whatis linux_banner"
+ "eval 1+1 | grep hexadecimal"
+ "q"
+)
+
+log_filter() {
+ res=$(awk '
+ /^\s*$/ {
+ next;
+ }
+ /WARNING: kernel relocated .* patching .* gdb minimal_symbol values/ {
+ next;
+ }
+
+ ###################Check cmd_list###################
+ /^p linux_banner$/ {
+ allow_regex="^linux_banner = \\$1 = 0x[0-9a-f]+ (<linux_banner>
)?\"Linux version";
+ next;
+ }
+ /^rd -a linux_banner | head -1$/ {
+ allow_regex="^[0-9a-f]+: Linux version";
+ next;
+ }
+ /^sym schedule$/ {
+ allow_regex="^[0-9a-f]+ \\(T\\) schedule ";
+ next;
+ }
+ /^whatis linux_banner$/ {
+ allow_regex="^const char linux_banner\\[\\];$";
+ next;
+ }
+ /^eval 1+1 | grep hexadecimal$/ {
+ allow_regex="^hexadecimal: 2 ";
+ next;
+ }
+ /^q$/ {
+ next;
+ }
+ ################End of cmd_list check################
+
+ $0 !~ allow_regex {
+ print $0;
+ }
+
+ ##################Crash error check##################
+ tolower($0) ~ /\<mismatch\>/ {print $0;next;}
+ tolower($0) ~ /cannot/ {print $0;next;}
+ tolower($0) ~ /\<fail\>/ {print $0;next;}
+ tolower($0) ~ /\<failed\>/ {print $0;next;}
+ tolower($0) ~ /\<error\>/ {print $0;next;}
+ tolower($0) ~ /\<invalid\>/ {print $0;next;}
+ tolower($0) ~ /unexpect/ {print $0;next;}
+ tolower($0) ~ /not supported/ {print $0;next;}
+ tolower($0) ~ /no such file or directory/ {print $0;next;}
+ ###############End of crash error check###############
+ ')
+
+ if [ -z "$res" ]; then
+ return 0
+ else
+ echo $res
+ return 1
+ fi
+}
+
+for ((i=0;i<${#cmd_list[@]};i++)); do
+ echo "echo '${cmd_list[$i]}'"
+ echo ${cmd_list[$i]}
+done | \
+$crash -s $vmcore $vmlinux 2>&1 | \
+log_filter
+
+exit_val=(${PIPESTATUS[@]})
+
+crash_exit_val=${exit_val[1]}
+filter_exit_val=${exit_val[2]}
+
+if [[ $crash_exit_val -eq 0 && $filter_exit_val -eq 0 ]]; then
+ echo "Crash test pass"
+ exit 0
+else
+ echo "Crash test fail"
+ exit 1
+fi
\ No newline at end of file
--
2.29.2