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
Original file line number Diff line number Diff line change
@@ -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
71 changes: 71 additions & 0 deletions Runner/suites/Kernel/DEBUG/MultiSource-STM-ETM/README.md
Original file line number Diff line number Diff line change
@@ -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.
173 changes: 173 additions & 0 deletions Runner/suites/Kernel/DEBUG/MultiSource-STM-ETM/run.sh
Original file line number Diff line number Diff line change
@@ -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
74 changes: 74 additions & 0 deletions Runner/suites/Kernel/DEBUG/STM-HWE-PORT-SWITCH/README.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -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
Loading