Skip to content

Commit e4d2204

Browse files
Added QDSS STM and TMC support in DEBUG suite
- MultiSource-STM-ETM: validates STM and ETM multi-source trace configuration - Sink-Status-STM-Toggle: tests STM sink status and toggle functionality - STM-HWE-PORT-SWITCH: verifies STM hardware event port switching - STM-Source-Enable-Disable: tests STM source enable/disable via sysfs - Added coresight_common.sh utility for shared functions Signed-off-by: Rohan Dutta <rohadutt@qti.qualcomm.com>
1 parent 89e3067 commit e4d2204

File tree

16 files changed

+1399
-0
lines changed

16 files changed

+1399
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
metadata:
2+
name: MultiSource-STM-ETM
3+
format: "Lava-Test Test Definition 1.0"
4+
description: "Validates concurrent STM and ETM trace collection across multiple cores."
5+
os:
6+
- linux
7+
scope:
8+
- coresight
9+
- kernel
10+
11+
run:
12+
steps:
13+
- REPO_PATH=$PWD || true
14+
- cd Runner/suites/Kernel/DEBUG/MultiSource-STM-ETM || true
15+
- ./run.sh || true
16+
- $REPO_PATH/Runner/utils/send-to-lava.sh MultiSource-STM-ETM.res || true
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Multi-Source STM + ETM Test
2+
3+
## Overview
4+
This test verifies the Coresight subsystem's ability to handle simultaneous trace data from multiple sources: STM (System Trace Macrocell) for software events, and ETM (Embedded Trace Macrocell) for instruction traces from all online CPUs. It iterates through available sinks (e.g., `tmc_etf0`, `tmc_etr0`) and checks if valid binary data is captured.
5+
6+
## Test Goals
7+
- Verify the Coresight subsystem's ability to handle simultaneous trace streams.
8+
- Validate the functionality of STM (System Trace Macrocell) for generating software event traces.
9+
- Validate the functionality of ETM (Embedded Trace Macrocell) for instruction tracing across all online CPUs.
10+
- Ensure that Coresight links and funnels properly multiplex data without dropping critical traces.
11+
- Verify that valid binary data is successfully captured across different available sinks.
12+
13+
## Prerequisites
14+
- Kernel must be built with Coresight support:
15+
- `CONFIG_CORESIGHT`
16+
- `CONFIG_CORESIGHT_STM`
17+
- `CONFIG_CORESIGHT_LINK_AND_SINK_TMC`
18+
- Availability of the common library: `Runner/utils/coresight_common.sh`
19+
- Root privileges (to configure Coresight sysfs nodes and read from character devices).
20+
21+
## Script Location
22+
`Runner/suites/Kernel/FunctionalArea/coresight/MultiSource-STM-ETM/run.sh`
23+
24+
## Files
25+
- `run.sh` - Main test script
26+
- `MultiSource-STM-ETM.res` - Summary result file with PASS/FAIL
27+
- `MultiSource-STM-ETM.log` - Full execution log (generated if logging is enabled)
28+
29+
## How It Works
30+
1. **Initialization:** Sources common Coresight helper functions (`coresight_common.sh`).
31+
2. **Setup:** Resets the Coresight topology to ensure a clean state.
32+
3. **Execution Loop:** Iterates through all available trace sinks (e.g., `tmc_etf0`, `tmc_etr0`).
33+
- Enables the current sink.
34+
- Enables STM as a trace source.
35+
- Enables all available ETMs (for all online CPUs) as trace sources.
36+
- Triggers trace data generation (both software events and CPU instruction execution).
37+
4. **Verification:** Reads the captured binary data from the sink and verifies its validity.
38+
5. **Teardown:** Disables all active sources and the sink before moving to the next iteration.
39+
40+
## Example Output
41+
```
42+
[INFO] 2026-03-16 07:41:58 - -----------------------------------------------------------------------------------------
43+
[INFO] 2026-03-16 07:41:58 - -------------------Starting MultiSource-STM-ETM Testcase----------------------------
44+
[INFO] 2026-03-16 07:41:58 - === Test Initialization ===
45+
[INFO] 2026-03-16 07:41:58 - Checking if required tools are available
46+
[INFO] 2026-03-16 07:41:58 - Testing Sink: tmc_etf0
47+
[PASS] 2026-03-16 07:41:58 - Captured 65536 bytes from tmc_etf0
48+
[INFO] 2026-03-16 07:41:58 - Testing Sink: tmc_etr0
49+
[PASS] 2026-03-16 07:41:58 - Captured 64 bytes from tmc_etr0
50+
[INFO] 2026-03-16 07:41:58 - Testing Sink: tmc_etr1
51+
[PASS] 2026-03-16 07:41:58 - Captured 64 bytes from tmc_etr1
52+
```
53+
54+
## Return Code
55+
56+
- `0` — Simultaneous trace capture succeeded for all tested sinks
57+
- `1` — Trace capture failed, returned invalid data, or a device failed to enable/disable
58+
59+
## Integration in CI
60+
61+
- Can be run standalone or via LAVA
62+
- Result file MultiSource-STM-ETM.res will be parsed by result_parse.sh
63+
64+
## Notes
65+
66+
- Testing multiple sources simultaneously stresses the Coresight funnels and links to ensure they can handle interleaved trace streams without data corruption or system instability.
67+
68+
## License
69+
70+
SPDX-License-Identifier: BSD-3-Clause-Clear
71+
(c) Qualcomm Technologies, Inc. and/or its subsidiaries.
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
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 (starting at $SCRIPT_DIR)" >&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+
# shellcheck disable=SC1090,SC1091
30+
. "$TOOLS/coresight_common.sh"
31+
32+
TESTNAME="MultiSource-STM-ETM"
33+
if command -v find_test_case_by_name >/dev/null 2>&1; then
34+
test_path=$(find_test_case_by_name "$TESTNAME")
35+
cd "$test_path" || exit 1
36+
else
37+
cd "$SCRIPT_DIR" || exit 1
38+
fi
39+
40+
res_file="./$TESTNAME.res"
41+
log_info "-----------------------------------------------------------------------------------------"
42+
log_info "-------------------Starting $TESTNAME Testcase----------------------------"
43+
log_info "=== Test Initialization ==="
44+
log_info "Checking if required tools are available"
45+
46+
for tool in timeout stat; do
47+
if ! command -v "$tool" >/dev/null 2>&1; then
48+
log_skip "Required tool '$tool' not found. Skipping test."
49+
echo "$TESTNAME SKIP" > "$res_file"
50+
exit 0
51+
fi
52+
done
53+
54+
CPU_PATH="/sys/devices/system/cpu/cpu"
55+
CORES=$(grep -c "processor" /proc/cpuinfo)
56+
STM_PATH="$CS_BASE/stm0"
57+
[ ! -d "$STM_PATH" ] && STM_PATH="$CS_BASE/coresight-stm"
58+
59+
# --- Helpers ---
60+
61+
toggle_etm_all() {
62+
_state=$1
63+
_count=0
64+
_toggled_count=0
65+
66+
while [ "$_count" -lt "$CORES" ]; do
67+
_skip=0
68+
69+
if [ -f "${CPU_PATH}${_count}/online" ]; then
70+
read -r _is_online < "${CPU_PATH}${_count}/online"
71+
if [ "$_is_online" = "0" ]; then
72+
log_info "CPU $_count is offline, skipping ETM toggle for this core."
73+
_skip=1
74+
fi
75+
fi
76+
77+
if [ "$_skip" -eq 0 ]; then
78+
_etm=""
79+
80+
if [ -f "$CS_BASE/ete$_count/enable_source" ]; then
81+
_etm="$CS_BASE/ete$_count/enable_source"
82+
elif [ -f "$CS_BASE/coresight-ete$_count/enable_source" ]; then
83+
_etm="$CS_BASE/coresight-ete$_count/enable_source"
84+
elif [ -f "$CS_BASE/etm$_count/enable_source" ]; then
85+
_etm="$CS_BASE/etm$_count/enable_source"
86+
elif [ -f "$CS_BASE/coresight-etm$_count/enable_source" ]; then
87+
_etm="$CS_BASE/coresight-etm$_count/enable_source"
88+
fi
89+
90+
if [ -n "$_etm" ]; then
91+
if echo "$_state" > "$_etm" 2>/dev/null; then
92+
_toggled_count=$((_toggled_count + 1))
93+
else
94+
log_warn "Failed to write $_state to $_etm"
95+
fi
96+
else
97+
log_warn "No ETM/ETE source found for CPU $_count in $CS_BASE"
98+
fi
99+
fi
100+
101+
_count=$((_count + 1))
102+
done
103+
104+
if [ "$_toggled_count" -eq 0 ]; then
105+
log_warn "No ETM/ETE devices were successfully toggled. Please verify Coresight configurations and path names."
106+
fi
107+
}
108+
109+
# --- Preflight ---
110+
111+
cs_check_base || { echo "$TESTNAME FAIL" > "$res_file"; exit 1; }
112+
113+
cs_global_reset
114+
toggle_etm_all 0
115+
116+
# shellcheck disable=SC2010
117+
SINKS=""
118+
for _d in "$CS_BASE"/tmc_et* "$CS_BASE"/coresight-tmc-et*; do
119+
[ -d "$_d" ] || continue
120+
_name="${_d##*/}"
121+
[ "$_name" = "tmc_etf1" ] && continue
122+
[ -f "$_d/enable_sink" ] || continue
123+
SINKS="$SINKS $_name"
124+
done
125+
SINKS="${SINKS# }"
126+
127+
if [ -z "$SINKS" ]; then
128+
log_fail "No suitable TMC sinks found"
129+
echo "$TESTNAME FAIL" > "$res_file"
130+
exit 1
131+
fi
132+
133+
for sinkname in $SINKS; do
134+
log_info "Testing Sink: $sinkname"
135+
136+
cs_global_reset
137+
OUTPUT_BIN="/tmp/$sinkname.bin"
138+
rm -f "$OUTPUT_BIN"
139+
140+
if ! cs_enable_sink "$sinkname"; then
141+
log_warn "Sink $sinkname enable_sink node not found"
142+
echo "$TESTNAME FAIL" > "$res_file"
143+
continue
144+
fi
145+
146+
toggle_etm_all 1
147+
148+
if [ -f "$STM_PATH/enable_source" ]; then
149+
echo 1 > "$STM_PATH/enable_source"
150+
else
151+
log_warn "STM source not found"
152+
fi
153+
154+
[ -c "/dev/$sinkname" ] && timeout 2s cat "/dev/$sinkname" > "$OUTPUT_BIN"
155+
156+
if [ -f "$OUTPUT_BIN" ]; then
157+
bin_size=$(stat -c%s "$OUTPUT_BIN")
158+
if [ "$bin_size" -ge 64 ]; then
159+
log_pass "Captured $bin_size bytes from $sinkname"
160+
echo "$TESTNAME PASS" > "$res_file"
161+
else
162+
log_fail "Captured data too small ($bin_size bytes) from $sinkname"
163+
echo "$TESTNAME FAIL" > "$res_file"
164+
fi
165+
else
166+
log_fail "No output file generated for $sinkname"
167+
echo "$TESTNAME FAIL" > "$res_file"
168+
fi
169+
170+
toggle_etm_all 0
171+
done
172+
173+
cs_global_reset
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# STM-HWE-PORT-SWITCH Test
2+
3+
## Overview
4+
This test verifies that the STM (System Trace Macrocell) attributes `hwevent_enable` and `port_enable` can be successfully toggled (0 and 1) via sysfs, regardless of whether the main STM source (`enable_source`) is currently active or inactive.
5+
6+
## Test Goals
7+
- Verify the ability to toggle STM hardware event enabling (`hwevent_enable`).
8+
- Verify the ability to toggle STM port enabling (`port_enable`).
9+
- Ensure that these attributes can be modified independently of the main STM source's active state (enabled or disabled).
10+
- Validate that sysfs reads accurately reflect the values written to these configuration attributes.
11+
- Ensure proper restoration of default values post-testing.
12+
13+
## Prerequisites
14+
- Kernel must be built with Coresight STM support (e.g., `CONFIG_CORESIGHT_STM`).
15+
- sysfs access to `/sys/bus/coresight/devices/stm0/` (or equivalent STM device path).
16+
- Access to configfs for STP policy directory creation.
17+
- Root privileges (to configure attributes, enable sources/sinks, and manage policies).
18+
19+
## Script Location
20+
`Runner/suites/Kernel/FunctionalArea/coresight/STM-HWE-PORT-SWITCH/run.sh`
21+
22+
## Files
23+
- `run.sh` - Main test script
24+
- `STM-HWE-PORT-SWITCH.res` - Summary result file with PASS/FAIL
25+
- `STM-HWE-PORT-SWITCH.log` - Full execution log (generated if logging is enabled)
26+
27+
## How It Works
28+
1. **Setup:**
29+
- Creates STP policy directories.
30+
- Resets Coresight devices to ensure a clean state.
31+
- Enables `tmc_etf0` as the trace sink.
32+
2. **Test Loop (Run for both `hwevent_enable` and `port_enable`):**
33+
- **Outer Loop:** Toggles the main STM `enable_source` (sets to 0, then 1).
34+
- **Inner Loop:** Toggles the target attribute (sets to 0, then 1).
35+
3. **Verification:** Reads back the attribute value to ensure it matches the written value.
36+
4. **Teardown:**
37+
- Resets all Coresight devices.
38+
- Restores `hwevent_enable` to 0.
39+
- Restores `port_enable` to 0xffffffff (all ports enabled).
40+
41+
## Example Output
42+
```
43+
[INFO] 2026-03-16 09:03:42 - -----------------------------------------------------------------------------------------
44+
[INFO] 2026-03-16 09:03:42 - -------------------Starting STM-HWE-PORT-SWITCH Testcase----------------------------
45+
[INFO] 2026-03-16 09:03:42 - Testing Attribute: hwevent_enable
46+
[PASS] 2026-03-16 09:03:42 - STM_Src:0 | hwevent_enable set to 0
47+
[PASS] 2026-03-16 09:03:42 - STM_Src:0 | hwevent_enable set to 1
48+
[PASS] 2026-03-16 09:03:42 - STM_Src:1 | hwevent_enable set to 0
49+
[PASS] 2026-03-16 09:03:42 - STM_Src:1 | hwevent_enable set to 1
50+
[INFO] 2026-03-16 09:03:42 - Testing Attribute: port_enable
51+
[PASS] 2026-03-16 09:03:42 - STM_Src:0 | port_enable set to 0
52+
[PASS] 2026-03-16 09:03:42 - STM_Src:0 | port_enable set to 1
53+
[PASS] 2026-03-16 09:03:42 - STM_Src:1 | port_enable set to 0
54+
[PASS] 2026-03-16 09:03:42 - STM_Src:1 | port_enable set to 1
55+
56+
## Return Code
57+
58+
- `0` — All attributes were toggled and verified successfully in all source states
59+
- `1` — One or more read/write verifications failed
60+
61+
## Integration in CI
62+
63+
- Can be run standalone or via LAVA
64+
- Result file STM-HWE-PORT-SWITCH.res will be parsed by result_parse.sh
65+
66+
## Notes
67+
68+
- Ensuring that configuration changes can happen while the main source is active is critical for dynamic trace adjustments without needing to tear down the entire Coresight topology.
69+
- 0xffffffff represents a bitmask enabling all 32 ports in standard STM configurations.
70+
71+
## License
72+
73+
SPDX-License-Identifier: BSD-3-Clause-Clear
74+
(c) Qualcomm Technologies, Inc. and/or its subsidiaries.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
metadata:
2+
name: STM-HWEvent-Port-Enable-Disable
3+
format: "Lava-Test Test Definition 1.0"
4+
description: "Validates the ability to enable and disable STM Hardware Events and Ports via sysfs."
5+
os:
6+
- linux
7+
scope:
8+
- coresight
9+
- kernel
10+
11+
run:
12+
steps:
13+
- REPO_PATH=$PWD || true
14+
- cd Runner/suites/Kernel/DEBUG/STM-HWE-PORT-SWITCH || true
15+
- ./run.sh || true
16+
- $REPO_PATH/Runner/utils/send-to-lava.sh STM-HWE-PORT-SWITCH.res || true

0 commit comments

Comments
 (0)