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
13 changes: 13 additions & 0 deletions Runner/suites/Kernel/DEBUG/ETM-Test-Mode/ETM-Test-Mode.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
metadata:
name: ETM-Test-Mode
description: "Validates ETM functionality by setting the 'mode' attribute to high (0xFFFFFFF) and enabling the cores."

os:
- linux
devices:
- qcm6490
- qcs9100
scope:
- coresight
- kernel
timeout: 60
21 changes: 21 additions & 0 deletions Runner/suites/Kernel/DEBUG/ETM-Test-Mode/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# ETM Test Mode

## Overview
This test verifies the stability and write-access of the **ETM (Embedded Trace Macrocell)** `mode` attribute. It sets the mode to `0XFFFFFFF` (enabling various mode bits like cycle-accurate tracing, etc., depending on the hardware revision) and attempts to enable the ETM sources.

## Execution
1. **Discovery**: Scans `/sys/bus/coresight/devices/` for ETM devices (`etm*` or `coresight-etm*`).
2. **Setup**:
* Resets all Coresight sources and sinks.
* Enables `tmc_etr0` as the trace sink.
3. **Test**:
* Iterates through all detected ETM devices.
* Writes `0XFFFFFFF` to the `mode` sysfs attribute.
* Enables the ETM source.
4. **Teardown**:
* Writes `0x0` to the `mode` sysfs attribute (restoring defaults).
* Disables all sources and sinks.

## Output
* Console logs showing detection and configuration of each core.
* `ETM-Test-Mode.res` containing the final Pass/Fail status.
135 changes: 135 additions & 0 deletions Runner/suites/Kernel/DEBUG/ETM-Test-Mode/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#!/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="ETM-Test-Mode"
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"
ETR_PATH="$CS_BASE/tmc_etr0"
[ ! -d "$ETR_PATH" ] && ETR_PATH="$CS_BASE/tmc_etr"


reset_source_sink() {
if [ -f "$CS_BASE/stm0/enable_source" ]; then
echo 0 > "$CS_BASE/stm0/enable_source"
fi

# shellcheck disable=SC2086
for etm in $ETM_LIST; do
if [ -f "$etm/enable_source" ]; then
echo 0 > "$etm/enable_source"
fi
done

if [ -f "$ETR_PATH/enable_sink" ]; then
echo 0 > "$ETR_PATH/enable_sink"
fi
if [ -f "$CS_BASE/tmc_etf0/enable_sink" ]; then
echo 0 > "$CS_BASE/tmc_etf0/enable_sink"
fi
}


# shellcheck disable=SC2010
ETM_LIST=$(ls -d "$CS_BASE"/etm* "$CS_BASE"/coresight-etm* 2>/dev/null)

if [ -z "$ETM_LIST" ]; then
log_fail "No Coresight ETM devices found"
echo "$TESTNAME: FAIL" >> "$res_file"
exit 1
fi

log_info "Found ETM devices: $(echo "$ETM_LIST" | tr '\n' ' ')"

reset_source_sink

if [ -d "$ETR_PATH" ]; then
log_info "Enabling Sink: $ETR_PATH"
echo 1 > "$ETR_PATH/enable_sink"
else
log_fail "TMC-ETR sink not found"
echo "$TESTNAME: FAIL" >> "$res_file"
exit 1
fi

fail_count=0

# shellcheck disable=SC2086
for etm in $ETM_LIST; do
log_info "Configuring $etm"

if [ -f "$etm/mode" ]; then
echo 0XFFFFFFF > "$etm/mode"
if [ $? -ne 0 ]; then
log_warn "Failed to set mode on $etm"
fail_count=$((fail_count + 1))
fi
else
log_warn "$etm does not have 'mode' attribute"
fi

if [ -f "$etm/enable_source" ]; then
echo 1 > "$etm/enable_source"
if [ $? -ne 0 ]; then
log_fail "Failed to enable $etm"
fail_count=$((fail_count + 1))
fi
fi
done

if [ $fail_count -eq 0 ]; then
log_pass "ETM Mode Configuration Successful"
echo "$TESTNAME: PASS" >> "$res_file"
else
log_fail "ETM Mode Configuration Failed ($fail_count errors)"
echo "$TESTNAME: FAIL" >> "$res_file"
fi

# shellcheck disable=SC2086
for etm in $ETM_LIST; do
if [ -f "$etm/mode" ]; then
echo 0x0 > "$etm/mode"
fi
done

reset_source_sink

# log_info "-------------------$TESTNAME Testcase Finished----------------------------"
13 changes: 13 additions & 0 deletions Runner/suites/Kernel/DEBUG/ETM-Trace/ETM-Trace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
metadata:
name: ETM-Trace-Enable-Disable
description: "Validates the stability of enabling and disabling ETM sources repeatedly and verifies trace data generation."

os:
- linux
devices:
- qcm6490
- qcs9100
scope:
- coresight
- kernel
timeout: 300
27 changes: 27 additions & 0 deletions Runner/suites/Kernel/DEBUG/ETM-Trace/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# ETM Trace Test

## Overview
This test validates the reliability of the ETM (Embedded Trace Macrocell) drivers by repeatedly enabling and disabling trace sources and verifying that data is successfully written to the sinks.

## Execution Logic
The test iterates through **every available sink** (excluding `tmc_etf1`) and **every available ETM source**.

For each Sink $\leftrightarrow$ Source pair, it performs `N` iterations (default: 2):
1. **Reset**: Disable all Coresight devices.
2. **Enable Sink**: Activate the current sink (e.g., `tmc_etr0`).
3. **Enable Source**: Activate the current ETM (e.g., `etm0`).
4. **Capture**: Sleep for 3 seconds to generate trace data, then dump the content of `/dev/<sink_name>` to a temporary binary file.
5. **Verify**:
* Check if the captured binary file size is $\ge$ 64 bytes.
* Check if the source disabled correctly.

## Usage
Run the script directly or via the runner.
Optional argument: Number of iterations per device pair.
```bash
./run.sh 5
```

## Output
* Console logs for each iteration.
* ETM-Trace-Enable-Disable.res containing the final Pass/Fail status.
174 changes: 174 additions & 0 deletions Runner/suites/Kernel/DEBUG/ETM-Trace/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
#!/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="ETM-Trace"
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"
TMP_DIR="/tmp/coresight-test"
FAIL_COUNT=0

RUNS=2
if [ -n "$1" ]; then
RUNS=$1
fi

rm -rf "$TMP_DIR"
mkdir -p "$TMP_DIR"


reset_devices() {
if [ -f "$CS_BASE/stm0/enable_source" ]; then
echo 0 > "$CS_BASE/stm0/enable_source" 2>/dev/null
fi

# shellcheck disable=SC2010
for etm in $(ls -d "$CS_BASE"/etm* "$CS_BASE"/coresight-etm* 2>/dev/null); do
if [ -f "$etm/enable_source" ]; then
echo 0 > "$etm/enable_source" 2>/dev/null
fi
done

for sink in "$CS_BASE"/tmc_et*; do
if [ -f "$sink/enable_sink" ]; then
echo 0 > "$sink/enable_sink" 2>/dev/null
fi
done
}

run_trace_test() {
sourcename=$1
sinkname=$2

bin_dir="$TMP_DIR/$sinkname"
mkdir -p "$bin_dir"

log_info ">>> Source: $(basename "$sourcename") | Sink: $sinkname"

if ! echo 1 > "$sourcename/enable_source"; then
log_fail "Failed to write 1 to $sourcename/enable_source"
return 1
fi

res=$(cat "$sourcename/enable_source")
if [ "$res" -eq 1 ]; then
log_info "Source enabled successfully"
else
log_fail "Source failed to enable (Value: $res)"
return 1
fi

sleep 3

outfile="$bin_dir/$(basename "$sourcename").bin"
timeout 5 cat "/dev/$sinkname" > "$outfile" 2>/dev/null

if [ -f "$outfile" ]; then
bin_size=$(stat -c%s "$outfile")
log_info " captured bin size: $bin_size bytes"

if [ "$bin_size" -ge 64 ]; then
log_pass "Trace data captured for $sourcename -> $sinkname"
else
log_fail "Trace data too small ($bin_size < 64)"
FAIL_COUNT=$((FAIL_COUNT + 1))
fi
else
log_fail "Failed to create output file from /dev/$sinkname"
FAIL_COUNT=$((FAIL_COUNT + 1))
fi

echo 0 > "$sourcename/enable_source"
res=$(cat "$sourcename/enable_source")

if [ "$res" -eq 0 ]; then
log_info "Source disabled successfully"
else
log_fail "Source failed to disable (Value: $res)"
FAIL_COUNT=$((FAIL_COUNT + 1))
fi
}


# shellcheck disable=SC2010
SINK_LIST=$(ls -d "$CS_BASE"/tmc_et* 2>/dev/null | grep -v tmc_etf1)
# shellcheck disable=SC2010
ETM_LIST=$(ls -d "$CS_BASE"/etm* "$CS_BASE"/coresight-etm* 2>/dev/null)

if [ -z "$SINK_LIST" ] || [ -z "$ETM_LIST" ]; then
log_fail "Missing Sinks or ETM devices"
echo "$TESTNAME: FAIL" >> "$res_file"
exit 1
fi

reset_devices

for sink_path in $SINK_LIST; do
sinkname=$(basename "$sink_path")

i=0
while [ $i -lt "$RUNS" ]; do
log_info "--- Iteration $((i+1)) for Sink: $sinkname ---"

for etm_path in $ETM_LIST; do
reset_devices

echo 1 > "$sink_path/enable_sink"

run_trace_test "$etm_path" "$sinkname"
done

i=$((i+1))
done
done

reset_devices

if [ "$FAIL_COUNT" -eq 0 ]; then
log_pass "ETM Trace Enable/Disable Test Completed Successfully"
echo "$TESTNAME: PASS" >> "$res_file"
else
log_fail "ETM Trace Enable/Disable Test Failed ($FAIL_COUNT errors)"
echo "$TESTNAME: FAIL" >> "$res_file"
fi

rm -rf "$TMP_DIR"
# log_info "-------------------$TESTNAME Testcase Finished----------------------------"
Loading
Loading