Skip to content

Commit 3884502

Browse files
committed
functestlib: Refactor scan_dmesg_errors() with scoped filtering and ShellCheck fixes from UFS/eMMC run.sh scripts
This change improves the scan_dmesg_errors() function to: - Filter dmesg errors based on a scoped keyword (e.g., 'ufs', 'mmc', 'bt') - Reduce false positives by narrowing context to relevant lines - Log both raw snapshot and filtered messages for traceability Also addressed ShellCheck warnings across the UFS/eMMC run.sh scripts: - SC2012: Replaced ls with find for safer handling of filenames - SC2034: Removed or justified unused variable assignments Signed-off-by: Srikanth Muppandam <[email protected]>
1 parent 8ee6093 commit 3884502

File tree

3 files changed

+63
-62
lines changed

3 files changed

+63
-62
lines changed

Runner/suites/Kernel/Baseport/Storage/UFS_Validation/run.sh

Lines changed: 21 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,12 @@ log_info "------------- Starting $TESTNAME Test ------------"
4040

4141
check_dependencies dd grep cut head tail udevadm
4242

43-
# --- Kernel Config Checks ---
4443
MANDATORY_CONFIGS="CONFIG_SCSI_UFSHCD CONFIG_SCSI_UFS_QCOM"
4544
OPTIONAL_CONFIGS="CONFIG_SCSI_UFSHCD_PLATFORM CONFIG_SCSI_UFSHCD_PCI CONFIG_SCSI_UFS_CDNS_PLATFORM CONFIG_SCSI_UFS_HISI CONFIG_SCSI_UFS_EXYNOS CONFIG_SCSI_UFS_ROCKCHIP CONFIG_SCSI_UFS_BSG"
4645

4746
log_info "Checking mandatory kernel configs for UFS..."
4847
if ! check_kernel_config "$MANDATORY_CONFIGS" 2>/dev/null; then
49-
log_skip "Missing one or more mandatory UFS kernel configs: $MANDATORY_CONFIGS"
48+
log_skip "Missing mandatory UFS kernel configs: $MANDATORY_CONFIGS"
5049
echo "$TESTNAME SKIP" > "$res_file"
5150
exit 0
5251
fi
@@ -61,45 +60,19 @@ for cfg in $OPTIONAL_CONFIGS; do
6160
done
6261
[ -n "$missing_optional" ] && log_info "Optional configs not present but continuing:$missing_optional"
6362

64-
# --- Device Tree Check ---
6563
check_dt_nodes "/sys/bus/platform/devices/*ufs*" || {
6664
echo "$TESTNAME SKIP" > "$res_file"
6765
exit 0
6866
}
6967

70-
# --- UFS Block Detection ---
71-
detect_ufs_partition_block() {
72-
if command -v lsblk >/dev/null 2>&1 && command -v udevadm >/dev/null 2>&1; then
73-
for part in $(lsblk -lnpo NAME,TYPE | awk '$2 == "part" {print $1}'); do
74-
if udevadm info --query=all --name="$part" 2>/dev/null | grep -qi "ufs"; then
75-
echo "$part"
76-
return 0
77-
fi
78-
done
79-
fi
80-
81-
for part in /dev/sd[a-z][0-9]*; do
82-
[ -e "$part" ] || continue
83-
if command -v udevadm >/dev/null 2>&1 &&
84-
udevadm info --query=all --name="$part" 2>/dev/null | grep -qi "ufs"; then
85-
echo "$part"
86-
return 0
87-
fi
88-
done
89-
90-
return 1
91-
}
92-
9368
block_dev=$(detect_ufs_partition_block)
9469
if [ -z "$block_dev" ]; then
9570
log_skip "No UFS block device found."
9671
echo "$TESTNAME SKIP" > "$res_file"
9772
exit 0
9873
fi
99-
10074
log_info "Detected UFS block: $block_dev"
10175

102-
# --- RootFS Detection ---
10376
if command -v findmnt >/dev/null 2>&1; then
10477
rootfs_dev=$(findmnt -n -o SOURCE /)
10578
else
@@ -110,10 +83,13 @@ fi
11083
resolved_block=$(readlink -f "$block_dev" 2>/dev/null)
11184
resolved_rootfs=$(readlink -f "$rootfs_dev" 2>/dev/null)
11285

113-
# --- Read Test (check if 'iflag=direct' supported) ---
114-
log_info "Running basic read test on $block_dev (non-rootfs)..."
86+
if [ -n "$resolved_block" ] && [ -n "$resolved_rootfs" ] && [ "$resolved_block" = "$resolved_rootfs" ]; then
87+
log_warn "Detected block ($resolved_block) is the root filesystem. Skipping read test."
88+
echo "$TESTNAME SKIP" > "$res_file"
89+
exit 0
90+
fi
11591

116-
# Test for iflag=direct support
92+
log_info "Running basic read test on $block_dev (non-rootfs)..."
11793
if echo | dd of=/dev/null iflag=direct 2>/dev/null; then
11894
DD_CMD="dd if=$block_dev of=/dev/null bs=1M count=32 iflag=direct"
11995
else
@@ -130,34 +106,41 @@ else
130106
exit 1
131107
fi
132108

133-
# --- I/O Stress Test ---
134109
log_info "Running I/O stress test (64MB read+write on tmpfile)..."
135110
tmpfile="$test_path/ufs_test.img"
136111

137-
# Prepare dd write command
138112
if echo | dd of=/dev/null conv=fsync 2>/dev/null; then
139113
DD_WRITE="dd if=/dev/zero of=$tmpfile bs=1M count=64 conv=fsync"
140114
else
141115
log_warn "'conv=fsync' not supported by dd. Using basic write."
142116
DD_WRITE="dd if=/dev/zero of=$tmpfile bs=1M count=64"
143117
fi
144118

145-
# Use simplified dd read for BusyBox compatibility
146119
if $DD_WRITE >/dev/null 2>&1 &&
147120
dd if="$tmpfile" of=/dev/null bs=1M count=64 >/dev/null 2>&1; then
148121
log_pass "UFS I/O stress test passed"
122+
if command -v stat >/dev/null 2>&1; then
123+
stat --format="[INFO] Size: %s bytes File: %n" "$tmpfile"
124+
else
125+
find "$tmpfile" -printf "[INFO] Size: %s bytes File: %p\n"
126+
fi
149127
rm -f "$tmpfile"
150128
else
151129
log_fail "UFS I/O stress test failed"
152130
df -h . | sed 's/^/[INFO] /'
153-
ls -lh "$test_path"/ufs_test.img | sed 's/^/[INFO] /'
154-
rm -f "$tmpfile"
131+
if [ -f "$tmpfile" ]; then
132+
if command -v stat >/dev/null 2>&1; then
133+
stat --format="[INFO] Size: %s bytes File: %n" "$tmpfile"
134+
else
135+
find "$tmpfile" -printf "[INFO] Size: %s bytes File: %p\n"
136+
fi
137+
rm -f "$tmpfile"
138+
fi
155139
echo "$TESTNAME FAIL" > "$res_file"
156140
exit 1
157141
fi
158-
# --- Dmesg Errors ---
159-
scan_dmesg_errors "ufs" "$test_path"
160142

143+
scan_dmesg_errors "ufs" "$test_path"
161144
log_pass "$TESTNAME completed successfully"
162145
echo "$TESTNAME PASS" > "$res_file"
163146
exit 0

Runner/suites/Kernel/Baseport/Storage/eMMC_Validation/run.sh

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,31 +40,26 @@ log_info "------------ Starting $TESTNAME Test -------------"
4040

4141
check_dependencies dd grep cut head tail udevadm
4242

43-
# --- Kernel Config Checks ---
4443
MANDATORY_CONFIGS="CONFIG_MMC CONFIG_MMC_BLOCK"
4544
OPTIONAL_CONFIGS="CONFIG_MMC_SDHCI CONFIG_MMC_SDHCI_MSM CONFIG_MMC_BLOCK_MINORS"
4645

47-
missing_optional=""
4846
log_info "Checking mandatory kernel configs for eMMC..."
4947
if ! check_kernel_config "$MANDATORY_CONFIGS" 2>/dev/null; then
50-
log_skip "Missing one or more mandatory eMMC kernel configs: $MANDATORY_CONFIGS"
48+
log_skip "Missing mandatory eMMC kernel configs: $MANDATORY_CONFIGS"
5149
echo "$TESTNAME SKIP" > "$res_file"
5250
exit 0
5351
fi
5452

5553
log_info "Checking optional kernel configs for eMMC..."
54+
missing_optional=""
5655
for cfg in $OPTIONAL_CONFIGS; do
5756
if ! check_kernel_config "$cfg" 2>/dev/null; then
5857
log_info "[OPTIONAL] $cfg is not enabled"
5958
missing_optional="$missing_optional $cfg"
6059
fi
6160
done
61+
[ -n "$missing_optional" ] && log_info "Optional configs not present but continuing:$missing_optional"
6262

63-
if [ -n "$missing_optional" ]; then
64-
log_info "Optional configs not present but continuing:$missing_optional"
65-
fi
66-
67-
# --- Device Tree and Block Device Check ---
6863
check_dt_nodes "/sys/bus/mmc/devices/*mmc*" || {
6964
echo "$TESTNAME SKIP" > "$res_file"
7065
exit 0
@@ -76,27 +71,26 @@ if [ -z "$block_dev" ]; then
7671
echo "$TESTNAME SKIP" > "$res_file"
7772
exit 0
7873
fi
79-
8074
log_info "Detected eMMC block: $block_dev"
8175

82-
# --- RootFS check fallback if findmnt is missing ---
83-
rootfs_dev="unknown"
8476
if command -v findmnt >/dev/null 2>&1; then
8577
rootfs_dev=$(findmnt -n -o SOURCE /)
8678
else
8779
log_warn "findmnt not available, using fallback rootfs detection"
8880
rootfs_dev=$(awk '$2 == "/" { print $1 }' /proc/mounts)
8981
fi
9082

91-
# --- Prevent direct read from rootfs ---
92-
if [ "$block_dev" = "$rootfs_dev" ]; then
93-
log_warn "eMMC block $block_dev is mounted as rootfs. Skipping direct read test."
83+
resolved_block=$(readlink -f "$block_dev" 2>/dev/null)
84+
resolved_rootfs=$(readlink -f "$rootfs_dev" 2>/dev/null)
85+
86+
if [ -n "$resolved_block" ] && [ -n "$resolved_rootfs" ] && [ "$resolved_block" = "$resolved_rootfs" ]; then
87+
log_warn "Detected eMMC block ($resolved_block) is the root filesystem. Skipping read test."
9488
else
9589
log_info "Running basic read test on $block_dev (non-rootfs)..."
9690
if dd if="$block_dev" of=/dev/null bs=1M count=32 iflag=direct status=none 2>/dev/null; then
9791
log_pass "eMMC read test succeeded"
9892
else
99-
log_warn "'iflag=direct' not supported by dd. Falling back to standard dd."
93+
log_warn "'iflag=direct' not supported by dd. Trying fallback..."
10094
if dd if="$block_dev" of=/dev/null bs=1M count=32 status=none 2>/dev/null; then
10195
log_pass "eMMC read test succeeded (fallback)"
10296
else
@@ -107,13 +101,17 @@ else
107101
fi
108102
fi
109103

110-
# --- I/O Stress Test ---
111104
log_info "Running I/O stress test (64MB read+write on tmpfile)..."
112105
tmpfile="$test_path/emmc_test.img"
113106

114107
if dd if=/dev/zero of="$tmpfile" bs=1M count=64 conv=fsync status=none 2>/dev/null; then
115108
if dd if="$tmpfile" of=/dev/null bs=1M status=none 2>/dev/null; then
116109
log_pass "eMMC I/O stress test passed"
110+
if command -v stat >/dev/null 2>&1; then
111+
stat --format="[INFO] Size: %s bytes File: %n" "$tmpfile"
112+
else
113+
find "$tmpfile" -printf "[INFO] Size: %s bytes File: %p\n"
114+
fi
117115
rm -f "$tmpfile"
118116
else
119117
log_fail "eMMC I/O stress test failed (read)"
@@ -122,10 +120,15 @@ if dd if=/dev/zero of="$tmpfile" bs=1M count=64 conv=fsync status=none 2>/dev/nu
122120
exit 1
123121
fi
124122
else
125-
log_warn "'conv=fsync' not supported by dd. Using basic write fallback."
123+
log_warn "'conv=fsync' not supported. Trying basic write fallback."
126124
if dd if=/dev/zero of="$tmpfile" bs=1M count=64 status=none 2>/dev/null &&
127125
dd if="$tmpfile" of=/dev/null bs=1M status=none 2>/dev/null; then
128126
log_pass "eMMC I/O stress test passed (fallback)"
127+
if command -v stat >/dev/null 2>&1; then
128+
stat --format="[INFO] Size: %s bytes File: %n" "$tmpfile"
129+
else
130+
find "$tmpfile" -printf "[INFO] Size: %s bytes File: %p\n"
131+
fi
129132
rm -f "$tmpfile"
130133
else
131134
log_fail "eMMC I/O stress test failed (fallback)"
@@ -135,9 +138,8 @@ else
135138
fi
136139
fi
137140

138-
# --- Dmesg Scan ---
139141
scan_dmesg_errors "mmc" "$test_path"
140-
141142
log_pass "$TESTNAME completed successfully"
142143
echo "$TESTNAME PASS" > "$res_file"
143144
exit 0
145+

Runner/utils/functestlib.sh

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,20 +1439,36 @@ detect_ufs_partition_block() {
14391439

14401440
# Check for dmesg I/O errors and log summary
14411441
scan_dmesg_errors() {
1442-
label="$1"
1443-
output_dir="$2"
1442+
label="$1" # Example: "ufs", "emmc", "wifi"
1443+
output_dir="$2" # Directory to store logs
1444+
extra_keywords="$3" # (Optional) Space-separated keywords for this label
14441445

1446+
[ -z "$label" ] && return 1
14451447
[ -z "$output_dir" ] && output_dir="."
1448+
14461449
snapshot_file="$output_dir/${label}_dmesg_snapshot.log"
14471450
error_file="$output_dir/${label}_dmesg_errors.log"
14481451

1449-
log_info "Scanning dmesg for recent I/O errors..."
1452+
log_info "Scanning dmesg for recent $label-related I/O errors..."
1453+
14501454
dmesg | tail -n 300 > "$snapshot_file"
1451-
grep -iE "error|fail|timeout|reset|crc" "$snapshot_file" > "$error_file"
1455+
1456+
# Common error indicators
1457+
common_keywords="error fail timeout reset crc abort fault invalid fatal warn"
1458+
1459+
# Build keyword pattern (common + optional extra)
1460+
pattern="($common_keywords"
1461+
if [ -n "$extra_keywords" ]; then
1462+
pattern="$pattern|$extra_keywords"
1463+
fi
1464+
pattern="$pattern)"
1465+
1466+
# Filter: lines must match label and error pattern
1467+
grep -iE "$label" "$snapshot_file" | grep -iE "$pattern" > "$error_file"
14521468

14531469
if [ -s "$error_file" ]; then
14541470
log_warn "Detected potential $label-related errors in dmesg:"
1455-
while read -r line; do
1471+
while IFS= read -r line; do
14561472
log_warn " dmesg: $line"
14571473
done < "$error_file"
14581474
else

0 commit comments

Comments
 (0)