diff --git a/tests/certify/kdump/kdump.sh b/tests/certify/kdump/kdump.sh index d1ec1b40260252cdbd7a7550b143c9139e507245..1d91167baf11d87926ceabd8c50adc0a547e3c13 100644 --- a/tests/certify/kdump/kdump.sh +++ b/tests/certify/kdump/kdump.sh @@ -6,135 +6,136 @@ FLAGFILE='crash.txt' BASE_PATH="$(cd "$(dirname "$0")";pwd)" VMLINUX_PATH=/lib/debug/lib/modules/`uname -r`/vmlinux +function check() { + local fail_msg="" + local debuginfo_load=$(rpm -qa | grep "debuginfo") + + command -v 'kexec' >/dev/null 2>&1 || fail_msg="${fail_msg}Fail: kexec-tools not found" + echo "===Check cmdline===" + if ! grep 'crashkernel=' /proc/cmdline; then + fail_msg="${fail_msg}Fail: error changing Boot Loader, no crashkernel=.\n" + fi + + echo "===Check kernel allocated memory===" + if [ $(cat /sys/kernel/kexec_crash_size) -le 0 ];then + fail_msg="${fail_msg}Fail: it's unallocated memory for kernel\n" + fi + + echo "===Check kernel-debuginfo rpm===" + if [[ $debuginfo_load =~ "kernel-debuginfo" ]] && [[ $debuginfo_load =~ "kernel-debuginfo-common" ]]; then + echo "kernel-debuginfo and kernel-debuginfo-common have loaded!" + else + fail_msg="${fail_msg}Fail: kernel-debuginfo and kernel-debuginfo-common should be loaded first!\n" + fi + + echo "===Check kernel version===" + kernel_debuginfo_ver=$(rpm -ql kernel-debuginfo|grep vmlinux|awk -F/ '{print $(NF-1)}') + if [ "$kernel_debuginfo_ver" != "$(uname -r)" ];then + echo "Error: The kernel version is inconsistent, kernel debuginfo version is $kernel_debuginfo_ver, but kernel version is $(uname -r)." + echo "please install kernel-debuginfo-`uname -r`" + test_fail + fi + + echo $VMLINUX_PATH + if [ -a $VMLINUX_PATH ]; then + echo "vmlinux file is exist!" + else + fail_msg="${fail_msg}Fail: vmlinux file is not exist, path is $VMLINUX_PATH\n" + fi + + if [ -n "${fail_msg}" ]; then + echo -e "${fail_msg}" + echo "Please fixed the above failures before continuing." + return 1 + else + echo "kdump prepare check success!" + fi + return 0 +} + function setup_kdump() { - if [ ! -x "/sbin/kexec" ]; then - echo "Fail: kexec-tools not found." - error=1 - fi - - if ! grep 'crashkernel=' /proc/cmdline; then - echo "Fail: error changing Boot Loader, no crashkernel=." - error=1 - fi - - debuginfo_load=$(rpm -qa | grep "debuginfo") - if [[ $debuginfo_load =~ "kernel-debuginfo" ]] && [[ $debuginfo_load =~ "kernel-debuginfo-common" ]]; then - echo "kernel-debuginfo and kernel-debuginfo-common have loaded!" - else - echo "Fail: kernel-debuginfo and kernel-debuginfo-common should be loaded first!" - error=1 - fi - - echo $VMLINUX_PATH - if [ -a $VMLINUX_PATH ]; then - echo "vmlinux file is exist!" - else - echo "Fail: vmlinux file is not exist, path is $VMLINUX_PATH" - error=1 - fi - - if [ "${error}" ]; then - echo "Please fixed the above failures before continuing." - return 1 - else - echo "kdump prepare check success!" - fi - - cat /etc/default/grub - cat /etc/kdump.conf - #kdump enable - ret="$(systemctl status kdump)" - echo $ret - active_str='Active: active' - if ! [[ $ret =~ $active_str ]]; then - echo "kdump is not enabled, start enable kdump" - systemctl start kdump.service - for ((i=0;i<5;i++)) - do - sleep 10 - ret="$(systemctl status kdump)" - if [[ $ret =~ $active_str ]]; then - break - fi - done - if [ $i -eq 5 ]; then - echo "Fail: error to enable kdump" - return 1 - fi - fi - echo "kdump enabled success" - - #Restart automatically excute ancert kdump check - conffile='/etc/rc.d/rc.local' - find_ret=$(find $BASE_PATH/../../ -name "ancert") - if [ $find_ret ]; then - python_excu='python3' - else - python_excu='' - fi - cmd1="cd $BASE_PATH/../../ " - cmd2="$python_excu ancert -g Kdump" - echo $cmd1 - echo $cmd2 - sed -i "\$a $cmd1" $conffile - sed -i "\$a $cmd2" $conffile - chmod +x $conffile - - return 0 + local conffile='/etc/rc.d/rc.local' + local find_ret=$(find $BASE_PATH/../../../ -name "ancert") + + check || return 1 + + cat /etc/default/grub + cat /etc/kdump.conf + #kdump enable + if ! systemctl is-active kdump; then + echo "kdump is not enabled, start enable kdump" + systemctl start kdump.service + for ((i=0;i<5;i++));do + sleep 10 + systemctl is-active kdump && break + done + [ $i -eq 5 ] && { echo "Fail: error to enable kdump";return 1; } + fi + echo "kdump enabled success" + + #Restart automatically excute ancert kdump check + [ -n "$find_ret" ] && python_excu='python3' || python_excu='' + cmd1="cd $BASE_PATH/../../../" + cmd2="$python_excu ancert -g Kdump --single_mode" + echo $cmd1 + echo $cmd2 + sed -i "\$a $cmd1" $conffile + sed -i "\$a $cmd2" $conffile + chmod +x $conffile + return 0 } function run_kdump_test() { - setup_kdump - if [ $? -ne 0 ]; then - echo "setup kdump fail" - test_fail - fi - - echo "start to trigger crash" - rm -rf $COREDIR - systemctl status kdump - echo "kdump test finish"> $FLAGFILE - sync - echo c > /proc/sysrq-trigger - return 0 + setup_kdump || { echo "setup kdump fail";test_fail; } + echo "start to trigger crash" + rm -rf $COREDIR + systemctl status kdump + echo "kdump test finish"> $FLAGFILE + sync + echo c > /proc/sysrq-trigger + return 0 } function run_vmcore_check() { - if [ "$(ls -A $COREDIR)" = "" ]; then - echo $COREDIR" is empty, kdump test fail!" - test_clean - test_fail - else - echo "vmcore folder is exist, start to run crash cmd!" - rm -f crash.log - echo q | crash $VMLINUX_PATH $COREDIR/`ls $COREDIR`/vmcore > crash.log - if [ $? -eq 1 ]; then - echo "crash cmd fail, kdump test fail!" - cat crash.log - test_clean - test_fail - else - cat crash.log - echo "kdump test success!" - return 0 - fi - fi + cat /etc/default/grub + echo -e "\nAllocate memory(`cat /sys/kernel/kexec_crash_size`) for the kernel\n" + cat /etc/kdump.conf + systemctl status kdump.service + + if [ "$(ls -A $COREDIR)" = "" ]; then + echo $COREDIR" is empty, kdump test fail!" + test_clean + test_fail + else + echo "===vmcore folder is exist, start crash analysis,run it(crash $VMLINUX_PATH $COREDIR/`ls $COREDIR`/vmcore > crash.log)===" + rm -f crash.log + if ! echo q | crash $VMLINUX_PATH $COREDIR/`ls $COREDIR`/vmcore > crash.log;then + echo "crash cmd fail, kdump test fail!" + cat crash.log + rm -rf crash.log + test_clean + test_fail + else + cat crash.log + rm -rf crash.log + echo "kdump test success!" + return 0 + fi + fi } function test_clean() { - echo "test finish, start to recover conf" - rm -f $FLAGFILE - conffile='/etc/rc.d/rc.local' - sed -i "\$d" $conffile - sed -i "\$d" $conffile + echo "test finish, start to recover conf" + for file in `find / -name "$FLAGFILE"`;do [ -f "$file" ] && rm -rf "$file";done + sed -i '/[K|k]dump/d' /etc/rc.d/rc.local } # # # # # # # # # # # # # # main # # # # # # # # # # # # # # print_test_info "Kdump" if [ -e $FLAGFILE ]; then - run_vmcore_check - test_clean + run_vmcore_check + test_clean else - run_kdump_test + run_kdump_test fi test_pass