From 8bd3bf1f014449483f45f035e486b8a4955838e0 Mon Sep 17 00:00:00 2001 From: Pengfei Xu Date: Wed, 17 Apr 2024 12:58:56 +0800 Subject: [PATCH 1/7] runtests: improve the runtests prints and add -d parm for dependence check Signed-off-by: Pengfei Xu --- runtests | 74 ++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 26 deletions(-) diff --git a/runtests b/runtests index 2f00dc0d..07b2eb47 100755 --- a/runtests +++ b/runtests @@ -4,6 +4,11 @@ source .env +readonly PASS_CODE=0 +readonly BLOCK_CODE=2 +readonly SKIP_CODE=4 +readonly NA_CODE=32 + START_TIME="" SUMMRY_LOG="" TESTS_CLIENT="tests-client" @@ -13,10 +18,17 @@ SUB_FOLDERS="" TEST_LIST_FILE="/tmp/tests" OLD_IFS="" +# For dependence check parameters, set skip for unknow staus as default +export HW_DEP="$SKIP_CODE" +export KERNEL_DEP="$SKIP_CODE" +export OTHER_DEP="$SKIP_CODE" +export OTHER_WARN="$SKIP_CODE" + usage() { cat << _EOF Usage: ${0##*/} [-f CMDFILES] [-c CMDLINE] [-o LOGFILE] -f CMDFILES execute user defined list of tests in files separated by ',' + -d DEPENDENCE_FILE check dependence for specified feature tests -c CMDLINE execute test case -o LOGFILE redirect output of tests to file @@ -26,9 +38,22 @@ Examples: ./runtests -f tests-client // exeucte tests-client/tests for all subfolders ./runtests -f tests-server // exeucte tests-server/tests for all subfolders ./runtests -c ./cet/quick_test -o cet_quick_test.log + ./runtests -d cet/tests // check cet dependence + ./runtests -d tests-server // check tests-server/tests for all subfolders dependence _EOF } +append_log() { + local info=$1 + local log_file=$2 + + if [[ -z "$log_file" ]]; then + echo -e "$info" + else + echo -e "$info" | tee -a "$log_file" + fi +} + err() { echo -e "\n$*" >&2 exit 1 @@ -45,11 +70,7 @@ runtest() { local result local case_result="" - if [[ -n "$logfile" ]]; then - echo "<<>" | tee -a "$logfile" - else - echo "<<>" - fi + append_log "<<>" "$logfile" if [[ -z "$subfolder" ]]; then echo "LKVS tests: $cmdline" >> /dev/kmsg @@ -74,13 +95,13 @@ runtest() { set +o pipefail case $code in - 0) + "$PASS_CODE") result="PASS" ;; - 2) + "$BLOCK_CODE") result="BLOCK" ;; - 32) + "$NA_CODE") result="NA" ;; *) @@ -88,11 +109,7 @@ runtest() { ;; esac - if [[ -n "$logfile" ]]; then - echo -e "<<>\n" | tee -a "$logfile" - else - echo -e "<<>\n" - fi + append_log "<<>\n" "$logfile" case_result=$(printf "[RESULT]%-68s%-11s%-12s%-8s" "[$cmdline]" " [$result]" "[$code]" "[${duration}s]") echo "$case_result" >> "$SUMMRY_LOG" } @@ -108,7 +125,7 @@ runcmdfile() { if [[ "$cmdfile" == *"/"* ]]; then subfolder=${cmdfile%/*} else - echo "cmdfile:$cmdfile(no '/') is not in a subfolder!" + append_log "cmdfile:$cmdfile(no '/') is not in a subfolder!" "$logfile" fi grep -v "^#.*" "$cmdfile" | grep -v "^$" > "$TEST_LIST_FILE" @@ -126,9 +143,9 @@ prepare_files_list() { local sub_folder="" for sub_folder in $SUB_FOLDERS; do - # Remov the / in the end + # Remove the / in the end sub_folder="${sub_folder%/}" - [[ "$sub_folder" == "common" ]] && continue + [[ "$sub_folder" == "common" || "$sub_folder" == "tools" ]] && continue if [[ -e "${sub_folder}/${test_file_type}" ]]; then if [[ -z "$TEST_FILES" ]]; then @@ -143,7 +160,7 @@ prepare_files_list() { TEST_FILES="${TEST_FILES},${sub_folder}/tests" fi else - echo "WARNING: No $test_file_type or tests file under $sub_folder folder." + append_log "WARNING: No $test_file_type or tests file under $sub_folder folder." "$LOGFILE" fi done } @@ -156,11 +173,7 @@ test_all() { prepare_files_list "$test_file_type" CMDFILES="$TEST_FILES" - if [[ -z "$LOGFILE" ]]; then - echo "Test files: $CMDFILES" - else - echo "Test files: $CMDFILES" | tee "$LOGFILE" - fi + append_log "Test files: $CMDFILES" "$LOGFILE" } # Default value @@ -168,11 +181,18 @@ test_all() { : CMDFILES="" : CMDLINE="" -while getopts ":o:f:c:h" opt; do +while getopts ":o:d:f:c:h" opt; do case "$opt" in o) LOGFILE=$OPTARG ;; + d) + CMDFILES=$OPTARG + [[ "$CMDFILES" == "$TESTS_CLIENT" ]] && test_all "$TESTS_CLIENT" + [[ "$CMDFILES" == "$TESTS_SERVER" ]] && test_all "$TESTS_SERVER" + #check_dep_for_tests "$TEST_FILES" + exit 0 + ;; f) CMDFILES=$OPTARG [[ "$CMDFILES" == "$TESTS_CLIENT" ]] && test_all "$TESTS_CLIENT" @@ -201,6 +221,8 @@ if [[ -z "$CMDFILES" ]] && [[ -z "$CMDLINE" ]]; then err "no test to run!" fi +cat /dev/null > "$LOGFILE" + START_TIME="$(date +%Y-%m-%d_%H-%M-%S)" SUMMRY_LOG="/tmp/lkvs_${START_TIME}_summary.log" echo "Test Start Time: $START_TIME" > "$SUMMRY_LOG" @@ -212,7 +234,7 @@ echo "Test Start Time: $START_TIME" > "$SUMMRY_LOG" for cmdfile in $(tr "," " " <<< "$CMDFILES"); do if [[ ! -f "$cmdfile" ]]; then - echo "WARNING: $cmdfile not found!" + append_log "WARNING: $cmdfile not found!" "$LOGFILE" continue fi @@ -220,8 +242,8 @@ for cmdfile in $(tr "," " " <<< "$CMDFILES"); do file_type="" file_type=$(file "$cmdfile") [[ "$file_type" == *"text"* ]] || { - echo "WARNING: -f $cmdfile is not a text type file, it's real type:|$file_type|" - echo "Please choose the correct tests file." + append_log "WARNING: -f $cmdfile is not a text type, it's real type:|$file_type|" "$LOGFILE" + append_log "Please choose the correct tests file." "$LOGFILE" usage continue } From 933aa1ead85f511d43ab3b2ba609e8bc1c2600ab Mon Sep 17 00:00:00 2001 From: Pengfei Xu Date: Wed, 17 Apr 2024 18:32:08 +0800 Subject: [PATCH 2/7] runtests: add the dependence check for hw and other reason Signed-off-by: Pengfei Xu --- runtests | 198 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 178 insertions(+), 20 deletions(-) diff --git a/runtests b/runtests index 07b2eb47..e544d136 100755 --- a/runtests +++ b/runtests @@ -2,12 +2,18 @@ # SPDX-License-Identifier: GPL-2.0-only # Copyright (c) 2022 Intel Corporation. +# shellcheck source=/dev/null source .env readonly PASS_CODE=0 readonly BLOCK_CODE=2 readonly SKIP_CODE=4 readonly NA_CODE=32 +PASS="PASS" +BLOCK="BLOCK" +SKIP="SKIP" +FAIL="FAIL" +NA="NA" START_TIME="" SUMMRY_LOG="" @@ -19,10 +25,14 @@ TEST_LIST_FILE="/tmp/tests" OLD_IFS="" # For dependence check parameters, set skip for unknow staus as default +readonly MARK_HW_DEP="@hw_dep" +readonly MARK_OTHER_DEP="@other_dep" +readonly MARK_WARN_DEP="@other_warn" export HW_DEP="$SKIP_CODE" -export KERNEL_DEP="$SKIP_CODE" export OTHER_DEP="$SKIP_CODE" export OTHER_WARN="$SKIP_CODE" +REASON="" +DEP_LOG="/tmp/lkvs_dependence.log" usage() { cat << _EOF @@ -59,6 +69,150 @@ err() { exit 1 } +check_test_file_legal() { + local cmdfile=$1 + + if [[ ! -f "$cmdfile" ]]; then + append_log "WARNING: $cmdfile not found!" "$LOGFILE" + return "$NA_CODE" + fi + + [[ $(which file) ]] && { + file_type="" + file_type=$(file "$cmdfile") + [[ "$file_type" == *"text"* ]] || { + append_log "WARNING: -f $cmdfile is not a text type, it's real type:|$file_type|" "$LOGFILE" + append_log "Please choose the correct tests file." "$LOGFILE" + return "$NA_CODE" + } + } + + return 0 +} + +init_dep_log() { + local dep_log=$1 + + cat /dev/null > "$dep_log" + { + echo "-----------------------------------------------------------------" + printf "%-16s%-13s%-16s%-13s%-20s\n" "Feature" "|HW_support" "|Other_support" \ + "|Other_WARN" "|Reason" + printf "%-16s%-13s%-16s%-13s%-20s\n" "-------" "-----------" "--------------" \ + "-----------" "-------" + } >> "$dep_log" +} + +check_dep_cmd() { + local dep_info=$1 + local dep=$2 + local dep_cmd dep_reason + + dep_cmd=$(echo "$dep_info" | awk -F "@" '{print $1}') + dep_reason=$(echo "$dep_info" | awk -F "@" '{print $2}') + + # Execute ret not zero, will return below error code as failed + eval "$dep_cmd" 1>/dev/null || { + if [[ -z "$dep_reason" ]]; then + REASON="$dep:$dep_cmd failed" + else + REASON="$dep:$dep_reason" + fi + return "$BLOCK_CODE" + } + + return 0 +} + +check_dep_info() { + local dep_infos=$1 + local subfolder=$2 + local dep=$3 + local ret="" + + if [[ -z "$dep_infos" ]]; then + REASON="No dependence check for $subfolder" + return "$SKIP_CODE" + fi + + IFS=$'\n' + for dep_info in $dep_infos; do + check_dep_cmd "$dep_info" "$dep" || { + ret=$? + IFS="$(printf ' \t\n')" + return "$ret" + } + done + IFS="$(printf ' \t\n')" +} + +# Don't input any other echo in it +get_ret_status() { + local ret=$1 + + case $ret in + "$PASS_CODE") #0 + echo "$PASS" + ;; + "$BLOCK_CODE") #2 + echo "$BLOCK" + ;; + "$SKIP_CODE") #4 + echo "$SKIP" + ;; + *) + echo "$NA" + ;; + esac +} + +check_dep_feature() { + local cmdfile=$1 + local subfolder="" + local hw_dep_info other_dep_info other_warn_info + local hw_sta other_sta warn_sta + + if [[ "$cmdfile" == *"/"* ]]; then + subfolder=${cmdfile%/*} + else + append_log "cmdfile:$cmdfile(no '/') is not in a subfolder, skip dependence check!" "$LOGFILE" + return "$SKIP_CODE" + fi + + hw_dep_info=$(grep "$MARK_HW_DEP" "$cmdfile" | awk -F: '{print $2}' | sed -e 's/^ *//g') + other_dep_info=$(grep "$MARK_OTHER_DEP" "$cmdfile" | awk -F: '{print $2}' | sed -e 's/^ *//g') + other_warn_info=$(grep "$MARK_WARN_DEP" "$cmdfile" | awk -F: '{print $2}' | sed -e 's/^ *//g') + + check_dep_info "$hw_dep_info" "$subfolder" "$MARK_HW_DEP" + ret=$? + hw_sta=$(get_ret_status "$ret") + [[ "$ret" == "$NA_CODE" || "$ret" == "$BLOCK_CODE" ]] && { + printf "%-16s%-13s%-16s%-13s%-20s\n" "$subfolder" "|$hw_sta" "|$SKIP" "|$SKIP" \ + "|$REASON" >> "$DEP_LOG" + return "$ret" + } + + check_dep_info "$other_dep_info" "$subfolder" "$MARK_OTHER_DEP" + ret=$? + other_sta=$(get_ret_status "$ret") + [[ "$ret" == "$NA_CODE" || "$ret" == "$BLOCK_CODE" ]] && { + printf "%-16s%-13s%-16s%-13s%-20s\n" "$subfolder" "|$hw_sta" "|$other_sta" "|$SKIP" \ + "|$REASON" >> "$DEP_LOG" + return "$ret" + } + + # It's a warning, will not block the subfolder test cases + check_dep_info "$other_warn_info" "$subfolder" "$MARK_WARN_DEP" + ret=$? + warn_sta=$(get_ret_status "$ret") + # warn_sta does not set the block, just NA to fail in some cases of this feature + [[ "$ret" == "$BLOCK_CODE" ]] && warn_sta="$NA" + + printf "%-16s%-13s%-16s%-13s%-20s\n" "$subfolder" "|$hw_sta" "|$other_sta" "|$warn_sta" \ + "|$REASON" >> "$DEP_LOG" + return 0 +} + runtest() { local cmdline=$1 local logfile=$2 @@ -96,21 +250,22 @@ runtest() { case $code in "$PASS_CODE") - result="PASS" + result="$PASS" ;; "$BLOCK_CODE") - result="BLOCK" + result="$BLOCK" ;; "$NA_CODE") - result="NA" + result="$NA" ;; *) - result="FAIL" + result="$FAIL" ;; esac append_log "<<>\n" "$logfile" - case_result=$(printf "[RESULT]%-68s%-11s%-12s%-8s" "[$cmdline]" " [$result]" "[$code]" "[${duration}s]") + case_result=$(printf "[RESULT]%-68s%-11s%-12s%-8s" "[$cmdline]" " [$result]" "[$code]" \ + "[${duration}s]") echo "$case_result" >> "$SUMMRY_LOG" } @@ -187,10 +342,19 @@ while getopts ":o:d:f:c:h" opt; do LOGFILE=$OPTARG ;; d) + init_dep_log "$DEP_LOG" CMDFILES=$OPTARG [[ "$CMDFILES" == "$TESTS_CLIENT" ]] && test_all "$TESTS_CLIENT" [[ "$CMDFILES" == "$TESTS_SERVER" ]] && test_all "$TESTS_SERVER" - #check_dep_for_tests "$TEST_FILES" + for cmdfile in $(tr "," " " <<< "$CMDFILES"); do + check_test_file_legal "$cmdfile" + + check_dep_feature "$cmdfile" || { + append_log "Skip $cmdfile due to dependece, please check $DEP_LOG" "$LOGFILE" + continue + } + done + cat "$DEP_LOG" exit 0 ;; f) @@ -232,21 +396,14 @@ echo "Test Start Time: $START_TIME" > "$SUMMRY_LOG" printf "%-76s%-11s%-12s%-8s\n" "--------" "------" "----------" "--------" } >> "$SUMMRY_LOG" +init_dep_log "$DEP_LOG" + for cmdfile in $(tr "," " " <<< "$CMDFILES"); do - if [[ ! -f "$cmdfile" ]]; then - append_log "WARNING: $cmdfile not found!" "$LOGFILE" - continue - fi + check_test_file_legal "$cmdfile" || continue - [[ $(which file) ]] && { - file_type="" - file_type=$(file "$cmdfile") - [[ "$file_type" == *"text"* ]] || { - append_log "WARNING: -f $cmdfile is not a text type, it's real type:|$file_type|" "$LOGFILE" - append_log "Please choose the correct tests file." "$LOGFILE" - usage - continue - } + check_dep_feature "$cmdfile" || { + append_log "Skip $cmdfile due to dependece, please check $DEP_LOG" "$LOGFILE" + continue } runcmdfile "$cmdfile" "$LOGFILE" @@ -261,3 +418,4 @@ echo "--------------------------------------------------------" >> "$SUMMRY_LOG" [[ -z "$LOGFILE" ]] || cat "$SUMMRY_LOG" >> "$LOGFILE" cat "$SUMMRY_LOG" +echo "Please check dependence info in $DEP_LOG" From 74ab1a037970b336fdcecb685ebc0f3e8b6402c8 Mon Sep 17 00:00:00 2001 From: Pengfei Xu Date: Tue, 23 Apr 2024 17:07:15 +0800 Subject: [PATCH 3/7] cet: add the tests dependence check Add the tests dependence check for cet: 1. hw_dep: could check if test platform CPU could support CET shstk 2. other_warn: could check if Glibc could support CET shstk, other_warn will fail partial cet cases, and will not block all CET cases. Signed-off-by: Pengfei Xu --- cet/tests | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cet/tests b/cet/tests index caa44b44..3d2752fe 100755 --- a/cet/tests +++ b/cet/tests @@ -1,5 +1,8 @@ # This file collects the CET(Control-flow Enforcement Technology) tests on # Intel® Architecture-based platforms. +# @hw_dep: cpuid_check 7 0 0 0 c 7 @ HW cpuid could not support CET SHSTK +# @other_dep: +# @other_warn: quick_test @ Glibc could not support CET # User space SHSTK tests without SHSTK Glibc supported cet_tests.sh -t cp_test -n shstk_cp -k "control protection" From 637cfc1f7815336a35dc886698bebfccccd5f036 Mon Sep 17 00:00:00 2001 From: Pengfei Xu Date: Tue, 23 Apr 2024 17:15:40 +0800 Subject: [PATCH 4/7] cet: add the kconfig check for kernel dependence check Signed-off-by: Pengfei Xu --- cet/tests | 2 +- common/common.sh | 2 +- common/general_test.sh | 61 ++++++++++++++++++++++++++++++++++++++++++ runtests | 3 ++- 4 files changed, 65 insertions(+), 3 deletions(-) create mode 100755 common/general_test.sh diff --git a/cet/tests b/cet/tests index 3d2752fe..658826a0 100755 --- a/cet/tests +++ b/cet/tests @@ -1,7 +1,7 @@ # This file collects the CET(Control-flow Enforcement Technology) tests on # Intel® Architecture-based platforms. # @hw_dep: cpuid_check 7 0 0 0 c 7 @ HW cpuid could not support CET SHSTK -# @other_dep: +# @other_dep: general_test.sh -t kconfig -k "CONFIG_X86_USER_SHADOW_STACK=y" # @other_warn: quick_test @ Glibc could not support CET # User space SHSTK tests without SHSTK Glibc supported diff --git a/common/common.sh b/common/common.sh index b66b1db7..80b9d587 100755 --- a/common/common.sh +++ b/common/common.sh @@ -236,7 +236,7 @@ test_kconfig() { local name="$2" if [[ ! "$value" =~ [ymn] ]]; then - test_print_err "Invalid koption value!" + test_print_err "Invalid koption value:$value" return 1 fi diff --git a/common/general_test.sh b/common/general_test.sh new file mode 100755 index 00000000..422f0a31 --- /dev/null +++ b/common/general_test.sh @@ -0,0 +1,61 @@ +#!/bin/bash +############################################################################### +# SPDX-License-Identifier: GPL-2.0-only # +# Copyright (c) 2024 Intel Corporation. # +# For general check like KCONFIG, CPU family model stepping # +############################################################################### + +# shellcheck source=/dev/null +cd "$(dirname "$0")" 2>/dev/null && source ../.env + +usage() { + cat <<__EOF + usage: ./${0##*/} [-t TEST_TYPE][-k KCONFIG or keywrod][-p parm][-h] + -t Test type like KCONFIG, FMS + -k KCONFIG name like CONFIG_XXX or keyword + -p PARM like y, null + -h show This +__EOF +} + +general_test() { + case $TYPE in + kconfig) + config_name=$(echo "$KEYWORD" | cut -d '=' -f1) + config_val=$(echo "$KEYWORD" | cut -d '=' -f2) + test_any_kconfig_match "$config_name" "$config_val" + ;; + # family model stepping check + fms) + #TODO, will add the fms check function + ;; + *) + die "Invalid TYPE:$TYPE" + ;; + esac +} + +while getopts :t:p:k:h arg; do + case $arg in + t) + TYPE=$OPTARG + ;; + p) + # TODO, will add more function to use PARM + # PARM=$OPTARG + ;; + k) + KEYWORD=$OPTARG + ;; + h) + usage + exit 0 + ;; + *) + usage + die "Option -$OPTARG requires an argument." + ;; + esac +done + +general_test diff --git a/runtests b/runtests index e544d136..5917d9e7 100755 --- a/runtests +++ b/runtests @@ -131,7 +131,7 @@ check_dep_info() { local ret="" if [[ -z "$dep_infos" ]]; then - REASON="No dependence check for $subfolder" + REASON="No dependence for $subfolder" return "$SKIP_CODE" fi @@ -208,6 +208,7 @@ check_dep_feature() { # warn_sta does not set the block, just NA to fail in some cases of this feature [[ "$ret" == "$BLOCK_CODE" ]] && warn_sta="$NA" + [[ -z "$REASON" ]] && REASON="No dependence for $subfolder" printf "%-16s%-13s%-16s%-13s%-20s\n" "$subfolder" "|$hw_sta" "|$other_sta" "|$warn_sta" \ "|$REASON" >> "$DEP_LOG" return 0 From 2d9939177245be791ef3983ce1e2b50f70be7629 Mon Sep 17 00:00:00 2001 From: Pengfei Xu Date: Wed, 24 Apr 2024 13:38:39 +0800 Subject: [PATCH 5/7] ifs: add the dmesg check function for ifs dependence check Signed-off-by: Pengfei Xu --- common/common.sh | 48 +++++++++++++++++++++++++++++++++++++++++- common/general_test.sh | 9 ++++++-- ifs/tests | 4 +++- runtests | 16 +++++++------- 4 files changed, 65 insertions(+), 12 deletions(-) diff --git a/common/common.sh b/common/common.sh index 80b9d587..dd4af6c5 100755 --- a/common/common.sh +++ b/common/common.sh @@ -242,7 +242,7 @@ test_kconfig() { # For each expression between '|' separators if [[ $(get_kconfig "$name") != "$value" ]]; then - test_print_err "$name does not match $value!" + test_print_trc "$name does not match $value!" return 1 else test_print_trc "$name matches with expect $value" @@ -359,6 +359,52 @@ dmesg_pattern_check() { return 1 } +# Check whole dmesg, which should contain key words +# Input $1: key word +# Output: 0 for true, otherwise false or die +full_dmesg_check() { + local type=$1 + local keyword1=$2 + local keyword2=$3 + local keyword3=$4 + local null="null" + local contain="contain" + local dmesg_head="" + local check_log="" + + dmesg_head=$(dmesg | grep "\[ 0.000000\]" | head -n 1) + [[ -n $dmesg_head ]] \ + || test_print_wrg "Dmesg is not started from 0.000000!" + check_log=$(dmesg | grep -v "dmesg" | grep -i "$keyword1" \ + | grep -i "$keyword2" \ + | grep -i "$keyword3") + + case $type in + "$contain") + if [[ -n "$check_log" ]]; then + test_print_trc "Dmesg contains $keyword1 $keyword2:$check_log, pass" + else + test_print_wrg "Dmesg doesn't contain $keyword1 $keyword2:$check_log, fail" + return 1 + fi + ;; + "$null") + if [[ -z "$check_log" ]]; then + test_print_trc "Dmesg doesn't contain $keyword1 $keyword2:$check_log, pass" + else + test_print_wrg "Dmesg contains $keyword1 $keyword2:$check_log, fail" + return 1 + fi + ;; + *) + test_print_wrg "Invalid type:$type" + return 2 + ;; + esac + + return 0 +} + # Record last timestamp in dmesg and store the value in variable # LAST_DMESG_TIMESTAMP. The value is refered in function extract_case_dmesg. last_dmesg_timestamp() { diff --git a/common/general_test.sh b/common/general_test.sh index 422f0a31..37e2db9e 100755 --- a/common/general_test.sh +++ b/common/general_test.sh @@ -29,6 +29,12 @@ general_test() { fms) #TODO, will add the fms check function ;; + dmesg) + key1=$(echo "$KEYWORD" | awk -F '&' '{print $1}') + key2=$(echo "$KEYWORD" | awk -F '&' '{print $2}')\ + key3=$(echo "$KEYWORD" | awk -F '&' '{print $3}') + full_dmesg_check "$PARM" "$key1" "$key2" "$key3" || return $? + ;; *) die "Invalid TYPE:$TYPE" ;; @@ -41,8 +47,7 @@ while getopts :t:p:k:h arg; do TYPE=$OPTARG ;; p) - # TODO, will add more function to use PARM - # PARM=$OPTARG + PARM=$OPTARG ;; k) KEYWORD=$OPTARG diff --git a/ifs/tests b/ifs/tests index c86db81e..263abf80 100755 --- a/ifs/tests +++ b/ifs/tests @@ -1,6 +1,8 @@ # This file collects Intel IFS(In Field SCAN) tests on # Intel® Architecture-based platforms. - +# @hw_dep: +# @other_dep: general_test.sh -t kconfig -k "CONFIG_INTEL_IFS=m" +# @other_warn: general_test.sh -t dmesg -p "contain" -k "sgx_init&returned 0" @ check if SGX is enabled in BIOS as IFS relies on enabled SGX # ifs_0 scan test cases, it works on SPR(Sapphire Rapids) platform and future server ifs_tests.sh -m 0 -p all -n load_ifs ifs_tests.sh -m 0 -p all -b 1 -n ifs_batch diff --git a/runtests b/runtests index 5917d9e7..74a6b2ce 100755 --- a/runtests +++ b/runtests @@ -25,9 +25,9 @@ TEST_LIST_FILE="/tmp/tests" OLD_IFS="" # For dependence check parameters, set skip for unknow staus as default -readonly MARK_HW_DEP="@hw_dep" -readonly MARK_OTHER_DEP="@other_dep" -readonly MARK_WARN_DEP="@other_warn" +readonly MARK_HW_DEP="@hw_dep:" +readonly MARK_OTHER_DEP="@other_dep:" +readonly MARK_WARN_DEP="@other_warn:" export HW_DEP="$SKIP_CODE" export OTHER_DEP="$SKIP_CODE" export OTHER_WARN="$SKIP_CODE" @@ -114,9 +114,9 @@ check_dep_cmd() { # Execute ret not zero, will return below error code as failed eval "$dep_cmd" 1>/dev/null || { if [[ -z "$dep_reason" ]]; then - REASON="$dep:$dep_cmd failed" + REASON="${dep} ${dep_cmd} failed" else - REASON="$dep:$dep_reason" + REASON="${dep}${dep_reason}" fi return "$BLOCK_CODE" } @@ -179,9 +179,9 @@ check_dep_feature() { return "$SKIP_CODE" fi - hw_dep_info=$(grep "$MARK_HW_DEP" "$cmdfile" | awk -F: '{print $2}' | sed -e 's/^ *//g') - other_dep_info=$(grep "$MARK_OTHER_DEP" "$cmdfile" | awk -F: '{print $2}' | sed -e 's/^ *//g') - other_warn_info=$(grep "$MARK_WARN_DEP" "$cmdfile" | awk -F: '{print $2}' | sed -e 's/^ *//g') + hw_dep_info=$(grep "$MARK_HW_DEP" "$cmdfile" | awk -F "$MARK_HW_DEP" '{print $2}' | sed -e 's/^ *//g') + other_dep_info=$(grep "$MARK_OTHER_DEP" "$cmdfile" | awk -F "$MARK_OTHER_DEP" '{print $2}' | sed -e 's/^ *//g') + other_warn_info=$(grep "$MARK_WARN_DEP" "$cmdfile" | awk -F "$MARK_WARN_DEP" '{print $2}' | sed -e 's/^ *//g') check_dep_info "$hw_dep_info" "$subfolder" "$MARK_HW_DEP" ret=$? From 3ac37655bde7b752dd15edf5528d291d40beeb61 Mon Sep 17 00:00:00 2001 From: Pengfei Xu Date: Wed, 24 Apr 2024 15:15:55 +0800 Subject: [PATCH 6/7] runtests: show the results of executed cases if runtests was stopped by accident As before runtests stopped by accident like ctrl+c, it will not show the results of the execution that has already done. Now add the cleanup function to show results of executed cases. Signed-off-by: Pengfei Xu --- runtests | 92 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 53 insertions(+), 39 deletions(-) diff --git a/runtests b/runtests index 74a6b2ce..a528babf 100755 --- a/runtests +++ b/runtests @@ -332,6 +332,56 @@ test_all() { append_log "Test files: $CMDFILES" "$LOGFILE" } +show_result() { + # Add the following print for the end of the case summary. + echo "--------------------------------------------------------" >> "$SUMMRY_LOG" + + [[ -z "$LOGFILE" ]] || cat "$SUMMRY_LOG" >> "$LOGFILE" + cat "$SUMMRY_LOG" + echo "Dependence info in $DEP_LOG and runtests log in $LOGFILE" +} + +# runtests_cleanup to show test result. TODO: restore the env if needed +runtests_cleanup() { + show_result + exit 0 +} + +run_tests() { + if [[ -z "$CMDFILES" ]] && [[ -z "$CMDLINE" ]]; then + usage + err "no test to run!" + fi + + cat /dev/null > "$LOGFILE" + + START_TIME="$(date +%Y-%m-%d_%H-%M-%S)" + SUMMRY_LOG="/tmp/lkvs_${START_TIME}_summary.log" + echo "Test Start Time: $START_TIME" > "$SUMMRY_LOG" + { + echo "--------------------------------------------------------" + printf "%-76s%-11s%-12s%-8s\n" "Testcase" "Result" "Exit Value" "Duration" + printf "%-76s%-11s%-12s%-8s\n" "--------" "------" "----------" "--------" + } >> "$SUMMRY_LOG" + + init_dep_log "$DEP_LOG" + + for cmdfile in $(tr "," " " <<< "$CMDFILES"); do + check_test_file_legal "$cmdfile" || continue + + check_dep_feature "$cmdfile" || { + append_log "Skip $cmdfile due to dependece, please check $DEP_LOG" "$LOGFILE" + continue + } + + runcmdfile "$cmdfile" "$LOGFILE" + done + + if [[ -n "$CMDLINE" ]]; then + runtest "$CMDLINE" "$LOGFILE" + fi +} + # Default value : "${LOGFILE:="./lkvs.log"}" : CMDFILES="" @@ -381,42 +431,6 @@ while getopts ":o:d:f:c:h" opt; do esac done -if [[ -z "$CMDFILES" ]] && [[ -z "$CMDLINE" ]]; then - usage - err "no test to run!" -fi - -cat /dev/null > "$LOGFILE" - -START_TIME="$(date +%Y-%m-%d_%H-%M-%S)" -SUMMRY_LOG="/tmp/lkvs_${START_TIME}_summary.log" -echo "Test Start Time: $START_TIME" > "$SUMMRY_LOG" -{ - echo "--------------------------------------------------------" - printf "%-76s%-11s%-12s%-8s\n" "Testcase" "Result" "Exit Value" "Duration" - printf "%-76s%-11s%-12s%-8s\n" "--------" "------" "----------" "--------" -} >> "$SUMMRY_LOG" - -init_dep_log "$DEP_LOG" - -for cmdfile in $(tr "," " " <<< "$CMDFILES"); do - check_test_file_legal "$cmdfile" || continue - - check_dep_feature "$cmdfile" || { - append_log "Skip $cmdfile due to dependece, please check $DEP_LOG" "$LOGFILE" - continue - } - - runcmdfile "$cmdfile" "$LOGFILE" -done - -if [[ -n "$CMDLINE" ]]; then - runtest "$CMDLINE" "$LOGFILE" -fi - -# Add the following print for the end of the case summary. -echo "--------------------------------------------------------" >> "$SUMMRY_LOG" - -[[ -z "$LOGFILE" ]] || cat "$SUMMRY_LOG" >> "$LOGFILE" -cat "$SUMMRY_LOG" -echo "Please check dependence info in $DEP_LOG" +trap runtests_cleanup SIGTERM SIGINT +run_tests +runtests_cleanup From ef81c03e9ed0cae562ab6684b1f4326877bdca15 Mon Sep 17 00:00:00 2001 From: Pengfei Xu Date: Wed, 24 Apr 2024 17:02:59 +0800 Subject: [PATCH 7/7] ifs: improve the other dependence check point and reason description Improve the other dependence check point and reason description, and no need dump csv file for ifs bach loading test case. Signed-off-by: Pengfei Xu --- ifs/ifs_tests.sh | 6 +++--- ifs/tests | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ifs/ifs_tests.sh b/ifs/ifs_tests.sh index 49a039f8..0e65bd5d 100755 --- a/ifs/ifs_tests.sh +++ b/ifs/ifs_tests.sh @@ -5,8 +5,9 @@ # Description: Test script to verify Intel IFS(In Field SCAN) functionality cd "$(dirname "$0")" 2>/dev/null || exit 1 +# shellcheck source=/dev/null source ../.env - +# shellcheck source=/dev/null source "ifs_common.sh" basic_usage() { @@ -56,7 +57,6 @@ run_ifs_tests() { check_file_content "${IFS_PATH}/${BATCH}" "none" "$CONTAIN" check_file_content "${IFS_PATH}/${VERSION}" "none" "$CONTAIN" init_log "$NAME" - dump_ifs_test "$NAME" ;; ifs_batch) modprobe -r "$IFS_NAME" @@ -70,9 +70,9 @@ run_ifs_tests() { check_file_content "${IFS_PATH}/${VERSION}" "none" "$NE" else test_print_wrg "No ${IFS_PATH}/${BATCH} file, is it 5.15 or old ifs kernel?" + return 2 fi init_log "$NAME" - dump_ifs_test "$NAME" ;; "$IMG_VERSION") modprobe -r "$IFS_NAME" diff --git a/ifs/tests b/ifs/tests index 263abf80..0298bf40 100755 --- a/ifs/tests +++ b/ifs/tests @@ -2,7 +2,7 @@ # Intel® Architecture-based platforms. # @hw_dep: # @other_dep: general_test.sh -t kconfig -k "CONFIG_INTEL_IFS=m" -# @other_warn: general_test.sh -t dmesg -p "contain" -k "sgx_init&returned 0" @ check if SGX is enabled in BIOS as IFS relies on enabled SGX +# @other_warn: ifs_tests.sh -m 0 -p all -b 1 -n ifs_batch @ check if SGX init ok and DIMM proper set as IFS relies on enabled SGX # ifs_0 scan test cases, it works on SPR(Sapphire Rapids) platform and future server ifs_tests.sh -m 0 -p all -n load_ifs ifs_tests.sh -m 0 -p all -b 1 -n ifs_batch