diff --git a/case-lib/hijack.sh b/case-lib/hijack.sh index 6f14e954..f1d1b8a7 100644 --- a/case-lib/hijack.sh +++ b/case-lib/hijack.sh @@ -12,6 +12,8 @@ function func_exit_handler() dlogi "Starting func_exit_handler($exit_status)" + finish_kmsg_collection + func_lib_check_and_disable_pipewire # call trace @@ -134,32 +136,6 @@ 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}" - journalctl_cmd --since=@"$KERNEL_CHECKPOINT" > "${journalctl_logs}" - elif [[ "$KERNEL_CHECKPOINT" == "disabled" ]]; then - dlogi "Save all kernel messages to ${journalctl_logs}" - journalctl_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 15d122ba..d1ce1cef 100644 --- a/case-lib/lib.sh +++ b/case-lib/lib.sh @@ -97,7 +97,7 @@ start_test() } # func_exit_handler() is in hijack.sh - trap 'func_exit_handler $?' EXIT + trap 'func_exit_handler $?' EXIT SIGTERM if test -z "$MAX_WAIT_FW_LOADING"; then local _pltf; _pltf=$("$SCRIPT_HOME/tools/sof-dump-status.py" -p) @@ -125,6 +125,7 @@ start_test() die "FW is not loaded for $MAX_WAIT_FW_LOADING" fi } + func_kmsg_collect export SOF_TEST_TOP_PID="$$" local prefix; prefix="ktime=$(ktime) sof-test PID=${SOF_TEST_TOP_PID}" @@ -198,6 +199,26 @@ stop_test() } +finish_kmsg_collection() +{ + if [[ -n "$DMESG_PID" ]]; then + kill "$DMESG_PID" 2>/dev/null + wait "$DMESG_PID" 2>/dev/null + unset KERNEL_CHECKPOINT + fi + + local journalctl_logs="$LOG_ROOT/dmesg.txt" + 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 +} + + ktime() { # Keep it coarse because of various delays. @@ -408,6 +429,24 @@ func_mtrace_collect() sudo bash -c "${mtraceCmd[*]} &" >& "$clogfile" } +func_kmsg_collect() { + local journalctl_logs="$LOG_ROOT/dmesg.txt" + + if [[ "$KERNEL_CHECKPOINT" =~ ^[0-9]{10} ]]; then + dlogi "Saving kernel messages since ${KERNEL_CHECKPOINT} to ${journalctl_logs}" + journalctl_cmd --since=@"$KERNEL_CHECKPOINT" -f >> "${journalctl_logs}" & + elif [[ "$KERNEL_CHECKPOINT" == "disabled" ]]; then + dlogi "Saving all kernel messages" + journalctl_cmd -f >> "${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 + return + fi + DMESG_PID=$! +} + func_lib_log_post_process() { # SyS-T log output a Zephyr feature, no need postprocess