@@ -61,12 +61,13 @@ is_module_loaded() {
6161 /sbin/lsmod | awk ' {print $1}' | grep -q " ^${module_name} $"
6262}
6363
64- # Insert a kernel module with optional parameters
64+ # load_kernel_module <path-to-ko> [params...]
65+ # 1) If already loaded, no-op
66+ # 2) Try insmod <ko> [params]
67+ # 3) If that fails, try modprobe <modname> [params]
6568load_kernel_module () {
66- module_path=" $1 "
67- shift
69+ module_path=" $1 " ; shift
6870 params=" $* "
69-
7071 module_name=$( basename " $module_path " .ko)
7172
7273 if is_module_loaded " $module_name " ; then
@@ -76,15 +77,24 @@ load_kernel_module() {
7677
7778 if [ ! -f " $module_path " ]; then
7879 log_error " Module file not found: $module_path "
79- return 1
80+ # still try modprobe if it exists in modules directory
81+ else
82+ log_info " Loading module via insmod: $module_path $params "
83+ if /sbin/insmod " $module_path " " $params " 2> insmod_err.log; then
84+ log_info " Module $module_name loaded successfully via insmod"
85+ return 0
86+ else
87+ log_warn " insmod failed: $( cat insmod_err.log) "
88+ fi
8089 fi
8190
82- log_info " Loading module: $module_path $params "
83- if /sbin/insmod " $module_path " " $params " 2> insmod_err.log; then
84- log_info " Module $module_name loaded successfully"
91+ # fallback to modprobe
92+ log_info " Falling back to modprobe $module_name $params "
93+ if /sbin/modprobe " $module_name " " $params " 2> modprobe_err.log; then
94+ log_info " Module $module_name loaded successfully via modprobe"
8595 return 0
8696 else
87- log_error " insmod failed: $( cat insmod_err .log) "
97+ log_error " modprobe failed: $( cat modprobe_err .log) "
8898 return 1
8999 fi
90100}
@@ -171,14 +181,25 @@ find_test_case_script_by_name() {
171181 find " $base_dir " -type d -iname " $test_name " -print -quit 2> /dev/null
172182}
173183
184+ # Check each given kernel config is set to y/m in /proc/config.gz, logs result, returns 0/1.
174185check_kernel_config () {
175- configs=" $1 "
176- for config_key in $configs ; do
177- if zcat /proc/config.gz | grep -qE " ^$config_key =(y|m)" ; then
178- log_pass " Kernel config $config_key is enabled"
186+ cfgs=$1
187+ for config_key in $cfgs ; do
188+ if command -v zgrep > /dev/null 2>&1 ; then
189+ if zgrep -qE " ^${config_key} =(y|m)" /proc/config.gz 2> /dev/null; then
190+ log_pass " Kernel config $config_key is enabled"
191+ else
192+ log_fail " Kernel config $config_key is missing or not enabled"
193+ return 1
194+ fi
179195 else
180- log_fail " Kernel config $config_key is missing or not enabled"
181- return 1
196+ # Fallback if zgrep is unavailable
197+ if gzip -dc /proc/config.gz 2> /dev/null | grep -qE " ^${config_key} =(y|m)" ; then
198+ log_pass " Kernel config $config_key is enabled"
199+ else
200+ log_fail " Kernel config $config_key is missing or not enabled"
201+ return 1
202+ fi
182203 fi
183204 done
184205 return 0
@@ -1653,41 +1674,71 @@ detect_ufs_partition_block() {
16531674 return 1
16541675}
16551676
1656- # Check for dmesg I/O errors and log summary
1677+ # scan_dmesg_check <label> [out_dir] [extra_err_kw] [ok_kw]
1678+ # Returns:
1679+ # 0 -> no errors; ok_kw matched (or not requested)
1680+ # 1 -> error lines found
1681+ # 2 -> no errors, but ok_kw (if given) NOT found
16571682scan_dmesg_errors () {
1658- label=" $1 " # Example: "ufs", "emmc", "wifi"
1659- output_dir=" $2 " # Directory to store logs
1660- extra_keywords=" $3 " # (Optional) Space-separated keywords for this label
1661-
1662- [ -z " $label " ] && return 1
1663- [ -z " $output_dir " ] && output_dir=" ."
1664-
1665- snapshot_file=" $output_dir /${label} _dmesg_snapshot.log"
1666- error_file=" $output_dir /${label} _dmesg_errors.log"
1667-
1668- log_info " Scanning dmesg for recent $label -related I/O errors..."
1669-
1670- dmesg | tail -n 300 > " $snapshot_file "
1671-
1672- # Common error indicators
1673- common_keywords=" error fail timeout reset crc abort fault invalid fatal warn"
1674-
1675- # Build keyword pattern (common + optional extra)
1676- pattern=" ($common_keywords "
1677- if [ -n " $extra_keywords " ]; then
1678- pattern=" $pattern |$extra_keywords "
1679- fi
1680- pattern=" $pattern )"
1681-
1682- # Filter: lines must match label and error pattern
1683- grep -iE " $label " " $snapshot_file " | grep -iE " $pattern " > " $error_file "
1684-
1685- if [ -s " $error_file " ]; then
1686- log_warn " Detected potential $label -related errors in dmesg:"
1683+ label=" $1 "
1684+ out_dir=" ${2:- .} "
1685+ extra_err=" ${3:- } "
1686+ ok_kw=" ${4:- } "
1687+
1688+ [ -z " $label " ] && return 3 # misuse
1689+
1690+ lines=" ${DMESG_LINES:- 300} "
1691+ snap=" $out_dir /${label} _dmesg_snapshot.log"
1692+ errf=" $out_dir /${label} _dmesg_errors.log"
1693+ okf=" $out_dir /${label} _dmesg_ok.log"
1694+
1695+ log_info " Scanning dmesg for ${label} : errors & success patterns"
1696+
1697+ dmesg | tail -n " $lines " > " $snap "
1698+
1699+ # Error keywords
1700+ common_err=' error|fail|timeout|reset|crc|abort|fault|invalid|fatal|warn|oops|panic'
1701+ err_pat=" $common_err "
1702+ [ -n " $extra_err " ] && err_pat=" ${err_pat} |${extra_err} "
1703+
1704+ # Find error lines (must match label AND error pattern)
1705+ grep -iE " $label " " $snap " | grep -iE " ($err_pat )" > " $errf " 2> /dev/null
1706+
1707+ if [ -s " $errf " ]; then
1708+ log_warn " Detected potential ${label} -related errors:"
16871709 while IFS= read -r line; do
16881710 log_warn " dmesg: $line "
1689- done < " $error_file "
1690- else
1691- log_info " No $label -related errors found in recent dmesg logs."
1711+ done < " $errf "
1712+ return 0
1713+ fi
1714+
1715+ # Optionally look for OK messages
1716+ if [ -n " $ok_kw " ]; then
1717+ grep -iE " $ok_kw " " $snap " > " $okf " 2> /dev/null
1718+ if [ -s " $okf " ]; then
1719+ log_pass " Found success pattern for $label in dmesg"
1720+ while IFS= read -r line; do
1721+ log_info " ok: $line "
1722+ done < " $okf "
1723+ return 1
1724+ else
1725+ log_warn " No success pattern ('$ok_kw ') found for $label "
1726+ return 2
1727+ fi
16921728 fi
1729+
1730+ log_info " No ${label} -related errors found (no OK pattern requested)"
1731+ return 1
1732+ }
1733+
1734+ # wait_for_path <path> [timeout_sec]
1735+ wait_for_path () {
1736+ _p=" $1 " ; _t=" ${2:- 3} "
1737+ i=0
1738+ while [ " $i " -lt " $_t " ]; do
1739+ [ -e " $_p " ] && return 0
1740+ sleep 1
1741+ i=$(( i+ 1 ))
1742+ done
1743+ return 1
16931744}
0 commit comments