Skip to content

Commit 4650502

Browse files
author
Jeevanandan Sandan
committed
feat: Added ufs functional tests
### Details - **UFS Read/Writes** - Verified ufs read writes. - **UFS Runtime Suspend/Resume** - Ensured proper state transitions during runtime power management. - **UFS Clock Scaling/Gating** - Checks whether the UFS clock is scaled and gated based on load and requirement. - **UFS Hibern8** - Validated entry and exit from Hibern8 low-power state. - **UFS Write Booster Check** - Verify whether the write booster is enabled for enhanced write performance. - **UFS Gear Validation** - Checked gear switching on load based on UFS spec version. ### Impact These tests improve coverage for UFS features. Signed-off-by: Jeevanandan Sandan <sandanka@qti.qualcomm.com>
1 parent ea73304 commit 4650502

21 files changed

Lines changed: 1444 additions & 4 deletions

File tree

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ fi
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
@@ -38,7 +39,7 @@ res_file="./$TESTNAME.res"
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

@@ -140,7 +142,7 @@ else
140142
exit 1
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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ fi
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
@@ -38,7 +39,7 @@ res_file="./$TESTNAME.res"
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"
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 1
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 1
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 1
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 1
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 1
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
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# UFS Gear Validation
2+
## Overview
3+
4+
This shell script executes on the DUT (Device-Under-Test) and verifies the UFS Gear based on the UFS spec supported by the device on application of load to UFS driver.
5+
6+
The test script performs these functional checks:
7+
8+
1. **Kernel Configuration**:
9+
- Validates presence of `CONFIG_SCSI_UFS_QCOM`, `CONFIG_SCSI_UFSHCD` and entries in `/proc/config.gz`.
10+
11+
2. **Read UFS Specification Version**:
12+
- Reads the UFS specification version from `/sys/devices/platform/soc@0/1d84000.ufs/device_descriptor/specification_version`
13+
- Based on the UFS specification version decides the max operating gear.
14+
15+
2. **Runtime Verification**:
16+
- Checks `/sys/devices/platform/soc@0/1d84000.ufs/power_info/gear` on application of load whether the operating gear is same as max supported gear.
17+
18+
## How to Run
19+
20+
```sh
21+
source init_env
22+
cd suites/Kernel/Baseport/Storage/ufs_gear_lane
23+
./run.sh
24+
```
25+
26+
## Prerequisites
27+
28+
- `dd`, `grep`, `sleep`, `findmnt`, `awk` must be available
29+
- Root access may be required for complete validation
30+
31+
## Result Format
32+
33+
Test result will be saved in `ufs_gear_check.res` as:
34+
- `UFS Gear Validation Successful. Test Passed` – if all validations pass
35+
- `UFS Gear did not reach max gear on load. Test Failed` – if any check fails
36+
37+
## License
38+
39+
```
40+
Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
41+
SPDX-License-Identifier: BSD-3-Clause-Clear
42+
```

0 commit comments

Comments
 (0)