From b7d2f35872bd962e3d815cb1c78940b77ab660c8 Mon Sep 17 00:00:00 2001 From: Emilia Kurdybelska Date: Mon, 2 Mar 2026 14:14:37 +0100 Subject: [PATCH] hijack.sh: exit_handler: collect dmesg throughout the whole test Start collecting dmesg logs in the beggining of the test and run collection in the background. Signed-off-by: Emilia Kurdybelska --- case-lib/hijack.sh | 32 ++++++-------------------------- case-lib/lib.sh | 21 ++++++++++++++++++++- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/case-lib/hijack.sh b/case-lib/hijack.sh index 6f14e954..8d912adc 100644 --- a/case-lib/hijack.sh +++ b/case-lib/hijack.sh @@ -12,6 +12,12 @@ function func_exit_handler() dlogi "Starting func_exit_handler($exit_status)" + if [[ -n "$DMESG_PID" ]]; then + kill "$DMESG_PID" 2>/dev/null + wait "$DMESG_PID" 2>/dev/null + unset KERNEL_CHECKPOINT + fi + func_lib_check_and_disable_pipewire # call trace @@ -134,32 +140,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..8638b726 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_dmesg_collect export SOF_TEST_TOP_PID="$$" local prefix; prefix="ktime=$(ktime) sof-test PID=${SOF_TEST_TOP_PID}" @@ -408,6 +409,24 @@ func_mtrace_collect() sudo bash -c "${mtraceCmd[*]} &" >& "$clogfile" } +func_dmesg_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