Skip to content

Commit 0def8dd

Browse files
Added CTI enable/disable, trigger mapping, and sysfs node access tests
This commit adds CTI validation test cases to verify basic enable/disable operations, trigger channel mapping functionality, and sysfs node accessibility across devices. * CTI-Enable-Disable: Validates enable/disable operations on all detected CTI devices and ensures correct state transitions. * CTI-Test: Verifies CTI trigger-in and trigger-out attach/detach functionality. * Node-Access: Ensures all readable CoreSight sysfs nodes can be accessed without failure. Signed-off-by: Rohan Dutta <rohadutt@qti.qualcomm.com>
1 parent 89e3067 commit 0def8dd

File tree

9 files changed

+844
-0
lines changed

9 files changed

+844
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
metadata:
2+
name: CTI-Enable-Disable
3+
format: "Lava-Test Test Definition 1.0"
4+
description: "Verifies that all Coresight CTI devices can be successfully enabled and disabled via sysfs."
5+
os:
6+
- linux
7+
scope:
8+
- coresight
9+
- kernel
10+
11+
run:
12+
steps:
13+
- REPO_PATH=$PWD || true
14+
- cd Runner/suites/Kernel/DEBUG/CTI-Enable-Disable || true
15+
- ./run.sh || true
16+
- $REPO_PATH/Runner/utils/send-to-lava.sh CTI-Enable-Disable.res || true
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Coresight CTI Enable/Disable Test
2+
3+
## Overview
4+
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.
5+
6+
## Test Goals
7+
8+
- Validate basic toggle functionality of Coresight CTI drivers.
9+
- Ensure all sysfs-exposed CTI drivers can be enabled and disabled without errors.
10+
- Verify that the device states are correctly reflected in sysfs after toggling.
11+
- Ensure proper cleanup and reset of devices to a clean state after testing.
12+
13+
## Prerequisites
14+
15+
- Kernel must be built with Coresight CTI support.
16+
- `sysfs` access to `/sys/bus/coresight/devices/`.
17+
- Root priviledges needed.
18+
19+
## Script Location
20+
21+
```
22+
Runner/suites/Kernel/DEBUG/CTI-Enable-Disable/run.sh
23+
```
24+
25+
## Files
26+
27+
- `run.sh` - Main test script
28+
- `CTI-Enable-Disable.res` - Summary result file with PASS/FAIL
29+
- `CTI-Enable-Disable.log` - Full execution log.
30+
31+
## How it works
32+
1. **Preparation**:
33+
* Disables `stm0`, `tmc_etr0`, and `tmc_etf0` to ensure a clean state.
34+
* Enables `tmc_etf0` (Embedded Trace FIFO) as a sink, as some CTI configurations may require an active sink.
35+
2. **Discovery**: Scans `/sys/bus/coresight/devices/` for any directory containing `cti`.
36+
3. **Iteration**: For each CTI device:
37+
* **Enable**: Writes `1` to the `enable` file.
38+
* **Verify**: Reads the `enable` file; expects `1`.
39+
* **Disable**: Writes `0` to the `enable` file.
40+
* **Verify**: Reads the `enable` file; expects `0`.
41+
4. **Cleanup**: Resets all devices to disabled state.
42+
43+
## Usage
44+
45+
Run the script directly. No iterations or special arguments are required for this basic test.
46+
47+
```bash
48+
./run.sh
49+
```
50+
51+
## Example Output
52+
53+
```
54+
[INFO] 2026-03-23 10:43:51 - -----------------------------------------------------------------------------------------
55+
[INFO] 2026-03-23 10:43:51 - -------------------Starting CTI-Enable-Disable Testcase----------------------------
56+
[INFO] 2026-03-23 10:43:51 - Saving state and resetting Coresight devices...
57+
[INFO] 2026-03-23 10:43:51 - Testing Device: cti_sys0
58+
[PASS] 2026-03-23 10:43:51 - cti_sys0 Enabled Successfully
59+
[PASS] 2026-03-23 10:43:51 - cti_sys0 Disabled Successfully
60+
[PASS] 2026-03-23 10:43:51 - CTI Enable/Disable Test Completed Successfully
61+
[INFO] 2026-03-23 10:43:51 - Restoring Coresight devices state...
62+
[INFO] 2026-03-23 10:09:51 - -------------------CTI-Enable-Disable Testcase Finished----------------------------
63+
```
64+
65+
## Return Code
66+
67+
- `0` — All CTI devices were toggled successfully
68+
- `1` — One or more CTI devices failed to toggle
69+
70+
## Integration in CI
71+
72+
- Can be run standalone or via LAVA
73+
- Result file `CTI-Enable-Disable.res` will be parsed by `result_parse.sh`
74+
75+
## Notes
76+
77+
- Some CTI cofigurations may require an active sink (like `tmc_etf0`) to function properly, which is handled in the preparation phase.
78+
- Ensure no other trace/debug sessions are actively using the CTI devices before running this test.
79+
80+
## License
81+
82+
SPDX-License-Identifier: BSD-3-Clause.
83+
(c) Qualcomm Technologies, Inc. and/or its subsidiaries.
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
#!/bin/sh
2+
3+
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
4+
# SPDX-License-Identifier: BSD-3-Clause
5+
6+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
7+
INIT_ENV=""
8+
SEARCH="$SCRIPT_DIR"
9+
while [ "$SEARCH" != "/" ]; do
10+
if [ -f "$SEARCH/init_env" ]; then
11+
INIT_ENV="$SEARCH/init_env"
12+
break
13+
fi
14+
SEARCH=$(dirname "$SEARCH")
15+
done
16+
17+
if [ -z "$INIT_ENV" ]; then
18+
echo "[ERROR] Could not find init_env" >&2
19+
exit 1
20+
fi
21+
22+
if [ -z "$__INIT_ENV_LOADED" ]; then
23+
# shellcheck disable=SC1090
24+
. "$INIT_ENV"
25+
fi
26+
27+
# shellcheck disable=SC1090,SC1091
28+
. "$TOOLS/functestlib.sh"
29+
30+
TESTNAME="CTI-Enable-Disable"
31+
if command -v find_test_case_by_name >/dev/null 2>&1; then
32+
test_path=$(find_test_case_by_name "$TESTNAME")
33+
cd "$test_path" || exit 1
34+
else
35+
cd "$SCRIPT_DIR" || exit 1
36+
fi
37+
38+
res_file="./$TESTNAME.res"
39+
log_info "-----------------------------------------------------------------------------------------"
40+
log_info "-------------------Starting $TESTNAME Testcase----------------------------"
41+
cs_base="/sys/bus/coresight/devices"
42+
fail_count=0
43+
44+
etf0_sink=""
45+
etr0_sink=""
46+
stm0_sink=""
47+
48+
save_and_reset_devices() {
49+
log_info "Saving state and resetting Coresight devices..."
50+
if [ -f "$cs_base/tmc_etf0/enable_sink" ]; then
51+
etf0_sink=$(cat "$cs_base/tmc_etf0/enable_sink" 2>/dev/null)
52+
echo 0 > "$cs_base/tmc_etf0/enable_sink" 2>/dev/null || true
53+
fi
54+
if [ -f "$cs_base/tmc_etr0/enable_sink" ]; then
55+
etr0_sink=$(cat "$cs_base/tmc_etr0/enable_sink" 2>/dev/null)
56+
echo 0 > "$cs_base/tmc_etr0/enable_sink" 2>/dev/null || true
57+
fi
58+
if [ -f "$cs_base/stm0/enable_source" ]; then
59+
stm0_sink=$(cat "$cs_base/stm0/enable_source" 2>/dev/null)
60+
echo 0 > "$cs_base/stm0/enable_source" 2>/dev/null || true
61+
fi
62+
}
63+
64+
cleanup() {
65+
log_info "Restoring Coresight devices state..."
66+
if [ -n "$etf0_sink" ] && [ -f "$cs_base/tmc_etf0/enable_sink" ]; then
67+
echo "$etf0_sink" > "$cs_base/tmc_etf0/enable_sink" 2>/dev/null || true
68+
fi
69+
if [ -n "$etr0_sink" ] && [ -f "$cs_base/tmc_etr0/enable_sink" ]; then
70+
echo "$etr0_sink" > "$cs_base/tmc_etr0/enable_sink" 2>/dev/null || true
71+
fi
72+
if [ -n "$stm0_sink" ] && [ -f "$cs_base/stm0/enable_source" ]; then
73+
echo "$stm0_sink" > "$cs_base/stm0/enable_source" 2>/dev/null || true
74+
fi
75+
}
76+
77+
trap cleanup EXIT
78+
79+
if [ ! -d "$cs_base" ]; then
80+
log_fail "Coresight directory not found: $cs_base"
81+
echo "$TESTNAME FAIL" > "$res_file"
82+
exit 1
83+
fi
84+
85+
save_and_reset_devices
86+
87+
if [ -f "$cs_base/tmc_etf0/enable_sink" ]; then
88+
echo 1 > "$cs_base/tmc_etf0/enable_sink"
89+
else
90+
log_warn "tmc_etf0 not found, proceeding without it..."
91+
fi
92+
93+
cti_list=""
94+
for _dev in "$cs_base"/cti*; do
95+
[ -e "$_dev" ] || continue
96+
cti_list="$cti_list $(basename "$_dev")"
97+
done
98+
99+
if [ -z "$cti_list" ]; then
100+
log_fail "No CTI devices found."
101+
echo "$TESTNAME FAIL" > "$res_file"
102+
exit 1
103+
else
104+
for cti in $cti_list; do
105+
dev_path="$cs_base/$cti"
106+
107+
if [ ! -f "$dev_path/enable" ]; then
108+
log_warn "Skipping $cti: 'enable' node not found"
109+
continue
110+
fi
111+
112+
log_info "Testing Device: $cti"
113+
114+
if ! echo 1 > "$dev_path/enable"; then
115+
log_fail "$cti: Failed to write 1 to enable"
116+
fail_count=$((fail_count + 1))
117+
continue
118+
fi
119+
120+
res=$(cat "$dev_path/enable")
121+
if [ "$res" -eq 1 ]; then
122+
log_pass "$cti Enabled Successfully"
123+
else
124+
log_fail "$cti Failed to Enable (Value: $res)"
125+
fail_count=$((fail_count + 1))
126+
fi
127+
128+
if ! echo 0 > "$dev_path/enable"; then
129+
log_fail "$cti: Failed to write 0 to enable"
130+
fail_count=$((fail_count + 1))
131+
continue
132+
fi
133+
134+
res=$(cat "$dev_path/enable")
135+
if [ "$res" -eq 0 ]; then
136+
log_pass "$cti Disabled Successfully"
137+
else
138+
log_fail "$cti Failed to Disable (Value: $res)"
139+
fail_count=$((fail_count + 1))
140+
fi
141+
done
142+
fi
143+
144+
if [ "$fail_count" -eq 0 ]; then
145+
log_pass "CTI Enable/Disable Test Completed Successfully"
146+
echo "$TESTNAME PASS" > "$res_file"
147+
else
148+
log_fail "CTI Enable/Disable Test Failed ($fail_count errors)"
149+
echo "$TESTNAME FAIL" > "$res_file"
150+
fi
151+
152+
log_info "-------------------$TESTNAME Testcase Finished----------------------------"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
metadata:
2+
name: CTI-Trigger-Map
3+
format: "Lava-Test Test Definition 1.0"
4+
description: "Validates Coresight Cross Trigger Interface (CTI) by mapping and unmapping triggers to channels."
5+
os:
6+
- linux
7+
scope:
8+
- coresight
9+
- kernel
10+
11+
run:
12+
steps:
13+
- REPO_PATH=$PWD || true
14+
- cd Runner/suites/Kernel/DEBUG/CTI-Test || true
15+
- ./run.sh || true
16+
- $REPO_PATH/Runner/utils/send-to-lava.sh CTI-Test.res || true
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# CTI Test
2+
3+
## Overview
4+
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).
5+
6+
## Test Goals
7+
8+
- Validate the core functionality of Coresight CTI driver.
9+
- Ensure hardware triggers can be correctly attached to CTI channels.
10+
- Validate compatibility across both Modern and Legacy sysfs interfaces.
11+
- Prevent device low-power states during testing to ensure register accessibility.
12+
13+
## Prerequisites
14+
15+
- Kernel must be built with Coresight CTI support.
16+
- `sysfs` access to `sys/module/lpm_levels/parameters/sleep_disabled`.
17+
- `sysfs` access to `/sys/bus/coresight/devices/`.
18+
- Root priviledges needed.
19+
20+
## Script Location
21+
22+
```
23+
Runner/suites/Kernel/DEBUG/CTI-Test/run.sh
24+
```
25+
26+
## Files
27+
28+
- `run.sh` - Main test script
29+
- `CTI-Test.res` - Summary result file with PASS/FAIL
30+
- `CTI-Test.log` - Full execution log.
31+
32+
## How it works
33+
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.
34+
2. **Discovery**: Finds all CTI devices in `/sys/bus/coresight/devices/`.
35+
3. **Mode Detection**: Checks for the existence of `enable` sysfs node to determine if the driver uses the Modern or Legacy sysfs interface.
36+
4. **Configuration Parsing**: Reads the `devid` (Modern) or `show_info` (Legacy) to calculate the maximum number of triggers and channels supported by the hardware.
37+
5. **Test Loop**:
38+
* Iterates through a subset of triggers (randomized within valid range).
39+
* Iterates through valid channels.
40+
* **Attach**: writes `channel trigger` to `trigin_attach` / `trigout_attach`.
41+
* **Verify**: Reads back via `chan_xtrigs_sel` and `chan_xtrigs_in`/`out` to confirm mapping.
42+
* **Detach**: Unmaps the trigger and confirms the entry is cleared.
43+
6. **Cleanup**: Restores the original LPM sleep setting.
44+
45+
## Usage
46+
47+
Run the script directly. No iterations or special arguments are required for this basic test.
48+
49+
```bash
50+
./run.sh
51+
```
52+
53+
## Example Output
54+
55+
```
56+
[INFO] 2026-03-24 04:56:37 - -----------------------------------------------------------------------------------------
57+
[INFO] 2026-03-24 04:56:37 - -------------------Starting CTI-Test Testcase----------------------------
58+
[INFO] 2026-03-24 04:56:37 - CTI Driver Version: Modern
59+
[INFO] 2026-03-24 04:56:37 - Device: cti_sys0 (MaxTrig: 8, MaxCh: 4)
60+
[INFO] 2026-03-24 04:56:37 - Attach trigin: trig 0 -> ch 0 on cti_sys0
61+
[INFO] 2026-03-24 04:56:37 - Attach trigout: trig 0 -> ch 0 on cti_sys0
62+
.....
63+
[INFO] 2026-03-24 04:56:39 - Attach trigout: trig 7 -> ch 2 on cti_sys0
64+
[INFO] 2026-03-24 04:56:39 - Attach trigin: trig 7 -> ch 3 on cti_sys0
65+
[INFO] 2026-03-24 04:56:39 - Attach trigout: trig 7 -> ch 3 on cti_sys0
66+
[PASS] 2026-03-24 04:56:39 - CTI map/unmap Test PASS
67+
[INFO] 2026-03-24 04:56:39 - -------------------CTI-Test Testcase Finished----------------------------
68+
```
69+
70+
## Return Code
71+
72+
- `0` — All triggers and channels mapped/unmapped successfully across all CTI devices
73+
- `1` — One or more mapping/unmapping operations failed
74+
75+
## Integration in CI
76+
77+
- Can be run standalone or via LAVA
78+
- Result file `CTI-Test.res` will be parsed by `result_parse.sh`
79+
80+
## Notes
81+
82+
- The test iterates through a randomized subset of triggers rather than exhaustively testing every combination to optimize execution time while maintaining coverage.
83+
- Disabling sleep modes is critical; if the device enters a low-power state, CTI registers may drop, causing false failures or system crashes.
84+
85+
## License
86+
87+
SPDX-License-Identifier: BSD-3-Clause.
88+
(c) Qualcomm Technologies, Inc. and/or its subsidiaries.

0 commit comments

Comments
 (0)