From c16aaf7541d1fdc82856710dec9503e1ba821d69 Mon Sep 17 00:00:00 2001 From: Marc Herbert Date: Wed, 28 Jun 2023 17:22:04 -0700 Subject: [PATCH 1/3] lib.sh: rename check_error_in_file() to check_error_in_fw_logfile() Preempts any confusion with kernel or other logs files. Signed-off-by: Marc Herbert --- case-lib/lib.sh | 2 +- test-case/check-sof-logger.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/case-lib/lib.sh b/case-lib/lib.sh index f07107a2..3cd95017 100644 --- a/case-lib/lib.sh +++ b/case-lib/lib.sh @@ -416,7 +416,7 @@ func_lib_start_log_collect() } -check_error_in_file() +check_error_in_fw_logfile() { local platf; platf=$(sof-dump-status.py -p) diff --git a/test-case/check-sof-logger.sh b/test-case/check-sof-logger.sh index d341c849..aacad43d 100755 --- a/test-case/check-sof-logger.sh +++ b/test-case/check-sof-logger.sh @@ -328,7 +328,7 @@ main() for f in "${stdout_files[@]}"; do local tracef="$LOG_ROOT/logger.$f.txt" - check_error_in_file "$tracef" || { + check_error_in_fw_logfile "$tracef" || { OK=false; printf '\n' } done From ea8f7e8dcc2f75afaf52fc3f685979a64cd6041d Mon Sep 17 00:00:00 2001 From: Marc Herbert Date: Thu, 29 Jun 2023 19:23:04 -0700 Subject: [PATCH 2/3] lib.sh: func_mtrace_collect(): don't hardcode logfile=mtrace.txt Add a new clogfile=$1 parameter to func_mtrace_collect() to make it consistent with the older func_sof_logger_collect() and define all logfile names in the same place. Also log the logfile name and stop abusing bash leniency that has let us treat and expand $mtraceCmd like an array even if it's not. Fixes initial commit c0729e8a5db0 ("Enable mtrace") which merely copied the logging code from the other func_sof_logger_collect() function which does use an array. Signed-off-by: Marc Herbert --- case-lib/lib.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/case-lib/lib.sh b/case-lib/lib.sh index 3cd95017..23314248 100644 --- a/case-lib/lib.sh +++ b/case-lib/lib.sh @@ -321,7 +321,7 @@ find_ldc_file() func_mtrace_collect() { - local clogfile=$LOG_ROOT/mtrace.txt + local clogfile="$1" if [ -z "$MTRACE" ]; then MTRACE=$(command -v mtrace-reader.py) || { @@ -330,8 +330,8 @@ func_mtrace_collect() } fi - local mtraceCmd="$MTRACE" - dlogi "Starting ${mtraceCmd[*]}" + local mtraceCmd=("$MTRACE") + dlogi "Starting ${mtraceCmd[*]} >& $clogfile &" # Cleaned up by func_exit_handler() in hijack.sh # shellcheck disable=SC2024 sudo "${mtraceCmd[@]}" >& "$clogfile" & @@ -358,7 +358,7 @@ func_sof_logger_collect() # The logger does not like empty '' arguments and $logopt can be # shellcheck disable=SC2206 local loggerCmd=("$SOFLOGGER" $logopt -l "$ldcFile") - dlogi "Starting ${loggerCmd[*]}" + dlogi "Starting ${loggerCmd[*]} > $logfile &" # Cleaned up by func_exit_handler() in hijack.sh # shellcheck disable=SC2024 sudo "${loggerCmd[@]}" > "$logfile" & @@ -398,7 +398,8 @@ func_lib_start_log_collect() if [ "X$is_etrace" == "X0" ]; then if is_ipc4 && is_firmware_file_zephyr; then - func_mtrace_collect + logfile="$LOG_ROOT"/mtrace.txt + func_mtrace_collect "$logfile" else log_file=$LOG_ROOT/slogger.txt log_opt="-t" From fb95d51e46f958ea5c2da4d019040bb9a467a22f Mon Sep 17 00:00:00 2001 From: Marc Herbert Date: Thu, 29 Jun 2023 19:32:57 -0700 Subject: [PATCH 3/3] hijack.sh: check for a non-empty mtrace.txt $logfile too Now that $logfile is defined for mtrace too, run the same check on it. Signed-off-by: Marc Herbert --- case-lib/hijack.sh | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/case-lib/hijack.sh b/case-lib/hijack.sh index 02f7e016..22c19e99 100644 --- a/case-lib/hijack.sh +++ b/case-lib/hijack.sh @@ -8,6 +8,8 @@ function func_exit_handler() { local exit_status=${1:-0} + dlogi "Starting func_exit_handler($exit_status)" + # call trace if [ "$exit_status" -ne 0 ] ; then dloge "Starting ${FUNCNAME[0]}(), exit status=$exit_status, FUNCNAME stack:" @@ -86,22 +88,6 @@ function func_exit_handler() exit_status=1 fi - if test -e "$logfile"; then - - wcLog=$(wc -l "$logfile") # show both line count and filename - dlogi "nlines=$wcLog" - - local nlines; nlines=$(wc -l < "$logfile") # line count only - # The first line is the sof-logger header - if [ "$nlines" -le 1 ]; then - dloge "Empty logger trace" - exit_status=1 - fi - else - dloge "Log file not found: $logfile" - exit_status=1 - fi - fi if [ "$SOF_LOGGING" != 'none' ] && is_ipc4 && is_firmware_file_zephyr; then @@ -113,6 +99,24 @@ function func_exit_handler() } fi + # Check $logfile when there is one + if [ -n "$logfile" ]; then + if test -e "$logfile"; then + wcLog=$(wc -l "$logfile") # show both line count and filename + dlogi "nlines=$wcLog" + + local nlines; nlines=$(wc -l < "$logfile") # line count only + # The first line is the sof-logger banner + if [ "$nlines" -le 1 ]; then + dloge "Empty logfile" + exit_status=1 + fi + else + dloge "Log file not found: $logfile" + exit_status=1 + fi + fi + stop_test || exit_status=1 if [ "$ENABLE_STORAGE_CHECKS" = '1' ]; then