Skip to content

Commit 4e8c92b

Browse files
Add ETM-Test-Mode and ETM-Trace folders
Signed-off-by: Rohan Dutta <rohadutt@qti.qualcomm.com>
1 parent 89e3067 commit 4e8c92b

File tree

6 files changed

+383
-0
lines changed

6 files changed

+383
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
metadata:
2+
name: ETM-Test-Mode
3+
description: "Validates ETM functionality by setting the 'mode' attribute to high (0xFFFFFFF) and enabling the cores."
4+
5+
os:
6+
- linux
7+
devices:
8+
- qcm6490
9+
- qcs9100
10+
scope:
11+
- coresight
12+
- kernel
13+
timeout: 60
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# ETM Test Mode
2+
3+
## Overview
4+
This test verifies the stability and write-access of the **ETM (Embedded Trace Macrocell)** `mode` attribute. It sets the mode to `0XFFFFFFF` (enabling various mode bits like cycle-accurate tracing, etc., depending on the hardware revision) and attempts to enable the ETM sources.
5+
6+
## Execution
7+
1. **Discovery**: Scans `/sys/bus/coresight/devices/` for ETM devices (`etm*` or `coresight-etm*`).
8+
2. **Setup**:
9+
* Resets all Coresight sources and sinks.
10+
* Enables `tmc_etr0` as the trace sink.
11+
3. **Test**:
12+
* Iterates through all detected ETM devices.
13+
* Writes `0XFFFFFFF` to the `mode` sysfs attribute.
14+
* Enables the ETM source.
15+
4. **Teardown**:
16+
* Writes `0x0` to the `mode` sysfs attribute (restoring defaults).
17+
* Disables all sources and sinks.
18+
19+
## Output
20+
* Console logs showing detection and configuration of each core.
21+
* `ETM-Test-Mode.res` containing the final Pass/Fail status.
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
#!/bin/sh
2+
3+
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
4+
# SPDX-License-Identifier: BSD-3-Clause
5+
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" >&2
19+
exit 1
20+
fi
21+
22+
if [ -z "$__INIT_ENV_LOADED" ]; then
23+
# shellcheck disable=SC1090
24+
. "$INIT_ENV"
25+
fi
26+
27+
# shellcheck disable=SC1090,SC1091
28+
. "$TOOLS/functestlib.sh"
29+
30+
TESTNAME="ETM-Test-Mode"
31+
if command -v find_test_case_by_name >/dev/null 2>&1; then
32+
test_path=$(find_test_case_by_name "$TESTNAME")
33+
cd "$test_path" || exit 1
34+
else
35+
cd "$SCRIPT_DIR" || exit 1
36+
fi
37+
38+
res_file="./$TESTNAME.res"
39+
rm -f "$res_file"
40+
touch "$res_file"
41+
42+
log_info "-----------------------------------------------------------------------------------------"
43+
log_info "-------------------Starting $TESTNAME Testcase----------------------------"
44+
45+
CS_BASE="/sys/bus/coresight/devices"
46+
ETR_PATH="$CS_BASE/tmc_etr0"
47+
[ ! -d "$ETR_PATH" ] && ETR_PATH="$CS_BASE/tmc_etr"
48+
49+
50+
reset_source_sink() {
51+
if [ -f "$CS_BASE/stm0/enable_source" ]; then
52+
echo 0 > "$CS_BASE/stm0/enable_source"
53+
fi
54+
55+
# shellcheck disable=SC2086
56+
for etm in $ETM_LIST; do
57+
if [ -f "$etm/enable_source" ]; then
58+
echo 0 > "$etm/enable_source"
59+
fi
60+
done
61+
62+
if [ -f "$ETR_PATH/enable_sink" ]; then
63+
echo 0 > "$ETR_PATH/enable_sink"
64+
fi
65+
if [ -f "$CS_BASE/tmc_etf0/enable_sink" ]; then
66+
echo 0 > "$CS_BASE/tmc_etf0/enable_sink"
67+
fi
68+
}
69+
70+
71+
# shellcheck disable=SC2010
72+
ETM_LIST=$(ls -d "$CS_BASE"/etm* "$CS_BASE"/coresight-etm* 2>/dev/null)
73+
74+
if [ -z "$ETM_LIST" ]; then
75+
log_fail "No Coresight ETM devices found"
76+
echo "$TESTNAME: FAIL" >> "$res_file"
77+
exit 1
78+
fi
79+
80+
log_info "Found ETM devices: $(echo "$ETM_LIST" | tr '\n' ' ')"
81+
82+
reset_source_sink
83+
84+
if [ -d "$ETR_PATH" ]; then
85+
log_info "Enabling Sink: $ETR_PATH"
86+
echo 1 > "$ETR_PATH/enable_sink"
87+
else
88+
log_fail "TMC-ETR sink not found"
89+
echo "$TESTNAME: FAIL" >> "$res_file"
90+
exit 1
91+
fi
92+
93+
fail_count=0
94+
95+
# shellcheck disable=SC2086
96+
for etm in $ETM_LIST; do
97+
log_info "Configuring $etm"
98+
99+
if [ -f "$etm/mode" ]; then
100+
echo 0XFFFFFFF > "$etm/mode"
101+
if [ $? -ne 0 ]; then
102+
log_warn "Failed to set mode on $etm"
103+
fail_count=$((fail_count + 1))
104+
fi
105+
else
106+
log_warn "$etm does not have 'mode' attribute"
107+
fi
108+
109+
if [ -f "$etm/enable_source" ]; then
110+
echo 1 > "$etm/enable_source"
111+
if [ $? -ne 0 ]; then
112+
log_fail "Failed to enable $etm"
113+
fail_count=$((fail_count + 1))
114+
fi
115+
fi
116+
done
117+
118+
if [ $fail_count -eq 0 ]; then
119+
log_pass "ETM Mode Configuration Successful"
120+
echo "$TESTNAME: PASS" >> "$res_file"
121+
else
122+
log_fail "ETM Mode Configuration Failed ($fail_count errors)"
123+
echo "$TESTNAME: FAIL" >> "$res_file"
124+
fi
125+
126+
# shellcheck disable=SC2086
127+
for etm in $ETM_LIST; do
128+
if [ -f "$etm/mode" ]; then
129+
echo 0x0 > "$etm/mode"
130+
fi
131+
done
132+
133+
reset_source_sink
134+
135+
# log_info "-------------------$TESTNAME Testcase Finished----------------------------"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
metadata:
2+
name: ETM-Trace-Enable-Disable
3+
description: "Validates the stability of enabling and disabling ETM sources repeatedly and verifies trace data generation."
4+
5+
os:
6+
- linux
7+
devices:
8+
- qcm6490
9+
- qcs9100
10+
scope:
11+
- coresight
12+
- kernel
13+
timeout: 300
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# ETM Trace Test
2+
3+
## Overview
4+
This test validates the reliability of the ETM (Embedded Trace Macrocell) drivers by repeatedly enabling and disabling trace sources and verifying that data is successfully written to the sinks.
5+
6+
## Execution Logic
7+
The test iterates through **every available sink** (excluding `tmc_etf1`) and **every available ETM source**.
8+
9+
For each Sink $\leftrightarrow$ Source pair, it performs `N` iterations (default: 2):
10+
1. **Reset**: Disable all Coresight devices.
11+
2. **Enable Sink**: Activate the current sink (e.g., `tmc_etr0`).
12+
3. **Enable Source**: Activate the current ETM (e.g., `etm0`).
13+
4. **Capture**: Sleep for 3 seconds to generate trace data, then dump the content of `/dev/<sink_name>` to a temporary binary file.
14+
5. **Verify**:
15+
* Check if the captured binary file size is $\ge$ 64 bytes.
16+
* Check if the source disabled correctly.
17+
18+
## Usage
19+
Run the script directly or via the runner.
20+
Optional argument: Number of iterations per device pair.
21+
```bash
22+
./run.sh 5
23+
```
24+
25+
## Output
26+
* Console logs for each iteration.
27+
* ETM-Trace-Enable-Disable.res containing the final Pass/Fail status.
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
#!/bin/sh
2+
3+
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
4+
# SPDX-License-Identifier: BSD-3-Clause
5+
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" >&2
19+
exit 1
20+
fi
21+
22+
if [ -z "$__INIT_ENV_LOADED" ]; then
23+
# shellcheck disable=SC1090
24+
. "$INIT_ENV"
25+
fi
26+
27+
# shellcheck disable=SC1090,SC1091
28+
. "$TOOLS/functestlib.sh"
29+
30+
TESTNAME="ETM-Trace"
31+
if command -v find_test_case_by_name >/dev/null 2>&1; then
32+
test_path=$(find_test_case_by_name "$TESTNAME")
33+
cd "$test_path" || exit 1
34+
else
35+
cd "$SCRIPT_DIR" || exit 1
36+
fi
37+
38+
res_file="./$TESTNAME.res"
39+
rm -f "$res_file"
40+
touch "$res_file"
41+
42+
log_info "-----------------------------------------------------------------------------------------"
43+
log_info "-------------------Starting $TESTNAME Testcase----------------------------"
44+
45+
CS_BASE="/sys/bus/coresight/devices"
46+
TMP_DIR="/tmp/coresight-test"
47+
FAIL_COUNT=0
48+
49+
RUNS=2
50+
if [ -n "$1" ]; then
51+
RUNS=$1
52+
fi
53+
54+
rm -rf "$TMP_DIR"
55+
mkdir -p "$TMP_DIR"
56+
57+
58+
reset_devices() {
59+
if [ -f "$CS_BASE/stm0/enable_source" ]; then
60+
echo 0 > "$CS_BASE/stm0/enable_source" 2>/dev/null
61+
fi
62+
63+
# shellcheck disable=SC2010
64+
for etm in $(ls -d "$CS_BASE"/etm* "$CS_BASE"/coresight-etm* 2>/dev/null); do
65+
if [ -f "$etm/enable_source" ]; then
66+
echo 0 > "$etm/enable_source" 2>/dev/null
67+
fi
68+
done
69+
70+
for sink in "$CS_BASE"/tmc_et*; do
71+
if [ -f "$sink/enable_sink" ]; then
72+
echo 0 > "$sink/enable_sink" 2>/dev/null
73+
fi
74+
done
75+
}
76+
77+
run_trace_test() {
78+
sourcename=$1
79+
sinkname=$2
80+
81+
bin_dir="$TMP_DIR/$sinkname"
82+
mkdir -p "$bin_dir"
83+
84+
log_info ">>> Source: $(basename "$sourcename") | Sink: $sinkname"
85+
86+
if ! echo 1 > "$sourcename/enable_source"; then
87+
log_fail "Failed to write 1 to $sourcename/enable_source"
88+
return 1
89+
fi
90+
91+
res=$(cat "$sourcename/enable_source")
92+
if [ "$res" -eq 1 ]; then
93+
log_info "Source enabled successfully"
94+
else
95+
log_fail "Source failed to enable (Value: $res)"
96+
return 1
97+
fi
98+
99+
sleep 3
100+
101+
outfile="$bin_dir/$(basename "$sourcename").bin"
102+
timeout 5 cat "/dev/$sinkname" > "$outfile" 2>/dev/null
103+
104+
if [ -f "$outfile" ]; then
105+
bin_size=$(stat -c%s "$outfile")
106+
log_info " captured bin size: $bin_size bytes"
107+
108+
if [ "$bin_size" -ge 64 ]; then
109+
log_pass "Trace data captured for $sourcename -> $sinkname"
110+
else
111+
log_fail "Trace data too small ($bin_size < 64)"
112+
FAIL_COUNT=$((FAIL_COUNT + 1))
113+
fi
114+
else
115+
log_fail "Failed to create output file from /dev/$sinkname"
116+
FAIL_COUNT=$((FAIL_COUNT + 1))
117+
fi
118+
119+
echo 0 > "$sourcename/enable_source"
120+
res=$(cat "$sourcename/enable_source")
121+
122+
if [ "$res" -eq 0 ]; then
123+
log_info "Source disabled successfully"
124+
else
125+
log_fail "Source failed to disable (Value: $res)"
126+
FAIL_COUNT=$((FAIL_COUNT + 1))
127+
fi
128+
}
129+
130+
131+
# shellcheck disable=SC2010
132+
SINK_LIST=$(ls -d "$CS_BASE"/tmc_et* 2>/dev/null | grep -v tmc_etf1)
133+
# shellcheck disable=SC2010
134+
ETM_LIST=$(ls -d "$CS_BASE"/etm* "$CS_BASE"/coresight-etm* 2>/dev/null)
135+
136+
if [ -z "$SINK_LIST" ] || [ -z "$ETM_LIST" ]; then
137+
log_fail "Missing Sinks or ETM devices"
138+
echo "$TESTNAME: FAIL" >> "$res_file"
139+
exit 1
140+
fi
141+
142+
reset_devices
143+
144+
for sink_path in $SINK_LIST; do
145+
sinkname=$(basename "$sink_path")
146+
147+
i=0
148+
while [ $i -lt "$RUNS" ]; do
149+
log_info "--- Iteration $((i+1)) for Sink: $sinkname ---"
150+
151+
for etm_path in $ETM_LIST; do
152+
reset_devices
153+
154+
echo 1 > "$sink_path/enable_sink"
155+
156+
run_trace_test "$etm_path" "$sinkname"
157+
done
158+
159+
i=$((i+1))
160+
done
161+
done
162+
163+
reset_devices
164+
165+
if [ "$FAIL_COUNT" -eq 0 ]; then
166+
log_pass "ETM Trace Enable/Disable Test Completed Successfully"
167+
echo "$TESTNAME: PASS" >> "$res_file"
168+
else
169+
log_fail "ETM Trace Enable/Disable Test Failed ($FAIL_COUNT errors)"
170+
echo "$TESTNAME: FAIL" >> "$res_file"
171+
fi
172+
173+
rm -rf "$TMP_DIR"
174+
# log_info "-------------------$TESTNAME Testcase Finished----------------------------"

0 commit comments

Comments
 (0)