Skip to content

Commit ddff25e

Browse files
authored
Merge pull request qualcomm-linux#103 from Sai-teja573/etm_script
Add etm_trace test script and README documentation
2 parents 6dac19b + 788c247 commit ddff25e

File tree

2 files changed

+172
-0
lines changed

2 files changed

+172
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# ETM_Trace Validation test
2+
Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
3+
SPDX-License-Identifier: BSD-3-Clause-Clear
4+
5+
## Overview
6+
This test case validates the CoreSight Embedded Trace Macrocell (ETM) trace capture functionality on the target device. It ensures that the ETM source and TMC sink are properly enabled and that trace data can be successfully captured and validated.
7+
8+
## Test Performs :
9+
1. Verifies the presence of required kernel configuration (CONFIG_CORESIGHT_SOURCE_ETM4X)
10+
2. Enables the CoreSight sink (tmc_etr0)
11+
3. Enables the CoreSight source (etm0)
12+
4. Captures trace data from /dev/tmc_etr0 into a binary file
13+
5. Validates that the trace file is non-empty
14+
15+
## Usage
16+
Instructions:
17+
1. **Copy repo to Target Device**: Use `scp` to transfer the scripts from the host to the target device. The scripts should be copied to any directory on the target device.
18+
2. **Verify Transfer**: Ensure that the repo has been successfully copied to the target device.
19+
3. **Run Scripts**: Navigate to the directory where these files are copied on the target device and execute the scripts as needed.
20+
21+
Run the etm_trace test using:
22+
---
23+
24+
#### Quick Example
25+
```sh
26+
git clone <this-repo>
27+
cd <this-repo>
28+
scp -r common Runner user@target_device_ip:<Path in device>
29+
ssh user@target_device_ip
30+
cd <Path in device>/Runner && ./run-test.sh etm_trace
31+
```
32+
---
33+
34+
## Prerequisites
35+
1. The kernel must be built with CONFIG_CORESIGHT_SOURCE_ETM4X enabled.
36+
2. CoreSight devices (etm0, tmc_etr0) must be exposed in /sys/bus/coresight/devices/.
37+
3. Root access may be required to access /dev/tmc_etr0 and write to system paths.
38+
---
39+
40+
## Result Format
41+
Test result will be saved in `etm_trace.res` as:
42+
43+
## Output
44+
A .res file is generated in the same directory:
45+
`etm_trace PASS` OR `etm_trace FAIL` OR `etm_trace SKIP`
46+
47+
## Skip Criteria
48+
1. If the required kernel configuration is missing, the result will be:
49+
2. `etm_trace SKIP`
50+
51+
## Sample Log
52+
```
53+
[INFO] 1980-01-06 00:04:29 - -----------------------------------------------------------------------------------------
54+
[INFO] 1980-01-06 00:04:29 - -------------------Starting etm_trace Testcase----------------------------
55+
[INFO] 1980-01-06 00:04:29 - === Test Initialization ===
56+
[INFO] 1980-01-06 00:04:29 - Enabling CoreSight sink (tmc_etr0)...
57+
[INFO] 1980-01-06 00:04:29 - Sink enabled successfully.
58+
[INFO] 1980-01-06 00:04:29 - Enabling CoreSight source (etm0)...
59+
[INFO] 1980-01-06 00:04:29 - Source enabled successfully.
60+
[INFO] 1980-01-06 00:04:29 - Capturing trace data to /tmp/qdss.bin...
61+
[INFO] 1980-01-06 00:04:29 - Trace data captured successfully.
62+
[PASS] 1980-01-06 00:04:29 - etm_trace : Test Passed
63+
sh-5.2# ls
64+
etm_trace.res run.sh
65+
sh-5.2# cat etm_trace.res
66+
etm_trace PASS
67+
```
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#!/bin/sh
2+
3+
# Copyright (c) Qualcomm Technologies, Inc.
4+
# SPDX-License-Identifier: BSD-3-Clause-Clear
5+
6+
# Robustly find and source init_env
7+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
8+
INIT_ENV=""
9+
SEARCH="$SCRIPT_DIR"
10+
while [ "$SEARCH" != "/" ]; do
11+
if [ -f "$SEARCH/init_env" ]; then
12+
INIT_ENV="$SEARCH/init_env"
13+
break
14+
fi
15+
SEARCH=$(dirname "$SEARCH")
16+
done
17+
18+
if [ -z "$INIT_ENV" ]; then
19+
echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2
20+
exit 1
21+
fi
22+
23+
# Only source if not already loaded (idempotent)
24+
if [ -z "$__INIT_ENV_LOADED" ]; then
25+
# shellcheck disable=SC1090
26+
. "$INIT_ENV"
27+
fi
28+
29+
# Always source functestlib.sh, using $TOOLS exported by init_env
30+
# shellcheck disable=SC1090,SC1091
31+
. "$TOOLS/functestlib.sh"
32+
33+
TESTNAME="etm_trace"
34+
test_path=$(find_test_case_by_name "$TESTNAME")
35+
cd "$test_path" || exit 1
36+
res_file="./$TESTNAME.res"
37+
38+
log_info "-----------------------------------------------------------------------------------------"
39+
log_info "-------------------Starting $TESTNAME Testcase----------------------------"
40+
log_info "=== Test Initialization ==="
41+
42+
pass=true
43+
44+
# Step 1: Check required kernel config
45+
required_configs="CONFIG_CORESIGHT_SOURCE_ETM4X"
46+
check_kernel_config "$required_configs" || {
47+
log_skip "$TESTNAME : Required kernel config missing"
48+
echo "$TESTNAME SKIP" > "$res_file"
49+
exit 0
50+
}
51+
52+
# Step 2: Enable CoreSight sink
53+
log_info "Enabling CoreSight sink (tmc_etr0)..."
54+
echo 1 > /sys/bus/coresight/devices/tmc_etr0/enable_sink
55+
if [ "$(cat /sys/bus/coresight/devices/tmc_etr0/enable_sink)" -eq 1 ]; then
56+
log_info "Sink enabled successfully."
57+
else
58+
log_fail "Failed to enable sink."
59+
pass=false
60+
fi
61+
62+
# Step 3: Enable CoreSight source
63+
log_info "Enabling CoreSight source (etm0)..."
64+
echo 1 > /sys/bus/coresight/devices/etm0/enable_source
65+
if [ "$(cat /sys/bus/coresight/devices/etm0/enable_source)" -eq 1 ]; then
66+
log_info "Source enabled successfully."
67+
else
68+
log_fail "Failed to enable source."
69+
pass=false
70+
fi
71+
72+
# Step 4: Capture trace data
73+
TRACE_FILE="/tmp/qdss.bin"
74+
log_info "Capturing trace data to $TRACE_FILE..."
75+
if cat /dev/tmc_etr0 > "$TRACE_FILE"; then
76+
log_info "Trace data captured successfully."
77+
else
78+
log_fail "Failed to capture trace data."
79+
pass=false
80+
fi
81+
82+
# Step 5: Validate trace output
83+
if [ -s "$TRACE_FILE" ]; then
84+
log_info "Trace file is not empty."
85+
else
86+
log_fail "Trace file is empty."
87+
pass=false
88+
fi
89+
90+
# Final result and cleanup
91+
if $pass; then
92+
log_pass "$TESTNAME : Test Passed"
93+
echo "$TESTNAME PASS" > "$res_file"
94+
rm -f "$TRACE_FILE"
95+
log_info "-------------------Completed $TESTNAME Testcase----------------------------"
96+
exit 0
97+
else
98+
log_fail "$TESTNAME : Test Failed"
99+
echo "$TESTNAME FAIL" > "$res_file"
100+
rm -f "$TRACE_FILE"
101+
log_info "-------------------Completed $TESTNAME Testcase----------------------------"
102+
exit 1
103+
fi
104+
105+

0 commit comments

Comments
 (0)