Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions Runner/suites/Kernel/DEBUG/TPDM-Integration-Test/README.md
Original file line number Diff line number Diff line change
@@ -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/FunctionalArea/coresight/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.
Original file line number Diff line number Diff line change
@@ -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
147 changes: 147 additions & 0 deletions Runner/suites/Kernel/DEBUG/TPDM-Integration-Test/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
#!/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"
fi

# shellcheck disable=SC1090,SC1091
. "$TOOLS/functestlib.sh"

TESTNAME="TPDM-Integration-Test"
res_file="./$TESTNAME.res"
log_info "-----------------------------------------------------------------------------------------"
log_info "-------------------Starting $TESTNAME Testcase----------------------------"
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 ""
}

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

NPU_CLK="/d/npu/ctrl"
[ ! -f "$NPU_CLK" ] && NPU_CLK="/sys/kernel/debug/npu/ctrl"

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
}

# shellcheck disable=SC2329
cleanup() {
reset_devices
if [ -f "$NPU_CLK" ]; then
echo off > "$NPU_CLK" 2>/dev/null
fi
}

trap cleanup EXIT INT TERM

reset_devices

if [ -f "$NPU_CLK" ]; then
echo on > "$NPU_CLK" 2>/dev/null
fi

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"
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----------------------------"
89 changes: 89 additions & 0 deletions Runner/suites/Kernel/DEBUG/TPDM-Trace-Sink/README.md
Original file line number Diff line number Diff line change
@@ -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 read from the sink's character device node.
- 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/FunctionalArea/coresight/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/<sink_dev>` and redirects it to `/tmp/<sink_dev>.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.
16 changes: 16 additions & 0 deletions Runner/suites/Kernel/DEBUG/TPDM-Trace-Sink/TPDM-Trace-Sink.yaml
Original file line number Diff line number Diff line change
@@ -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
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.