Skip to content

Commit aab5563

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 aab5563

File tree

13 files changed

+877
-0
lines changed

13 files changed

+877
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
metadata:
2+
name: MultiSource-STM-ETM
3+
description: "Validates concurrent STM and ETM trace collection across multiple cores."
4+
5+
os:
6+
- linux
7+
devices:
8+
- qcm6490
9+
- qcs9100
10+
scope:
11+
- coresight
12+
- kernel
13+
timeout: 300
14+
15+
run:
16+
steps:
17+
- REPO_PATH=$PWD
18+
- cd Runner/suites/Kernel/DEBUG/MultiSource-STM-ETM
19+
- ./run.sh || true
20+
- $REPO_PATH/Runner/utils/send-to-lava.sh MultiSource-STM-ETM.res || true
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Multi-Source STM + ETM Test
2+
3+
## Description
4+
This test verifies the Coresight subsystem's ability to handle simultaneous trace data from:
5+
1. **STM (System Trace Macrocell)**: Software events.
6+
2. **ETM (Embedded Trace Macrocell)**: Instruction trace from all online CPUs.
7+
8+
It iterates through available sinks (e.g., `tmc_etf0`, `tmc_etr0`) and checks if valid binary data is captured.
9+
10+
## Dependencies
11+
- **Library**: `Runner/utils/coresight_common.sh`
12+
- **Kernel Config**: `CONFIG_CORESIGHT`, `CONFIG_CORESIGHT_STM`, `CONFIG_CORESIGHT_LINK_AND_SINK_TMC`.
13+
14+
## Execution
15+
Run the script directly:
16+
```bash
17+
./run.sh
18+
```
19+
20+
## Result
21+
A result.res file is generated
22+
```bash
23+
MultiSource_tmc_etf0: Pass
24+
MultiSource_tmc_etr0: Pass
25+
```
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
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+
rm -f "$res_file"
42+
touch "$res_file"
43+
44+
log_info "-----------------------------------------------------------------------------------------"
45+
log_info "-------------------Starting $TESTNAME Testcase----------------------------"
46+
log_info "=== Test Initialization ==="
47+
log_info "Checking if required tools are available"
48+
49+
CPU_PATH="/sys/devices/system/cpu/cpu"
50+
CORES=$(grep -c "processor" /proc/cpuinfo)
51+
STM_PATH="$CS_BASE/stm0"
52+
[ ! -d "$STM_PATH" ] && STM_PATH="$CS_BASE/coresight-stm"
53+
54+
# --- Helpers ---
55+
56+
toggle_etm_all() {
57+
_state=$1
58+
_count=0
59+
while [ "$_count" -lt "$CORES" ]; do
60+
[ -f "${CPU_PATH}${_count}/online" ] && echo 1 > "${CPU_PATH}${_count}/online"
61+
62+
if [ -d "$CS_BASE/ete$_count" ]; then
63+
_etm="$CS_BASE/ete$_count/enable_source"
64+
elif [ -d "$CS_BASE/coresight-ete$_count" ]; then
65+
_etm="$CS_BASE/coresight-ete$_count/enable_source"
66+
elif [ -d "$CS_BASE/etm$_count" ]; then
67+
_etm="$CS_BASE/etm$_count/enable_source"
68+
elif [ -d "$CS_BASE/coresight-etm$_count" ]; then
69+
_etm="$CS_BASE/coresight-etm$_count/enable_source"
70+
else
71+
_count=$((_count + 1))
72+
continue
73+
fi
74+
75+
[ -f "$_etm" ] && echo "$_state" > "$_etm"
76+
_count=$((_count + 1))
77+
done
78+
}
79+
80+
# --- Preflight ---
81+
82+
cs_check_base || { echo "$TESTNAME FAIL" >> "$res_file"; exit 1; }
83+
84+
# Reset all sources and sinks before starting
85+
cs_global_reset
86+
toggle_etm_all 0
87+
88+
# shellcheck disable=SC2010
89+
SINKS=""
90+
for _d in "$CS_BASE"/tmc_et* "$CS_BASE"/coresight-tmc-et*; do
91+
[ -d "$_d" ] || continue
92+
_name="${_d##*/}"
93+
[ "$_name" = "tmc_etf1" ] && continue
94+
[ -f "$_d/enable_sink" ] || continue
95+
SINKS="$SINKS $_name"
96+
done
97+
SINKS="${SINKS# }"
98+
99+
if [ -z "$SINKS" ]; then
100+
log_fail "No suitable TMC sinks found"
101+
echo "$TESTNAME FAIL" >> "$res_file"
102+
exit 1
103+
fi
104+
105+
for sinkname in $SINKS; do
106+
log_info "Testing Sink: $sinkname"
107+
108+
cs_global_reset
109+
OUTPUT_BIN="/tmp/$sinkname.bin"
110+
rm -f "$OUTPUT_BIN"
111+
112+
if ! cs_enable_sink "$sinkname"; then
113+
log_warn "Sink $sinkname enable_sink node not found"
114+
echo "$TESTNAME FAIL" >> "$res_file"
115+
continue
116+
fi
117+
118+
toggle_etm_all 1
119+
120+
if [ -f "$STM_PATH/enable_source" ]; then
121+
echo 1 > "$STM_PATH/enable_source"
122+
else
123+
log_warn "STM source not found"
124+
fi
125+
126+
[ -c "/dev/$sinkname" ] && timeout 2s cat "/dev/$sinkname" > "$OUTPUT_BIN"
127+
128+
if [ -f "$OUTPUT_BIN" ]; then
129+
bin_size=$(stat -c%s "$OUTPUT_BIN")
130+
if [ "$bin_size" -ge 64 ]; then
131+
log_pass "Captured $bin_size bytes from $sinkname"
132+
echo "$TESTNAME PASS" >> "$res_file"
133+
else
134+
log_fail "Captured data too small ($bin_size bytes) from $sinkname"
135+
echo "$TESTNAME FAIL" >> "$res_file"
136+
fi
137+
else
138+
log_fail "No output file generated for $sinkname"
139+
echo "$TESTNAME FAIL" >> "$res_file"
140+
fi
141+
142+
toggle_etm_all 0
143+
done
144+
145+
cs_global_reset
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
## Execution
7+
1. **Setup**:
8+
* Creates STP policy directories.
9+
* Resets Coresight devices.
10+
* Enables `tmc_etf0` as the sink.
11+
2. **Test Loop (Run for both `hwevent_enable` and `port_enable`)**:
12+
* **Outer Loop**: Toggles STM `enable_source` (0, then 1).
13+
* **Inner Loop**: Toggles the target attribute (0, then 1).
14+
* **Verification**: Reads back the attribute value to ensure it matches the written value.
15+
3. **Teardown**:
16+
* Resets all devices.
17+
* Restores `hwevent_enable` to `0`.
18+
* Restores `port_enable` to `0xffffffff` (all ports enabled).
19+
20+
## Output
21+
* Console logs detailing the read/write operations.
22+
* `STM-HWEvent-Port-Enable-Disable.res` containing Pass/Fail status for each attribute.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
metadata:
2+
name: STM-HWEvent-Port-Enable-Disable
3+
description: "Validates the ability to enable and disable STM Hardware Events and Ports via sysfs."
4+
5+
os:
6+
- linux
7+
devices:
8+
- qcm6490
9+
- qcs9100
10+
scope:
11+
- coresight
12+
- kernel
13+
timeout: 60
14+
15+
run:
16+
steps:
17+
- REPO_PATH=$PWD
18+
- cd Runner/suites/Kernel/DEBUG/STM-HWE-PORT-SWITCH
19+
- ./run.sh || true
20+
- $REPO_PATH/Runner/utils/send-to-lava.sh STM-HWE-PORT-SWITCH.res || true
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
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="STM-HWE-PORT-SWITCH"
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+
STM_PATH="$CS_BASE/stm0"
47+
[ ! -d "$STM_PATH" ] && STM_PATH="$CS_BASE/coresight-stm"
48+
ETF_PATH="$CS_BASE/tmc_etf0"
49+
ETR_PATH="$CS_BASE/tmc_etr0"
50+
DEBUGFS="/sys/kernel/debug/tracing"
51+
52+
reset_source_sink() {
53+
if [ -f "$STM_PATH/enable_source" ]; then
54+
echo 0 > "$STM_PATH/enable_source"
55+
fi
56+
if [ -f "$ETF_PATH/enable_sink" ]; then
57+
echo 0 > "$ETF_PATH/enable_sink"
58+
fi
59+
if [ -f "$ETR_PATH/enable_sink" ]; then
60+
echo 0 > "$ETR_PATH/enable_sink"
61+
fi
62+
if [ -f "$DEBUGFS/tracing_on" ]; then
63+
echo 0 > "$DEBUGFS/tracing_on"
64+
fi
65+
}
66+
67+
test_attribute() {
68+
attr_name=$1
69+
attr_path="$STM_PATH/$attr_name"
70+
71+
log_info "Testing Attribute: $attr_name"
72+
73+
if [ ! -f "$attr_path" ]; then
74+
log_warn "Attribute $attr_name not found at $STM_PATH"
75+
return 0
76+
fi
77+
78+
for stm_state in 0 1; do
79+
echo "$stm_state" > "$STM_PATH/enable_source"
80+
81+
for val in 0 1; do
82+
echo "$val" > "$attr_path"
83+
readback=$(cat "$attr_path")
84+
85+
86+
if [ "$attr_name" = "hwevent_enable" ]; then
87+
if [ "$readback" -eq "$val" ]; then
88+
log_pass "STM_Src:$stm_state | $attr_name set to $val"
89+
else
90+
log_fail "STM_Src:$stm_state | Failed to set $attr_name to $val (Read: $readback)"
91+
echo "$TESTNAME FAIL" >> "$res_file"
92+
return 1
93+
fi
94+
elif [ "$attr_name" = "port_enable" ]; then
95+
if [ "$val" -eq 1 ] && [ "$readback" != "0" ] && [ "$readback" != "0x0" ]; then
96+
log_pass "STM_Src:$stm_state | $attr_name set to $val"
97+
elif [ "$val" -eq 0 ] && [ "$readback" = "0" ]; then
98+
log_pass "STM_Src:$stm_state | $attr_name set to $val"
99+
elif [ "$val" -eq 0 ] && [ "$readback" = "0x0" ]; then
100+
log_pass "STM_Src:$stm_state | $attr_name set to $val"
101+
else
102+
log_fail "STM_Src:$stm_state | Failed to set $attr_name to $val (Read: $readback)"
103+
echo "$TESTNAME FAIL" >> "$res_file"
104+
return 1
105+
fi
106+
fi
107+
done
108+
done
109+
110+
echo "$TESTNAME PASS" >> "$res_file"
111+
return 0
112+
}
113+
114+
115+
if [ ! -d "$STM_PATH" ]; then
116+
log_fail "STM device not found"
117+
echo "$TESTNAME FAIL" >> "$res_file"
118+
exit 1
119+
fi
120+
121+
log_info "Creating Policy Directories..."
122+
mkdir -p /sys/kernel/config/stp-policy/stm0:p_ost.policy/default
123+
124+
reset_source_sink
125+
126+
if [ -f "$ETF_PATH/enable_sink" ]; then
127+
echo 1 > "$ETF_PATH/enable_sink"
128+
fi
129+
130+
test_attribute "hwevent_enable"
131+
test_attribute "port_enable"
132+
133+
reset_source_sink
134+
135+
if [ -f "$STM_PATH/hwevent_enable" ]; then
136+
echo 0 > "$STM_PATH/hwevent_enable"
137+
fi
138+
if [ -f "$STM_PATH/port_enable" ]; then
139+
echo 0xffffffff > "$STM_PATH/port_enable"
140+
fi
141+
142+
# log_info "-------------------$TESTNAME Testcase Finished----------------------------"

0 commit comments

Comments
 (0)