diff --git a/lib/ts_common.sh b/lib/ts_common.sh index b318f7384c0428bc79c791cdffa3f3f8da5937b0..61ecbb2d82d673d5ff60e9ae975d7e710a19bdcf 100644 --- a/lib/ts_common.sh +++ b/lib/ts_common.sh @@ -14,6 +14,32 @@ tc_teardown_common() { return 0 } + +# 检查内核是否打开制定config +# Args: +# $1 -- config +# 返回值 +# 0 -- 匹配到config +# 1 -- 没有匹配 +check_config(){ + if [ -f /proc/config.gz ]; then + if zcat /proc/config.gz | grep "$1"; then + return 0 + else + return 1 + fi + fi + config_file="/lib/modules/$(uname -r)/config" + if [ -f "$config_file" ]; then + if grep "$1" "$config_file"; then + return 0 + else + return 1 + fi + fi + return 1 +} + # Run a single blktest test case # Usage: run_one block/001 # Arguments: @@ -65,7 +91,10 @@ run_one() { msg "${output}" # Analyze the results - # Priority: [failed] > [not run] > [passed] > empty output + # Priority: [failed] > [passed] > [not run] > empty output + # Rule: has [passed] and no [failed] -> pass (ignore [not run]) + # all [not run] or empty output -> skip + # has [failed] -> fail # Check for empty output first (no test device available) if [[ -z "$output" ]] || [[ -z "$(echo "$output" | tr -d '[:space:]')" ]]; then msg "Result: skip test (no output, possibly no test device available)" @@ -73,19 +102,14 @@ run_one() { elif echo "$output" | grep -q '\[failed\]'; then msg "Result: test fail" return 1 - elif echo "$output" | grep -q '\[not run\]'; then - # Check if there are any [passed] results - if echo "$output" | grep -q '\[passed\]'; then - # Mixed results: some passed, some not run - treat as skip - msg "Result: skip test (some tests not run)" - else - # All tests are [not run] - msg "Result: skip test" - fi - skip_test "Test case ${test_case} skipped: contains [not run] results" elif echo "$output" | grep -q '\[passed\]'; then + # Has [passed] and no [failed] -> pass (ignore [not run]) msg "Result: test pass" return 0 + elif echo "$output" | grep -q '\[not run\]'; then + # All tests are [not run], no [passed] + msg "Result: skip test (all tests not run)" + skip_test "Test case ${test_case} skipped: all tests [not run]" else # No recognizable test results msg "Result: test fail (no valid test results found)" diff --git a/testcase/blktrace/blktrace-001.sh b/testcase/blktrace/blktrace-001.sh index ccddd63822206567aae9899c0e3900aa7b2a8e33..3b85ebabeb402aeee953dbfe53dcc27a6f8c5de1 100755 --- a/testcase/blktrace/blktrace-001.sh +++ b/testcase/blktrace/blktrace-001.sh @@ -26,7 +26,8 @@ g_tmpdir="$(mktemp -d)" tc_setup() { msg "this is tc_setup" - # @预置条件: + # @预置条件: 内核支持BLK_DEV_ZONED + skip_if_false check_config "^CONFIG_BLK_DEV_ZONED=" return 0 } diff --git a/testcase/blktrace/blktrace-002.sh b/testcase/blktrace/blktrace-002.sh index f9e0a385b865fb2ae953a2d47749fe156418c637..e8ab01f4f646f3d6f32771e0784c7c070118704b 100755 --- a/testcase/blktrace/blktrace-002.sh +++ b/testcase/blktrace/blktrace-002.sh @@ -26,7 +26,8 @@ g_tmpdir="$(mktemp -d)" tc_setup() { msg "this is tc_setup" - # @预置条件: + # @预置条件: 内核支持BLK_DEV_ZONED + skip_if_false check_config "^CONFIG_BLK_DEV_ZONED=" return 0 }