diff --git a/Runner/suites/Kernel/Baseport/etm_trace/README.md b/Runner/suites/Kernel/Baseport/etm_trace/README.md new file mode 100644 index 00000000..46bc9f05 --- /dev/null +++ b/Runner/suites/Kernel/Baseport/etm_trace/README.md @@ -0,0 +1,67 @@ +# ETM_Trace Validation test +Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. +SPDX-License-Identifier: BSD-3-Clause-Clear + +## Overview +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. + +## Test Performs : +1. Verifies the presence of required kernel configuration (CONFIG_CORESIGHT_SOURCE_ETM4X) +2. Enables the CoreSight sink (tmc_etr0) +3. Enables the CoreSight source (etm0) +4. Captures trace data from /dev/tmc_etr0 into a binary file +5. Validates that the trace file is non-empty + +## Usage +Instructions: +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. +2. **Verify Transfer**: Ensure that the repo has been successfully copied to the target device. +3. **Run Scripts**: Navigate to the directory where these files are copied on the target device and execute the scripts as needed. + +Run the etm_trace test using: +--- + +#### Quick Example +```sh +git clone +cd +scp -r common Runner user@target_device_ip: +ssh user@target_device_ip +cd /Runner && ./run-test.sh etm_trace +``` +--- + +## Prerequisites +1. The kernel must be built with CONFIG_CORESIGHT_SOURCE_ETM4X enabled. +2. CoreSight devices (etm0, tmc_etr0) must be exposed in /sys/bus/coresight/devices/. +3. Root access may be required to access /dev/tmc_etr0 and write to system paths. +--- + + ## Result Format +Test result will be saved in `etm_trace.res` as: + +## Output +A .res file is generated in the same directory: +`etm_trace PASS` OR `etm_trace FAIL` OR `etm_trace SKIP` + +## Skip Criteria +1. If the required kernel configuration is missing, the result will be: +2. `etm_trace SKIP` + +## Sample Log +``` +[INFO] 1980-01-06 00:04:29 - ----------------------------------------------------------------------------------------- +[INFO] 1980-01-06 00:04:29 - -------------------Starting etm_trace Testcase---------------------------- +[INFO] 1980-01-06 00:04:29 - === Test Initialization === +[INFO] 1980-01-06 00:04:29 - Enabling CoreSight sink (tmc_etr0)... +[INFO] 1980-01-06 00:04:29 - Sink enabled successfully. +[INFO] 1980-01-06 00:04:29 - Enabling CoreSight source (etm0)... +[INFO] 1980-01-06 00:04:29 - Source enabled successfully. +[INFO] 1980-01-06 00:04:29 - Capturing trace data to /tmp/qdss.bin... +[INFO] 1980-01-06 00:04:29 - Trace data captured successfully. +[PASS] 1980-01-06 00:04:29 - etm_trace : Test Passed +sh-5.2# ls +etm_trace.res run.sh +sh-5.2# cat etm_trace.res +etm_trace PASS +``` \ No newline at end of file diff --git a/Runner/suites/Kernel/Baseport/etm_trace/run.sh b/Runner/suites/Kernel/Baseport/etm_trace/run.sh new file mode 100755 index 00000000..dbfe23ab --- /dev/null +++ b/Runner/suites/Kernel/Baseport/etm_trace/run.sh @@ -0,0 +1,105 @@ +#!/bin/sh + +# Copyright (c) Qualcomm Technologies, Inc. +# SPDX-License-Identifier: BSD-3-Clause-Clear + +# Robustly find and source init_env +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 (starting at $SCRIPT_DIR)" >&2 + exit 1 +fi + +# Only source if not already loaded (idempotent) +if [ -z "$__INIT_ENV_LOADED" ]; then + # shellcheck disable=SC1090 + . "$INIT_ENV" +fi + +# Always source functestlib.sh, using $TOOLS exported by init_env +# shellcheck disable=SC1090,SC1091 +. "$TOOLS/functestlib.sh" + +TESTNAME="etm_trace" +test_path=$(find_test_case_by_name "$TESTNAME") +cd "$test_path" || exit 1 +res_file="./$TESTNAME.res" + +log_info "-----------------------------------------------------------------------------------------" +log_info "-------------------Starting $TESTNAME Testcase----------------------------" +log_info "=== Test Initialization ===" + +pass=true + +# Step 1: Check required kernel config +required_configs="CONFIG_CORESIGHT_SOURCE_ETM4X" +check_kernel_config "$required_configs" || { + log_skip "$TESTNAME : Required kernel config missing" + echo "$TESTNAME SKIP" > "$res_file" + exit 0 +} + +# Step 2: Enable CoreSight sink +log_info "Enabling CoreSight sink (tmc_etr0)..." +echo 1 > /sys/bus/coresight/devices/tmc_etr0/enable_sink +if [ "$(cat /sys/bus/coresight/devices/tmc_etr0/enable_sink)" -eq 1 ]; then + log_info "Sink enabled successfully." +else + log_fail "Failed to enable sink." + pass=false +fi + +# Step 3: Enable CoreSight source +log_info "Enabling CoreSight source (etm0)..." +echo 1 > /sys/bus/coresight/devices/etm0/enable_source +if [ "$(cat /sys/bus/coresight/devices/etm0/enable_source)" -eq 1 ]; then + log_info "Source enabled successfully." +else + log_fail "Failed to enable source." + pass=false +fi + +# Step 4: Capture trace data +TRACE_FILE="/tmp/qdss.bin" +log_info "Capturing trace data to $TRACE_FILE..." +if cat /dev/tmc_etr0 > "$TRACE_FILE"; then + log_info "Trace data captured successfully." +else + log_fail "Failed to capture trace data." + pass=false +fi + +# Step 5: Validate trace output +if [ -s "$TRACE_FILE" ]; then + log_info "Trace file is not empty." +else + log_fail "Trace file is empty." + pass=false +fi + +# Final result and cleanup +if $pass; then + log_pass "$TESTNAME : Test Passed" + echo "$TESTNAME PASS" > "$res_file" + rm -f "$TRACE_FILE" + log_info "-------------------Completed $TESTNAME Testcase----------------------------" + exit 0 +else + log_fail "$TESTNAME : Test Failed" + echo "$TESTNAME FAIL" > "$res_file" + rm -f "$TRACE_FILE" + log_info "-------------------Completed $TESTNAME Testcase----------------------------" + exit 1 +fi + +