Skip to content

Commit d524c67

Browse files
Added coresight ftrace-dump-etf-base script
Signed-off-by: Rohan Dutta <rohadutt@qti.qualcomm.com>
1 parent 8f852a0 commit d524c67

3 files changed

Lines changed: 247 additions & 0 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
metadata:
2+
name: Ftrace-Dump-ETF-Base
3+
format: "Lava-Test Test Definition 1.0"
4+
description: "Validates STM trace data flow to an ETF sink through Ftrace. It ensures correct sink selection and verifies successful trace capture by reading ETF output."
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/Ftrace-Dump-ETF-Base || true
15+
- ./run.sh || true
16+
- $REPO_PATH/Runner/utils/send-to-lava.sh Ftrace-Dump-ETF-Base.res || true
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Ftrace-Dump-ETF-Base
2+
3+
## Overview
4+
The `Ftrace-Dump-ETF-Base` test case validates STM trace data flow to an ETF sink through Ftrace. It ensures correct sink selection and verifies successful trace capture by reading ETF output.
5+
6+
## Test Goals
7+
8+
- Verify that the CoreSight sink correctly switches to ETF mode.
9+
- Validate STM trace data routing to ETF via Ftrace integration.
10+
- Ensure sched_switch events are captured and stored in the ETF buffer.
11+
- Confirm valid trace data generation by checking ETF output size.
12+
13+
## Prerequisites
14+
15+
- Coresight framework enabled in the kernel
16+
- Multiple Coresight sink devices should be present
17+
- Coresight STM and ETM device nodes for post-test data generation
18+
19+
## Script Location
20+
21+
```
22+
Runner/suites/Kernel/DEBUG/Ftrace-Dump-ETF-Base/run.sh
23+
```
24+
25+
## Files
26+
27+
- `run.sh` - Main test script
28+
- `Ftrace-Dump-ETF-Base.res` - Summary result file with PASS/FAIL
29+
- `Ftrace-Dump-ETF-Base.log` - Full execution log.
30+
31+
## How it works
32+
1. Mounts required filesystems, resets all CoreSight sources and sinks, and disables any existing tracing.
33+
2. Enables the ETF sink and verifies that the sink switch to ETF is successful.
34+
3. Connects the STM source to Ftrace and enables sched_switch events as the trace input.
35+
4. Starts tracing, allows the system to run for a fixed duration, then stops tracing.
36+
5. Reads trace data from the ETF device and verifies successful capture by checking the output size.
37+
38+
## Usage
39+
40+
Run the script directly. No iterations or special arguments are required for this basic test.
41+
42+
```bash
43+
./run.sh
44+
```
45+
46+
## Example Output
47+
48+
```
49+
[INFO] 2026-04-06 06:19:42 - ---------------------------Ftrace-Dump-ETF-Base Starting---------------------------
50+
[INFO] 2026-04-06 06:19:42 - Using Source: stm0, Sink: tmc_etf0
51+
[INFO] 2026-04-06 06:19:42 - PASS: sink switch to tmc_etf0 successful
52+
[INFO] 2026-04-06 06:19:42 - Linking Ftrace to stm0...
53+
[INFO] 2026-04-06 06:20:03 - Collected bin size: 65536 bytes
54+
[INFO] 2026-04-06 06:20:03 - PASS: tmc_etf0 sink data through Ftrace verified
55+
[INFO] 2026-04-06 06:20:03 - ---------------------------Ftrace-Dump-ETF-Base Finished---------------------------
56+
```
57+
58+
## Return Code
59+
60+
- `0` — All stress test cases passed
61+
- `1` — One or more stress test cases failed
62+
63+
## Integration in CI
64+
65+
- Can be run standalone or via LAVA
66+
- Result file `Ftrace-Dump-ETF-Base.res` will be parsed by `result_parse.sh`
67+
68+
## Notes
69+
70+
- The test relies on Ftrace sched_switch events as the trace data source.
71+
- The test will stop and flag a failure as soon as any sink remains enabled after reset, ensuring strict correctness.
72+
73+
## License
74+
75+
SPDX-License-Identifier: BSD-3-Clause.
76+
(c) Qualcomm Technologies, Inc. and/or its subsidiaries.
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
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+
__INIT_ENV_LOADED=1
26+
fi
27+
28+
# shellcheck disable=SC1090,SC1091
29+
. "$TOOLS/functestlib.sh"
30+
# shellcheck disable=SC1090,SC1091
31+
. "$TOOLS/coresight_helper.sh"
32+
33+
TESTNAME="Ftrace-Dump-ETF-Base"
34+
test_path=$(find_test_case_by_name "$TESTNAME")
35+
cd "$test_path" || exit 1
36+
res_file="./$TESTNAME.res"
37+
log_info "---------------------------$TESTNAME Starting---------------------------"
38+
39+
cs_base="/sys/bus/coresight/devices"
40+
debugfs="/sys/kernel/debug"
41+
[ ! -d "$debugfs/tracing" ] && debugfs="/debug"
42+
43+
fail=0
44+
45+
if [ ! -d "$cs_base" ]; then
46+
log_warn "Coresight directory $cs_base not found. Skipping test."
47+
echo "$TESTNAME SKIP" > "$res_file"
48+
exit 0
49+
fi
50+
51+
trap cleanup EXIT HUP INT TERM
52+
53+
cleanup
54+
55+
stm_path=""
56+
for stm_node in "$cs_base"/*stm*; do
57+
if [ -d "$stm_node" ] && [ -f "$stm_node/enable_source" ]; then
58+
stm_path="$stm_node"
59+
break
60+
fi
61+
done
62+
63+
if [ -z "$stm_path" ]; then
64+
log_warn "No valid STM source found in $cs_base. Skipping test."
65+
echo "$TESTNAME SKIP" > "$res_file"
66+
exit 0
67+
fi
68+
69+
sink_path=""
70+
for sink_node in "$cs_base"/*; do
71+
[ ! -d "$sink_node" ] && continue
72+
[ "$(basename "$sink_node")" = "tmc_etf1" ] && continue
73+
74+
if [ -f "$sink_node/enable_sink" ]; then
75+
sink_path="$sink_node"
76+
break
77+
fi
78+
done
79+
80+
if [ -z "$sink_path" ]; then
81+
log_warn "No valid Sink found in $cs_base. Skipping test."
82+
echo "$TESTNAME SKIP" > "$res_file"
83+
exit 0
84+
fi
85+
86+
sink_name="$(basename "$sink_path")"
87+
stm_name="$(basename "$stm_path")"
88+
89+
if [ ! -c "/dev/$sink_name" ]; then
90+
log_warn "Character device /dev/$sink_name not found for data read. Skipping test."
91+
echo "$TESTNAME SKIP" > "$res_file"
92+
exit 0
93+
fi
94+
95+
ftrace_link="/sys/class/stm_source/ftrace/stm_source_link"
96+
if [ ! -f "$ftrace_link" ]; then
97+
log_warn "Ftrace STM source link capability missing at $ftrace_link. Skipping test."
98+
echo "$TESTNAME SKIP" > "$res_file"
99+
exit 0
100+
fi
101+
102+
log_info "Using Source: $stm_name, Sink: $sink_name"
103+
104+
[ -f "$stm_path/hwevent_enable" ] && echo 0 > "$stm_path/hwevent_enable" 2>/dev/null
105+
[ -f "$stm_path/port_enable" ] && echo 0xffffffff > "$stm_path/port_enable" 2>/dev/null
106+
107+
echo 1 > "$sink_path/enable_sink" 2>/dev/null
108+
109+
ret=$(tr -d ' ' < "$sink_path/enable_sink" 2>/dev/null)
110+
111+
if [ "$ret" = "1" ]; then
112+
log_info "PASS: sink switch to $sink_name successful"
113+
else
114+
log_fail "FAIL: sink switch to $sink_name failed"
115+
fail=1
116+
fi
117+
118+
if [ "$fail" -eq 0 ]; then
119+
log_info "Linking Ftrace to $stm_name..."
120+
echo "$stm_name" > "$ftrace_link" 2>/dev/null
121+
122+
[ -f "$debugfs/tracing/tracing_on" ] && echo 1 > "$debugfs/tracing/tracing_on"
123+
[ -f "$debugfs/tracing/events/sched/sched_switch/enable" ] && echo 1 > "$debugfs/tracing/events/sched/sched_switch/enable"
124+
125+
echo 1 > "$stm_path/enable_source" 2>/dev/null
126+
127+
sleep 20
128+
129+
cleanup
130+
131+
trace_file="/tmp/${sink_name}_ftrace.bin"
132+
rm -f "$trace_file"
133+
134+
cat "/dev/$sink_name" > "$trace_file" 2>/dev/null
135+
136+
bin_size=$(wc -c < "$trace_file" 2>/dev/null | tr -d ' ')
137+
[ -z "$bin_size" ] && bin_size=0
138+
139+
log_info "Collected bin size: $bin_size bytes"
140+
141+
if [ -f "$trace_file" ] && [ "$bin_size" -ge 65536 ]; then
142+
log_pass "PASS: $sink_name sink data through Ftrace verified"
143+
else
144+
log_fail "FAIL: $sink_name sink data through Ftrace insufficient or missing"
145+
fail=1
146+
fi
147+
fi
148+
149+
if [ "$fail" -eq 0 ]; then
150+
echo "$TESTNAME PASS" > "$res_file"
151+
else
152+
echo "$TESTNAME FAIL" > "$res_file"
153+
fi
154+
155+
log_info "---------------------------$TESTNAME Finished---------------------------"

0 commit comments

Comments
 (0)