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,13 @@
metadata:
name: MultiSource-STM-ETM
description: "Validates concurrent STM and ETM trace collection across multiple cores."

os:
- linux
devices:
- qcm6490
- qcs9100
scope:
- coresight
- kernel
timeout: 300
25 changes: 25 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,25 @@
# Multi-Source STM + ETM Test

## Description
This test verifies the Coresight subsystem's ability to handle simultaneous trace data from:
1. **STM (System Trace Macrocell)**: Software events.
2. **ETM (Embedded Trace Macrocell)**: Instruction trace from all online CPUs.

It iterates through available sinks (e.g., `tmc_etf0`, `tmc_etr0`) and checks if valid binary data is captured.

## Dependencies
- **Library**: `Runner/utils/coresight_common.sh`
- **Kernel Config**: `CONFIG_CORESIGHT`, `CONFIG_CORESIGHT_STM`, `CONFIG_CORESIGHT_LINK_AND_SINK_TMC`.

## Execution
Run the script directly:
```bash
./run.sh
```

## Result
A result.res file is generated
```bash
MultiSource_tmc_etf0: Pass
MultiSource_tmc_etr0: Pass
```
152 changes: 152 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,152 @@
#!/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"

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"
rm -f "$res_file"
touch "$res_file"

log_info "-----------------------------------------------------------------------------------------"
log_info "-------------------Starting $TESTNAME Testcase----------------------------"
log_info "=== Test Initialization ==="
log_info "Checking if required tools are available"

CS_BASE="/sys/bus/coresight/devices"
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"

reset_source_sink() {
# shellcheck disable=SC2045
for dev in $(ls "$CS_BASE"); do
path="$CS_BASE/$dev"
if [ -f "$path/enable_source" ]; then
val=$(cat "$path/enable_source")
if [ "$val" -eq 1 ]; then
echo 0 > "$path/enable_source"
[ -f "$path/reset" ] && echo 1 > "$path/reset"
fi
fi
if [ -f "$path/enable_sink" ]; then
val=$(cat "$path/enable_sink")
[ "$val" -eq 1 ] && echo 0 > "$path/enable_sink"
fi
done
}

toggle_etm_all() {
state=$1
count=0
while [ "$count" -lt "$CORES" ]; do
[ -f "$CPU_PATH$count/online" ] && echo 1 > "$CPU_PATH$count/online"

if [ -d "$CS_BASE/ete$count" ]; then
etm_path="$CS_BASE/ete$count/enable_source"
elif [ -d "$CS_BASE/coresight-ete$count" ]; then
etm_path="$CS_BASE/coresight-ete$count/enable_source"
elif [ -d "$CS_BASE/etm$count" ]; then
etm_path="$CS_BASE/etm$count/enable_source"
elif [ -d "$CS_BASE/coresight-etm$count" ]; then
etm_path="$CS_BASE/coresight-etm$count/enable_source"
else
count=$((count + 1))
continue
fi

[ -f "$etm_path" ] && echo "$state" > "$etm_path"
count=$((count + 1))
done
}

reset_source_sink
toggle_etm_all 0

# shellcheck disable=SC2010
SINKS=$(ls "$CS_BASE" | grep "tmc_et" | grep -v "tmc_etf1")

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"

reset_source_sink
OUTPUT_BIN="/tmp/$sinkname.bin"
rm -f "$OUTPUT_BIN"

if [ -f "$CS_BASE/$sinkname/enable_sink" ]; then
echo 1 > "$CS_BASE/$sinkname/enable_sink"
else
log_warn "Sink $sinkname enable file 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

if [ -c "/dev/$sinkname" ]; then
timeout 2s cat "/dev/$sinkname" > "$OUTPUT_BIN"
fi

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

reset_source_sink
# log_info "-------------------$TESTNAME Testcase Finished----------------------------"
22 changes: 22 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,22 @@
# 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.

## Execution
1. **Setup**:
* Creates STP policy directories.
* Resets Coresight devices.
* Enables `tmc_etf0` as the sink.
2. **Test Loop (Run for both `hwevent_enable` and `port_enable`)**:
* **Outer Loop**: Toggles STM `enable_source` (0, then 1).
* **Inner Loop**: Toggles the target attribute (0, then 1).
* **Verification**: Reads back the attribute value to ensure it matches the written value.
3. **Teardown**:
* Resets all devices.
* Restores `hwevent_enable` to `0`.
* Restores `port_enable` to `0xffffffff` (all ports enabled).

## Output
* Console logs detailing the read/write operations.
* `STM-HWEvent-Port-Enable-Disable.res` containing Pass/Fail status for each attribute.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
metadata:
name: STM-HWEvent-Port-Enable-Disable
description: "Validates the ability to enable and disable STM Hardware Events and Ports via sysfs."

os:
- linux
devices:
- qcm6490
- qcs9100
scope:
- coresight
- kernel
timeout: 60
142 changes: 142 additions & 0 deletions Runner/suites/Kernel/DEBUG/STM-HWE-PORT-SWITCH/run.sh
Original file line number Diff line number Diff line change
@@ -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" = "hwevent_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 "hwevent_enable"
test_attribute "port_enable"

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

# log_info "-------------------$TESTNAME Testcase Finished----------------------------"
Loading
Loading