Skip to content

Commit 5e67990

Browse files
committed
case-lib: refactor kernel logs collecting
Start collecting kernel logs in the beggining of the test and run collection in the background. Signed-off-by: Emilia Kurdybelska <emiliax.kurdybelska@intel.com>
1 parent 6cbcd70 commit 5e67990

39 files changed

+70
-98
lines changed

case-lib/hijack.sh

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ function func_exit_handler()
1212

1313
dlogi "Starting func_exit_handler($exit_status)"
1414

15+
finish_kmsg_collection
16+
1517
func_lib_check_and_disable_pipewire
1618

1719
# call trace
@@ -134,32 +136,6 @@ function func_exit_handler()
134136
storage_checks || exit_status=1
135137
fi
136138

137-
local journalctl_logs="$LOG_ROOT/dmesg.txt"
138-
if [[ "$KERNEL_CHECKPOINT" =~ ^[0-9]{10} ]]; then
139-
# Do not collect the entire duration of the test but only the
140-
# last iteration.
141-
dlogi "Save kernel messages since ${KERNEL_CHECKPOINT} to ${journalctl_logs}"
142-
journalctl_cmd --since=@"$KERNEL_CHECKPOINT" > "${journalctl_logs}"
143-
elif [[ "$KERNEL_CHECKPOINT" == "disabled" ]]; then
144-
dlogi "Save all kernel messages to ${journalctl_logs}"
145-
journalctl_cmd > "${journalctl_logs}"
146-
else
147-
dloge 'Kernel check point "KERNEL_CHECKPOINT" is not properly set'
148-
dloge "KERNEL_CHECKPOINT=$KERNEL_CHECKPOINT"
149-
test "$exit_status" -ne 0 || exit_status=1
150-
fi
151-
if test -s "${journalctl_logs}"; then
152-
wcLog=$(wc -l "${journalctl_logs}")
153-
dlogi "nlines=$wcLog"
154-
else
155-
dlogw "Empty ${journalctl_logs}"
156-
fi
157-
# Make sure the logs are written on disk just in case of DUT power reset.
158-
sync
159-
160-
# After log collected, KERNEL_CHECKPOINT will not be used any more
161-
unset KERNEL_CHECKPOINT
162-
163139
# get ps command result as list
164140
local -a cmd_lst
165141
# $$ as current script pid

case-lib/lib.sh

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ minvalue() { printf '%d' $(( "$1" < "$2" ? "$1" : "$2" )); }
8383
#
8484
start_test()
8585
{
86+
setup_kernel_check_point
87+
func_kmsg_collect
88+
8689
if [ "$SOF_TEST_PIPEWIRE" == true ]; then
8790
func_lib_enable_pipewire
8891
fi
@@ -97,7 +100,7 @@ start_test()
97100
}
98101

99102
# func_exit_handler() is in hijack.sh
100-
trap 'func_exit_handler $?' EXIT
103+
trap 'func_exit_handler $?' EXIT SIGTERM
101104

102105
if test -z "$MAX_WAIT_FW_LOADING"; then
103106
local _pltf; _pltf=$("$SCRIPT_HOME/tools/sof-dump-status.py" -p)
@@ -157,7 +160,6 @@ start_test()
157160
local start_msg="$prefix: starting"
158161
dlogi "$start_msg"
159162
logger -p user.info "$start_msg"
160-
161163
}
162164

163165
# See high-level description in start_test header above
@@ -198,6 +200,23 @@ stop_test()
198200
}
199201

200202

203+
finish_kmsg_collection()
204+
{
205+
dlogi "Finishing dmesg collection"
206+
sudo pkill -9 journalctl
207+
208+
local journalctl_logs="$LOG_ROOT/dmesg.txt"
209+
if test -s "${journalctl_logs}"; then
210+
wcLog=$(wc -l "${journalctl_logs}")
211+
dlogi "nlines=$wcLog"
212+
else
213+
dlogw "Empty ${journalctl_logs}"
214+
fi
215+
# Make sure the logs are written on disk just in case of DUT power reset.
216+
sync
217+
}
218+
219+
201220
ktime()
202221
{
203222
# Keep it coarse because of various delays.
@@ -276,7 +295,9 @@ setup_kernel_check_point()
276295
# appear in the next one, see comments in config.sh. Add 3 extra
277296
# second to account for our own, sof-test delays after PASS/FAIL
278297
# decision: time spent collecting logs etc.
279-
if [ -z "$KERNEL_CHECKPOINT" ]; then
298+
if [[ "$KERNEL_CHECKPOINT" == "disabled" ]]; then
299+
dlogi "KERNEL_CHECKPOINT already set as DISABLED"
300+
elif [ -z "$KERNEL_CHECKPOINT" ]; then
280301
KERNEL_CHECKPOINT=$(($(date +%s) - SOF_TEST_INTERVAL - 3))
281302
else
282303
# Not the first time we are called so this is a test
@@ -408,6 +429,21 @@ func_mtrace_collect()
408429
sudo bash -c "${mtraceCmd[*]} &" >& "$clogfile"
409430
}
410431

432+
func_kmsg_collect() {
433+
local journalctl_logs="$LOG_ROOT/dmesg.txt"
434+
435+
if [[ "$KERNEL_CHECKPOINT" =~ ^[0-9]{10} ]]; then
436+
dlogi "Saving kernel messages since ${KERNEL_CHECKPOINT} to ${journalctl_logs}"
437+
journalctl_cmd --since=@"$KERNEL_CHECKPOINT" -f >> "${journalctl_logs}" &
438+
elif [[ "$KERNEL_CHECKPOINT" == "disabled" ]]; then
439+
dlogi "KERNEL_CHECKPOINT set as DISABLED, saving all kernel messages"
440+
journalctl_cmd -f >> "${journalctl_logs}" &
441+
else
442+
dlogi "KERNEL_CHECKPOINT is not properly set, saving all kernel messages"
443+
journalctl_cmd -f >> "${journalctl_logs}" &
444+
fi
445+
}
446+
411447
func_lib_log_post_process()
412448
{
413449
# SyS-T log output a Zephyr feature, no need postprocess

test-case/check-8bit-play-rec.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ main()
116116

117117
logger_disabled || func_lib_start_log_collect
118118

119-
setup_kernel_check_point
120119
func_lib_check_sudo
121120
func_pipeline_export "$tplg" "type:any"
122121

test-case/check-alsa-conformance.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,6 @@ main()
325325
{
326326
init_globals
327327

328-
setup_kernel_check_point
329-
330328
start_test
331329

332330
check_alsa_conformance_suite

test-case/check-alsabat.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ OPT_NAME['s']='sof-logger' OPT_DESC['s']="Open sof-logger trace the data wi
6161
OPT_HAS_ARG['s']=0 OPT_VAL['s']=1
6262

6363
func_opt_parse_option "$@"
64-
setup_kernel_check_point
6564

6665
pcm_p=${OPT_VAL['p']}
6766
pcm_c=${OPT_VAL['c']}

test-case/check-audio-equalizer.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ func_pipeline_export "$tplg" "eq:any"
4444
sofcard=${SOFCARD:-0}
4545

4646
start_test
47-
setup_kernel_check_point
4847

4948
# Test equalizer
5049
func_test_eq()

test-case/check-capture.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ if [[ -n "$new_tplg_filename" && "$TPLG" != *nocodec* ]]; then
7575
fi
7676
logger_disabled || func_lib_start_log_collect
7777

78-
setup_kernel_check_point
7978
func_lib_check_sudo
8079
func_pipeline_export "$tplg" "type:capture & ${OPT_VAL['S']}"
8180

test-case/check-float-play-rec.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ main()
9191

9292
logger_disabled || func_lib_start_log_collect
9393

94-
setup_kernel_check_point
9594
func_lib_check_sudo
9695
func_pipeline_export "$tplg" "type:any"
9796

test-case/check-fw-echo-reference.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ start_test
4444
logger_disabled || func_lib_start_log_collect
4545

4646
func_pipeline_export "$tplg" "echo:any"
47-
setup_kernel_check_point
4847

4948
if [ "$PIPELINE_COUNT" != "2" ]; then
5049
die "Only detect $PIPELINE_COUNT pipeline(s) from topology, but two are needed"
@@ -66,7 +65,7 @@ do
6665
fi
6766
done
6867

69-
for i in $(seq 1 $loop_cnt)
68+
for i in $(seq 1 "$loop_cnt")
7069
do
7170
for fmt in $fmts
7271
do

test-case/check-ipc-flood.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ OPT_NAME['l']='loop' OPT_DESC['l']='loop count'
2828
OPT_HAS_ARG['l']=1 OPT_VAL['l']=1
2929

3030
func_opt_parse_option "$@"
31-
setup_kernel_check_point
3231

3332
lpc_loop_cnt=${OPT_VAL['c']}
3433
ipc_flood_dfs=${OPT_VAL['f']}
@@ -47,12 +46,12 @@ sof-kernel-dump.sh | grep sof-audio | grep -q "Firmware debug" ||
4746
func_lib_check_sudo
4847

4948
dlogi "Check $ipc_flood_dfs"
50-
sudo test -e $ipc_flood_dfs ||
49+
sudo test -e "$ipc_flood_dfs" ||
5150
skip_test "${BASH_SOURCE[0]} need $ipc_flood_dfs to run the test case"
5251

5352
dlogi "Running ipc flood test!"
5453

55-
for i in $(seq 1 $loop_cnt)
54+
for i in $(seq 1 "$loop_cnt")
5655
do
5756
# TODO: use journalctl to replace dmesg
5857
# cleanup dmesg buffer for each iteration

0 commit comments

Comments
 (0)