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: CTI-Enable-Disable
format: "Lava-Test Test Definition 1.0"
description: "Verifies that all Coresight CTI devices can be successfully enabled and disabled via sysfs."
os:
- linux
scope:
- coresight
- kernel

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

## Overview
This test validates the basic toggle functionality of the Coresight Cross Trigger Interface (CTI) drivers. It ensures that every CTI device exposed in sysfs can be turned on and off without errors.

## Test Goals

- Validate basic toggle functionality of Coresight CTI drivers.
- Ensure all sysfs-exposed CTI drivers can be enabled and disabled without errors.
- Verify that the device states are correctly reflected in sysfs after toggling.
- Ensure proper cleanup and reset of devices to a clean state after testing.

## Prerequisites

- Kernel must be built with Coresight CTI support.
- `sysfs` access to `/sys/bus/coresight/devices/`.
- Root priviledges needed.

## Script Location

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

## Files

- `run.sh` - Main test script
- `CTI-Enable-Disable.res` - Summary result file with PASS/FAIL
- `CTI-Enable-Disable.log` - Full execution log.

## How it works
1. **Preparation**:
* Disables `stm0`, `tmc_etr0`, and `tmc_etf0` to ensure a clean state.
* Enables `tmc_etf0` (Embedded Trace FIFO) as a sink, as some CTI configurations may require an active sink.
2. **Discovery**: Scans `/sys/bus/coresight/devices/` for any directory containing `cti`.
3. **Iteration**: For each CTI device:
* **Enable**: Writes `1` to the `enable` file.
* **Verify**: Reads the `enable` file; expects `1`.
* **Disable**: Writes `0` to the `enable` file.
* **Verify**: Reads the `enable` file; expects `0`.
4. **Cleanup**: Resets all devices to disabled state.

## Usage

Run the script directly. No iterations or special arguments are required for this basic test.

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

## Example Output

```
[INFO] 2026-03-23 10:43:51 - -----------------------------------------------------------------------------------------
[INFO] 2026-03-23 10:43:51 - -------------------Starting CTI-Enable-Disable Testcase----------------------------
[INFO] 2026-03-23 10:43:51 - Saving state and resetting Coresight devices...
[INFO] 2026-03-23 10:43:51 - Testing Device: cti_sys0
[PASS] 2026-03-23 10:43:51 - cti_sys0 Enabled Successfully
[PASS] 2026-03-23 10:43:51 - cti_sys0 Disabled Successfully
[PASS] 2026-03-23 10:43:51 - CTI Enable/Disable Test Completed Successfully
[INFO] 2026-03-23 10:43:51 - Restoring Coresight devices state...
[INFO] 2026-03-23 10:09:51 - -------------------CTI-Enable-Disable Testcase Finished----------------------------
```

## Return Code

- `0` — All CTI devices were toggled successfully
- `1` — One or more CTI devices failed to toggle

## Integration in CI

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

## Notes

- Some CTI cofigurations may require an active sink (like `tmc_etf0`) to function properly, which is handled in the preparation phase.
- Ensure no other trace/debug sessions are actively using the CTI devices before running this test.

## License

SPDX-License-Identifier: BSD-3-Clause.
(c) Qualcomm Technologies, Inc. and/or its subsidiaries.
152 changes: 152 additions & 0 deletions Runner/suites/Kernel/DEBUG/CTI-Enable-Disable/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" >&2
exit 1
fi

if [ -z "$__INIT_ENV_LOADED" ]; then
# shellcheck disable=SC1090
. "$INIT_ENV"
fi

# shellcheck disable=SC1090,SC1091
. "$TOOLS/functestlib.sh"

TESTNAME="CTI-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

ORIG_ETF0_SINK=""
ORIG_ETR0_SINK=""
ORIG_STM0_SOURCE=""

save_and_reset_devices() {
log_info "Saving state and resetting Coresight devices..."
if [ -f "$CS_BASE/tmc_etf0/enable_sink" ]; then
ORIG_ETF0_SINK=$(cat "$CS_BASE/tmc_etf0/enable_sink" 2>/dev/null)
echo 0 > "$CS_BASE/tmc_etf0/enable_sink" 2>/dev/null || true
fi
if [ -f "$CS_BASE/tmc_etr0/enable_sink" ]; then
ORIG_ETR0_SINK=$(cat "$CS_BASE/tmc_etr0/enable_sink" 2>/dev/null)
echo 0 > "$CS_BASE/tmc_etr0/enable_sink" 2>/dev/null || true
fi
if [ -f "$CS_BASE/stm0/enable_source" ]; then
ORIG_STM0_SOURCE=$(cat "$CS_BASE/stm0/enable_source" 2>/dev/null)
echo 0 > "$CS_BASE/stm0/enable_source" 2>/dev/null || true
fi
}

cleanup() {
log_info "Restoring Coresight devices state..."
if [ -n "$ORIG_ETF0_SINK" ] && [ -f "$CS_BASE/tmc_etf0/enable_sink" ]; then
echo "$ORIG_ETF0_SINK" > "$CS_BASE/tmc_etf0/enable_sink" 2>/dev/null || true
fi
if [ -n "$ORIG_ETR0_SINK" ] && [ -f "$CS_BASE/tmc_etr0/enable_sink" ]; then
echo "$ORIG_ETR0_SINK" > "$CS_BASE/tmc_etr0/enable_sink" 2>/dev/null || true
fi
if [ -n "$ORIG_STM0_SOURCE" ] && [ -f "$CS_BASE/stm0/enable_source" ]; then
echo "$ORIG_STM0_SOURCE" > "$CS_BASE/stm0/enable_source" 2>/dev/null || true
fi
}

trap cleanup EXIT

if [ ! -d "$CS_BASE" ]; then
log_fail "Coresight directory not found: $CS_BASE"
echo "$TESTNAME FAIL" > "$res_file"
exit 1
fi

save_and_reset_devices

if [ -f "$CS_BASE/tmc_etf0/enable_sink" ]; then
echo 1 > "$CS_BASE/tmc_etf0/enable_sink"
else
log_warn "tmc_etf0 not found, proceeding without it..."
fi

CTI_LIST=""
for _dev in "$CS_BASE"/cti*; do
[ -e "$_dev" ] || continue
CTI_LIST="$CTI_LIST $(basename "$_dev")"
done

if [ -z "$CTI_LIST" ]; then
log_fail "No CTI devices found."
echo "$TESTNAME FAIL" > "$res_file"
exit 1
else
for cti in $CTI_LIST; do
dev_path="$CS_BASE/$cti"

if [ ! -f "$dev_path/enable" ]; then
log_warn "Skipping $cti: 'enable' node not found"
continue
fi

log_info "Testing Device: $cti"

if ! echo 1 > "$dev_path/enable"; then
log_fail "$cti: Failed to write 1 to enable"
FAIL_COUNT=$((FAIL_COUNT + 1))
continue
fi

res=$(cat "$dev_path/enable")
if [ "$res" -eq 1 ]; then
log_pass "$cti Enabled Successfully"
else
log_fail "$cti Failed to Enable (Value: $res)"
FAIL_COUNT=$((FAIL_COUNT + 1))
fi

if ! echo 0 > "$dev_path/enable"; then
log_fail "$cti: Failed to write 0 to enable"
FAIL_COUNT=$((FAIL_COUNT + 1))
continue
fi

res=$(cat "$dev_path/enable")
if [ "$res" -eq 0 ]; then
log_pass "$cti Disabled Successfully"
else
log_fail "$cti Failed to Disable (Value: $res)"
FAIL_COUNT=$((FAIL_COUNT + 1))
fi
done
fi

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

log_info "-------------------$TESTNAME Testcase Finished----------------------------"
16 changes: 16 additions & 0 deletions Runner/suites/Kernel/DEBUG/CTI-Test/CTI-Test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
metadata:
name: CTI-Trigger-Map
format: "Lava-Test Test Definition 1.0"
description: "Validates Coresight Cross Trigger Interface (CTI) by mapping and unmapping triggers to channels."
os:
- linux
scope:
- coresight
- kernel

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

## Overview
This test verifies the functionality of the Coresight CTI (Cross Trigger Interface) driver. It ensures that hardware triggers can be successfully mapped (attached) to CTI channels and subsequently unmapped (detached).

## Test Goals

- Validate the core functionality of Coresight CTI driver.
- Ensure hardware triggers can be correctly attached to CTI channels.
- Validate compatibility across both Modern and Legacy sysfs interfaces.
- Prevent device low-power states during testing to ensure register accessibility.

## Prerequisites

- Kernel must be built with Coresight CTI support.
- `sysfs` access to `sys/module/lpm_levels/parameters/sleep_disabled`.
- `sysfs` access to `/sys/bus/coresight/devices/`.
- Root priviledges needed.

## Script Location

```
Runner/suites/Kernel/DEBUG/CTI-Test/run.sh
```

## Files

- `run.sh` - Main test script
- `CTI-Test.res` - Summary result file with PASS/FAIL
- `CTI-Test.log` - Full execution log.

## How it works
1. **Sleep Disable**: Temporarily prevents the device from entering low-power modes (`/sys/module/lpm_levels/parameters/sleep_disabled`) to ensure CTI registers are accessible.
2. **Discovery**: Finds all CTI devices in `/sys/bus/coresight/devices/`.
3. **Mode Detection**: Checks for the existence of `enable` sysfs node to determine if the driver uses the Modern or Legacy sysfs interface.
4. **Configuration Parsing**: Reads the `devid` (Modern) or `show_info` (Legacy) to calculate the maximum number of triggers and channels supported by the hardware.
5. **Test Loop**:
* Iterates through a subset of triggers (randomized within valid range).
* Iterates through valid channels.
* **Attach**: writes `channel trigger` to `trigin_attach` / `trigout_attach`.
* **Verify**: Reads back via `chan_xtrigs_sel` and `chan_xtrigs_in`/`out` to confirm mapping.
* **Detach**: Unmaps the trigger and confirms the entry is cleared.
6. **Cleanup**: Restores the original LPM sleep setting.

## Usage

Run the script directly. No iterations or special arguments are required for this basic test.

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

## Example Output

```
[INFO] 2026-03-24 04:56:37 - -----------------------------------------------------------------------------------------
[INFO] 2026-03-24 04:56:37 - -------------------Starting CTI-Test Testcase----------------------------
[INFO] 2026-03-24 04:56:37 - CTI Driver Version: Modern
[INFO] 2026-03-24 04:56:37 - Device: cti_sys0 (MaxTrig: 8, MaxCh: 4)
[INFO] 2026-03-24 04:56:37 - Attach trigin: trig 0 -> ch 0 on cti_sys0
[INFO] 2026-03-24 04:56:37 - Attach trigout: trig 0 -> ch 0 on cti_sys0
.....
[INFO] 2026-03-24 04:56:39 - Attach trigout: trig 7 -> ch 2 on cti_sys0
[INFO] 2026-03-24 04:56:39 - Attach trigin: trig 7 -> ch 3 on cti_sys0
[INFO] 2026-03-24 04:56:39 - Attach trigout: trig 7 -> ch 3 on cti_sys0
[PASS] 2026-03-24 04:56:39 - CTI map/unmap Test PASS
[INFO] 2026-03-24 04:56:39 - -------------------CTI-Test Testcase Finished----------------------------
```

## Return Code

- `0` — All triggers and channels mapped/unmapped successfully across all CTI devices
- `1` — One or more mapping/unmapping operations failed

## Integration in CI

- Can be run standalone or via LAVA
- Result file `CTI-Test.res` will be parsed by `result_parse.sh`

## Notes

- The test iterates through a randomized subset of triggers rather than exhaustively testing every combination to optimize execution time while maintaining coverage.
- Disabling sleep modes is critical; if the device enters a low-power state, CTI registers may drop, causing false failures or system crashes.

## License

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