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,19 @@
metadata:
name: ETM-Enable-Disable
format: "Lava-Test Test Definition 1.0"
description: "Verifies the activation and deactivation functionality of Embedded
Trace Macrocell (ETM) devices. This test individually enables and disables
each ETM via its sysfs 'enable_source' node, followed by testing bulk enable
and disable operations across all cores simultaneously."
os:
- linux
scope:
- coresight
- kernel

run:
steps:
- REPO_PATH=$PWD || true
- cd Runner/suites/Kernel/DEBUG/ETM-Enable-Disable || true
- ./run.sh || true
- $REPO_PATH/Runner/utils/send-to-lava.sh ETM-Enable-Disable.res || true
80 changes: 80 additions & 0 deletions Runner/suites/Kernel/DEBUG/ETM-Enable-Disable/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# ETM-Enable-Disable Test

## Overview

This test validates the user-space sysfs interface for activating and deactivating Embedded Trace Macrocells (ETM). It ensures that the kernel properly handles ETM component state transitions by evaluating individual enable/disable cycles, as well as bulk enable and bulk disable sequences.

## Test Goals

Validate the user-space sysfs interface for ETM activation and deactivation.
Ensure the kernel properly handles individual enable/disable cycles for each CoreSight ETM device.
Verify bulk enable sequences (activating all ETMs simultaneously).
Verify bulk disable sequences (deactivating all ETMs simultaneously).

## Prerequisites

Kernel must be built with CoreSight core and ETM drivers.
CoreSight ETM Devices (etm* or coresight-etm*) must be present.
A valid sink like tmc_etf0 (or default tmc_etf) must be available.
sysfs must be mounted and accessible.
Root privileges (to write to sysfs nodes).

## Script Location

```
Runner/suites/Kernel/DEBUG/ETM-Enable-Disable/run.sh
```

## Files

- `run.sh` - Main test script
- `ETM-Enable-Disable.res` - Summary result file with PASS/FAIL based on aggregated results
- `ETM-Enable-Disable.log` - Full execution log (generated if logging is enabled)

## How It Works

1. **Discovery**: The script automatically queries the sysfs coresight bus to build a list of available ETMs.
2. **Individual Testing**: Performs individual enable and disable cycles for each detected CoreSight ETM device.
3. **Bulk Enable**: Executes a sequence to activate all discovered ETMs simultaneously.
4. **Bulk Disable**: Executes a sequence to deactivate all discovered ETMs simultaneously.
5. **Evaluation**: Evaluates the success of both individual and bulk operations, logging the status transitions.

## Usage

The script automatically queries the `sysfs` coresight bus to build a list of available ETMs and performs the transitions without requiring manual arguments.

```bash
./run.sh
```

## Example Output

```
[INFO] 2026-03-17 11:37:15 - -----------------------------------------------------------------------------------------
[INFO] 2026-03-17 11:37:15 - -------------------Starting ETM-Enable-Disable Testcase----------------------------
[INFO] 2026-03-17 11:37:15 - /sys/bus/coresight/devices/etm0 initial status: 0
[INFO] 2026-03-17 11:37:15 - enable /sys/bus/coresight/devices/etm0 PASS
[INFO] 2026-03-17 11:37:15 - disable /sys/bus/coresight/devices/etm0 PASS
......
[INFO] 2026-03-17 11:43:27 - Testing etm_enable_all_cores...
[INFO] 2026-03-17 11:43:28 - Testing etm_disable_all_cores...
[PASS] 2026-03-17 11:43:28 - ETM enable and disable test end: PASS
[INFO] 2026-03-17 11:43:28 - -------------------ETM-Enable-Disable Testcase Finished----------------------------
```

## Return Code

- `0` — All individual and bulk ETM state transitions completed successfully
- `1` — One or more ETM state transitions failed

## Integration in CI

- Can be run standalone or via LAVA
- Result file ETM-Enable-Disable.res will be parsed by result_parse.sh

## Notes
- This test does not require manual arguments as it automatically detects the available CoreSight topology.

## License
SPDX-License-Identifier: BSD-3-Clause-Clear
(c) Qualcomm Technologies, Inc. and/or its subsidiaries.
163 changes: 163 additions & 0 deletions Runner/suites/Kernel/DEBUG/ETM-Enable-Disable/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
#!/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-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"

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: No ETF sink found" >> "$res_file"
exit 1
fi

ETM_LIST=""
for _etm in "$CS_BASE"/etm* "$CS_BASE"/coresight-etm* "$CS_BASE"/coresight-ete*; do
[ -d "$_etm" ] || continue
ETM_LIST="$ETM_LIST $_etm"
done

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

fail_count=0

reset_devices() {
for dev in "$CS_BASE"/*; do
[ -d "$dev" ] || continue
if [ -f "$dev/enable_source" ]; then
echo 0 > "$dev/enable_source" 2>/dev/null
fi
if [ -f "$dev/enable_sink" ]; then
echo 0 > "$dev/enable_sink" 2>/dev/null
fi
done
}

reset_devices

log_info "Enabling ETF Sink at $ETF_PATH"
echo 1 > "$ETF_PATH/enable_sink" 2>/dev/null

for etm in $ETM_LIST; do
if [ -f "$etm/enable_source" ]; then
res=$(cat "$etm/enable_source" 2>/dev/null)
log_info "$etm initial status: ${res:-unknown}"

echo 1 > "$etm/enable_source" 2>/dev/null
res=$(cat "$etm/enable_source" 2>/dev/null)

if [ "$res" = "1" ]; then
log_info "enable $etm PASS"
else
log_fail "enable $etm FAIL"
fail_count=$((fail_count + 1))
fi

echo 0 > "$etm/enable_source" 2>/dev/null
res=$(cat "$etm/enable_source" 2>/dev/null)

if [ "$res" = "0" ]; then
log_info "disable $etm PASS"
else
log_fail "disable $etm FAIL"
fail_count=$((fail_count + 1))
fi
fi
done

log_info "Testing etm_enable_all_cores..."
for etm in $ETM_LIST; do
if [ -f "$etm/enable_source" ]; then
echo 1 > "$etm/enable_source" 2>/dev/null
fi
done

for etm in $ETM_LIST; do
if [ -f "$etm/enable_source" ]; then
res=$(cat "$etm/enable_source" 2>/dev/null)
if [ "$res" != "1" ]; then
log_fail "Failed to enable $etm during all_cores test"
fail_count=$((fail_count + 1))
fi
fi
done

log_info "Testing etm_disable_all_cores..."
for etm in $ETM_LIST; do
if [ -f "$etm/enable_source" ]; then
echo 0 > "$etm/enable_source" 2>/dev/null
fi
done

for etm in $ETM_LIST; do
if [ -f "$etm/enable_source" ]; then
res=$(cat "$etm/enable_source" 2>/dev/null)
if [ "$res" != "0" ]; then
log_fail "Failed to disable $etm during all_cores test"
fail_count=$((fail_count + 1))
fi
fi
done

reset_devices

if [ "$fail_count" -eq 0 ]; then
log_pass "ETM enable and disable test end: PASS"
echo "$TESTNAME: PASS" >> "$res_file"
else
log_fail "ETM enable and disable test end: FAIL ($fail_count errors)"
echo "$TESTNAME: FAIL" >> "$res_file"
fi

log_info "-------------------$TESTNAME Testcase Finished----------------------------"
18 changes: 18 additions & 0 deletions Runner/suites/Kernel/DEBUG/ETM-Register/ETM-Register.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
metadata:
name: ETM-Register
format: "Lava-Test Test Definition 1.0"
description: "Verifies read access to ETM (Embedded Trace Macrocell) registers
located in the sysfs management (mgmt) and base directories. Validates that
the registers can be read without errors while the ETM is active."
os:
- linux
scope:
- coresight
- kernel

run:
steps:
- REPO_PATH=$PWD || true
- cd Runner/suites/Kernel/DEBUG/ETM-Register || true
- ./run.sh || true
- $REPO_PATH/Runner/utils/send-to-lava.sh ETM-Register.res || true
87 changes: 87 additions & 0 deletions Runner/suites/Kernel/DEBUG/ETM-Register/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# ETM-Register Test

## Overview

This test case validates the readability of the CoreSight Embedded Trace Macrocell (ETM) sysfs registers. It iterates through all available ETM devices, temporarily enables them as trace sources with an active sink (ETF), and attempts to read their management (mgmt) and base node configurations to ensure they are accessible without throwing I/O or kernel errors.

## Test Goals

- Validate the readability of CoreSight ETM sysfs registers.
- Ensure management (mgmt) and base node configurations are accessible.
- Verify that reading these registers while the source is active does not cause I/O errors or kernel panics.
- Confirm smooth transition and sequential testing across multiple ETM devices.

## Prerequisites

- Kernel must be built with `CoreSight ETM` and TMC drivers.
- `CoreSight ETM` sources (etm* or coresight-etm*) must be present.
- A valid TMC sink, such as tmc_etf0 (or generic tmc_etf), must be available.
- `sysfs` must be mounted and accessible at `/sys`.
- Root privileges (to write to sysfs nodes and configure sources/sinks).

## Script Location

```
Runner/suites/Kernel/DEBUG/ETM-Register/run.sh
```

## Files

- `run.sh` - Main test script
- `ETM-Register.res` - Summary result file with PASS/FAIL based on whether all mgmt registers were successfully read
- `ETM-Register.log` - Full execution log (generated if logging is enabled)

## How It Works

1. **Discovery**: The script automatically discovers all available ETM devices and the designated ETF sink in the sysfs directory.
2. **Iteration**: For each discovered ETM device:
- **Setup**: Temporarily enables the tmc_etf sink.
- **Enable Source**: Enables the current ETM device as a trace source.
- **Read Registers**: Attempts to read the management (mgmt/) registers and base node configurations for the active ETM.
- **Verification**: Checks that the read operations succeed without throwing I/O errors or kernel issues.
- **Teardown**: Disables the ETM source and the sink before moving to the next device.

## Usage

The script automatically discovers available ETM devices and tests them sequentially. No manual arguments are required.

```bash
./run.sh
```

## Example Output

```
[INFO] 2026-03-17 11:29:22 - -----------------------------------------------------------------------------------------
[INFO] 2026-03-17 11:29:22 - -------------------Starting ETM-Register Testcase----------------------------
[INFO] 2026-03-17 11:29:22 - Found 8 ETM devices
[INFO] 2026-03-17 11:29:22 - Testing ETM node: /sys/bus/coresight/devices/etm0
[INFO] 2026-03-17 11:29:23 - Testing ETM node: /sys/bus/coresight/devices/etm1
[INFO] 2026-03-17 11:29:23 - Testing ETM node: /sys/bus/coresight/devices/etm2
[INFO] 2026-03-17 11:29:23 - Testing ETM node: /sys/bus/coresight/devices/etm3
[INFO] 2026-03-17 11:29:23 - Testing ETM node: /sys/bus/coresight/devices/etm4
[INFO] 2026-03-17 11:29:23 - Testing ETM node: /sys/bus/coresight/devices/etm5
[INFO] 2026-03-17 11:29:23 - Testing ETM node: /sys/bus/coresight/devices/etm6
[INFO] 2026-03-17 11:29:24 - Testing ETM node: /sys/bus/coresight/devices/etm7
[PASS] 2026-03-17 11:29:24 - ETM Register Read Test Successful
[INFO] 2026-03-17 11:29:24 - -------------------ETM-Register Testcase Finished----------------------------
```

## Return Code

- `0` — All management registers across all ETM devices were successfull read without errors
- `1` — One or more register read attempts threw an I/O error or failed

## Integration in CI

- Can be run standalone or via LAVA
- Result file ETM-Register.res will be parsed by result_parse.sh

## Notes

- The test specifically enables the ETM device as an active trace source before reading the registers to ensure access is valid under active tracing conditions.

## License

SPDX-License-Identifier: BSD-3-Clause-Clear
(c) Qualcomm Technologies, Inc. and/or its subsidiaries.
Loading