diff --git a/Runner/suites/Kernel/DEBUG/TPDM-Enable-Disable/README.md b/Runner/suites/Kernel/DEBUG/TPDM-Enable-Disable/README.md new file mode 100644 index 00000000..a06124cd --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/TPDM-Enable-Disable/README.md @@ -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. \ No newline at end of file diff --git a/Runner/suites/Kernel/DEBUG/TPDM-Enable-Disable/TPDM-Enable-Disable.yaml b/Runner/suites/Kernel/DEBUG/TPDM-Enable-Disable/TPDM-Enable-Disable.yaml new file mode 100644 index 00000000..52b6f4f9 --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/TPDM-Enable-Disable/TPDM-Enable-Disable.yaml @@ -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 \ No newline at end of file diff --git a/Runner/suites/Kernel/DEBUG/TPDM-Enable-Disable/run.sh b/Runner/suites/Kernel/DEBUG/TPDM-Enable-Disable/run.sh new file mode 100755 index 00000000..0715f03c --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/TPDM-Enable-Disable/run.sh @@ -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 + # 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 + 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----------------------------" \ No newline at end of file diff --git a/Runner/suites/Kernel/DEBUG/TPDM-Interface-Access/README.md b/Runner/suites/Kernel/DEBUG/TPDM-Interface-Access/README.md new file mode 100644 index 00000000..da9ca385 --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/TPDM-Interface-Access/README.md @@ -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. \ No newline at end of file diff --git a/Runner/suites/Kernel/DEBUG/TPDM-Interface-Access/TPDM-Interface-Access.yaml b/Runner/suites/Kernel/DEBUG/TPDM-Interface-Access/TPDM-Interface-Access.yaml new file mode 100644 index 00000000..09dad41a --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/TPDM-Interface-Access/TPDM-Interface-Access.yaml @@ -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 \ No newline at end of file diff --git a/Runner/suites/Kernel/DEBUG/TPDM-Interface-Access/run.sh b/Runner/suites/Kernel/DEBUG/TPDM-Interface-Access/run.sh new file mode 100755 index 00000000..cb340382 --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/TPDM-Interface-Access/run.sh @@ -0,0 +1,206 @@ +#!/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-Interface-Access" +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_warn "TMC-ETF sink not found. Some operations may fail." +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 + done +} + +dataset_map(){ + case "$1" in + 2) mode_config="dsb" ;; + 4) mode_config="cmb" ;; + 8) mode_config="tc" ;; + 16) mode_config="bc" ;; + 24) mode_config="tc bc" ;; + 32) mode_config="gpr" ;; + 36) mode_config="cmb gpr" ;; + 50) mode_config="dsb bc gpr" ;; + 62) mode_config="dsb cmb tc bc gpr" ;; + 64) mode_config="mcmb" ;; + *) mode_config="none" ;; + esac +} + +mode_atrr(){ + mode=$1 + fail_flag=0 + + for attr_file in "$CS_BASE/$tpdm_device/$mode"*; do + if [ -f "$attr_file" ] && [ -r "$attr_file" ]; then + if ! cat "$attr_file" >/dev/null 2>&1; then + log_fail "Failed to read attribute: $attr_file" + fail_flag=1 + fi + fi + done + return $fail_flag +} + +a_fail=0 +tpdm_found=0 + +for npu_dir in "$CS_BASE"/tpdm-npu* "$CS_BASE"/coresight-tpdm-npu*; do + if [ -d "$npu_dir" ]; then + 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 + break + fi +done + +log_info "Performing initial device reset..." +reset_devices +[ -n "$ETF_PATH" ] && [ -f "$ETF_PATH/enable_sink" ] && echo 1 > "$ETF_PATH/enable_sink" + +log_info "--- Phase 1: Source dataset mode tests ---" + +for tpdm_path in "$CS_BASE"/tpdm* "$CS_BASE"/coresight-tpdm*; do + [ ! -d "$tpdm_path" ] && continue + tpdm_device=$(basename "$tpdm_path") + tpdm_found=$((tpdm_found + 1)) + + if echo "$tpdm_device" | grep -q "tpdm-turing-llm"; then + log_info "Skipping unsupported source: $tpdm_device" + continue + fi + + if [ ! -f "$tpdm_path/enable_source" ]; then + continue + fi + + log_info "Testing device: $tpdm_device" + + echo 1 > "$tpdm_path/enable_source" 2>/dev/null + + datasets=$(cat "$tpdm_path/enable_datasets" 2>/dev/null) + set_mode=$(printf "%d" "0x$datasets" 2>/dev/null || echo 0) + dataset_map "$set_mode" + + log_info " Default datasets: $datasets (Mode: $set_mode) -> Configurations: $mode_config" + + for mode in $mode_config; do + if [ "$mode" = "none" ]; then + continue + fi + + mode_atrr "$mode" + if mycmd; then + log_pass " PASS: $mode attributes" + else + log_fail " FAIL: $mode attributes" + a_fail=$((a_fail + 1)) + fi + done + + echo 0 > "$tpdm_path/enable_source" 2>/dev/null +done + +if [ "$tpdm_found" -eq 0 ]; then + log_fail "Result: $TESTNAME FAIL (No TPDM devices found)" + echo "$TESTNAME FAIL" >> "$res_file" + exit 1 +fi + +if [ "$a_fail" -eq 0 ]; then + log_pass "Phase 1 Completed: All TPDM mode attributes check passed" +else + log_fail "Phase 1 Completed: TPDM mode attributes check failed with $a_fail errors" +fi + +log_info "Performing mid-test device reset..." +reset_devices + +log_info "--- Phase 2: Readable attributes check ---" + +for tpdm_path in "$CS_BASE"/tpdm* "$CS_BASE"/coresight-tpdm*; do + [ ! -d "$tpdm_path" ] && continue + tpdm_device=$(basename "$tpdm_path") + + if echo "$tpdm_device" | grep -q "tpdm-turing-llm"; then + continue + fi + + if_count=0 + for attr_file in "$tpdm_path"/*; do + if [ -f "$attr_file" ] && [ -r "$attr_file" ]; then + if_count=$((if_count + 1)) + fi + done + + log_info "Reading $if_count accessible nodes under $tpdm_device" + + for attr_file in "$tpdm_path"/*; do + if [ -f "$attr_file" ] && [ -r "$attr_file" ]; then + cat "$attr_file" >/dev/null 2>&1 + fi + done +done + +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 + +if [ "$a_fail" -eq 0 ]; then + log_pass "Result: $TESTNAME PASS" + echo "$TESTNAME PASS" > "$res_file" +else + log_fail "Result: $TESTNAME FAIL ($a_fail errors detected)" + echo "$TESTNAME FAIL" > "$res_file" +fi + +log_info "-------------------$TESTNAME Testcase Finished----------------------------" \ No newline at end of file