diff --git a/Runner/suites/Kernel/DEBUG/TPDM-Integration-Test/README.md b/Runner/suites/Kernel/DEBUG/TPDM-Integration-Test/README.md new file mode 100644 index 00000000..26009e40 --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/TPDM-Integration-Test/README.md @@ -0,0 +1,74 @@ +# TPDM Integration Test + +## Overview + +This test acts as an integration validation for the Coresight Trace Port Debug Module (TPDM). It verifies actual trace data generation and routing by artificially injecting data into the TPDM's `integration_test` nodes and confirming that the data successfully reaches the trace sink (ETF) by monitoring its internal Read/Write Pointer (`mgmt/rwp`). + +## Test Goals + +- Verify the end-to-end trace generation and routing capabilities of TPDM devices. +- Inject artificial trace data using the Coresight `integration_test` sysfs nodes. +- Validate that the injected trace data successfully reaches the TMC-ETF sink. +- Confirm success by observing a change in the ETF's `mgmt/rwp` (Read/Write Pointer) register value, which indicates data was written to the FIFO. + +## Prerequisites + +- Kernel must be built with Coresight TPDM and TMC (ETF) support. +- `sysfs` access to `/sys/bus/coresight/devices/`. +- Root privileges (to configure devices and write to `integration_test` nodes). + +## Script Location + +``` +Runner/suites/Kernel/DEBUG/TPDM-Integration-Test/run.sh +``` + +## Files + +- `run.sh` - Main test script +- `TPDM-Integration-Test.res` - Summary result file with PASS/FAIL +- `TPDM-Integration-Test.log` - Full execution log (generated if logging is enabled) + +## How It Works + +1. **Setup**: Resets the Coresight topology to a clean state. +2. **Enable**: Activates the `tmc_etf0` (or available ETF) sink and the target TPDM source. +3. **Baseline**: Reads and stores the initial value of the ETF's `mgmt/rwp` register. +4. **Injection**: Writes dummy/test data to the TPDM's `integration_test` sysfs node to force trace generation. +5. **Verification**: Reads the ETF's `mgmt/rwp` register again. The test passes if the new value is different from the baseline value (proving data flowed into the sink). +6. **Teardown**: Disables the TPDM and ETF devices. + +## Example Output + +``` +[INFO] 2026-03-23 05:33:24 - ------------------------------------------------------ +[INFO] 2026-03-23 05:33:24 - ----- Coresight TPDM integration Test Starting ----- +[INFO] 2026-03-23 05:33:24 - tpdm0 Integration Test Start +[INFO] 2026-03-23 05:33:24 - tpdm0 Integration Test PASS +[INFO] 2026-03-23 05:33:24 - tpdm1 Integration Test Start +[INFO] 2026-03-23 05:33:24 - tpdm1 Integration Test PASS +.... +[INFO] 2026-03-23 05:33:24 - tpdm9 Integration Test Start +[INFO] 2026-03-23 05:33:24 - tpdm9 Integration Test PASS +[PASS] 2026-03-23 05:33:24 - -----PASS: All TPDM devices integration test----- +[INFO] 2026-03-23 05:33:24 - -------------------TPDM-Integration-Test Testcase Finished---------------------------- +``` + +## Return Code + +- `0` — The `mgmt/rwp` value changed successfully after data injection (PASS) +- `1` — The `mgmt/rwp` value did not change, indicating trace data was lost or not generated (FAIL) + +## Integration in CI + +- Can be run standalone or via LAVA +- Result file `TPDM-Integration-Test.res` will be parsed by `result_parse.sh` + +## Notes + +- The `mgmt/rwp` (Read/Write Pointer) is a hardware register in the Trace Memory Controller (TMC) that increments as trace data is written into its SRAM/FIFO. Checking this register is a reliable, lightweight way to verify data flow without needing to dump and parse the entire binary trace buffer. + +## License + +SPDX-License-Identifier: BSD-3-Clause-Clear +(c) Qualcomm Technologies, Inc. and/or its subsidiaries. \ No newline at end of file diff --git a/Runner/suites/Kernel/DEBUG/TPDM-Integration-Test/TPDM-Integration-Test.yaml b/Runner/suites/Kernel/DEBUG/TPDM-Integration-Test/TPDM-Integration-Test.yaml new file mode 100644 index 00000000..0d7406f9 --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/TPDM-Integration-Test/TPDM-Integration-Test.yaml @@ -0,0 +1,16 @@ +metadata: + name: TPDM-Integration-Test + format: "Lava-Test Test Definition 1.0" + description: "Coresight TPDM integration test script to verify trace generation by writing to integration_test nodes and verifying the ETF mgmt/rwp changes." + os: + - linux + scope: + - coresight + - kernel + +run: + steps: + - REPO_PATH=$PWD || true + - cd Runner/suites/Kernel/DEBUG/TPDM-Integration-Test || true + - ./run.sh || true + - $REPO_PATH/Runner/utils/send-to-lava.sh TPDM-Integration-Test.res || true \ No newline at end of file diff --git a/Runner/suites/Kernel/DEBUG/TPDM-Integration-Test/run.sh b/Runner/suites/Kernel/DEBUG/TPDM-Integration-Test/run.sh new file mode 100755 index 00000000..05a509c0 --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/TPDM-Integration-Test/run.sh @@ -0,0 +1,125 @@ +#!/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="TPDM-Integration-Test" +res_file="./$TESTNAME.res" +log_info "-----------------------------------------------------------------------------------------" +log_info "-------------------Starting $TESTNAME Testcase----------------------------" +cs_base="/sys/bus/coresight/devices" + +etf_path=$(find_path "tmc_etf0" "tmc_etf" "tmc_etf1" "coresight-tmc_etf" "coresight-tmc_etf0") +if [ -z "$etf_path" ]; then + log_fail "TMC-ETF sink not found. Cannot proceed with integration test." + echo "$TESTNAME FAIL" > "$res_file" + exit 1 +fi + +# shellcheck disable=SC2329 +cleanup() { + reset_devices + disable_npu_clocks +} + +trap cleanup EXIT INT TERM + +reset_devices +enable_npu_clocks + +if [ -f "$etf_path/enable_sink" ]; then + echo 1 > "$etf_path/enable_sink" 2>/dev/null +fi + +retval=0 +tpdm_found=0 + +for tpdm_path in "$cs_base"/tpdm* "$cs_base"/coresight-tpdm*; do + [ ! -d "$tpdm_path" ] && continue + tpdm_found=1 + + tpdm_name=$(basename "$tpdm_path") + + if [ ! -f "$tpdm_path/integration_test" ]; then + continue + fi + + log_info "$tpdm_name Integration Test Start" + + if [ -f "$tpdm_path/enable_source" ]; then + echo 1 > "$tpdm_path/enable_source" 2>/dev/null + fi + + pre_rwp="" + if [ -f "$etf_path/mgmt/rwp" ]; then + # shellcheck disable=SC2162 + read -r pre_rwp < "$etf_path/mgmt/rwp" + fi + + i=1 + while [ "$i" -le 10 ]; do + echo 1 > "$tpdm_path/integration_test" 2>/dev/null + echo 2 > "$tpdm_path/integration_test" 2>/dev/null + i=$((i+1)) + done + + curr_rwp="" + if [ -f "$etf_path/mgmt/rwp" ]; then + # shellcheck disable=SC2162 + read -r curr_rwp < "$etf_path/mgmt/rwp" + fi + + if [ -n "$curr_rwp" ] && [ "$curr_rwp" != "$pre_rwp" ]; then + log_info "$tpdm_name Integration Test PASS" + else + log_fail "$tpdm_name Integration Test FAIL" + retval=1 + fi + + if [ -f "$tpdm_path/enable_source" ]; then + echo 0 > "$tpdm_path/enable_source" 2>/dev/null + fi +done + +if [ "$tpdm_found" -eq 0 ]; then + log_fail "FAIL: No TPDM device found" + echo "$TESTNAME FAIL" > "$res_file" + retval=1 +fi + +if [ "$retval" -eq 0 ]; then + log_pass "-----PASS: All TPDM devices integration test-----" + echo "$TESTNAME PASS" > "$res_file" +else + log_fail "----FAIL: Some TPDM devices integration test fail----" + echo "$TESTNAME FAIL" > "$res_file" +fi + +log_info "-------------------$TESTNAME Testcase Finished----------------------------" \ No newline at end of file diff --git a/Runner/suites/Kernel/DEBUG/TPDM-Trace-Sink/README.md b/Runner/suites/Kernel/DEBUG/TPDM-Trace-Sink/README.md new file mode 100644 index 00000000..fc96389b --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/TPDM-Trace-Sink/README.md @@ -0,0 +1,89 @@ +# TPDM-Trace-Sink Test + +## Overview + +This test script evaluates the enabling and disabling sequence of all available Coresight TPDM sources against all available TMC trace sinks. It automatically dumps the raw binary trace data generated by the sink `/dev/` nodes into the `/tmp` directory. It purposefully ignores the `tmc_etf1` sink and `tpdm-turing-llm` source. + +## Test Goals + +- Evaluate the enabling and disabling sequence of Coresight TPDM sources against TMC sinks. +- Verify that `enable_source` sysfs nodes accurately reflect read/write state transitions. +- Ensure raw binary trace data can be successfully captured from the sink's character device node by validating the generation of a non-empty trace file. +- Validate stability across multiple iterations for all compatible source/sink device pairs. + +## Prerequisites + +- Kernel must be built with Coresight TPDM and TMC support. +- `sysfs` access to `/sys/bus/coresight/devices/`. +- Access to read from sink character devices (e.g., `/dev/tmc_etf0`). +- Root privileges (to configure Coresight devices and read trace data). + +## Script Location + +``` +Runner/suites/Kernel/DEBUG/TPDM-Trace-Sink/run.sh +``` + +## Files + +- `run.sh` - Main test script +- `TPDM-Trace-Sink.res` - Summary result file with PASS/FAIL +- `TPDM-Trace-Sink.log` - Full execution log (generated if logging is enabled) + +## How It Works + +1. **Iterations**: Runs the entire evaluation loop 2 times (loop 0 and 1). +2. **Discovery**: + - Discovers all TMC sinks (`/sys/bus/coresight/devices/tmc_et*`), explicitly ignoring `tmc_etf1`. + - Discovers all TPDM sources (`/sys/bus/coresight/devices/tpdm*`), explicitly ignoring `tpdm-turing-llm`. +3. **Execution Loop** (For each compatible Sink <-> Source pair): + - Executes `reset_source_sink` to cleanly clear out active sources and sinks. + - Enables the current TMC trace sink by writing `1` to `enable_sink`. + - Enables the current TPDM source by writing `1` to `enable_source`. + - Verifies that reading from the TPDM's `enable_source` returns `1`. + - Reads the trace payload from `/dev/` and redirects it to `/tmp/.bin`. + - Disables the current TPDM source by writing `0` to `enable_source`. + - Verifies that reading from the TPDM's `enable_source` returns `0`. +4. **Teardown**: Performs a final `reset_source_sink` to clean up the environment post-testing. + +## Example Output + +``` +[INFO] 2026-03-23 06:16:46 - ----------------------------------------------------------------------------------------- +[INFO] 2026-03-23 06:16:46 - -------------------Starting TPDM-Trace-Sink Testcase---------------------------- +[INFO] 2026-03-23 06:16:46 - Performing initial device reset... +[INFO] 2026-03-23 06:16:46 - [Iteration 0] Starting sink evaluation... +[INFO] 2026-03-23 06:16:46 - Testing Sink: tmc_etf0 +[INFO] 2026-03-23 06:16:46 - Enabled source: tpdm0 +[INFO] 2026-03-23 06:16:47 - Enabled source: tpdm1 +[INFO] 2026-03-23 06:16:48 - Enabled source: tpdm10 +[INFO] 2026-03-23 06:16:49 - Enabled source: tpdm2 +[INFO] 2026-03-23 06:16:50 - Enabled source: tpdm3 +....... +[INFO] 2026-03-23 06:17:50 - Enabled source: tpdm5 +[INFO] 2026-03-23 06:17:51 - Enabled source: tpdm6 +[INFO] 2026-03-23 06:17:52 - Enabled source: tpdm7 +[INFO] 2026-03-23 06:17:53 - Enabled source: tpdm8 +[INFO] 2026-03-23 06:17:54 - Enabled source: tpdm9 +[PASS] 2026-03-23 06:17:55 - TPDM-Trace-Sink: PASS +[INFO] 2026-03-23 06:17:55 - -------------------TPDM-Trace-Sink Testcase Finished---------------------------- +``` + +## Return Code + +- `0` — All iterations and compatible device pairs successfully wrote/verified states and the fail flag remained `0` +- `1` — A failure occurred during enablement, disablement, verification, or trace data capture + +## Integration in CI + +- Can be run standalone or via LAVA +- Result file `TPDM-Trace-Sink.res` will be parsed by `result_parse.sh` + +## Notes + +- `tmc_etf1` and `tpdm-turing-llm` are hardcoded to be ignored in this specific test script to prevent known incompatibilities or access violations. + +## License + +SPDX-License-Identifier: BSD-3-Clause-Clear +(c) Qualcomm Technologies, Inc. and/or its subsidiaries. \ No newline at end of file diff --git a/Runner/suites/Kernel/DEBUG/TPDM-Trace-Sink/TPDM-Trace-Sink.yaml b/Runner/suites/Kernel/DEBUG/TPDM-Trace-Sink/TPDM-Trace-Sink.yaml new file mode 100644 index 00000000..9c2ef6d9 --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/TPDM-Trace-Sink/TPDM-Trace-Sink.yaml @@ -0,0 +1,16 @@ +metadata: + name: TPDM-Trace-Sink + format: "Lava-Test Test Definition 1.0" + description: "Iterates over available TMC trace sinks (excluding tmc_etf1) and TPDM sources (excluding turing-llm), enables them, dumps sink trace data to /tmp, and safely disables them." + os: + - linux + scope: + - coresight + - kernel + +run: + steps: + - REPO_PATH=$PWD || true + - cd Runner/suites/Kernel/DEBUG/TPDM-Trace-Sink || true + - ./run.sh || true + - $REPO_PATH/Runner/utils/send-to-lava.sh TPDM-Trace-Sink.res || true \ No newline at end of file diff --git a/Runner/suites/Kernel/DEBUG/TPDM-Trace-Sink/run.sh b/Runner/suites/Kernel/DEBUG/TPDM-Trace-Sink/run.sh new file mode 100755 index 00000000..42931130 --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/TPDM-Trace-Sink/run.sh @@ -0,0 +1,150 @@ +#!/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="TPDM-Trace-Sink" +res_file="./$TESTNAME.res" +log_info "-----------------------------------------------------------------------------------------" +log_info "-------------------Starting $TESTNAME Testcase----------------------------" +cs_base="/sys/bus/coresight/devices" + +# shellcheck disable=SC2329 +cleanup() { + reset_devices + disable_npu_clocks +} +trap cleanup EXIT INT TERM + +fail=0 +sink_found=0 +tpdm_found=0 +i=0 + +log_info "Performing initial device reset..." +reset_devices +enable_npu_clocks + +while [ "$i" -le 1 ]; do + log_info "[Iteration $i] Starting sink evaluation..." + + for sink_path in "$cs_base"/tmc_et* "$cs_base"/coresight-tmc_et*; do + [ ! -d "$sink_path" ] && continue + + sink_dev=$(basename "$sink_path") + + if [ "$sink_dev" = "tmc_etf1" ] || [ "$sink_dev" = "coresight-tmc_etf1" ]; then + continue + fi + + sink_found=$((sink_found + 1)) + log_info "Testing Sink: $sink_dev" + + if [ -f "$sink_path/enable_sink" ]; then + echo 1 > "$sink_path/enable_sink" 2>/dev/null + fi + + for node_path in "$cs_base"/tpdm* "$cs_base"/coresight-tpdm*; do + [ ! -d "$node_path" ] && continue + + node_name=$(basename "$node_path") + + if echo "$node_name" | grep -q "tpdm-turing-llm"; then + continue + fi + + if [ ! -f "$node_path/enable_source" ]; then + continue + fi + + tpdm_found=$((tpdm_found + 1)) + + echo 1 > "$node_path/enable_source" 2>/dev/null + res=$(cat "$node_path/enable_source" 2>/dev/null) + + if [ "$res" != "1" ]; then + log_fail "Failed to enable source: $node_name" + fail=1 + else + log_info "Enabled source: $node_name" + fi + + sleep 1 + trace_file="/tmp/${sink_dev}_${node_name}.bin" + + if [ -c "/dev/$sink_dev" ]; then + cat "/dev/$sink_dev" > "$trace_file" 2>/dev/null + + if [ -s "$trace_file" ]; then + log_info "Trace validation PASS" + else + log_fail "Trace validation FAIL" + fail=1 + fi + else + log_fail "/dev/$sink_dev character device not found!" + fail=1 + fi + + echo 0 > "$node_path/enable_source" 2>/dev/null + res=$(cat "$node_path/enable_source" 2>/dev/null) + + if [ "$res" = "1" ]; then + log_fail "Failed to disable source: $node_name" + fail=1 + fi + done + + if [ -f "$sink_path/enable_sink" ]; then + echo 0 > "$sink_path/enable_sink" 2>/dev/null + fi + done + i=$((i+1)) +done + +if [ "$sink_found" -eq 0 ]; then + log_fail "No valid TMC sinks found!" + fail=1 +fi + +if [ "$tpdm_found" -eq 0 ]; then + log_fail "No valid TPDM sources found!" + fail=1 +fi + +if [ "$fail" -eq 0 ]; then + log_pass "$TESTNAME: PASS" + echo "$TESTNAME PASS" > "$res_file" +else + log_fail "$TESTNAME: FAIL" + echo "$TESTNAME FAIL" > "$res_file" +fi + +log_info "-------------------$TESTNAME Testcase Finished----------------------------" \ No newline at end of file diff --git a/Runner/utils/coresight_helper.sh b/Runner/utils/coresight_helper.sh new file mode 100755 index 00000000..10aa1fa0 --- /dev/null +++ b/Runner/utils/coresight_helper.sh @@ -0,0 +1,40 @@ +#!/bin/sh + +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. +# SPDX-License-Identifier: BSD-3-Clause + +export CS_BASE="/sys/bus/coresight/devices" + +find_path() { + for _dir_name in "$@"; do + if [ -d "$CS_BASE/$_dir_name" ]; then + echo "$CS_BASE/$_dir_name" + return 0 + fi + done + echo "" +} + +reset_devices() { + for node in "$CS_BASE"/*; do + [ -d "$node" ] || continue + [ -f "$node/enable_source" ] && echo 0 > "$node/enable_source" 2>/dev/null + [ -f "$node/enable_sink" ] && echo 0 > "$node/enable_sink" 2>/dev/null + done +} + +enable_npu_clocks() { + if [ -f "/sys/kernel/debug/npu/ctrl" ]; then + echo on > "/sys/kernel/debug/npu/ctrl" 2>/dev/null + elif [ -f "/d/npu/ctrl" ]; then + echo on > "/d/npu/ctrl" 2>/dev/null + fi +} + +disable_npu_clocks() { + if [ -f "/sys/kernel/debug/npu/ctrl" ]; then + echo off > "/sys/kernel/debug/npu/ctrl" 2>/dev/null + elif [ -f "/d/npu/ctrl" ]; then + echo off > "/d/npu/ctrl" 2>/dev/null + fi +} \ No newline at end of file