Skip to content

Commit a499f84

Browse files
author
Jeevanandan Sandan
committed
feat: added ufs functional tests
- UFS Read/Writes - Verifies the UFS read/writes in the user partition > - UFS Runtime Suspend/Resume - Ensure proper link_state transitions during load and no-load > - UFS Clock Scaling/Gating - Ensures UFS clock is scaled and gated based on load and requirement > - UFS Hibern8 - Validate active/hibern8 entry exit on-demand > - UFS Write Booster - Check whether UFS Write Booster is enabled on write > - UFS Gear Validation - Check gear switching on load > Impact: > These tests improve the functional coverage for UFS Signed-off-by: Jeevanandan Sandan <sandanka@qti.qualcomm.com>
1 parent ea73304 commit a499f84

21 files changed

Lines changed: 1453 additions & 13 deletions

File tree

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ done
1717

1818
if [ -z "$INIT_ENV" ]; then
1919
echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2
20-
exit 1
20+
exit 0
2121
fi
2222

2323
# Only source if not already loaded
2424
if [ -z "$__INIT_ENV_LOADED" ]; then
2525
# shellcheck disable=SC1090
2626
. "$INIT_ENV"
27+
export __INIT_ENV_LOADED=1
2728
fi
2829

2930
# Always source functestlib.sh
@@ -32,13 +33,13 @@ fi
3233

3334
TESTNAME="UFS_Validation"
3435
test_path=$(find_test_case_by_name "$TESTNAME")
35-
cd "$test_path" || exit 1
36+
cd "$test_path" || exit 0
3637
res_file="./$TESTNAME.res"
3738

3839
log_info "--------------------------------------------------"
3940
log_info "------------- Starting $TESTNAME Test ------------"
4041

41-
check_dependencies dd grep cut head tail udevadm
42+
check_dependencies dd
4243

4344
MANDATORY_CONFIGS="CONFIG_SCSI_UFSHCD CONFIG_SCSI_UFS_QCOM"
4445
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"
@@ -62,6 +63,7 @@ done
6263

6364
check_dt_nodes "/sys/bus/platform/devices/*ufs*" || {
6465
echo "$TESTNAME SKIP" > "$res_file"
66+
log_skip "UFS Device Tree nodes not found"
6567
exit 0
6668
}
6769

@@ -103,7 +105,7 @@ else
103105
log_fail "UFS read test failed"
104106
log_info "Try manually: $DD_CMD"
105107
echo "$TESTNAME FAIL" > "$res_file"
106-
exit 1
108+
exit 0
107109
fi
108110

109111
log_info "Running I/O stress test (64MB read+write on tmpfile)..."
@@ -137,10 +139,10 @@ else
137139
rm -f "$tmpfile"
138140
fi
139141
echo "$TESTNAME FAIL" > "$res_file"
140-
exit 1
142+
exit 0
141143
fi
142144

143-
scan_dmesg_errors "ufs" "$test_path"
145+
scan_dmesg_errors "$test_path" "ufs"
144146
log_pass "$TESTNAME completed successfully"
145147
echo "$TESTNAME PASS" > "$res_file"
146-
exit 0
148+
exit 0

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ done
1717

1818
if [ -z "$INIT_ENV" ]; then
1919
echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2
20-
exit 1
20+
exit 0
2121
fi
2222

2323
# Only source if not already loaded
2424
if [ -z "$__INIT_ENV_LOADED" ]; then
2525
# shellcheck disable=SC1090
2626
. "$INIT_ENV"
27+
export __INIT_ENV_LOADED=1
2728
fi
2829

2930
# Always source functestlib.sh
@@ -32,13 +33,13 @@ fi
3233

3334
TESTNAME="eMMC_Validation"
3435
test_path=$(find_test_case_by_name "$TESTNAME")
35-
cd "$test_path" || exit 1
36+
cd "$test_path" || exit 0
3637
res_file="./$TESTNAME.res"
3738

3839
log_info "--------------------------------------------------"
3940
log_info "------------ Starting $TESTNAME Test -------------"
4041

41-
check_dependencies dd grep cut head tail udevadm
42+
check_dependencies dd grep
4243

4344
MANDATORY_CONFIGS="CONFIG_MMC CONFIG_MMC_BLOCK"
4445
OPTIONAL_CONFIGS="CONFIG_MMC_SDHCI CONFIG_MMC_SDHCI_MSM CONFIG_MMC_BLOCK_MINORS"
@@ -96,7 +97,7 @@ else
9697
else
9798
log_fail "eMMC read test failed"
9899
echo "$TESTNAME FAIL" > "$res_file"
99-
exit 1
100+
exit 0
100101
fi
101102
fi
102103
fi
@@ -117,7 +118,7 @@ if dd if=/dev/zero of="$tmpfile" bs=1M count=64 conv=fsync status=none 2>/dev/nu
117118
log_fail "eMMC I/O stress test failed (read)"
118119
rm -f "$tmpfile"
119120
echo "$TESTNAME FAIL" > "$res_file"
120-
exit 1
121+
exit 0
121122
fi
122123
else
123124
log_warn "'conv=fsync' not supported. Trying basic write fallback."
@@ -134,7 +135,7 @@ else
134135
log_fail "eMMC I/O stress test failed (fallback)"
135136
rm -f "$tmpfile"
136137
echo "$TESTNAME FAIL" > "$res_file"
137-
exit 1
138+
exit 0
138139
fi
139140
fi
140141

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# UFS Clock Scaling and Gating Validation
2+
## Overview
3+
4+
This shell script executes on the DUT (Device-Under-Test) and verifies the UFS clock scaling and clock gating functionality by monitoring clock frequency changes during I/O load and idle states.
5+
6+
The test script performs these functional checks:
7+
8+
1. **Kernel Configuration**:
9+
- Validates presence of mandatory configs: `CONFIG_SCSI_UFSHCD`, `CONFIG_SCSI_UFS_QCOM`
10+
- Checks 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`
11+
12+
2. **Device Tree Validation**:
13+
- Verifies UFS device tree nodes exist at `/sys/bus/platform/devices/*ufs*`
14+
- Detects UFS block device partition
15+
16+
3. **Clock Frequency Node Detection**:
17+
- Locates current frequency node: `/sys/devices/platform/soc@0/*ufs*/devfreq/*ufs*/cur_freq`
18+
- Locates max frequency node: `/sys/devices/platform/soc@0/*ufs*/devfreq/*ufs*/max_freq`
19+
- Locates min frequency node: `/sys/devices/platform/soc@0/*ufs*/devfreq/*ufs*/min_freq`
20+
21+
4. **Clock Scaling Verification**:
22+
- Generates I/O load using `dd` command (writes 2GB of data)
23+
- Monitors whether UFS clock scales up to maximum frequency during load
24+
- Validates clock frequency on application of load
25+
26+
5. **Clock Gating Verification**:
27+
- Waits for UFS driver to enter idle state
28+
- Monitors whether UFS clock gates down to minimum frequency when idle
29+
- Validates ufs clock is gated when no load is present
30+
31+
## How to Run
32+
33+
```sh
34+
source init_env
35+
cd suites/Kernel/Baseport/Storage/ufs_clock_scaling
36+
./run.sh
37+
```
38+
39+
## Prerequisites
40+
41+
- `dd`, `sleep` must be available
42+
- Root access may be required for complete validation
43+
- Sufficient storage space for temporary test file (approximately 2GB)
44+
45+
## Result Format
46+
47+
Test result will be saved in `ufs_clock_scaling.res` as:
48+
- `ufs_clock_scaling PASS` – if both clock scaling and gating validations pass
49+
- `ufs_clock_scaling FAIL` – if either clock scaling or gating check fails
50+
- `ufs_clock_scaling SKIP` – if required kernel configs, device tree nodes, or UFS devices are not found
51+
52+
## License
53+
54+
```
55+
Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
56+
SPDX-License-Identifier: BSD-3-Clause-Clear
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
#!/bin/sh
2+
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
3+
# SPDX-License-Identifier: BSD-3-Clause-Clear
4+
5+
# Robustly find and source init_env
6+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
7+
INIT_ENV=""
8+
SEARCH="$SCRIPT_DIR"
9+
while [ "$SEARCH" != "/" ]; do
10+
if [ -f "$SEARCH/init_env" ]; then
11+
INIT_ENV="$SEARCH/init_env"
12+
break
13+
fi
14+
SEARCH=$(dirname "$SEARCH")
15+
done
16+
17+
if [ -z "$INIT_ENV" ]; then
18+
echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2
19+
exit 0
20+
fi
21+
22+
# Only source if not already loaded
23+
if [ -z "$__INIT_ENV_LOADED" ]; then
24+
# shellcheck disable=SC1090
25+
. "$INIT_ENV"
26+
export __INIT_ENV_LOADED=1
27+
fi
28+
29+
# Always source functestlib.sh
30+
# shellcheck disable=SC1090,SC1091
31+
. "$TOOLS/functestlib.sh"
32+
33+
TESTNAME="ufs_clock_scaling"
34+
test_path=$(find_test_case_by_name "$TESTNAME")
35+
cd "$test_path" || exit 0
36+
res_file="./$TESTNAME.res"
37+
38+
log_info "--------------------------------------------------"
39+
log_info "------------- Starting $TESTNAME Test ------------"
40+
41+
check_dependencies dd sleep
42+
43+
MANDATORY_CONFIGS="CONFIG_SCSI_UFSHCD CONFIG_SCSI_UFS_QCOM"
44+
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"
45+
46+
log_info "Checking mandatory kernel configs for UFS..."
47+
if ! check_kernel_config "$MANDATORY_CONFIGS" 2>/dev/null; then
48+
log_skip "Missing mandatory UFS kernel configs: $MANDATORY_CONFIGS"
49+
echo "$TESTNAME SKIP" > "$res_file"
50+
exit 0
51+
fi
52+
53+
log_info "Checking optional kernel configs for UFS..."
54+
missing_optional=""
55+
for cfg in $OPTIONAL_CONFIGS; do
56+
if ! check_kernel_config "$cfg" 2>/dev/null; then
57+
log_info "[OPTIONAL] $cfg is not enabled"
58+
missing_optional="$missing_optional $cfg"
59+
fi
60+
done
61+
[ -n "$missing_optional" ] && log_info "Optional configs not present but continuing:$missing_optional"
62+
63+
check_dt_nodes "/sys/bus/platform/devices/*ufs*" || {
64+
echo "$TESTNAME SKIP" > "$res_file"
65+
log_skip "UFS Device Tree nodes not found"
66+
exit 0
67+
}
68+
69+
block_dev=$(detect_ufs_partition_block)
70+
if [ -z "$block_dev" ]; then
71+
log_skip "No UFS block device found."
72+
echo "$TESTNAME SKIP" > "$res_file"
73+
exit 0
74+
fi
75+
log_info "Detected UFS block: $block_dev"
76+
77+
log_info "Validating UFS clock scaling & clock gating"
78+
# Check for UFS clock freq node and assign to variable
79+
log_info "Checking for UFS clock freq node..."
80+
if ! check_dt_nodes "/sys/devices/platform/soc@0/*ufs*/devfreq/*ufs*/cur_freq"; then
81+
log_skip "UFS clock frequency node not found"
82+
echo "$TESTNAME SKIP" > "$res_file"
83+
exit 0
84+
fi
85+
86+
UFS_CLOCK_FREQ_NODE=$(get_dt_node_path "/sys/devices/platform/soc@0/*ufs*/devfreq/*ufs*/cur_freq")
87+
if [ -z "$UFS_CLOCK_FREQ_NODE" ]; then
88+
log_skip "Failed to get UFS clock frequency node path"
89+
echo "$TESTNAME SKIP" > "$res_file"
90+
exit 0
91+
fi
92+
log_info "Found UFS clock freq node: $UFS_CLOCK_FREQ_NODE"
93+
94+
# Check for UFS clock max freq node and assign to variable
95+
log_info "Checking for UFS max clock freq node..."
96+
if ! check_dt_nodes "/sys/devices/platform/soc@0/*ufs*/devfreq/*ufs*/max_freq"; then
97+
log_skip "UFS max frequency node not found"
98+
echo "$TESTNAME SKIP" > "$res_file"
99+
exit 0
100+
fi
101+
102+
UFS_MAX_FREQ_NODE=$(get_dt_node_path "/sys/devices/platform/soc@0/*ufs*/devfreq/*ufs*/max_freq")
103+
if [ -z "$UFS_MAX_FREQ_NODE" ]; then
104+
log_skip "Failed to get UFS max clock frequency node path"
105+
echo "$TESTNAME SKIP" > "$res_file"
106+
exit 0
107+
fi
108+
log_info "Found UFS max freq node: $UFS_MAX_FREQ_NODE"
109+
110+
UFS_MAX_FREQ=$(cat "$UFS_MAX_FREQ_NODE" 2>/dev/null)
111+
if [ -z "$UFS_MAX_FREQ" ]; then
112+
log_skip "Failed to read max frequency from $UFS_MAX_FREQ_NODE"
113+
echo "$TESTNAME FAIL" > "$res_file"
114+
exit 0
115+
fi
116+
log_info "Max UFS clock frequency supported is $UFS_MAX_FREQ"
117+
118+
# Generate load using dd command and check for ufs cur_freq
119+
log_info "Starting I/O load test to verify UFS clock scaling..."
120+
tmpfile="/ufs_clock_scaling.tmp"
121+
122+
# Start dd in background
123+
dd if=/dev/zero of="$tmpfile" bs=2M count=1024 >/dev/null 2>&1 &
124+
DD_PID=$!
125+
126+
log_info "Checking whether UFS clock is scaled during load..."
127+
UFS_CLOCK_SCALED=0
128+
129+
# Use check_node_status to verify ufs clock scaling
130+
if ! check_node_status "$UFS_CLOCK_FREQ_NODE" "$UFS_MAX_FREQ" 5 0.5; then
131+
log_fail "UFS clock is not scaled"
132+
else
133+
log_pass "UFS clock is scaled to $UFS_MAX_FREQ"
134+
UFS_CLOCK_SCALED=1
135+
fi
136+
137+
# Wait for dd to complete if it's still running
138+
if kill -0 $DD_PID 2>/dev/null; then
139+
log_info "Waiting for I/O load test to complete..."
140+
wait $DD_PID 2>/dev/null
141+
sync
142+
fi
143+
144+
# Clean up temp file
145+
rm -f "$tmpfile"
146+
147+
# wait for 10 seconds for UFS driver to go to idle state
148+
sleep 10
149+
150+
UFS_MIN_FREQ_NODE=$(get_dt_node_path "/sys/devices/platform/soc@0/*ufs*/devfreq/*ufs*/min_freq")
151+
if [ -z "$UFS_MIN_FREQ_NODE" ]; then
152+
log_skip "Failed to get UFS min clock frequency node path"
153+
echo "$TESTNAME SKIP" > "$res_file"
154+
exit 0
155+
fi
156+
log_info "Found UFS min freq node: $UFS_MIN_FREQ_NODE"
157+
158+
UFS_MIN_FREQ=$(cat "$UFS_MIN_FREQ_NODE" 2>/dev/null)
159+
if [ -z "$UFS_MIN_FREQ" ]; then
160+
log_skip "Failed to read min frequency from $UFS_MIN_FREQ"
161+
echo "$TESTNAME FAIL" > "$res_file"
162+
exit 0
163+
fi
164+
log_info "Min UFS clock frequency supported is $UFS_MIN_FREQ"
165+
166+
log_info "Checking whether UFS clock is gated when no load is applied"
167+
UFS_CLOCK_GATED=0
168+
169+
# Use check_node_status to verify ufs clock scaling
170+
if ! check_node_status "$UFS_CLOCK_FREQ_NODE" "$UFS_MIN_FREQ" 5 0.5; then
171+
log_fail "UFS clock is not gated"
172+
else
173+
log_pass "UFS clock is gated to $UFS_MAX_FREQ"
174+
UFS_CLOCK_GATED=1
175+
fi
176+
177+
if [ "$UFS_CLOCK_SCALED" -ne 1 ] && [ "$UFS_CLOCK_GATED" -ne 1 ]; then
178+
log_fail "UFS clock scaling & gating test failed"
179+
echo "$TESTNAME FAIL" > "$res_file"
180+
exit 0
181+
fi
182+
183+
scan_dmesg_errors "$test_path" "ufs"
184+
log_pass "$TESTNAME completed successfully"
185+
echo "$TESTNAME PASS" > "$res_file"
186+
exit 0
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
metadata:
2+
name: ufs-clock-scaling
3+
format: "Lava-Test Test Definition 1.0"
4+
description: "Check whether UFS clock is scaled when load is applied"
5+
os:
6+
- linux
7+
scope:
8+
- functional
9+
10+
run:
11+
steps:
12+
- REPO_PATH=$PWD
13+
- cd Runner/suites/Kernel/Baseport/Storage/ufs_clock_scaling
14+
- ./run.sh || true
15+
- $REPO_PATH/Runner/utils/send-to-lava.sh ufs_clock_scaling.res || true

0 commit comments

Comments
 (0)