diff --git a/Runner/suites/Kernel/DEBUG/Ftrace-Dump-ETF-Base/Ftrace-Dump-ETF-Base.yaml b/Runner/suites/Kernel/DEBUG/Ftrace-Dump-ETF-Base/Ftrace-Dump-ETF-Base.yaml new file mode 100644 index 00000000..579e55c8 --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/Ftrace-Dump-ETF-Base/Ftrace-Dump-ETF-Base.yaml @@ -0,0 +1,16 @@ +metadata: + name: Ftrace-Dump-ETF-Base + format: "Lava-Test Test Definition 1.0" + 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." + os: + - linux + scope: + - coresight + - kernel + +run: + steps: + - REPO_PATH=$PWD || true + - cd Runner/suites/Kernel/DEBUG/Ftrace-Dump-ETF-Base || true + - ./run.sh || true + - $REPO_PATH/Runner/utils/send-to-lava.sh Ftrace-Dump-ETF-Base.res || true \ No newline at end of file diff --git a/Runner/suites/Kernel/DEBUG/Ftrace-Dump-ETF-Base/README.md b/Runner/suites/Kernel/DEBUG/Ftrace-Dump-ETF-Base/README.md new file mode 100644 index 00000000..cef1260b --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/Ftrace-Dump-ETF-Base/README.md @@ -0,0 +1,76 @@ +# Ftrace-Dump-ETF-Base + +## Overview +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. + +## Test Goals + +- Verify that the CoreSight sink correctly switches to ETF mode. +- Validate STM trace data routing to ETF via Ftrace integration. +- Ensure sched_switch events are captured and stored in the ETF buffer. +- Confirm valid trace data generation by checking ETF output size. + +## Prerequisites + +- Coresight framework enabled in the kernel +- Multiple Coresight sink devices should be present +- Coresight STM and ETM device nodes for post-test data generation + +## Script Location + +``` +Runner/suites/Kernel/DEBUG/Ftrace-Dump-ETF-Base/run.sh +``` + +## Files + +- `run.sh` - Main test script +- `Ftrace-Dump-ETF-Base.res` - Summary result file with PASS/FAIL +- `Ftrace-Dump-ETF-Base.log` - Full execution log. + +## How it works +1. Mounts required filesystems, resets all CoreSight sources and sinks, and disables any existing tracing. +2. Enables the ETF sink and verifies that the sink switch to ETF is successful. +3. Connects the STM source to Ftrace and enables sched_switch events as the trace input. +4. Starts tracing, allows the system to run for a fixed duration, then stops tracing. +5. Reads trace data from the ETF device and verifies successful capture by checking the output size. + +## Usage + +Run the script directly. No iterations or special arguments are required for this basic test. + +```bash +./run.sh +``` + +## Example Output + +``` +[INFO] 2026-04-06 06:19:42 - ---------------------------Ftrace-Dump-ETF-Base Starting--------------------------- +[INFO] 2026-04-06 06:19:42 - Using Source: stm0, Sink: tmc_etf0 +[INFO] 2026-04-06 06:19:42 - PASS: sink switch to tmc_etf0 successful +[INFO] 2026-04-06 06:19:42 - Linking Ftrace to stm0... +[INFO] 2026-04-06 06:20:03 - Collected bin size: 65536 bytes +[INFO] 2026-04-06 06:20:03 - PASS: tmc_etf0 sink data through Ftrace verified +[INFO] 2026-04-06 06:20:03 - ---------------------------Ftrace-Dump-ETF-Base Finished--------------------------- +``` + +## Return Code + +- `0` — All stress test cases passed +- `1` — One or more stress test cases failed + +## Integration in CI + +- Can be run standalone or via LAVA +- Result file `Ftrace-Dump-ETF-Base.res` will be parsed by `result_parse.sh` + +## Notes + +- The test relies on Ftrace sched_switch events as the trace data source. +- The test will stop and flag a failure as soon as any sink remains enabled after reset, ensuring strict correctness. + +## License + +SPDX-License-Identifier: BSD-3-Clause. +(c) Qualcomm Technologies, Inc. and/or its subsidiaries. \ No newline at end of file diff --git a/Runner/suites/Kernel/DEBUG/Ftrace-Dump-ETF-Base/run.sh b/Runner/suites/Kernel/DEBUG/Ftrace-Dump-ETF-Base/run.sh new file mode 100755 index 00000000..3923febb --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/Ftrace-Dump-ETF-Base/run.sh @@ -0,0 +1,155 @@ +#!/bin/sh + +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. +# SPDX-License-Identifier: BSD-3-Clause + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +INIT_ENV="" +SEARCH="$SCRIPT_DIR" +while [ "$SEARCH" != "/" ]; do + if [ -f "$SEARCH/init_env" ]; then + INIT_ENV="$SEARCH/init_env" + break + fi + SEARCH=$(dirname "$SEARCH") +done + +if [ -z "$INIT_ENV" ]; then + echo "[ERROR] Could not find init_env" >&2 + exit 1 +fi + +if [ -z "$__INIT_ENV_LOADED" ]; then + # shellcheck disable=SC1090 + . "$INIT_ENV" + __INIT_ENV_LOADED=1 +fi + +# shellcheck disable=SC1090,SC1091 +. "$TOOLS/functestlib.sh" +# shellcheck disable=SC1090,SC1091 +. "$TOOLS/coresight_helper.sh" + +TESTNAME="Ftrace-Dump-ETF-Base" +test_path=$(find_test_case_by_name "$TESTNAME") +cd "$test_path" || exit 1 +res_file="./$TESTNAME.res" +log_info "---------------------------$TESTNAME Starting---------------------------" + +cs_base="/sys/bus/coresight/devices" +debugfs="/sys/kernel/debug" +[ ! -d "$debugfs/tracing" ] && debugfs="/debug" + +fail=0 + +if [ ! -d "$cs_base" ]; then + log_warn "Coresight directory $cs_base not found. Skipping test." + echo "$TESTNAME SKIP" > "$res_file" + exit 0 +fi + +trap cleanup EXIT HUP INT TERM + +cleanup + +stm_path="" +for stm_node in "$cs_base"/*stm*; do + if [ -d "$stm_node" ] && [ -f "$stm_node/enable_source" ]; then + stm_path="$stm_node" + break + fi +done + +if [ -z "$stm_path" ]; then + log_warn "No valid STM source found in $cs_base. Skipping test." + echo "$TESTNAME SKIP" > "$res_file" + exit 0 +fi + +sink_path="" +for sink_node in "$cs_base"/*; do + [ ! -d "$sink_node" ] && continue + [ "$(basename "$sink_node")" = "tmc_etf1" ] && continue + + if [ -f "$sink_node/enable_sink" ]; then + sink_path="$sink_node" + break + fi +done + +if [ -z "$sink_path" ]; then + log_warn "No valid Sink found in $cs_base. Skipping test." + echo "$TESTNAME SKIP" > "$res_file" + exit 0 +fi + +sink_name="$(basename "$sink_path")" +stm_name="$(basename "$stm_path")" + +if [ ! -c "/dev/$sink_name" ]; then + log_warn "Character device /dev/$sink_name not found for data read. Skipping test." + echo "$TESTNAME SKIP" > "$res_file" + exit 0 +fi + +ftrace_link="/sys/class/stm_source/ftrace/stm_source_link" +if [ ! -f "$ftrace_link" ]; then + log_warn "Ftrace STM source link capability missing at $ftrace_link. Skipping test." + echo "$TESTNAME SKIP" > "$res_file" + exit 0 +fi + +log_info "Using Source: $stm_name, Sink: $sink_name" + +[ -f "$stm_path/hwevent_enable" ] && echo 0 > "$stm_path/hwevent_enable" 2>/dev/null +[ -f "$stm_path/port_enable" ] && echo 0xffffffff > "$stm_path/port_enable" 2>/dev/null + +echo 1 > "$sink_path/enable_sink" 2>/dev/null + +ret=$(tr -d ' ' < "$sink_path/enable_sink" 2>/dev/null) + +if [ "$ret" = "1" ]; then + log_info "PASS: sink switch to $sink_name successful" +else + log_fail "FAIL: sink switch to $sink_name failed" + fail=1 +fi + +if [ "$fail" -eq 0 ]; then + log_info "Linking Ftrace to $stm_name..." + echo "$stm_name" > "$ftrace_link" 2>/dev/null + + [ -f "$debugfs/tracing/tracing_on" ] && echo 1 > "$debugfs/tracing/tracing_on" + [ -f "$debugfs/tracing/events/sched/sched_switch/enable" ] && echo 1 > "$debugfs/tracing/events/sched/sched_switch/enable" + + echo 1 > "$stm_path/enable_source" 2>/dev/null + + sleep 20 + + cleanup + + trace_file="/tmp/${sink_name}_ftrace.bin" + rm -f "$trace_file" + + cat "/dev/$sink_name" > "$trace_file" 2>/dev/null + + bin_size=$(wc -c < "$trace_file" 2>/dev/null | tr -d ' ') + [ -z "$bin_size" ] && bin_size=0 + + log_info "Collected bin size: $bin_size bytes" + + if [ -f "$trace_file" ] && [ "$bin_size" -ge 65536 ]; then + log_pass "PASS: $sink_name sink data through Ftrace verified" + else + log_fail "FAIL: $sink_name sink data through Ftrace insufficient or missing" + fail=1 + fi +fi + +if [ "$fail" -eq 0 ]; then + echo "$TESTNAME PASS" > "$res_file" +else + echo "$TESTNAME FAIL" > "$res_file" +fi + +log_info "---------------------------$TESTNAME Finished---------------------------"