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
88 changes: 88 additions & 0 deletions Runner/suites/Kernel/DEBUG/TPDM-Enable-Disable/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# TPDM-Enable-Disable Test

## Overview

This test acts as a stress test for the Coresight Trace Port Debug Module (TPDM) drivers. It repeatedly enables and disables all available TPDM sources to verify the stability and correctness of the toggling mechanism under repeated stress.

## Test Goals

- Validate the stability of the TPDM drivers under repeated enable/disable cycles.
- Ensure all TPDM sources can be successfully toggled without causing system hangs or crashes.
- Verify that sysfs states correctly reflect the enabled/disabled status across multiple rapid transitions.
- Ensure 100% success rate across 50 iterations for pass criteria.

## Prerequisites

- Kernel must be built with Coresight TPDM support.
- `sysfs` access to `/sys/bus/coresight/devices/`.
- Root privileges (to configure source enables).

## Script Location

Runner/suites/Kernel/DEBUG/TPDM-Enable-Disable/run.sh


## Files

- `run.sh` - Main test script
- `TPDM-Enable-Disable.res` - Summary result file with PASS/FAIL
- `TPDM-Enable-Disable.log` - Full execution log (generated if logging is enabled)

## How It Works

1. **Discovery**: Scans `/sys/bus/coresight/devices/` for all available TPDM devices (e.g., `tpdm*`).
2. **Setup**: Resets all Coresight devices to ensure a clean state.
3. **Loop (50 Iterations)**:
- **Enable**: Attempts to enable each discovered TPDM device.
- **Verify**: Confirms the device successfully transitioned to the enabled state.
- **Disable**: Attempts to disable each TPDM device.
- **Verify**: Confirms the device successfully transitioned to the disabled state.
4. **Teardown**: Ensures all devices are left in a disabled, clean state.

## Usage

Run the script directly via the framework:

```bash
./run.sh
```

## Example Output

```
[INFO] 2026-03-23 05:42:18 - -----------------------------------------------------------------------------------------
[INFO] 2026-03-23 05:42:18 - -------------------Starting TPDM-Enable-Disable Testcase----------------------------
[INFO] 2026-03-23 05:42:18 - Iteration: 0 - PASS
[INFO] 2026-03-23 05:42:19 - Iteration: 1 - PASS
[INFO] 2026-03-23 05:42:19 - Iteration: 2 - PASS
[INFO] 2026-03-23 05:42:20 - Iteration: 3 - PASS
[INFO] 2026-03-23 05:42:20 - Iteration: 4 - PASS
.....
[INFO] 2026-03-23 05:42:38 - Iteration: 49 - PASS
[INFO] 2026-03-23 05:42:39 - Iteration: 50 - PASS
[PASS] 2026-03-23 05:42:39 - -------------enable/disable TPDMs Test PASS-------------
[INFO] 2026-03-23 05:42:39 - -------------------TPDM-Enable-Disable Testcase Finished----------------------------
```

## Return Code

- `0` — All 50 iterations successfully enabled and disabled the TPDM sources
- `1` — One or more iterations failed to toggle a source or verify its state

## Integration in CI

- Can be run standalone or via LAVA

- Result file TPDM-Enable-Disable.res will be parsed by result_parse.sh

## Notes

- The test performs exactly 50 iterations specifically to catch intermittent concurrency bugs or resource leaks in the driver's enable/disable path.

- A failure in any single iteration immediately flags the overall test run as a failure.

## 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-Enable-Disable
format: "Lava-Test Test Definition 1.0"
description: "Script to repeatedly enable and disable all TPDM coresight sources and verify their status."
os:
- linux
scope:
- coresight
- kernel

run:
steps:
- REPO_PATH=$PWD || true
- cd Runner/suites/Kernel/DEBUG/TPDM-Enable-Disable || true
- ./run.sh || true
- $REPO_PATH/Runner/utils/send-to-lava.sh TPDM-Enable-Disable.res || true
131 changes: 131 additions & 0 deletions Runner/suites/Kernel/DEBUG/TPDM-Enable-Disable/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
#!/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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the unset-safe/idempotent repo pattern here:

if [ -z "${__INIT_ENV_LOADED:-}" ]; then
    . "$INIT_ENV"
    __INIT_ENV_LOADED=1
fi

The current form expands "$__INIT_ENV_LOADED" directly and does not set the marker after sourcing.

# shellcheck disable=SC1090
. "$INIT_ENV"
fi

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

TESTNAME="TPDM-Enable-Disable"
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."
echo "$TESTNAME FAIL" > "$res_file"
exit 1
fi

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

find_path() and reset_devices() logic is duplicated across multiple new TPDM runners. There does not appear to be an existing CoreSight/TPDM helper in the common libs today, but the duplication is already visible across this PR. Please consider moving the shared CoreSight helpers (sink discovery, source/sink reset, optional NPU clock control) into functestlib.sh or a dedicated shared helper file rather than open-coding them four times.

done
}

tpdm_count=0
for node_path in "$CS_BASE"/tpdm* "$CS_BASE"/coresight-tpdm*; do
[ -d "$node_path" ] && tpdm_count=$((tpdm_count + 1))
done

if [ "$tpdm_count" -eq 0 ]; then
log_fail "No TPDM devices found on the system."
echo "$TESTNAME FAIL" > "$res_file"
exit 1
fi

fail=0
i=0

reset_devices

[ -f "$ETF_PATH/enable_sink" ] && echo 1 > "$ETF_PATH/enable_sink" 2>/dev/null

while [ "$i" -le 50 ]; do
iter_fail=0

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

echo 1 > "$node_path/enable_source" 2>/dev/null
if [ "$(cat "$node_path/enable_source" 2>/dev/null)" != "1" ]; then
iter_fail=1
log_fail "Iter $i: Failed to enable $node_name"
echo "$TESTNAME FAIL" > "$res_file"
fi

echo 0 > "$node_path/enable_source" 2>/dev/null
if [ "$(cat "$node_path/enable_source" 2>/dev/null)" = "1" ]; then
iter_fail=1
log_fail "Iter $i: Failed to disable $node_name"
echo "$TESTNAME FAIL" > "$res_file"
fi
done

if [ "$iter_fail" -eq 0 ]; then
log_info "Iteration: $i - PASS"
else
log_fail "Iteration: $i - FAIL"
fail=1
fi

i=$((i+1))
done

[ -f "$ETF_PATH/enable_sink" ] && echo 0 > "$ETF_PATH/enable_sink" 2>/dev/null
reset_devices

if [ "$fail" -eq 0 ]; then
log_pass "-------------enable/disable TPDMs Test PASS-------------"
echo "$TESTNAME PASS" > "$res_file"
else
log_fail "-------------enable/disable TPDMs Test FAIL-------------"
echo "$TESTNAME FAIL" > "$res_file"
fi

log_info "-------------------$TESTNAME Testcase Finished----------------------------"
102 changes: 102 additions & 0 deletions Runner/suites/Kernel/DEBUG/TPDM-Interface-Access/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# TPDM-Interface-Access Test

## Overview
This test performs comprehensive reads across all Trace Profiling and Diagnostics Monitor (TPDM) sysfs interfaces within the Coresight subsystem. It ensures that sysfs nodes correctly expose dataset properties and that interfaces remain securely readable without causing panics or "Invalid argument" responses.

## Test Goals

- Dynamically scan and iterate through all registered TPDM devices in `/sys/bus/coresight/devices/`.
- Validate the dataset map implementation mapping (DSB, CMB, TC, BC, GPR, MCMB).
- Validate dataset configuration properties (e.g. converting hexadecimal active datasets mappings to logical subsystem checks).
- Prevent and detect attribute read failures on dynamically exposed sysfs device interfaces.

## Prerequisites

- Kernel must be built with Coresight TPDM/ETF source support.
- `sysfs` access to `/sys/bus/coresight/devices/`.
- DebugFS access to `/d/npu/ctrl` or `/sys/kernel/debug/npu/ctrl` for TPDM-NPU tests.
- Root privileges (to configure Coresight source elements and access hardware attributes).

## Script Location

```
Runner/suites/Kernel/DEBUG/TPDM-Interface-Access/run.sh
```

## Files

- `run.sh` - Main test script
- `TPDM-Interface-Access.res` - Summary result file with PASS/FAIL
- `TPDM-Interface-Access.log` - Full execution log (generated if logging is enabled via functestlib)

## How It Works

The test uses a two-pronged approach:

1. **Dataset Verification Phase**:
- Dynamically discovers all TPDM nodes.
- Parses the active bit map exposed by the node's `enable_datasets` file.
- Translates the hex output to human-readable subsets (e.g., DSB, CMB).
- Dynamically probes every sysfs file matching the mapped properties to ensure driver readability.
2. **Global Read Validation Phase**:
- Flushes all coresight elements (Resets sinks and sources to `0`).
- Recursively performs standard `cat` reads on every readable (`-r`) generic node under the device.
- Detects node read failures that typically indicate misconfigured kernel data boundaries.

## Usage

Run the script directly. No iterations or special arguments are required for this basic test.

```bash
./run.sh
```


## Example Output

```
[INFO] 2026-03-23 05:56:52 - ------------------------------------------------------
[INFO] 2026-03-23 05:56:52 - Starting Testcase: TPDM-Interface-Access
[INFO] 2026-03-23 05:56:52 - Performing initial device reset...
[INFO] 2026-03-23 05:56:52 - --- Phase 1: Source dataset mode tests ---
[INFO] 2026-03-23 05:56:52 - Testing device: tpdm0
[INFO] 2026-03-23 05:56:52 - Default datasets: (Mode: 00) -> Configurations: none
[INFO] 2026-03-23 05:56:52 - Testing device: tpdm1
[INFO] 2026-03-23 05:56:52 - Default datasets: (Mode: 00) -> Configurations: none
......
[INFO] 2026-03-23 05:56:52 - Testing device: tpdm8
[INFO] 2026-03-23 05:56:52 - Default datasets: (Mode: 00) -> Configurations: none
[INFO] 2026-03-23 05:56:52 - Testing device: tpdm9
[INFO] 2026-03-23 05:56:52 - Default datasets: (Mode: 00) -> Configurations: none
[PASS] 2026-03-23 05:56:52 - Phase 1 Completed: All TPDM mode attributes check passed
[INFO] 2026-03-23 05:56:52 - Performing mid-test device reset...
[INFO] 2026-03-23 05:56:52 - --- Phase 2: Readable attributes check ---
[INFO] 2026-03-23 05:56:52 - Reading 8 accessible nodes under tpdm0
[INFO] 2026-03-23 05:56:52 - Reading 8 accessible nodes under tpdm1
......
[INFO] 2026-03-23 05:56:52 - Reading 8 accessible nodes under tpdm8
[INFO] 2026-03-23 05:56:52 - Reading 8 accessible nodes under tpdm9
[PASS] 2026-03-23 05:56:52 - Result: TPDM-Interface-Access PASS
[INFO] 2026-03-23 05:33:24 - -------------------TPDM-Interface-Access Testcase Finished----------------------------

```

## Return Code

- `0` — All attributes were read successfully without any panics, permission denials, or generic read errors
- `1` — One or more files in the TPDM tree failed to perform a valid return on cat

## Integration in CI

- Can be run standalone or via LAVA
- Result file TPDM-Interface-Access.res will be parsed by result_parse.sh

## Notes

- `tpdm-turing-llm` node paths are hardcoded to be skipped as per hardware testing constraints
- If tpdm-npu is detected, the framework will temporarily write to the NPU debugger control map at /sys/kernel/debug/npu/ctrl

## 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-Interface-Access
format: "Lava-Test Test Definition 1.0"
description: "Test reading all active and inactive TPDM node interfaces, verifying dataset configurations and sysfs attributes."
os:
- linux
scope:
- coresight
- kernel

run:
steps:
- REPO_PATH=$PWD || true
- cd Runner/suites/Kernel/DEBUG/TPDM-Interface-Access || true
- ./run.sh || true
- $REPO_PATH/Runner/utils/send-to-lava.sh TPDM-Interface-Access.res || true
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.