Skip to content

Commit 3f1fd80

Browse files
committed
Add stm_cpu trace test script and README documentation
Includes script to validate STM tracing via kernel configs, module loading, and trace capture. Adds README with usage, prerequisites, and result format. Signed-off-by: Sai-teja573 <[email protected]>
1 parent 6dac19b commit 3f1fd80

File tree

2 files changed

+194
-0
lines changed

2 files changed

+194
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# STM CPU Trace Validation test
2+
Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
3+
SPDX-License-Identifier: BSD-3-Clause-Clear
4+
5+
## Overview
6+
This test case validates the System Trace Macrocell (STM) functionality on the target device by configuring the STM source, enabling tracing, and capturing trace data. It ensures that the STM infrastructure is correctly initialized and capable of generating trace output.
7+
8+
## Test Performs :
9+
1. Verifies presence of required kernel configurations
10+
2. Mounts **configfs** and **debugfs**
11+
3. Loads STM-related kernel modules
12+
4. configures STM policy directories
13+
5. Enables ETF sink and STM source
14+
6. Captures and validates trace output
15+
16+
## Usage
17+
Instructions:
18+
1. **Copy repo to Target Device**: Use `scp` to transfer the scripts from the host to the target device. The scripts should be copied to any directory on the target device.
19+
2. **Verify Transfer**: Ensure that the repo has been successfully copied to the target device.
20+
3. **Run Scripts**: Navigate to the directory where these files are copied on the target device and execute the scripts as needed.
21+
22+
Run the etm_trace test using:
23+
---
24+
25+
#### Quick Example
26+
```sh
27+
git clone <this-repo>
28+
cd <this-repo>
29+
scp -r common Runner user@target_device_ip:<Path in device>
30+
ssh user@target_device_ip
31+
cd <Path in device>/Runner && ./run-test.sh stm_cpu
32+
```
33+
---
34+
35+
## Prerequisites
36+
1. Required kernel configs must be enabled: 
37+
   CONFIG_STM_PROTO_BASIC
38+
   CONFIG_STM_PROTO_SYS_T 
39+
   CONFIG_STM_DUMMY 
40+
   CONFIG_STM_SOURCE_CONSOLE 
41+
   CONFIG_STM_SOURCE_HEARTBEAT
42+
2. Root access is required to mount filesystems and load kernel modules.
43+
3. init_env and functestlib.sh must be present and correctly configured.
44+
---
45+
46+
## Result Format
47+
Test result will be saved in `stm_cpu.res` as:
48+
49+
## Output
50+
A .res file is generated in the same directory:
51+
`stm_cpu PASS` OR `stm_cpu FAIL` OR `stm_cpu SKIP`
52+
53+
## Skip Criteria
54+
1. If the required kernel configuration is missing, the result will be:
55+
2. `stm_cpu SKIP`
56+
57+
## Sample Log
58+
```
59+
[INFO] 1970-01-01 00:44:35 - -----------------------------------------------------------------------------------------
60+
[INFO] 1970-01-01 00:44:35 - -------------------Starting stm_cpu Testcase----------------------------
61+
[INFO] 1970-01-01 00:44:35 - === Test Initialization ===
62+
[FAIL] 1970-01-01 00:44:35 - Kernel config CONFIG_STM_PROTO_BASIC is missing or not enabled
63+
[SKIP] 1970-01-01 00:44:35 - stm_cpu : Required kernel configs missing
64+
```
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
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 1
21+
fi
22+
23+
# Only source if not already loaded (idempotent)
24+
if [ -z "$__INIT_ENV_LOADED" ]; then
25+
# shellcheck disable=SC1090
26+
. "$INIT_ENV"
27+
fi
28+
29+
# shellcheck disable=SC1090,SC1091
30+
. "$TOOLS/functestlib.sh"
31+
32+
TESTNAME="stm_cpu"
33+
test_path=$(find_test_case_by_name "$TESTNAME")
34+
cd "$test_path" || exit 1
35+
res_file="./$TESTNAME.res"
36+
37+
log_info "-----------------------------------------------------------------------------------------"
38+
log_info "-------------------Starting $TESTNAME Testcase----------------------------"
39+
log_info "=== Test Initialization ==="
40+
41+
# Step 1: Check required kernel configs individually
42+
CONFIGS="CONFIG_STM_PROTO_BASIC CONFIG_STM_PROTO_SYS_T CONFIG_STM_DUMMY CONFIG_STM_SOURCE_CONSOLE CONFIG_STM_SOURCE_HEARTBEAT"
43+
for cfg in $CONFIGS; do
44+
log_info "Checking if $cfg is enabled"
45+
if ! check_kernel_config "$cfg" >/dev/null; then
46+
log_fail "$cfg is not enabled"
47+
echo "$TESTNAME FAIL" > "$res_file"
48+
exit 1
49+
fi
50+
done
51+
52+
# Step 2: Mount configfs if not mounted
53+
if ! mountpoint -q /sys/kernel/config 2>/dev/null && [ -z "$(ls /sys/kernel/config 2>/dev/null)" ]; then
54+
mount -t configfs configfs /sys/kernel/config || {
55+
log_skip "$TESTNAME : Failed to mount configfs"
56+
echo "$TESTNAME SKIP" > "$res_file"
57+
exit 0
58+
}
59+
fi
60+
61+
# Step 3: Create STM policy directories
62+
mkdir -p /sys/kernel/config/stp-policy/stm0_basic.policy/default || {
63+
log_skip "$TESTNAME : Failed to create STM policy directories"
64+
echo "$TESTNAME SKIP" > "$res_file"
65+
exit 0
66+
}
67+
68+
# Step 4: Enable ETF sink only if not already enabled
69+
if [ "$(cat /sys/bus/coresight/devices/tmc_etf0/enable_sink)" != "1" ]; then
70+
echo 1 > /sys/bus/coresight/devices/tmc_etf0/enable_sink || {
71+
log_skip "$TESTNAME : Failed to enable ETF sink"
72+
echo "$TESTNAME SKIP" > "$res_file"
73+
exit 0
74+
}
75+
fi
76+
77+
# Step 5: Load STM modules
78+
for mod in stm_heartbeat stm_console stm_ftrace; do
79+
mod_path=$(find_kernel_module "$mod")
80+
load_kernel_module "$mod_path" || {
81+
log_skip "$TESTNAME : Failed to load module $mod"
82+
echo "$TESTNAME SKIP" > "$res_file"
83+
exit 0
84+
}
85+
done
86+
87+
# Step 6: Link STM source to ftrace
88+
echo stm0 > /sys/class/stm_source/ftrace/stm_source_link
89+
90+
# Step 7: Mount debugfs if not mounted
91+
if ! mountpoint -q /sys/kernel/debug 2>/dev/null && [ -z "$(ls /sys/kernel/debug 2>/dev/null)" ]; then
92+
mount -t debugfs nodev /sys/kernel/debug || {
93+
log_skip "$TESTNAME : Failed to mount debugfs"
94+
echo "$TESTNAME SKIP" > "$res_file"
95+
exit 0
96+
}
97+
fi
98+
99+
# Step 8: Enable tracing
100+
echo 1 > /sys/kernel/debug/tracing/tracing_on
101+
echo 1 > /sys/kernel/debug/tracing/events/sched/sched_switch/enable
102+
echo 1 > /sys/bus/coresight/devices/stm0/enable_source
103+
104+
# Step 9: Capture trace output
105+
trace_output="/tmp/qdss_etf_stm.bin"
106+
rm -f "$trace_output"
107+
108+
if [ ! -e /dev/tmc_etf0 ]; then
109+
log_skip "$TESTNAME : Trace device /dev/tmc_etf0 not found"
110+
echo "$TESTNAME SKIP" > "$res_file"
111+
exit 0
112+
fi
113+
114+
cat /dev/tmc_etf0 > "$trace_output"
115+
116+
# Step 10: Validate trace output is not empty
117+
if [ -s "$trace_output" ]; then
118+
log_pass "$TESTNAME : Trace captured successfully"
119+
echo "$TESTNAME PASS" > "$res_file"
120+
rm -f "$trace_output"
121+
log_info "------------------- Completed $TESTNAME Testcase ----------------------------"
122+
exit 0
123+
else
124+
log_fail "$TESTNAME : Trace output is empty"
125+
echo "$TESTNAME FAIL" > "$res_file"
126+
rm -f "$trace_output"
127+
log_info "------------------- Completed $TESTNAME Testcase ----------------------------"
128+
exit 1
129+
fi
130+

0 commit comments

Comments
 (0)