From cf8a6793da3173b271018f6f70a872188ebf12f6 Mon Sep 17 00:00:00 2001 From: "Wu, BinX" Date: Wed, 6 May 2020 22:51:50 +0800 Subject: [PATCH] lib: hijack: use journalctl command to dump kernel information use journalctl instead of catch information from /var/log/kern.log file 1. DMESG_LOG_START_LINE => CASE_KERNEL_START_TIME 2. with this change, sof-get-kernel-line is not useful, remove it Signed-off-by: Wu, BinX --- README.md | 4 ---- case-lib/hijack.sh | 11 +++-------- case-lib/lib.sh | 9 ++++----- test-case/check-reboot.sh | 4 ++-- test-case/check-sof-logger.sh | 4 ++-- test-case/verify-kernel-module-load-probe.sh | 4 ++-- test-case/verify-pcm-list.sh | 4 ++-- test-case/verify-sof-firmware-load.sh | 4 ++-- tools/sof-get-kernel-line.sh | 12 ------------ 9 files changed, 17 insertions(+), 39 deletions(-) delete mode 100755 tools/sof-get-kernel-line.sh diff --git a/README.md b/README.md index 4ed73f39..67ae854a 100644 --- a/README.md +++ b/README.md @@ -108,10 +108,6 @@ apl * sof-get-default-tplg.sh
Load the tplg file name from system log which is recorded from system bootup -* sof-get-kernel-line.sh -
Print all kernel versions and their line numbers from /var/log/kern.log, - with the most recent - * sof-kernel-dump.sh
Catch all kernel information after system boot up from /var/log/kern.log file diff --git a/case-lib/hijack.sh b/case-lib/hijack.sh index eea7d82f..43035b0b 100644 --- a/case-lib/hijack.sh +++ b/case-lib/hijack.sh @@ -20,15 +20,10 @@ function func_exit_handler() sleep 1s fi # when case ends, store kernel log - # /var/log/kern.log format: - # f1 f2 f3 f4 f5 f6 f7 f8... - # Mouth day Time MachineName kernel: [ time] content - # May 15 21:28:38 MachineName kernel: [ 6.469255] sof-audio-pci 0000:00:0e.0: ipc rx: 0x90020000: GLB_TRACE_MSG - # May 15 21:28:38 MachineName kernel: [ 6.469268] sof-audio-pci 0000:00:0e.0: ipc rx done: 0x90020000: GLB_TRACE_MSG - if [[ -n "$DMESG_LOG_START_LINE" && "$DMESG_LOG_START_LINE" -ne 0 ]]; then - tail -n +"$DMESG_LOG_START_LINE" /var/log/kern.log |cut -f5- -d ' ' > "$LOG_ROOT/dmesg.txt" + if [[ -n "$CASE_KERNEL_START_TIME" ]]; then + journalctl --dmesg --no-pager --no-hostname -o short-precise --since="$CASE_KERNEL_START_TIME" > "$LOG_ROOT/dmesg.txt" else - cut -f5- -d ' ' /var/log/kern.log > "$LOG_ROOT/dmesg.txt" + journalctl --dmesg --no-pager --no-hostname -o short-precise > "$LOG_ROOT/dmesg.txt" fi # get ps command result as list diff --git a/case-lib/lib.sh b/case-lib/lib.sh index 9803544b..106a9b72 100644 --- a/case-lib/lib.sh +++ b/case-lib/lib.sh @@ -191,9 +191,8 @@ func_lib_get_tplg_path() return 0 } -# force ask buffer data write into file system -sudo sync -f -# catch kern.log last line as current case start line -if [ ! "$DMESG_LOG_START_LINE" ]; then - DMESG_LOG_START_LINE=$(wc -l /var/log/kern.log|awk '{print $1;}') +if [ ! "$CASE_KERNEL_START_TIME" ]; then + # format time stamp output for journalctl command + func_lib_setup_kernel_last_time + CASE_KERNEL_START_TIME="$KERNEL_LAST_TIME" fi diff --git a/test-case/check-reboot.sh b/test-case/check-reboot.sh index 02ef5166..0dbec78e 100755 --- a/test-case/check-reboot.sh +++ b/test-case/check-reboot.sh @@ -144,14 +144,14 @@ sudo chown $UID $boot_file old_content="$(cat $boot_file|grep -v '^exit')" # write the information to /etc/rc.local # LOG_ROOT to make sure all tests, including sub-cases, write log to the same target folder -# DMESG_LOG_START_LINE to just keep last kernel bootup log +# CASE_KERNEL_START_TIME to just keep last kernel bootup log boot_once_flag=$(realpath $(which sof-boot-once.sh)) cat << END > $boot_file $old_content $boot_once_flag export LOG_ROOT='$(realpath $LOG_ROOT)' -export DMESG_LOG_START_LINE=$(wc -l /var/log/kern.log|awk '{print $1;}') +export CASE_KERNEL_START_TIME='$(journalctl --dmesg --no-pager -n 1 |head -n 1|awk '{print $(NF-3)" "$(NF-2);}')' bash -c '$full_cmd' exit 0 diff --git a/test-case/check-sof-logger.sh b/test-case/check-sof-logger.sh index e8fdc9b9..d5312ad5 100755 --- a/test-case/check-sof-logger.sh +++ b/test-case/check-sof-logger.sh @@ -21,8 +21,8 @@ func_opt_parse_option "$@" #TODO: need to add arguments for user to give location for logger and ldc file -# hijack DMESG_LOG_START_LINE which refer dump kernel log in exit function -DMESG_LOG_START_LINE=$(sof-get-kernel-line.sh|tail -n 1 |awk '{print $1;}') +# hijack CASE_KERNEL_START_TIME which refer dump kernel log in exit function +unset CASE_KERNEL_START_TIME # check sof-logger location if [ -z $(which sof-logger) ]; then diff --git a/test-case/verify-kernel-module-load-probe.sh b/test-case/verify-kernel-module-load-probe.sh index 9bec1143..722bc652 100755 --- a/test-case/verify-kernel-module-load-probe.sh +++ b/test-case/verify-kernel-module-load-probe.sh @@ -15,8 +15,8 @@ source $(dirname ${BASH_SOURCE[0]})/../case-lib/lib.sh func_opt_parse_option "$@" -# hijack DMESG_LOG_START_LINE which refer dump kernel log in exit function -DMESG_LOG_START_LINE=$(sof-get-kernel-line.sh|tail -n 1 |awk '{print $1;}') +# hijack CASE_KERNEL_START_TIME which refer dump kernel log in exit function +unset CASE_KERNEL_START_TIME dlogi "Checking if sof relative modules loaded" dlogc "lsmod | grep \"sof\"" diff --git a/test-case/verify-pcm-list.sh b/test-case/verify-pcm-list.sh index 356c9ce1..34456d00 100755 --- a/test-case/verify-pcm-list.sh +++ b/test-case/verify-pcm-list.sh @@ -26,8 +26,8 @@ tplg=${OPT_VALUE_lst['t']} tplg_path=`func_lib_get_tplg_path "$tplg"` [[ "$?" != "0" ]] && dloge "No available topology for this test case" && exit 1 -# hijack DMESG_LOG_START_LINE which refer dump kernel log in exit function -DMESG_LOG_START_LINE=$(sof-get-kernel-line.sh|tail -n 1 |awk '{print $1;}') +# hijack CASE_KERNEL_START_TIME which refer dump kernel log in exit function +unset CASE_KERNEL_START_TIME tplg_str="$(sof-tplgreader.py $tplg_path -d id pcm type -o)" pcm_str="$(sof-dump-status.py -i ${SOFCARD:-0})" diff --git a/test-case/verify-sof-firmware-load.sh b/test-case/verify-sof-firmware-load.sh index 8d6763b2..79e43a85 100755 --- a/test-case/verify-sof-firmware-load.sh +++ b/test-case/verify-sof-firmware-load.sh @@ -18,8 +18,8 @@ source $(dirname ${BASH_SOURCE[0]})/../case-lib/lib.sh func_opt_parse_option "$@" if [ ! "$(alias |grep 'Sub-Test')" ];then - # hijack DMESG_LOG_START_LINE which refer dump kernel log in exit function - DMESG_LOG_START_LINE=$(sof-get-kernel-line.sh|tail -n 1 |awk '{print $1;}') + # hijack CASE_KERNEL_START_TIME which refer dump kernel log in exit function + unset CASE_KERNEL_START_TIME cmd="sof-kernel-dump.sh" else cmd="dmesg" diff --git a/tools/sof-get-kernel-line.sh b/tools/sof-get-kernel-line.sh deleted file mode 100755 index ad4d599d..00000000 --- a/tools/sof-get-kernel-line.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -# dump line number + kernel version -# for example: -# 22 4.15.0-74-generic -# 1092 4.15.0-74-generic -# 2156 4.15.0-74-generic -# 3246 4.15.0-74-generic -log_file=${1:-"/var/log/kern.log"} -[[ ! -f "$log_file" ]] && builtin exit 1 -bootup_keyword='\[ 0.000000\] Linux version ' -grep -na "$bootup_keyword" "$log_file"|sed 's/\x0//g'|awk -F ':' '{print $1 $(NF-2);}'|sed "s/$bootup_keyword//g"|awk '{print $1, $2;}'