diff --git a/case-lib/hijack.sh b/case-lib/hijack.sh index fe1bf682..e96fddfc 100644 --- a/case-lib/hijack.sh +++ b/case-lib/hijack.sh @@ -168,6 +168,31 @@ function func_exit_handler() storage_checks || exit_status=1 fi + local journalctl_logs="$LOG_ROOT/dmesg.txt" + if [[ "$KERNEL_CHECKPOINT" =~ ^[0-9]{10} ]]; then + # Do not collect the entire duration of the test but only the + # last iteration. + dlogi "Save kernel messages since ${KERNEL_CHECKPOINT} to ${journalctl_logs}" + kernel_logger_cmd --since=@"$KERNEL_CHECKPOINT" > "${journalctl_logs}" + elif [[ "$KERNEL_CHECKPOINT" == "disabled" ]]; then + dlogi "Save all kernel messages to ${journalctl_logs}" + kernel_logger_cmd > "${journalctl_logs}" + else + dloge 'Kernel check point "KERNEL_CHECKPOINT" is not properly set' + dloge "KERNEL_CHECKPOINT=$KERNEL_CHECKPOINT" + test "$exit_status" -ne 0 || exit_status=1 + fi + if test -s "${journalctl_logs}"; then + wcLog=$(wc -l "${journalctl_logs}") + dlogi "nlines=$wcLog" + else + dlogw "Empty ${journalctl_logs}" + fi + # Make sure the logs are written on disk just in case of DUT power reset. + sync + + # After log collected, KERNEL_CHECKPOINT will not be used any more + unset KERNEL_CHECKPOINT # get ps command result as list local -a cmd_lst # $$ as current script pid diff --git a/case-lib/lib.sh b/case-lib/lib.sh index 7eaaa9ab..b393dc0b 100644 --- a/case-lib/lib.sh +++ b/case-lib/lib.sh @@ -294,6 +294,7 @@ storage_checks() setup_kernel_check_point() { + sudo true # Make the check point $SOF_TEST_INTERVAL second(s) earlier to avoid # log loss. Note this may lead to an error caused by one test # appear in the next one, see comments in config.sh. Add 3 extra @@ -1140,10 +1141,20 @@ is_sof_used() } # a wrapper to journalctl with required style -journalctl_cmd() +kernel_logger_cmd() { - sudo journalctl -k -q --no-pager --utc --output=short-monotonic \ - --no-hostname "$@" + if command -v journalctl >/dev/null 2>&1; then + sudo journalctl -k -q --no-pager --utc --output=short-monotonic --no-hostname "$@" + else + local mapped_args=() + local arg + + for arg in "$@"; do + mapped_args+=("${arg/--priority/--level}") + done + + sudo dmesg -k --nopager "${mapped_args[@]}" + fi } # Force the exit handler to collect all the logs since boot time instead @@ -1157,7 +1168,7 @@ disable_kernel_check_point() # shellcheck disable=SC2120 sof_firmware_boot_complete() { - journalctl_cmd "$@" | grep -i 'sof.*firmware[[:blank:]]*boot[[:blank:]]*complete' + kernel_logger_cmd "$@" | grep -i 'sof.*firmware[[:blank:]]*boot[[:blank:]]*complete' } # If the firmware is loaded then you probably want to use the newer @@ -1246,7 +1257,7 @@ fw_relfilepath() fw_relfilepath_from_klogs() { local rel_filepath - rel_filepath=$(journalctl -k | + rel_filepath=$(kernel_logger_cmd | awk '/sof.*[[:blank:]]request_firmware[[:blank:]]/ { sub(/^.*request_firmware/,""); last_loaded_file=$1 } @@ -1354,11 +1365,11 @@ grep_firmware_info_in_logs() { # dump the version info and ABI info # "head -n" makes this compatible with set -e. - journalctl_cmd "$@" | grep "Firmware info" -A1 | head -n 12 + kernel_logger_cmd "$@" | grep "Firmware info" -A1 | head -n 12 # For dumping the firmware information when DUT runs IPC4 mode - journalctl_cmd "$@" | grep "firmware version" -A1 | head -n 12 + kernel_logger_cmd "$@" | grep "firmware version" -A1 | head -n 12 # dump the debug info - journalctl_cmd "$@" | grep "Firmware debug build" -A3 | head -n 12 + kernel_logger_cmd "$@" | grep "Firmware debug build" -A3 | head -n 12 } # check if NTP Synchronized, if so return 0 otherwise return 1 diff --git a/test-case/verify-sof-firmware-load.sh b/test-case/verify-sof-firmware-load.sh index d6866a44..b0467b6b 100755 --- a/test-case/verify-sof-firmware-load.sh +++ b/test-case/verify-sof-firmware-load.sh @@ -23,7 +23,7 @@ disable_kernel_check_point start_test -cmd="journalctl_cmd" +cmd="kernel_logger_cmd" dlogi "Checking SOF Firmware load info in kernel log" if sof_firmware_boot_complete; then @@ -42,7 +42,7 @@ else # failed, show some logs printf ' ------\n Check journalctl status: \n ---- \n' systemctl --no-pager status systemd-journald* || true - journalctl_cmd --lines 50 || true + kernel_logger_cmd --lines 50 || true die "Cannot find any 'sof boot complete' message in logs since boot time" fi diff --git a/tools/sof-kernel-log-check.sh b/tools/sof-kernel-log-check.sh index 588bbbd2..7b0c9399 100755 --- a/tools/sof-kernel-log-check.sh +++ b/tools/sof-kernel-log-check.sh @@ -459,7 +459,7 @@ fi # confirm begin_timestamp is in UNIX timestamp format, otherwise search full log if [[ $begin_timestamp =~ ^[0-9]{10} ]]; then - cmd="journalctl_cmd --since=@$begin_timestamp" + cmd="kernel_logger_cmd --since=@$begin_timestamp" else die "Invalid begin_timestamp $1 argument: $begin_timestamp" fi @@ -469,7 +469,7 @@ declare -p cmd if err=$($cmd --priority=err | grep -v -E -e "$ignore_str" "${sof_local_extra_kernel_ignores[@]}"); then - type journalctl_cmd + type kernel_logger_cmd echo "$(date -u '+%Y-%m-%d %T %Z')" "[ERROR]" "Caught kernel log error" echo "===========================>>" echo "$err"