From 00cc2754c1969651b83872f5f4d60754130a22d0 Mon Sep 17 00:00:00 2001 From: Rohan Dutta Date: Wed, 18 Feb 2026 16:03:49 +0530 Subject: [PATCH] Added QDSS STM and TMC support in DEBUG suite - MultiSource-STM-ETM: validates STM and ETM multi-source trace configuration - Sink-Status-STM-Toggle: tests STM sink status and toggle functionality - STM-HWE-PORT-SWITCH: verifies STM hardware event port switching - STM-Source-Enable-Disable: tests STM source enable/disable via sysfs - Added coresight_common.sh utility for shared functions Signed-off-by: Rohan Dutta --- .../MultiSource-STM-ETM.yaml | 16 ++ .../DEBUG/MultiSource-STM-ETM/README.md | 71 ++++++ .../Kernel/DEBUG/MultiSource-STM-ETM/run.sh | 173 +++++++++++++++ .../DEBUG/STM-HWE-PORT-SWITCH/README.md | 74 +++++++ .../STM-HWE-PORT-SWITCH.yaml | 16 ++ .../Kernel/DEBUG/STM-HWE-PORT-SWITCH/run.sh | 142 ++++++++++++ .../DEBUG/STM-Source-Enable-Disable/README.md | 67 ++++++ .../STM-Source-Enable-Disable.yaml | 16 ++ .../DEBUG/STM-Source-Enable-Disable/run.sh | 169 ++++++++++++++ .../Kernel/DEBUG/STM-Trace-Marker/README.md | 71 ++++++ .../STM-Trace-Marker/STM-Trace-Marker.yaml | 16 ++ .../Kernel/DEBUG/STM-Trace-Marker/run.sh | 206 ++++++++++++++++++ .../DEBUG/Sink-Status-STM-Toggle/README.md | 85 ++++++++ .../Sink-Status-STM-Toggle.yaml | 16 ++ .../DEBUG/Sink-Status-STM-Toggle/run.sh | 200 +++++++++++++++++ Runner/utils/coresight_common.sh | 61 ++++++ 16 files changed, 1399 insertions(+) create mode 100644 Runner/suites/Kernel/DEBUG/MultiSource-STM-ETM/MultiSource-STM-ETM.yaml create mode 100644 Runner/suites/Kernel/DEBUG/MultiSource-STM-ETM/README.md create mode 100755 Runner/suites/Kernel/DEBUG/MultiSource-STM-ETM/run.sh create mode 100644 Runner/suites/Kernel/DEBUG/STM-HWE-PORT-SWITCH/README.md create mode 100644 Runner/suites/Kernel/DEBUG/STM-HWE-PORT-SWITCH/STM-HWE-PORT-SWITCH.yaml create mode 100755 Runner/suites/Kernel/DEBUG/STM-HWE-PORT-SWITCH/run.sh create mode 100644 Runner/suites/Kernel/DEBUG/STM-Source-Enable-Disable/README.md create mode 100644 Runner/suites/Kernel/DEBUG/STM-Source-Enable-Disable/STM-Source-Enable-Disable.yaml create mode 100755 Runner/suites/Kernel/DEBUG/STM-Source-Enable-Disable/run.sh create mode 100644 Runner/suites/Kernel/DEBUG/STM-Trace-Marker/README.md create mode 100644 Runner/suites/Kernel/DEBUG/STM-Trace-Marker/STM-Trace-Marker.yaml create mode 100755 Runner/suites/Kernel/DEBUG/STM-Trace-Marker/run.sh create mode 100644 Runner/suites/Kernel/DEBUG/Sink-Status-STM-Toggle/README.md create mode 100644 Runner/suites/Kernel/DEBUG/Sink-Status-STM-Toggle/Sink-Status-STM-Toggle.yaml create mode 100755 Runner/suites/Kernel/DEBUG/Sink-Status-STM-Toggle/run.sh create mode 100755 Runner/utils/coresight_common.sh diff --git a/Runner/suites/Kernel/DEBUG/MultiSource-STM-ETM/MultiSource-STM-ETM.yaml b/Runner/suites/Kernel/DEBUG/MultiSource-STM-ETM/MultiSource-STM-ETM.yaml new file mode 100644 index 00000000..701942f2 --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/MultiSource-STM-ETM/MultiSource-STM-ETM.yaml @@ -0,0 +1,16 @@ +metadata: + name: MultiSource-STM-ETM + format: "Lava-Test Test Definition 1.0" + description: "Validates concurrent STM and ETM trace collection across multiple cores." + os: + - linux + scope: + - coresight + - kernel + +run: + steps: + - REPO_PATH=$PWD || true + - cd Runner/suites/Kernel/DEBUG/MultiSource-STM-ETM || true + - ./run.sh || true + - $REPO_PATH/Runner/utils/send-to-lava.sh MultiSource-STM-ETM.res || true \ No newline at end of file diff --git a/Runner/suites/Kernel/DEBUG/MultiSource-STM-ETM/README.md b/Runner/suites/Kernel/DEBUG/MultiSource-STM-ETM/README.md new file mode 100644 index 00000000..86ac00e8 --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/MultiSource-STM-ETM/README.md @@ -0,0 +1,71 @@ +# Multi-Source STM + ETM Test + +## Overview +This test verifies the Coresight subsystem's ability to handle simultaneous trace data from multiple sources: STM (System Trace Macrocell) for software events, and ETM (Embedded Trace Macrocell) for instruction traces from all online CPUs. It iterates through available sinks (e.g., `tmc_etf0`, `tmc_etr0`) and checks if valid binary data is captured. + +## Test Goals +- Verify the Coresight subsystem's ability to handle simultaneous trace streams. +- Validate the functionality of STM (System Trace Macrocell) for generating software event traces. +- Validate the functionality of ETM (Embedded Trace Macrocell) for instruction tracing across all online CPUs. +- Ensure that Coresight links and funnels properly multiplex data without dropping critical traces. +- Verify that valid binary data is successfully captured across different available sinks. + +## Prerequisites +- Kernel must be built with Coresight support: + - `CONFIG_CORESIGHT` + - `CONFIG_CORESIGHT_STM` + - `CONFIG_CORESIGHT_LINK_AND_SINK_TMC` +- Availability of the common library: `Runner/utils/coresight_common.sh` +- Root privileges (to configure Coresight sysfs nodes and read from character devices). + +## Script Location +`Runner/suites/Kernel/DEBUG/MultiSource-STM-ETM/run.sh` + +## Files +- `run.sh` - Main test script +- `MultiSource-STM-ETM.res` - Summary result file with PASS/FAIL +- `MultiSource-STM-ETM.log` - Full execution log (generated if logging is enabled) + +## How It Works +1. **Initialization:** Sources common Coresight helper functions (`coresight_common.sh`). +2. **Setup:** Resets the Coresight topology to ensure a clean state. +3. **Execution Loop:** Iterates through all available trace sinks (e.g., `tmc_etf0`, `tmc_etr0`). + - Enables the current sink. + - Enables STM as a trace source. + - Enables all available ETMs (for all online CPUs) as trace sources. + - Triggers trace data generation (both software events and CPU instruction execution). +4. **Verification:** Reads the captured binary data from the sink and verifies its validity. +5. **Teardown:** Disables all active sources and the sink before moving to the next iteration. + +## Example Output +``` +[INFO] 2026-03-16 07:41:58 - ----------------------------------------------------------------------------------------- +[INFO] 2026-03-16 07:41:58 - -------------------Starting MultiSource-STM-ETM Testcase---------------------------- +[INFO] 2026-03-16 07:41:58 - === Test Initialization === +[INFO] 2026-03-16 07:41:58 - Checking if required tools are available +[INFO] 2026-03-16 07:41:58 - Testing Sink: tmc_etf0 +[PASS] 2026-03-16 07:41:58 - Captured 65536 bytes from tmc_etf0 +[INFO] 2026-03-16 07:41:58 - Testing Sink: tmc_etr0 +[PASS] 2026-03-16 07:41:58 - Captured 64 bytes from tmc_etr0 +[INFO] 2026-03-16 07:41:58 - Testing Sink: tmc_etr1 +[PASS] 2026-03-16 07:41:58 - Captured 64 bytes from tmc_etr1 +``` + +## Return Code + +- `0` — Simultaneous trace capture succeeded for all tested sinks +- `1` — Trace capture failed, returned invalid data, or a device failed to enable/disable + +## Integration in CI + +- Can be run standalone or via LAVA +- Result file MultiSource-STM-ETM.res will be parsed by result_parse.sh + +## Notes + +- Testing multiple sources simultaneously stresses the Coresight funnels and links to ensure they can handle interleaved trace streams without data corruption or system instability. + +## 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/MultiSource-STM-ETM/run.sh b/Runner/suites/Kernel/DEBUG/MultiSource-STM-ETM/run.sh new file mode 100755 index 00000000..d19f5aa7 --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/MultiSource-STM-ETM/run.sh @@ -0,0 +1,173 @@ +#!/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 (starting at $SCRIPT_DIR)" >&2 + exit 1 +fi + +if [ -z "$__INIT_ENV_LOADED" ]; then + # shellcheck disable=SC1090 + . "$INIT_ENV" +fi + +# shellcheck disable=SC1090,SC1091 +. "$TOOLS/functestlib.sh" +# shellcheck disable=SC1090,SC1091 +. "$TOOLS/coresight_common.sh" + +TESTNAME="MultiSource-STM-ETM" +if command -v find_test_case_by_name >/dev/null 2>&1; then + test_path=$(find_test_case_by_name "$TESTNAME") + cd "$test_path" || exit 1 +else + cd "$SCRIPT_DIR" || exit 1 +fi + +res_file="./$TESTNAME.res" +log_info "-----------------------------------------------------------------------------------------" +log_info "-------------------Starting $TESTNAME Testcase----------------------------" +log_info "=== Test Initialization ===" +log_info "Checking if required tools are available" + +for tool in timeout stat; do + if ! command -v "$tool" >/dev/null 2>&1; then + log_skip "Required tool '$tool' not found. Skipping test." + echo "$TESTNAME SKIP" > "$res_file" + exit 0 + fi +done + +CPU_PATH="/sys/devices/system/cpu/cpu" +CORES=$(grep -c "processor" /proc/cpuinfo) +STM_PATH="$CS_BASE/stm0" +[ ! -d "$STM_PATH" ] && STM_PATH="$CS_BASE/coresight-stm" + +# --- Helpers --- + +toggle_etm_all() { + _state=$1 + _count=0 + _toggled_count=0 + + while [ "$_count" -lt "$CORES" ]; do + _skip=0 + + if [ -f "${CPU_PATH}${_count}/online" ]; then + read -r _is_online < "${CPU_PATH}${_count}/online" + if [ "$_is_online" = "0" ]; then + log_info "CPU $_count is offline, skipping ETM toggle for this core." + _skip=1 + fi + fi + + if [ "$_skip" -eq 0 ]; then + _etm="" + + if [ -f "$CS_BASE/ete$_count/enable_source" ]; then + _etm="$CS_BASE/ete$_count/enable_source" + elif [ -f "$CS_BASE/coresight-ete$_count/enable_source" ]; then + _etm="$CS_BASE/coresight-ete$_count/enable_source" + elif [ -f "$CS_BASE/etm$_count/enable_source" ]; then + _etm="$CS_BASE/etm$_count/enable_source" + elif [ -f "$CS_BASE/coresight-etm$_count/enable_source" ]; then + _etm="$CS_BASE/coresight-etm$_count/enable_source" + fi + + if [ -n "$_etm" ]; then + if echo "$_state" > "$_etm" 2>/dev/null; then + _toggled_count=$((_toggled_count + 1)) + else + log_warn "Failed to write $_state to $_etm" + fi + else + log_warn "No ETM/ETE source found for CPU $_count in $CS_BASE" + fi + fi + + _count=$((_count + 1)) + done + + if [ "$_toggled_count" -eq 0 ]; then + log_warn "No ETM/ETE devices were successfully toggled. Please verify Coresight configurations and path names." + fi +} + +# --- Preflight --- + +cs_check_base || { echo "$TESTNAME FAIL" > "$res_file"; exit 1; } + +cs_global_reset +toggle_etm_all 0 + +# shellcheck disable=SC2010 +SINKS="" +for _d in "$CS_BASE"/tmc_et* "$CS_BASE"/coresight-tmc-et*; do + [ -d "$_d" ] || continue + _name="${_d##*/}" + [ "$_name" = "tmc_etf1" ] && continue + [ -f "$_d/enable_sink" ] || continue + SINKS="$SINKS $_name" +done +SINKS="${SINKS# }" + +if [ -z "$SINKS" ]; then + log_fail "No suitable TMC sinks found" + echo "$TESTNAME FAIL" > "$res_file" + exit 1 +fi + +for sinkname in $SINKS; do + log_info "Testing Sink: $sinkname" + + cs_global_reset + OUTPUT_BIN="/tmp/$sinkname.bin" + rm -f "$OUTPUT_BIN" + + if ! cs_enable_sink "$sinkname"; then + log_warn "Sink $sinkname enable_sink node not found" + echo "$TESTNAME FAIL" > "$res_file" + continue + fi + + toggle_etm_all 1 + + if [ -f "$STM_PATH/enable_source" ]; then + echo 1 > "$STM_PATH/enable_source" + else + log_warn "STM source not found" + fi + + [ -c "/dev/$sinkname" ] && timeout 2s cat "/dev/$sinkname" > "$OUTPUT_BIN" + + if [ -f "$OUTPUT_BIN" ]; then + bin_size=$(stat -c%s "$OUTPUT_BIN") + if [ "$bin_size" -ge 64 ]; then + log_pass "Captured $bin_size bytes from $sinkname" + echo "$TESTNAME PASS" > "$res_file" + else + log_fail "Captured data too small ($bin_size bytes) from $sinkname" + echo "$TESTNAME FAIL" > "$res_file" + fi + else + log_fail "No output file generated for $sinkname" + echo "$TESTNAME FAIL" > "$res_file" + fi + + toggle_etm_all 0 +done + +cs_global_reset \ No newline at end of file diff --git a/Runner/suites/Kernel/DEBUG/STM-HWE-PORT-SWITCH/README.md b/Runner/suites/Kernel/DEBUG/STM-HWE-PORT-SWITCH/README.md new file mode 100644 index 00000000..002b136d --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/STM-HWE-PORT-SWITCH/README.md @@ -0,0 +1,74 @@ +# STM-HWE-PORT-SWITCH Test + +## Overview +This test verifies that the STM (System Trace Macrocell) attributes `hwevent_enable` and `port_enable` can be successfully toggled (0 and 1) via sysfs, regardless of whether the main STM source (`enable_source`) is currently active or inactive. + +## Test Goals +- Verify the ability to toggle STM hardware event enabling (`hwevent_enable`). +- Verify the ability to toggle STM port enabling (`port_enable`). +- Ensure that these attributes can be modified independently of the main STM source's active state (enabled or disabled). +- Validate that sysfs reads accurately reflect the values written to these configuration attributes. +- Ensure proper restoration of default values post-testing. + +## Prerequisites +- Kernel must be built with Coresight STM support (e.g., `CONFIG_CORESIGHT_STM`). +- sysfs access to `/sys/bus/coresight/devices/stm0/` (or equivalent STM device path). +- Access to configfs for STP policy directory creation. +- Root privileges (to configure attributes, enable sources/sinks, and manage policies). + +## Script Location +`Runner/suites/Kernel/DEBUG/STM-HWE-PORT-SWITCH/run.sh` + +## Files +- `run.sh` - Main test script +- `STM-HWE-PORT-SWITCH.res` - Summary result file with PASS/FAIL +- `STM-HWE-PORT-SWITCH.log` - Full execution log (generated if logging is enabled) + +## How It Works +1. **Setup:** + - Creates STP policy directories. + - Resets Coresight devices to ensure a clean state. + - Enables `tmc_etf0` as the trace sink. +2. **Test Loop (Run for both `hwevent_enable` and `port_enable`):** + - **Outer Loop:** Toggles the main STM `enable_source` (sets to 0, then 1). + - **Inner Loop:** Toggles the target attribute (sets to 0, then 1). +3. **Verification:** Reads back the attribute value to ensure it matches the written value. +4. **Teardown:** + - Resets all Coresight devices. + - Restores `hwevent_enable` to 0. + - Restores `port_enable` to 0xffffffff (all ports enabled). + +## Example Output +``` +[INFO] 2026-03-16 09:03:42 - ----------------------------------------------------------------------------------------- +[INFO] 2026-03-16 09:03:42 - -------------------Starting STM-HWE-PORT-SWITCH Testcase---------------------------- +[INFO] 2026-03-16 09:03:42 - Testing Attribute: hwevent_enable +[PASS] 2026-03-16 09:03:42 - STM_Src:0 | hwevent_enable set to 0 +[PASS] 2026-03-16 09:03:42 - STM_Src:0 | hwevent_enable set to 1 +[PASS] 2026-03-16 09:03:42 - STM_Src:1 | hwevent_enable set to 0 +[PASS] 2026-03-16 09:03:42 - STM_Src:1 | hwevent_enable set to 1 +[INFO] 2026-03-16 09:03:42 - Testing Attribute: port_enable +[PASS] 2026-03-16 09:03:42 - STM_Src:0 | port_enable set to 0 +[PASS] 2026-03-16 09:03:42 - STM_Src:0 | port_enable set to 1 +[PASS] 2026-03-16 09:03:42 - STM_Src:1 | port_enable set to 0 +[PASS] 2026-03-16 09:03:42 - STM_Src:1 | port_enable set to 1 + +## Return Code + +- `0` — All attributes were toggled and verified successfully in all source states +- `1` — One or more read/write verifications failed + +## Integration in CI + +- Can be run standalone or via LAVA +- Result file STM-HWE-PORT-SWITCH.res will be parsed by result_parse.sh + +## Notes + +- Ensuring that configuration changes can happen while the main source is active is critical for dynamic trace adjustments without needing to tear down the entire Coresight topology. +- 0xffffffff represents a bitmask enabling all 32 ports in standard STM configurations. + +## 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/STM-HWE-PORT-SWITCH/STM-HWE-PORT-SWITCH.yaml b/Runner/suites/Kernel/DEBUG/STM-HWE-PORT-SWITCH/STM-HWE-PORT-SWITCH.yaml new file mode 100644 index 00000000..7618a5ec --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/STM-HWE-PORT-SWITCH/STM-HWE-PORT-SWITCH.yaml @@ -0,0 +1,16 @@ +metadata: + name: STM-HWEvent-Port-Enable-Disable + format: "Lava-Test Test Definition 1.0" + description: "Validates the ability to enable and disable STM Hardware Events and Ports via sysfs." + os: + - linux + scope: + - coresight + - kernel + +run: + steps: + - REPO_PATH=$PWD || true + - cd Runner/suites/Kernel/DEBUG/STM-HWE-PORT-SWITCH || true + - ./run.sh || true + - $REPO_PATH/Runner/utils/send-to-lava.sh STM-HWE-PORT-SWITCH.res || true \ No newline at end of file diff --git a/Runner/suites/Kernel/DEBUG/STM-HWE-PORT-SWITCH/run.sh b/Runner/suites/Kernel/DEBUG/STM-HWE-PORT-SWITCH/run.sh new file mode 100755 index 00000000..b2ae6afb --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/STM-HWE-PORT-SWITCH/run.sh @@ -0,0 +1,142 @@ +#!/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="STM-HWE-PORT-SWITCH" +if command -v find_test_case_by_name >/dev/null 2>&1; then + test_path=$(find_test_case_by_name "$TESTNAME") + cd "$test_path" || exit 1 +else + cd "$SCRIPT_DIR" || exit 1 +fi + +res_file="./$TESTNAME.res" +rm -f "$res_file" +touch "$res_file" + +log_info "-----------------------------------------------------------------------------------------" +log_info "-------------------Starting $TESTNAME Testcase----------------------------" + +CS_BASE="/sys/bus/coresight/devices" +STM_PATH="$CS_BASE/stm0" +[ ! -d "$STM_PATH" ] && STM_PATH="$CS_BASE/coresight-stm" +ETF_PATH="$CS_BASE/tmc_etf0" +ETR_PATH="$CS_BASE/tmc_etr0" +DEBUGFS="/sys/kernel/debug/tracing" + +reset_source_sink() { + if [ -f "$STM_PATH/enable_source" ]; then + echo 0 > "$STM_PATH/enable_source" + fi + if [ -f "$ETF_PATH/enable_sink" ]; then + echo 0 > "$ETF_PATH/enable_sink" + fi + if [ -f "$ETR_PATH/enable_sink" ]; then + echo 0 > "$ETR_PATH/enable_sink" + fi + if [ -f "$DEBUGFS/tracing_on" ]; then + echo 0 > "$DEBUGFS/tracing_on" + fi +} + +test_attribute() { + attr_name=$1 + attr_path="$STM_PATH/$attr_name" + + log_info "Testing Attribute: $attr_name" + + if [ ! -f "$attr_path" ]; then + log_warn "Attribute $attr_name not found at $STM_PATH" + return 0 + fi + + for stm_state in 0 1; do + echo "$stm_state" > "$STM_PATH/enable_source" + + for val in 0 1; do + echo "$val" > "$attr_path" + readback=$(cat "$attr_path") + + + if [ "$attr_name" = "hwe_enable" ]; then + if [ "$readback" -eq "$val" ]; then + log_pass "STM_Src:$stm_state | $attr_name set to $val" + else + log_fail "STM_Src:$stm_state | Failed to set $attr_name to $val (Read: $readback)" + echo "$TESTNAME FAIL" > "$res_file" + return 1 + fi + elif [ "$attr_name" = "port_enable" ]; then + if [ "$val" -eq 1 ] && [ "$readback" != "0" ] && [ "$readback" != "0x0" ]; then + log_pass "STM_Src:$stm_state | $attr_name set to $val" + elif [ "$val" -eq 0 ] && [ "$readback" = "0" ]; then + log_pass "STM_Src:$stm_state | $attr_name set to $val" + elif [ "$val" -eq 0 ] && [ "$readback" = "0x0" ]; then + log_pass "STM_Src:$stm_state | $attr_name set to $val" + else + log_fail "STM_Src:$stm_state | Failed to set $attr_name to $val (Read: $readback)" + echo "$TESTNAME FAIL" > "$res_file" + return 1 + fi + fi + done + done + + echo "$TESTNAME PASS" > "$res_file" + return 0 +} + + +if [ ! -d "$STM_PATH" ]; then + log_fail "STM device not found" + echo "$TESTNAME FAIL" > "$res_file" + exit 1 +fi + +log_info "Creating Policy Directories..." +mkdir -p /sys/kernel/config/stp-policy/stm0:p_ost.policy/default + +reset_source_sink + +if [ -f "$ETF_PATH/enable_sink" ]; then + echo 1 > "$ETF_PATH/enable_sink" +fi + +test_attribute "hwe_enable" +test_attribute "port_enable" + +reset_source_sink + +if [ -f "$STM_PATH/hwe_enable" ]; then + echo 0 > "$STM_PATH/hwe_enable" +fi +if [ -f "$STM_PATH/port_enable" ]; then + echo 0xffffffff > "$STM_PATH/port_enable" +fi + +# log_info "-------------------$TESTNAME Testcase Finished----------------------------" \ No newline at end of file diff --git a/Runner/suites/Kernel/DEBUG/STM-Source-Enable-Disable/README.md b/Runner/suites/Kernel/DEBUG/STM-Source-Enable-Disable/README.md new file mode 100644 index 00000000..3c93656a --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/STM-Source-Enable-Disable/README.md @@ -0,0 +1,67 @@ +# STM Source Enable/Disable Stress Test + +## Overview +This test validates the stability of the STM (System Trace Macrocell) driver by repeatedly enabling and disabling the source in a loop. + +## Test Goals +- Validate the stability and reliability of the STM driver under stress. +- Ensure the STM source can be repeatedly enabled and disabled without causing kernel panics or hangs. +- Verify that sysfs state correctly reflects the enabled/disabled status across multiple rapid transitions. +- Confirm proper initialization and teardown of STP policy directories and global tracing events. + +## Prerequisites +- Kernel must be built with Coresight STM support (e.g., `CONFIG_CORESIGHT_STM`). +- sysfs access to `/sys/bus/coresight/devices/`. +- Access to configfs for STP policy directory creation. +- Root privileges (to configure sysfs nodes, reset devices, and create policies). + +## Script Location +`Runner/suites/Kernel/DEBUG/STM-Source-Enable-Disable/run.sh` + +## Files +- `run.sh` - Main test script +- `STM-Source-Enable-Disable.res` - Summary result file with PASS/FAIL +- `STM-Source-Enable-Disable.log` - Full execution log (generated if logging is enabled) + +## How It Works +1. **Setup:** + - Creates STP policy directories. + - Resets all Coresight source/sink devices. + - Disables hardware events and clears global tracing events. +2. **Loop (50 Iterations):** + - Resets source/sink. + - Enables `tmc_etf` sink. + - Enables `stm` source -> Checks if `enable_source` is 1. + - Disables `stm` source -> Checks if `enable_source` is 0. +3. **Teardown:** + - Resets all devices back to their default, disabled state. + +## Example Output +``` +[INFO] 2026-03-16 09:51:32 - ----------------------------------------------------------------------------------------- +[INFO] 2026-03-16 09:51:32 - -------------------Starting STM-Source-Enable-Disable Testcase---------------------------- +[INFO] 2026-03-16 09:51:32 - Setting up STP policy... +[INFO] 2026-03-16 09:51:32 - Using existing STP policy: p_basic +[INFO] 2026-03-16 09:51:32 - Initial cleanup... +[INFO] 2026-03-16 09:51:32 - Starting 50 iteration loop... +[PASS] 2026-03-16 09:51:33 - STM source enable/disable loop passed (50 iterations) +``` + +## Return Code + +- `0` — All 50 iterations successfully enabled and disabled the STM source +- `1` — One or more iterations failed to toggle the source or verify its state + +## Integration in CI + +- Can be run standalone or via LAVA +- Result file STM-Source-Enable-Disable.res will be parsed by result_parse.sh + +## Notes + +- The test performs 50 iterations specifically to catch intermittent concurrency bugs or race conditions in the driver's enable/disable path. + +## 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/STM-Source-Enable-Disable/STM-Source-Enable-Disable.yaml b/Runner/suites/Kernel/DEBUG/STM-Source-Enable-Disable/STM-Source-Enable-Disable.yaml new file mode 100644 index 00000000..375906a2 --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/STM-Source-Enable-Disable/STM-Source-Enable-Disable.yaml @@ -0,0 +1,16 @@ +metadata: + name: STM-Source-Enable-Disable + format: "Lava-Test Test Definition 1.0" + description: "Stress test that toggles the STM source enablement 50 times to ensure stability." + os: + - linux + scope: + - coresight + - kernel + +run: + steps: + - REPO_PATH=$PWD || true + - cd Runner/suites/Kernel/DEBUG/STM-Source-Enable-Disable || true + - ./run.sh || true + - $REPO_PATH/Runner/utils/send-to-lava.sh STM-Source-Enable-Disable.res || true \ No newline at end of file diff --git a/Runner/suites/Kernel/DEBUG/STM-Source-Enable-Disable/run.sh b/Runner/suites/Kernel/DEBUG/STM-Source-Enable-Disable/run.sh new file mode 100755 index 00000000..4c98d54d --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/STM-Source-Enable-Disable/run.sh @@ -0,0 +1,169 @@ +#!/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="STM-Source-Enable-Disable" +if command -v find_test_case_by_name >/dev/null 2>&1; then + test_path=$(find_test_case_by_name "$TESTNAME") + cd "$test_path" || exit 1 +else + cd "$SCRIPT_DIR" || exit 1 +fi + +res_file="./$TESTNAME.res" +log_info "-----------------------------------------------------------------------------------------" +log_info "-------------------Starting $TESTNAME Testcase----------------------------" + +CS_BASE="/sys/bus/coresight/devices" +FAIL_COUNT=0 + +find_first_existing_path() { + for _dir_name in "$@"; do + if [ -d "$CS_BASE/$_dir_name" ]; then + echo "$CS_BASE/$_dir_name" + return 0 + fi + done + echo "" +} + +STM_PATH=$(find_first_existing_path "stm0" "coresight-stm") +ETF_PATH=$(find_first_existing_path "tmc_etf0" "tmc_etf" "tmc_etf1") +DEBUGFS="/sys/kernel/debug/tracing" + +reset_source_sink() { + for dev in "$CS_BASE"/*/; do + [ -d "$dev" ] || continue + if [ -f "$dev/enable_source" ]; then + val=$(cat "$dev/enable_source" 2>/dev/null) + if [ "$val" = "1" ]; then + echo 0 > "$dev/enable_source" 2>/dev/null + [ -f "$dev/reset" ] && echo 1 > "$dev/reset" 2>/dev/null + fi + fi + if [ -f "$dev/enable_sink" ]; then + val=$(cat "$dev/enable_sink" 2>/dev/null) + [ "$val" = "1" ] && echo 0 > "$dev/enable_sink" 2>/dev/null + fi + done +} + +if [ -z "$STM_PATH" ]; then + log_fail "STM device not found in $CS_BASE" + echo "$TESTNAME FAIL" > "$res_file" + exit 1 +fi + +STM_NAME=$(basename "$STM_PATH") + +log_info "Setting up STP policy..." +STP_POLICY_BASE="/sys/kernel/config/stp-policy" + +if ! grep -q "configfs" /proc/mounts 2>/dev/null; then + log_warn "configfs not mounted — skipping STP policy setup" + echo "$TESTNAME Skip" > "$res_file" + exit 0 +fi + +if [ ! -d "$STP_POLICY_BASE" ]; then + log_warn "STP policy path not available: $STP_POLICY_BASE — skipping" + echo "$TESTNAME Skip" > "$res_file" + exit 0 +fi + +if mkdir "$STP_POLICY_BASE/$STM_NAME:p_ost.policy" 2>/dev/null && \ + mkdir "$STP_POLICY_BASE/$STM_NAME:p_ost.policy/default" 2>/dev/null; then + log_info "Using STP policy: p_ost" +elif mkdir "$STP_POLICY_BASE/$STM_NAME:p_basic.policy" 2>/dev/null && \ + mkdir "$STP_POLICY_BASE/$STM_NAME:p_basic.policy/default" 2>/dev/null; then + log_info "Using STP policy: p_basic" +elif [ -d "$STP_POLICY_BASE/$STM_NAME:p_basic.policy/default" ]; then + log_info "Using existing STP policy: p_basic" +elif [ -d "$STP_POLICY_BASE/$STM_NAME:p_ost.policy/default" ]; then + log_info "Using existing STP policy: p_ost" +else + log_warn "No STP policy could be created — skipping" + echo "$TESTNAME Skip" > "$res_file" + exit 0 +fi + +log_info "Initial cleanup..." +reset_source_sink + +if [ -f "$STM_PATH/hwevent_enable" ]; then + echo 0 > "$STM_PATH/hwevent_enable" +fi +if [ -f "$STM_PATH/port_enable" ]; then + echo 0xffffffff > "$STM_PATH/port_enable" +fi + +if ! grep -q "debugfs" /proc/mounts 2>/dev/null; then + log_warn "debugfs not mounted — skipping events/enable reset" +elif [ -f "$DEBUGFS/events/enable" ]; then + echo 0 > "$DEBUGFS/events/enable" +else + log_warn "$DEBUGFS/events/enable not found — skipping" +fi + +log_info "Starting 50 iteration loop..." + +if [ -n "$ETF_PATH" ] && [ -f "$ETF_PATH/enable_sink" ]; then + echo 1 > "$ETF_PATH/enable_sink" 2>/dev/null +fi + +_count=1 +while [ "$_count" -le 50 ]; do + + echo 1 > "$STM_PATH/enable_source" 2>/dev/null + val=$(cat "$STM_PATH/enable_source" 2>/dev/null) + + if [ "$val" != "1" ]; then + log_fail "Iteration $_count: Failed to enable STM source" + FAIL_COUNT=$((FAIL_COUNT + 1)) + fi + + echo 0 > "$STM_PATH/enable_source" 2>/dev/null + val=$(cat "$STM_PATH/enable_source" 2>/dev/null) + + if [ "$val" != "0" ]; then + log_fail "Iteration $_count: Failed to disable STM source" + FAIL_COUNT=$((FAIL_COUNT + 1)) + fi + + _count=$((_count + 1)) +done + +reset_source_sink + +if [ "$FAIL_COUNT" -eq 0 ]; then + log_pass "STM source enable/disable loop passed (50 iterations)" + echo "$TESTNAME PASS" > "$res_file" +else + log_fail "STM source enable/disable loop failed ($FAIL_COUNT failures)" + echo "$TESTNAME FAIL" > "$res_file" +fi diff --git a/Runner/suites/Kernel/DEBUG/STM-Trace-Marker/README.md b/Runner/suites/Kernel/DEBUG/STM-Trace-Marker/README.md new file mode 100644 index 00000000..a7fff199 --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/STM-Trace-Marker/README.md @@ -0,0 +1,71 @@ +# STM-Trace-Marker Test + +## Overview +This test case verifies the functionality of the System Trace Macrocell (STM) by generating software trace events via Ftrace and capturing them in the Embedded Trace FIFO (ETF). + +## Test Goals +- Verify STM functionality by generating software trace events via Ftrace. +- Capture software trace events in the Embedded Trace FIFO (ETF). +- Validate that the captured binary data in the sink meets the expected size thresholds. + +## Prerequisites +- **Hardware:** + - STM Source: `stm0` (must be present in `/sys/bus/coresight/devices/`) + - ETF Sink: `tmc_etf0` (must be present in `/sys/bus/coresight/devices/`) +- **Software:** `configfs`, `debugfs` +- **Tools:** `timeout`, `stat`, `seq`, `awk` +- **Permissions:** Root access required to write to sysfs and debugfs nodes. + +## Script Location +`Runner/suites/Kernel/DEBUG/STM-Trace-Marker/STM-Trace-Marker.sh` + +## Files +- `STM-Trace-Marker.sh` - Main test script +- `STM-Trace-Marker.res` - Summary result file with PASS/FAIL + +## How It Works +1. **Setup:** + - Mounts `configfs` at `/sys/kernel/config`. + - Mounts `debugfs` at `/sys/kernel/debug`. + - Creates default STP policies for `stm0`. +2. **Execution:** + - Links the STM source to Ftrace. + - Enables the ETF sink (`tmc_etf0`). + - Writes marker data for the specified number of iterations. +3. **Verification:** + - Verifies that the captured binary data in the sink meets the expected size thresholds. + +## Example Output +``` +[INFO] 2026-03-16 10:26:35 - ----------------------------------------------------------------------------------------- +[INFO] 2026-03-16 10:26:35 - -------------------Starting STM-Trace-Marker Testcase---------------------------- +[INFO] 2026-03-16 10:26:35 - === Test Initialization === +[INFO] 2026-03-16 10:26:35 - Checking if required tools are available +[INFO] 2026-03-16 10:26:35 - Cleaning up Ftrace and STM settings... +[INFO] 2026-03-16 10:26:35 - Configuring Coresight Path... +[INFO] 2026-03-16 10:26:35 - Enabling Ftrace events... +[INFO] 2026-03-16 10:26:35 - Generating 500 trace marker events... +[INFO] 2026-03-16 10:26:45 - Dumping ETF buffer to /tmp/etf0.bin... +[INFO] 2026-03-16 10:26:45 - Captured binary size: 65536 bytes +[PASS] 2026-03-16 10:26:45 - Successfully captured STM trace data (65536 bytes) +[INFO] 2026-03-16 10:26:45 - Cleaning up Ftrace and STM settings... +``` + +## Return Code + +- `0` — Captured data met the expected size threshold and all transitions passed +- `1` — Verification failed or required components (hardware/filesystems) were missing + +## Integration in CI + +- Can be run standalone or via LAVA +- Result file STM-Trace-Marker.res will be parsed by result_parse.sh + +## Notes + +- The test relies heavily on the presence of `/sys/kernel/debug` and `/sys/kernel/config` to correctly route Ftrace data to the STM device. + +## 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/STM-Trace-Marker/STM-Trace-Marker.yaml b/Runner/suites/Kernel/DEBUG/STM-Trace-Marker/STM-Trace-Marker.yaml new file mode 100644 index 00000000..be077d3c --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/STM-Trace-Marker/STM-Trace-Marker.yaml @@ -0,0 +1,16 @@ +metadata: + name: MultiSource-STM-ETM + format: "Lava-Test Test Definition 1.0" + description: "Validates concurrent STM and ETM trace collection across multiple cores." + os: + - linux + scope: + - coresight + - kernel + +run: + steps: + - REPO_PATH=$PWD || true + - cd Runner/suites/Kernel/DEBUG/STM-Trace-Marker || true + - ./run.sh || true + - $REPO_PATH/Runner/utils/send-to-lava.sh STM-Trace-Marker.res || true \ No newline at end of file diff --git a/Runner/suites/Kernel/DEBUG/STM-Trace-Marker/run.sh b/Runner/suites/Kernel/DEBUG/STM-Trace-Marker/run.sh new file mode 100755 index 00000000..668c35fe --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/STM-Trace-Marker/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 (starting at $SCRIPT_DIR)" >&2 + exit 1 +fi + +if [ -z "$__INIT_ENV_LOADED" ]; then + # shellcheck disable=SC1090 + . "$INIT_ENV" +fi + +# shellcheck disable=SC1090,SC1091 +. "$TOOLS/functestlib.sh" +# shellcheck disable=SC1090,SC1091 +. "$TOOLS/coresight_common.sh" + +TESTNAME="STM-Trace-Marker" +if command -v find_test_case_by_name >/dev/null 2>&1; then + test_path=$(find_test_case_by_name "$TESTNAME") + cd "$test_path" || exit 1 +else + cd "$SCRIPT_DIR" || exit 1 +fi + +res_file="./$TESTNAME.res" +log_info "-----------------------------------------------------------------------------------------" +log_info "-------------------Starting $TESTNAME Testcase----------------------------" +log_info "=== Test Initialization ===" +log_info "Checking if required tools are available" + +for tool in timeout stat seq; do + if ! command -v "$tool" >/dev/null 2>&1; then + log_skip "Required tool '$tool' not found. Skipping test." + echo "$TESTNAME SKIP" > "$res_file" + exit 0 + fi +done + +RUNS=500 +if [ -n "$1" ]; then + case "$1" in + ''|*[!0-9]*) + log_warn "Invalid RUNS argument '$1' - using default: 500" + ;; + *) + RUNS=$1 + ;; + esac +fi + +if [ -z "$CS_BASE" ]; then + CS_BASE="/sys/bus/coresight/devices" +fi + +STM_PATH="$CS_BASE/stm0" +ETF_PATH="$CS_BASE/tmc_etf0" +DEBUG_FS="/sys/kernel/debug" +CONFIG_FS="/sys/kernel/config" +TRACE_MARKER="$DEBUG_FS/tracing/trace_marker" +STM_SOURCE_LINK="/sys/class/stm_source/ftrace/stm_source_link" +TMP_OUT="/tmp/etf0.bin" + +find_first_existing_path() { + for _dir_name in "$@"; do + if [ -d "$CS_BASE/$_dir_name" ]; then + echo "$CS_BASE/$_dir_name" + return 0 + fi + done + echo "" +} + +# Resolve paths +STM_PATH=$(find_first_existing_path "stm0" "coresight-stm") +ETF_PATH=$(find_first_existing_path "tmc_etf0" "tmc_etf" "tmc_etf1") + +cleanup_trace_marker() { + log_info "Cleaning up Ftrace and STM settings..." + + [ -f "$DEBUG_FS/tracing/tracing_on" ] && echo 0 > "$DEBUG_FS/tracing/tracing_on" 2>/dev/null + + [ -f "$DEBUG_FS/tracing/events/sched/sched_switch/enable" ] && \ + echo 0 > "$DEBUG_FS/tracing/events/sched/sched_switch/enable" 2>/dev/null + + if [ -n "$STM_PATH" ] && [ -f "$STM_PATH/enable_source" ]; then + echo 0 > "$STM_PATH/enable_source" 2>/dev/null + fi + + if [ -n "$ETF_PATH" ] && [ -f "$ETF_PATH/enable_sink" ]; then + echo 0 > "$ETF_PATH/enable_sink" 2>/dev/null + fi +} + +if [ -z "$STM_PATH" ] || [ -z "$ETF_PATH" ]; then + log_fail "Device STM or ETF not found in $CS_BASE" + echo "$TESTNAME FAIL" > "$res_file" + exit 1 +fi + +STM_NAME=$(basename "$STM_PATH") +ETF_NAME=$(basename "$ETF_PATH") + +cleanup_trace_marker + +if command -v cs_global_reset >/dev/null 2>&1; then + cs_global_reset +fi + +mkdir -p "$CONFIG_FS/stp-policy/$STM_NAME:p_basic.policy/default" 2>/dev/null + +log_info "Configuring Coresight Path..." +echo 0 > "$STM_PATH/hwevent_enable" 2>/dev/null + +echo 1 > "$ETF_PATH/enable_sink" +if [ "$(cat "$ETF_PATH/enable_sink" 2>/dev/null)" != "1" ]; then + log_fail "Failed to enable ETF sink ($ETF_NAME)" + echo "$TESTNAME FAIL" > "$res_file" + cleanup_trace_marker + exit 1 +fi + +if [ -f "$STM_SOURCE_LINK" ]; then + echo "$STM_NAME" > "$STM_SOURCE_LINK" 2>/dev/null +else + log_fail "STM Source Link not found at $STM_SOURCE_LINK" + echo "$TESTNAME FAIL" > "$res_file" + cleanup_trace_marker + exit 1 +fi + +echo 0xffffffff > "$STM_PATH/port_enable" 2>/dev/null +echo 1 > "$STM_PATH/enable_source" +if [ "$(cat "$STM_PATH/enable_source" 2>/dev/null)" != "1" ]; then + log_fail "Failed to enable STM source ($STM_NAME)" + echo "$TESTNAME FAIL" > "$res_file" + cleanup_trace_marker + exit 1 +fi + +if [ ! -f "$TRACE_MARKER" ]; then + log_fail "Trace marker file missing: $TRACE_MARKER" + echo "$TESTNAME FAIL" > "$res_file" + cleanup_trace_marker + exit 1 +fi + +log_info "Enabling Ftrace events..." +echo 1 > "$DEBUG_FS/tracing/events/sched/sched_switch/enable" 2>/dev/null +echo 1 > "$DEBUG_FS/tracing/tracing_on" 2>/dev/null + +log_info "Generating $RUNS trace marker events..." +for i in $(seq 1 "$RUNS"); do + echo "STM_TEST_MARKER_$i" > "$TRACE_MARKER" 2>/dev/null +done + +sleep 10 + +echo 0 > "$DEBUG_FS/tracing/tracing_on" 2>/dev/null +echo 0 > "$DEBUG_FS/tracing/events/sched/sched_switch/enable" 2>/dev/null + +log_info "Dumping ETF buffer to $TMP_OUT..." +true > "$TMP_OUT" + +if [ -c "/dev/$ETF_NAME" ]; then + timeout 5s cat "/dev/$ETF_NAME" > "$TMP_OUT" 2>/dev/null +else + log_fail "/dev/$ETF_NAME char device missing" + echo "$TESTNAME FAIL" > "$res_file" + cleanup_trace_marker + exit 1 +fi + +if [ -s "$TMP_OUT" ]; then + bin_size=$(stat -c%s "$TMP_OUT") + log_info "Captured binary size: $bin_size bytes" + + if [ "$bin_size" -ge 65536 ]; then + log_pass "Successfully captured STM trace data ($bin_size bytes)" + echo "$TESTNAME PASS" > "$res_file" + else + log_fail "Captured data too small ($bin_size bytes). Expected >= 4096" + echo "$TESTNAME FAIL" > "$res_file" + fi +else + log_fail "Output file not generated or is completely empty" + echo "$TESTNAME FAIL" > "$res_file" +fi + +cleanup_trace_marker + +# log_info "-------------------$TESTNAME Testcase Finished----------------------------" \ No newline at end of file diff --git a/Runner/suites/Kernel/DEBUG/Sink-Status-STM-Toggle/README.md b/Runner/suites/Kernel/DEBUG/Sink-Status-STM-Toggle/README.md new file mode 100644 index 00000000..82cd2e3d --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/Sink-Status-STM-Toggle/README.md @@ -0,0 +1,85 @@ +# Coresight Sink Status Test (STM Toggle) + +## Overview +This test verifies the dependency behavior between Coresight Sources (STM, ETM) and Sinks (TMC-ETF, TMC-ETR). It ensures that sinks open and close correctly based on the activity of connected sources. + +## Test Goals +- Verify the dependency management between Coresight trace sources and sinks. +- Ensure sinks correctly activate when a connected source (STM) is enabled. +- Ensure sinks correctly deactivate and release resources when the sole connected source is disabled. +- Validate multi-source behavior, ensuring a sink remains active if at least one connected source (e.g., ETM) is still active after another (e.g., STM) is disabled. + +## Prerequisites +- Kernel must be built with Coresight STM and ETM support. +- sysfs access to `/sys/bus/coresight/devices/`. +- Root privileges (to configure source and sink enables). + +## Script Location +`Runner/suites/Kernel/DEBUG/Sink-Status-STM-Toggle/run.sh` + +## Files +- `run.sh` - Main test script +- `Sink-Status-STM-Toggle.res` - Summary result file with PASS/FAIL +- `Sink-Status-STM-Toggle.log` - Full execution log (generated if logging is enabled) + +## How It Works +The test performs validation for every available sink (`tmc_etf0`, `tmc_etr0`, etc., excluding `tmc_etf1`). + +### Phase 1: Single Source (STM Only) +- **Setup:** Resets all Coresight devices. +- **Enable:** Enables the Sink -> Enables the STM Source. Verifies that the Sink's `enable_sink` attribute is 1. +- **Disable:** Disables the STM Source. Verifies that the Sink's `enable_sink` attribute drops to 0 (releasing the resource). + +### Phase 2: Multi-Source (STM + ETM) +*(Note: Runs only if an ETM device is detected)* +- **Setup:** Resets all Coresight devices. +- **Enable:** Enables the Sink -> Enables the STM Source -> Enables the ETM Source. Verifies that the Sink's `enable_sink` attribute is 1. +- **Partial Disable:** Disables only the STM Source. Verifies that the Sink's `enable_sink` attribute remains 1 (since the active ETM should keep the sink open). +- **Cleanup:** Resets all devices. + +## Example Output +``` +[INFO] 2026-03-16 09:33:19 - ----------------------------------------------------------------------------------------- +[INFO] 2026-03-16 09:33:19 - -------------------Starting Sink-Status-STM-Toggle Testcase---------------------------- +[INFO] 2026-03-16 09:33:19 - === Phase 1: STM Only Test === +[INFO] 2026-03-16 09:33:19 - Testing Sink: tmc_etf0 +[PASS] 2026-03-16 09:33:20 - Phase1_STM_Enable: /sys/bus/coresight/devices/tmc_etf0 status is 1 +[PASS] 2026-03-16 09:33:21 - Phase1_STM_Disable: /sys/bus/coresight/devices/tmc_etf0 status is 0 +[INFO] 2026-03-16 09:33:21 - Testing Sink: tmc_etr0 +[PASS] 2026-03-16 09:33:22 - Phase1_STM_Enable: /sys/bus/coresight/devices/tmc_etr0 status is 1 +[PASS] 2026-03-16 09:33:23 - Phase1_STM_Disable: /sys/bus/coresight/devices/tmc_etr0 status is 0 +[INFO] 2026-03-16 09:33:23 - Testing Sink: tmc_etr1 +[PASS] 2026-03-16 09:33:24 - Phase1_STM_Enable: /sys/bus/coresight/devices/tmc_etr1 status is 1 +[PASS] 2026-03-16 09:33:25 - Phase1_STM_Disable: /sys/bus/coresight/devices/tmc_etr1 status is 0 +[INFO] 2026-03-16 09:33:25 - === Phase 2: STM + ETM Test === +[INFO] 2026-03-16 09:33:25 - Testing Sink (Multi-Source): tmc_etf0 +[PASS] 2026-03-16 09:33:26 - Phase2_Both_Enable: /sys/bus/coresight/devices/tmc_etf0 status is 1 +[PASS] 2026-03-16 09:33:26 - Phase2_STM_Disable_ETM_Active: /sys/bus/coresight/devices/tmc_etf0 status is 1 +[INFO] 2026-03-16 09:33:26 - Testing Sink (Multi-Source): tmc_etr0 +[PASS] 2026-03-16 09:33:27 - Phase2_Both_Enable: /sys/bus/coresight/devices/tmc_etr0 status is 1 +[PASS] 2026-03-16 09:33:27 - Phase2_STM_Disable_ETM_Active: /sys/bus/coresight/devices/tmc_etr0 status is 1 +[INFO] 2026-03-16 09:33:27 - Testing Sink (Multi-Source): tmc_etr1 +[PASS] 2026-03-16 09:33:28 - Phase2_Both_Enable: /sys/bus/coresight/devices/tmc_etr1 status is 1 +[PASS] 2026-03-16 09:33:28 - Phase2_STM_Disable_ETM_Active: /sys/bus/coresight/devices/tmc_etr1 status is 1 +[PASS] 2026-03-16 09:33:28 - Sink status check passed across all phases +``` + +## Return Code + +- `0` — All sink states transitioned correctly across all phases and tested sinks +- `1` — One or more sinks failed to report the correct state during transitions + +## Integration in CI + +- Can be run standalone or via LAVA +- Result file Sink-Status-STM-Toggle.res will be parsed by result_parse.sh + +## Notes + +- tmc_etf1 is explicitly excluded from the available sinks for this test. +- The multi-source phase dynamically skips itself if no ETM devices are found on the target platform, preventing false failures on STM-only configurations. + +## 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/Sink-Status-STM-Toggle/Sink-Status-STM-Toggle.yaml b/Runner/suites/Kernel/DEBUG/Sink-Status-STM-Toggle/Sink-Status-STM-Toggle.yaml new file mode 100644 index 00000000..0bd1f93c --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/Sink-Status-STM-Toggle/Sink-Status-STM-Toggle.yaml @@ -0,0 +1,16 @@ +metadata: + name: Sink-Status-STM-Toggle + format: "Lava-Test Test Definition 1.0" + description: "Verifies that Coresight sinks maintain correct enabled/disabled states when sources (STM/ETM) are toggled." + os: + - linux + scope: + - coresight + - kernel + +run: + steps: + - REPO_PATH=$PWD || true + - cd Runner/suites/Kernel/DEBUG/Sink-Status-STM-Toggle || true + - ./run.sh || true + - $REPO_PATH/Runner/utils/send-to-lava.sh Sink-Status-STM-Toggle.res || true \ No newline at end of file diff --git a/Runner/suites/Kernel/DEBUG/Sink-Status-STM-Toggle/run.sh b/Runner/suites/Kernel/DEBUG/Sink-Status-STM-Toggle/run.sh new file mode 100755 index 00000000..ed6bd87e --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/Sink-Status-STM-Toggle/run.sh @@ -0,0 +1,200 @@ +#!/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="Sink-Status-STM-Toggle" +if command -v find_test_case_by_name >/dev/null 2>&1; then + test_path=$(find_test_case_by_name "$TESTNAME") + cd "$test_path" || exit 1 +else + cd "$SCRIPT_DIR" || exit 1 +fi + +res_file="./$TESTNAME.res" +log_info "-----------------------------------------------------------------------------------------" +log_info "-------------------Starting $TESTNAME Testcase----------------------------" + +CS_BASE="/sys/bus/coresight/devices" +FAIL_COUNT=0 + + +find_first_existing_path() { + for _dir_name in "$@"; do + if [ -d "$CS_BASE/$_dir_name" ]; then + echo "$CS_BASE/$_dir_name" + return 0 + fi + done + echo "" +} + +# Resolve paths +STM_PATH=$(find_first_existing_path "stm0" "coresight-stm") +ETM_PATH=$(find_first_existing_path "etm0" "etm" "coresight-etm0" "coresight-etm4x" "coresight-ete0") + +reset_devices() { + if [ -n "$STM_PATH" ] && [ -f "$STM_PATH/enable_source" ]; then + echo 0 > "$STM_PATH/enable_source" 2>/dev/null + fi + if [ -n "$ETM_PATH" ] && [ -f "$ETM_PATH/enable_source" ]; then + echo 0 > "$ETM_PATH/enable_source" 2>/dev/null + fi + + for s in "$CS_BASE"/tmc_et*; do + [ -d "$s" ] || continue + if [ -f "$s/curr_sink" ]; then + echo 0 > "$s/curr_sink" 2>/dev/null + fi + if [ -f "$s/enable_sink" ]; then + echo 0 > "$s/enable_sink" 2>/dev/null + fi + done +} + +check_sink_status() { + local_sink=$1 + expected=$2 + stage=$3 + + if [ -f "$local_sink/curr_sink" ]; then + val=$(cat "$local_sink/curr_sink") + else + val=$(cat "$local_sink/enable_sink") + fi + + if [ "$val" != "$expected" ]; then + log_fail "$stage: $local_sink status is $val (Expected: $expected)" + return 1 + else + log_pass "$stage: $local_sink status is $val" + return 0 + fi +} + +if [ -z "$STM_PATH" ]; then + log_fail "STM device not found in $CS_BASE" + echo "$TESTNAME FAIL" > "$res_file" + exit 1 +fi + +SINK_LIST="" +for _sink in "$CS_BASE"/tmc_et*; do + [ -d "$_sink" ] || continue + case "$_sink" in + *tmc_etf1) continue ;; + esac + SINK_LIST="${SINK_LIST:+$SINK_LIST }$_sink" +done + +if [ -z "$SINK_LIST" ]; then + log_fail "No suitable sinks found" + echo "$TESTNAME Fail" > "$res_file" + exit 1 +fi + +if [ -f "$CS_BASE/tmc_etr0/out_mode" ]; then + echo mem > "$CS_BASE/tmc_etr0/out_mode" +fi + +log_info "=== Phase 1: STM Only Test ===" + +for sink in $SINK_LIST; do + log_info "Testing Sink: $(basename "$sink")" + + reset_devices + echo 1 > "$sink/enable_sink" + echo 1 > "$STM_PATH/enable_source" + sleep 1 + + if ! check_sink_status "$sink" 1 "Phase1_STM_Enable"; then + FAIL_COUNT=$((FAIL_COUNT + 1)) + fi + + echo 0 > "$STM_PATH/enable_source" + sleep 1 + + echo 0 > "$sink/enable_sink" + if ! check_sink_status "$sink" 0 "Phase1_STM_Disable"; then + FAIL_COUNT=$((FAIL_COUNT + 1)) + fi +done + +log_info "=== Phase 2: STM + ETM Test ===" + +HAS_ETM=0 +if [ -n "$ETM_PATH" ] && [ -f "$ETM_PATH/enable_source" ]; then + HAS_ETM=1 +fi +if [ -d "$ETM_PATH" ]; then + if [ -f /proc/config.gz ]; then + if zcat /proc/config.gz | grep -q "CONFIG_CORESIGHT_SOURCE_ETM4X=y"; then + HAS_ETM=1 + fi + else + HAS_ETM=1 + fi +fi + +if [ "$HAS_ETM" -eq 1 ]; then + for sink in $SINK_LIST; do + log_info "Testing Sink (Multi-Source): $(basename "$sink")" + + reset_devices + echo 1 > "$sink/enable_sink" + + echo 1 > "$STM_PATH/enable_source" + echo 1 > "$ETM_PATH/enable_source" + sleep 1 + + if ! check_sink_status "$sink" 1 "Phase2_Both_Enable"; then + FAIL_COUNT=$((FAIL_COUNT + 1)) + fi + + echo 0 > "$STM_PATH/enable_source" + + if ! check_sink_status "$sink" 1 "Phase2_STM_Disable_ETM_Active"; then + FAIL_COUNT=$((FAIL_COUNT + 1)) + fi + + reset_devices + done +else + log_info "Skipping Phase 2 (ETM not found or not enabled)" +fi + +reset_devices + +if [ "$FAIL_COUNT" -eq 0 ]; then + log_pass "Sink status check passed across all phases" + echo "$TESTNAME PASS" > "$res_file" +else + log_fail "Sink status check failed ($FAIL_COUNT errors)" + echo "$TESTNAME FAIL" > "$res_file" +fi + +# log_info "-------------------$TESTNAME Testcase Finished----------------------------" \ No newline at end of file diff --git a/Runner/utils/coresight_common.sh b/Runner/utils/coresight_common.sh new file mode 100755 index 00000000..09336f0f --- /dev/null +++ b/Runner/utils/coresight_common.sh @@ -0,0 +1,61 @@ +#!/bin/sh +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. +# SPDX-License-Identifier: BSD-3-Clause + +# --- Logging helpers --- +CS_BASE="/sys/bus/coresight/devices" +CS_RESET_NODE="/sys/bus/coresight/reset_source_sink" + +# Helper for all reset +cs_global_reset() { + if [ -f "$CS_RESET_NODE" ]; then + echo 1 > "$CS_RESET_NODE" 2>/dev/null + else + for _sink in tmc_etr0 tmc_etf0 coresight-tmc-etr coresight-tmc-etf; do + if [ -f "$CS_BASE/$_sink/enable_sink" ]; then + echo 0 > "$CS_BASE/$_sink/enable_sink" 2>/dev/null + fi + done + fi +} + +# Helper to find sinks +cs_find_sinks() { + # shellcheck disable=SC2010 + ls "$CS_BASE" 2>/dev/null | grep -E "tmc.et[fr]|tmc-et[fr]" +} + +# Helper to enable sinks +cs_enable_sink() { + _sname="$1" + _spath="$CS_BASE/$_sname" + if [ ! -f "$_spath/enable_sink" ]; then + return 1 + fi + echo 1 > "$_spath/enable_sink" +} + +# Helper to disable sink +cs_disable_sink() { + _sname="$1" + _spath="$CS_BASE/$_sname" + if [ -f "$_spath/enable_sink" ]; then + echo 0 > "$_spath/enable_sink" 2>/dev/null + fi +} + +# Helper to find sources +cs_find_sources() { + _pattern="$1" + # shellcheck disable=SC2010 + ls "$CS_BASE" 2>/dev/null | grep "$_pattern" +} + +# Helper to check bases +cs_check_base() { + if [ ! -d "$CS_BASE" ]; then + log_fail "Coresight sysfs not found: $CS_BASE" + return 1 + fi + return 0 +} \ No newline at end of file