Skip to content

Commit 5e7343c

Browse files
author
Jeevanandan Sandan
committed
- 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 - Fixed Review Comments Impact: These tests improve the functional coverage for UFS Signed-off-by: Jeevanandan Sandan <sandanka@qti.qualcomm.com>
1 parent 3725379 commit 5e7343c

File tree

21 files changed

+1586
-12
lines changed

21 files changed

+1586
-12
lines changed

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

Lines changed: 8 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="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"
146148
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+
3+
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
4+
# SPDX-License-Identifier: BSD-3-Clause-Clear
5+
6+
# Robustly find and source init_env
7+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
8+
INIT_ENV=""
9+
SEARCH="$SCRIPT_DIR"
10+
while [ "$SEARCH" != "/" ]; do
11+
if [ -f "$SEARCH/init_env" ]; then
12+
INIT_ENV="$SEARCH/init_env"
13+
break
14+
fi
15+
SEARCH=$(dirname "$SEARCH")
16+
done
17+
18+
if [ -z "$INIT_ENV" ]; then
19+
echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2
20+
exit 0
21+
fi
22+
23+
# Only source if not already loaded
24+
if [ -z "$__INIT_ENV_LOADED" ]; then
25+
# shellcheck disable=SC1090
26+
. "$INIT_ENV"
27+
export __INIT_ENV_LOADED=1
28+
fi
29+
30+
# Always source functestlib.sh
31+
# shellcheck disable=SC1090,SC1091
32+
. "$TOOLS/functestlib.sh"
33+
34+
TESTNAME="ufs_clock_scaling"
35+
test_path=$(find_test_case_by_name "$TESTNAME")
36+
cd "$test_path" || exit 0
37+
res_file="./$TESTNAME.res"
38+
39+
log_info "--------------------------------------------------"
40+
log_info "------------- Starting $TESTNAME Test ------------"
41+
42+
check_dependencies dd sleep
43+
44+
# Run common UFS prechecks
45+
if ! ufs_precheck_common; then
46+
log_skip "Required UFS configurations are not available"
47+
echo "$TESTNAME SKIP" > "$res_file"
48+
exit 0
49+
fi
50+
log_info "UFS prechecks successful"
51+
52+
if PRIMARY_UFS_CONTROLLER=$(get_primary_ufs_controller "/"); then
53+
log_info "Primary UFS Controller is $PRIMARY_UFS_CONTROLLER"
54+
else
55+
log_fail "Failed to get the primary UFS controller from rootfs"
56+
echo "$TESTNAME FAIL" > "$res_file"
57+
exit 0
58+
fi
59+
60+
log_info "Validating UFS clock scaling & clock gating"
61+
# Check for UFS clock freq node and assign to variable
62+
log_info "Checking for UFS clock freq node..."
63+
if UFS_CLOCK_FREQ_NODE=$(ufs_get_dt_node_path "/sys/devices/platform/soc@0/$PRIMARY_UFS_CONTROLLER/devfreq/*ufs*/cur_freq"); then
64+
log_info "Found UFS clock frequency node: $UFS_CLOCK_FREQ_NODE"
65+
else
66+
log_skip "Failed to get UFS clock frequency node"
67+
echo "$TESTNAME SKIP" > "$res_file"
68+
exit 0
69+
fi
70+
71+
# Check for UFS clock max freq node and assign to variable
72+
log_info "Checking for UFS max clock freq node..."
73+
if UFS_MAX_FREQ_NODE=$(ufs_get_dt_node_path "/sys/devices/platform/soc@0/$PRIMARY_UFS_CONTROLLER/devfreq/*ufs*/max_freq"); then
74+
log_info "Found UFS controller's max_frequency node: $UFS_MAX_FREQ_NODE"
75+
else
76+
log_skip "Failed to get UFS max clock frequency node"
77+
echo "$TESTNAME SKIP" > "$res_file"
78+
exit 0
79+
fi
80+
81+
UFS_MAX_FREQ=$(cat "$UFS_MAX_FREQ_NODE" 2>/dev/null)
82+
if [ -z "$UFS_MAX_FREQ" ]; then
83+
log_fail "Failed to read max frequency from $UFS_MAX_FREQ_NODE"
84+
echo "$TESTNAME FAIL" > "$res_file"
85+
exit 0
86+
fi
87+
log_info "Max UFS clock frequency supported is $UFS_MAX_FREQ"
88+
89+
# Check for UFS clock min freq node and assign to variable
90+
log_info "Checking for UFS min clock freq node..."
91+
if UFS_MIN_FREQ_NODE=$(ufs_get_dt_node_path "/sys/devices/platform/soc@0/$PRIMARY_UFS_CONTROLLER/devfreq/*ufs*/min_freq"); then
92+
log_info "Found UFS controller's min_frequency node: $UFS_MIN_FREQ_NODE"
93+
else
94+
log_skip "Failed to get UFS min clock frequency node"
95+
echo "$TESTNAME SKIP" > "$res_file"
96+
exit 0
97+
fi
98+
99+
UFS_MIN_FREQ=$(cat "$UFS_MIN_FREQ_NODE" 2>/dev/null)
100+
if [ -z "$UFS_MIN_FREQ" ]; then
101+
log_fail "Failed to read min frequency from $UFS_MIN_FREQ_NODE"
102+
echo "$TESTNAME FAIL" > "$res_file"
103+
exit 0
104+
fi
105+
log_info "Min UFS clock frequency supported is $UFS_MIN_FREQ"
106+
107+
# Generate load using dd command and check for ufs cur_freq
108+
log_info "Starting I/O load test to verify UFS clock scaling..."
109+
tmpfile="$test_path/${TESTNAME}.tmp"
110+
111+
# checking if necessary space is available in rootfs
112+
ensure_rootfs_min_size 3
113+
114+
# Start dd in background
115+
dd if=/dev/zero of="$tmpfile" bs=2M count=1024 >/dev/null 2>&1 &
116+
DD_PID=$!
117+
118+
log_info "Checking whether UFS clock is scaled during load..."
119+
UFS_CLOCK_SCALED=0
120+
RETRIES=10
121+
RETRY_TIMEOUT=1
122+
attempt=1
123+
124+
# Start background sync process to flush the storage requests to disk
125+
log_info "Starting continuous sync in background..."
126+
(
127+
while :; do
128+
sync
129+
sleep 0.2
130+
done
131+
) &
132+
sync_pid=$!
133+
134+
while [ $attempt -le $RETRIES ]; do
135+
# shellcheck disable=SC2002
136+
current_freq=$(cat "$UFS_CLOCK_FREQ_NODE" 2>/dev/null | tr -d '\n' | tr -d '\r')
137+
138+
if [ -n "$current_freq" ] && [ "$current_freq" -gt "$UFS_MIN_FREQ" ]; then
139+
log_pass "UFS clock is scaled to $current_freq (greater than MIN_FREQ: $UFS_MIN_FREQ)"
140+
UFS_CLOCK_SCALED=1
141+
break
142+
fi
143+
144+
log_info "Attempt $attempt/$RETRIES: Current frequency $current_freq"
145+
146+
if [ $attempt -lt $RETRIES ]; then
147+
sleep $RETRY_TIMEOUT
148+
fi
149+
150+
attempt=$((attempt + 1))
151+
done
152+
153+
# Wait for dd to complete if it's still running
154+
if kill -0 $DD_PID 2>/dev/null; then
155+
log_info "Waiting for I/O load test to complete..."
156+
wait $DD_PID 2>/dev/null
157+
fi
158+
159+
kill "$sync_pid" 2>/dev/null || true
160+
wait "$sync_pid" 2>/dev/null || true
161+
log_info "Stopped background sync process"
162+
163+
# Clean up temp file
164+
rm -f "$tmpfile"
165+
166+
log_info "Checking whether UFS clock is gated when no load is applied"
167+
UFS_CLOCK_GATED=0
168+
169+
# Use ufs_check_node_status to verify ufs clock scaling
170+
if ! ufs_check_node_status_with_timeout "$UFS_CLOCK_FREQ_NODE" "$UFS_MIN_FREQ" 60; then
171+
log_fail "UFS clock is not gated"
172+
else
173+
log_pass "UFS clock is gated to $UFS_MIN_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)