diff --git a/Runner/suites/Kernel/DEBUG/ETM-Enable-Disable/ETM-Enable-Disable.yaml b/Runner/suites/Kernel/DEBUG/ETM-Enable-Disable/ETM-Enable-Disable.yaml new file mode 100644 index 00000000..ba02d95d --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/ETM-Enable-Disable/ETM-Enable-Disable.yaml @@ -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 \ No newline at end of file diff --git a/Runner/suites/Kernel/DEBUG/ETM-Enable-Disable/README.md b/Runner/suites/Kernel/DEBUG/ETM-Enable-Disable/README.md new file mode 100644 index 00000000..eaad8192 --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/ETM-Enable-Disable/README.md @@ -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. diff --git a/Runner/suites/Kernel/DEBUG/ETM-Enable-Disable/run.sh b/Runner/suites/Kernel/DEBUG/ETM-Enable-Disable/run.sh new file mode 100755 index 00000000..f52a7c6a --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/ETM-Enable-Disable/run.sh @@ -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----------------------------" \ No newline at end of file diff --git a/Runner/suites/Kernel/DEBUG/ETM-Register/ETM-Register.yaml b/Runner/suites/Kernel/DEBUG/ETM-Register/ETM-Register.yaml new file mode 100644 index 00000000..88831b06 --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/ETM-Register/ETM-Register.yaml @@ -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 \ No newline at end of file diff --git a/Runner/suites/Kernel/DEBUG/ETM-Register/README.md b/Runner/suites/Kernel/DEBUG/ETM-Register/README.md new file mode 100644 index 00000000..31d3397c --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/ETM-Register/README.md @@ -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. \ No newline at end of file diff --git a/Runner/suites/Kernel/DEBUG/ETM-Register/run.sh b/Runner/suites/Kernel/DEBUG/ETM-Register/run.sh new file mode 100755 index 00000000..25cee353 --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/ETM-Register/run.sh @@ -0,0 +1,138 @@ +#!/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-Register" +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 - Missing ETF sink" > "$res_file" + exit 1 +fi + +ETM_LIST="" +ETM_NUM=0 +for _etm in "$CS_BASE"/etm* "$CS_BASE"/coresight-etm* "$CS_BASE"/coresight-ete*; do + [ -d "$_etm" ] || continue + ETM_LIST="$ETM_LIST $_etm" + ETM_NUM=$((ETM_NUM + 1)) +done + +fail_count=0 + +if [ -z "$ETM_LIST" ] || [ "$ETM_NUM" -eq 0 ]; then + log_fail "No Coresight ETM devices found" + echo "$TESTNAME FAIL - No ETMs found" > "$res_file" + exit 1 +fi + +log_info "Found $ETM_NUM ETM devices" + +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 + +echo 1 > "$ETF_PATH/enable_sink" 2>/dev/null + +for etm in $ETM_LIST; do + log_info "Testing ETM node: $etm" + + if [ -f "$etm/enable_source" ]; then + echo 1 > "$etm/enable_source" 2>/dev/null + fi + + if [ -d "$etm/mgmt" ]; then + for reg in "$etm"/mgmt/*; do + [ -e "$reg" ] || continue + if ! cat "$reg" >/dev/null 2>&1; then + log_warn "FAIL: Could not read $reg" + echo "FAIL: Could not read $reg" >> "$res_file" + fail_count=$((fail_count + 1)) + fi + done + fi + + for node in "$etm"/*; do + if [ -f "$node" ] && [ -r "$node" ]; then + base_node=${node##*/} + case "$base_node" in + addr_single|addr_start|addr_stop) continue ;; + esac + cat "$node" >/dev/null 2>&1 + fi + done + + if [ -f "$etm/enable_source" ]; then + echo 0 > "$etm/enable_source" 2>/dev/null + fi +done + +reset_devices + +if [ "$fail_count" -eq 0 ]; then + log_pass "ETM Register Read Test Successful" + echo "$TESTNAME PASS" > "$res_file" +else + log_fail "ETM Register Read Test Failed ($fail_count read errors)" + echo "$TESTNAME FAIL" > "$res_file" +fi + +log_info "-------------------$TESTNAME Testcase Finished----------------------------" \ No newline at end of file diff --git a/Runner/suites/Kernel/DEBUG/ETM-Test-Mode/ETM-Test-Mode.yaml b/Runner/suites/Kernel/DEBUG/ETM-Test-Mode/ETM-Test-Mode.yaml new file mode 100644 index 00000000..f51a3205 --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/ETM-Test-Mode/ETM-Test-Mode.yaml @@ -0,0 +1,16 @@ +metadata: + name: ETM-Test-Mode + format: "Lava-Test Test Definition 1.0" + description: "Validates ETM functionality by setting the 'mode' attribute to high (0xFFFFFFF) and enabling the cores." + os: + - linux + scope: + - coresight + - kernel + +run: + steps: + - REPO_PATH=$PWD || true + - cd Runner/suites/Kernel/DEBUG/ETM-Test-Mode || true + - ./run.sh || true + - $REPO_PATH/Runner/utils/send-to-lava.sh ETM-Test-Mode.res || true \ No newline at end of file diff --git a/Runner/suites/Kernel/DEBUG/ETM-Test-Mode/README.md b/Runner/suites/Kernel/DEBUG/ETM-Test-Mode/README.md new file mode 100644 index 00000000..718244e5 --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/ETM-Test-Mode/README.md @@ -0,0 +1,77 @@ +# ETM Test Mode + +## Overview + +This test verifies the stability and write-access of the **ETM (Embedded Trace Macrocell)** `mode` attribute. It sets the mode to `0XFFFFFFF` (enabling various mode bits like cycle-accurate tracing, etc., depending on the hardware revision) and attempts to enable the ETM sources. + +## Test Goals + +- Verify the stability and write-access of the Coresight ETM `mode` attribute +- Ensure ETM sources can be successfully enabled when complex mode bits are activated (`0XFFFFFFF`) +- Validate that the system does not crash or return errors during aggressive mode configurations +- Ensure proper teardown and restoration of default ETM mode values + +## Prerequisites + +- Kernel must be built with Coresight ETM support +- `sysfs` access to `/sys/bus/coresight/devices/` +- Root privileges (to write to `mode` and enable entries) + +## Script Location + +``` +Runner/suites/Kernel/DEBUG/ETM-Test-Mode/run.sh +``` + +## Files + +- `run.sh` - Main test script +- `ETM-Test-Mode.res` - Summary result file with PASS/FAIL +- `ETM-Test-Mode.log` - Full execution log (generated if logging is enabled) + +## How It Works + +1. **Discovery**: Scans `/sys/bus/coresight/devices/` for ETM devices (`etm*` or `coresight-etm*`). +2. **Setup**: + - Resets all Coresight sources and sinks. + - Enables `tmc_etr0` as the trace sink. +3. **Test**: + - Iterates through all detected ETM devices. + - Writes `0XFFFFFFF` to the `mode` sysfs attribute. + - Enables the ETM source. +4. **Teardown**: + - Writes `0x0` to the `mode` sysfs attribute (restoring defaults). + - Disables all sources and sinks. + +## Example Output + +``` +[INFO] 2026-03-17 11:11:53 - ----------------------------------------------------------------------------------------- +[INFO] 2026-03-17 11:11:53 - -------------------Starting ETM-Test-Mode Testcase---------------------------- +[INFO] 2026-03-17 11:11:53 - Enabling Sink: /sys/bus/coresight/devices/tmc_etr0 +[INFO] 2026-03-17 11:11:53 - Configuring etm0 +[INFO] 2026-03-17 11:11:53 - etm0 mode set and verified: 0xfffffff +[INFO] 2026-03-17 11:11:53 - etm0 enabled and verified (enable_source=1) +..... +[PASS] 2026-03-17 11:11:54 - ETM Mode Configuration Successful +[INFO] 2026-03-17 11:11:54 - -------------------ETM-Test-Mode Testcase Finished---------------------------- +``` + +## Return Code + +- `0` — All ETM devices successfully configured and enabled with the test mode +- `1` — One or more ETM devices failed configuration or enablement + +## Integration in CI + +- Can be run standalone or via LAVA +- Result file `ETM-Test-Mode.res` will be parsed by `result_parse.sh` + +## Notes + +- Writing `0XFFFFFFF` acts as a stress test by attempting to flip all available configuration bits simultaneously. The exact features enabled (e.g., cycle-accurate tracing) will vary depending on the specific hardware revision of the ETM. + +## License + +SPDX-License-Identifier: BSD-3-Clause-Clear +(c) Qualcomm Technologies, Inc. and/or its subsidiaries. diff --git a/Runner/suites/Kernel/DEBUG/ETM-Test-Mode/run.sh b/Runner/suites/Kernel/DEBUG/ETM-Test-Mode/run.sh new file mode 100755 index 00000000..f5ed1fb7 --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/ETM-Test-Mode/run.sh @@ -0,0 +1,165 @@ +#!/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-Test-Mode" +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 "" +} + +reset_source_sink() { + 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 +} + +ETR_PATH=$(find_path "tmc_etr0" "tmc_etr" "tmc_etr1" "coresight-tmc_etr") +if [ -z "$ETR_PATH" ]; then + log_fail "TMC-ETR sink not found" + echo "$TESTNAME FAIL: No ETR sink found" >> "$res_file" + exit 1 +fi + +ETM_LIST="" +for _etm in "$CS_BASE"/etm* "$CS_BASE"/coresight-etm*; do + [ -d "$_etm" ] || continue + ETM_LIST="$ETM_LIST $_etm" +done +ETM_LIST="${ETM_LIST# }" + +if [ -z "$ETM_LIST" ]; then + log_fail "No Coresight ETM devices found" + echo "$TESTNAME FAIL: No ETM devices found" >> "$res_file" + exit 1 +fi + +reset_source_sink + +log_info "Enabling Sink: $ETR_PATH" +echo 1 > "$ETR_PATH/enable_sink" 2>/dev/null + +fail_count=0 +no_mode_count=0 +etm_total=0 + +for etm in $ETM_LIST; do + etm_total=$((etm_total + 1)) + etm_name=$(basename "$etm") + + log_info "Configuring $etm_name" + + if [ ! -f "$etm/mode" ]; then + log_fail "$etm_name does not have 'mode' attribute - required for this test" + echo "FAIL: $etm_name missing 'mode' attribute" >> "$res_file" + fail_count=$((fail_count + 1)) + no_mode_count=$((no_mode_count + 1)) + continue + fi + + echo 0xFFFFFFF > "$etm/mode" 2>/dev/null + actual_mode=$(cat "$etm/mode" 2>/dev/null) + + if [ -z "$actual_mode" ]; then + log_fail "Failed to read back mode from $etm_name after write" + echo "FAIL: $etm_name failed to read back mode" >> "$res_file" + fail_count=$((fail_count + 1)) + continue + fi + + expect_dec=$((0xFFFFFFF)) + actual_dec=$((${actual_mode:-0})) + + if [ "$actual_dec" != "$expect_dec" ]; then + log_fail "$etm_name mode readback mismatch: wrote 0xFFFFFFF, read back $actual_mode" + echo "FAIL: $etm_name mode mismatch (Wrote 0xFFFFFFF, Read $actual_mode)" >> "$res_file" + fail_count=$((fail_count + 1)) + continue + fi + + log_info "$etm_name mode set and verified: $actual_mode" + + if [ -f "$etm/enable_source" ]; then + echo 1 > "$etm/enable_source" 2>/dev/null + readback=$(cat "$etm/enable_source" 2>/dev/null) + if [ "$readback" != "1" ]; then + log_fail "Failed to enable $etm_name: enable_source readback=$readback (expected 1)" + echo "FAIL: $etm_name failed to enable (enable_source readback=$readback)" >> "$res_file" + fail_count=$((fail_count + 1)) + else + log_info "$etm_name enabled and verified (enable_source=1)" + fi + else + log_warn "$etm_name has no enable_source attribute, skipping enable step" + fi +done + +if [ "$no_mode_count" -eq "$etm_total" ]; then + log_fail "No ETM devices had a 'mode' attribute - test cannot validate ETM mode" + echo "$TESTNAME FAIL" >> "$res_file" +elif [ "$fail_count" -eq 0 ]; then + log_pass "ETM Mode Configuration Successful" + echo "$TESTNAME PASS" >> "$res_file" +else + log_fail "ETM Mode Configuration Failed ($fail_count errors)" + echo "$TESTNAME FAIL" >> "$res_file" +fi + +for etm in $ETM_LIST; do + if [ -f "$etm/mode" ]; then + echo 0x0 > "$etm/mode" 2>/dev/null + fi +done + +reset_source_sink + +log_info "-------------------$TESTNAME Testcase Finished----------------------------" \ No newline at end of file diff --git a/Runner/suites/Kernel/DEBUG/ETM-Trace/ETM-Trace.yaml b/Runner/suites/Kernel/DEBUG/ETM-Trace/ETM-Trace.yaml new file mode 100644 index 00000000..25f9b2aa --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/ETM-Trace/ETM-Trace.yaml @@ -0,0 +1,16 @@ +metadata: + name: ETM-Trace-Enable-Disable + format: "Lava-Test Test Definition 1.0" + description: "Validates the stability of enabling and disabling ETM sources repeatedly and verifies trace data generation." + os: + - linux + scope: + - coresight + - kernel + +run: + steps: + - REPO_PATH=$PWD || true + - cd Runner/suites/Kernel/DEBUG/ETM-Trace || true + - ./run.sh || true + - $REPO_PATH/Runner/utils/send-to-lava.sh ETM-Trace.res || true \ No newline at end of file diff --git a/Runner/suites/Kernel/DEBUG/ETM-Trace/README.md b/Runner/suites/Kernel/DEBUG/ETM-Trace/README.md new file mode 100644 index 00000000..897a09ee --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/ETM-Trace/README.md @@ -0,0 +1,87 @@ +# ETM Trace Test + +## Overview + +This test validates the reliability of the ETM (Embedded Trace Macrocell) drivers by repeatedly enabling and disabling trace sources and verifying that data is successfully written to the sinks. + +## Test Goals + +- Validate the reliability and stability of ETM drivers under repeated use. +- Verify that trace data is successfully generated by sources and written to sinks. +- Ensure that captured trace data meets a minimum size threshold (>= 64 bytes) to confirm actual data generation. +- Confirm robust enabling, disabling, and resetting of the Coresight topology during active trace sessions. + +## Prerequisites + +- Kernel must be built with Coresight ETM support. +- `sysfs` access to `/sys/bus/coresight/devices/`. +- Access to read from sink character devices (e.g., `/dev/tmc_etr0`). +- Root privileges (to configure devices and read trace data). + +## Script Location + +``` +Runner/suites/Kernel/DEBUG/ETM-Trace/run.sh +``` + +## Files + +- `run.sh` - Main test script +- `ETM-Trace.res` - Summary result file with PASS/FAIL +- `ETM-Trace.log` - Full execution log (generated if logging is enabled) + +## How It Works + +The test iterates through **every available sink** (excluding `tmc_etf1`) and **every available ETM source**. + +For each Sink <-> Source pair, it performs N iterations (default: 2): + +1. **Reset**: Disable all Coresight devices. +2. **Enable Sink**: Activate the current sink (e.g., `tmc_etr0`). +3. **Enable Source**: Activate the current ETM (e.g., `etm0`). +4. **Capture**: Sleep for 3 seconds to generate trace data, then dump the content of `/dev/` to a temporary binary file. +5. **Verify**: + - Check if the captured binary file size is >= 64 bytes. + - Check if the source disabled correctly. + +## Usage + +Run the script directly or via the runner. +Optional argument: Number of iterations per device pair. + +```bash +./run.sh 5 +``` + +## Example Output + +``` +[INFO] 2026-03-17 10:57:01 - ----------------------------------------------------------------------------------------- +[INFO] 2026-03-17 10:57:01 - -------------------Starting ETM-Trace Testcase---------------------------- +[INFO] 2026-03-17 10:57:01 - Running 3 iteration(s) per sink +[INFO] 2026-03-17 10:57:01 - --- Iteration 1 for Sink: tmc_etf0 --- +[INFO] 2026-03-17 10:57:01 - Source: etm0 | Sink: tmc_etf0 +[INFO] 2026-03-17 10:57:01 - Source enabled successfully +[INFO] 2026-03-17 10:57:04 - Captured bin size: 4736 bytes +[PASS] 2026-03-17 10:57:04 - Trace data captured for /sys/bus/coresight/devices/etm0 -> tmc_etf0 +[INFO] 2026-03-17 10:57:04 - Source disabled successfully +..... +[PASS] 2026-03-17 11:00:41 - ETM Trace Enable/Disable Test Completed Successfully +``` + +## Return Code +- `0` — All iterations for all Sink <-> Source pairs passed and captured sufficient data +- `1` — One or more captures failed, returned insufficient data, or failed to disable properly + +## Integration in CI +- Can be run standalone or via LAVA +- Result file ETM-Trace.res will be parsed by result_parse.sh + +## Notes +- `tmc_etf1` is explicitly excluded from the available sinks for this test. +- The 3-second sleep during the capture phase allows enough time for the system to generate realistic trace traffic. +- The >= 64-byte threshold ensures that the captured file isn't just an empty or malformed trace stream. + +## License +SPDX-License-Identifier: BSD-3-Clause-Clear +(c) Qualcomm Technologies, Inc. and/or its subsidiaries. diff --git a/Runner/suites/Kernel/DEBUG/ETM-Trace/run.sh b/Runner/suites/Kernel/DEBUG/ETM-Trace/run.sh new file mode 100755 index 00000000..92e1da0b --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/ETM-Trace/run.sh @@ -0,0 +1,204 @@ +#!/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-Trace" +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----------------------------" + +for _tool in timeout stat; do + if ! command -v "$_tool" >/dev/null 2>&1; then + log_warn "Required tool '$_tool' not found - skipping test" + echo "$TESTNAME: SKIP" > "$res_file" + exit 0 + fi +done + +CS_BASE="/sys/bus/coresight/devices" +TMP_DIR="/tmp/coresight-test" +FAIL_COUNT=0 + +RUNS=2 +if [ -n "$1" ]; then + case "$1" in + ''|*[!0-9]*) + log_warn "Invalid RUNS argument '$1' - must be a positive integer, using default: 2" + ;; + *) + if [ "$1" -gt 0 ]; then + RUNS=$1 + else + log_warn "RUNS argument must be > 0, using default: 2" + fi + ;; + esac +fi +log_info "Running $RUNS iteration(s) per sink" + +rm -rf "$TMP_DIR" +mkdir -p "$TMP_DIR" + +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 + +SINK_LIST="" +for _sink in "$CS_BASE"/tmc_et*; do + [ -d "$_sink" ] || continue + case "$_sink" in + *tmc_etf1*) continue ;; + esac + SINK_LIST="$SINK_LIST $_sink" +done + +if [ -z "$SINK_LIST" ] || [ -z "$ETM_LIST" ]; then + log_fail "Missing Sinks or ETM devices. Cannot proceed." + echo "$TESTNAME FAIL - Missing target Coresight nodes" > "$res_file" + exit 1 +fi + +reset_devices() { + for stm in "$CS_BASE"/stm* "$CS_BASE"/coresight-stm*; do + [ -d "$stm" ] || continue + [ -f "$stm/enable_source" ] && echo 0 > "$stm/enable_source" 2>/dev/null + done + + for etm in $ETM_LIST; do + [ -f "$etm/enable_source" ] && echo 0 > "$etm/enable_source" 2>/dev/null + done + + for sink in $SINK_LIST; do + [ -f "$sink/enable_sink" ] && echo 0 > "$sink/enable_sink" 2>/dev/null + done +} + +run_trace_test() { + sourcename=$1 + sinkname=$2 + source_base=$(basename "$sourcename") + + bin_dir="$TMP_DIR/$sinkname" + mkdir -p "$bin_dir" + outfile="$bin_dir/$source_base.bin" + + log_info "Source: $source_base | Sink: $sinkname" + + echo 1 > "$sourcename/enable_source" 2>/dev/null + res=$(cat "$sourcename/enable_source" 2>/dev/null) + if [ "$res" = "1" ]; then + log_info "Source enabled successfully" + else + log_fail "Source failed to enable (Value: $res)" + echo "$TESTNAME FAIL - [Enable Error] $source_base -> $sinkname" >> "$res_file" + return 1 + fi + + sleep 3 + timeout 5 cat "/dev/$sinkname" > "$outfile" 2>/dev/null + + if [ -f "$outfile" ]; then + bin_size=$(stat -c%s "$outfile" 2>/dev/null || echo 0) + log_info "Captured bin size: $bin_size bytes" + + if [ "$bin_size" -ge 64 ]; then + log_pass "Trace data captured for $sourcename -> $sinkname" + else + log_fail "Trace data too small ($bin_size < 64 bytes)" + echo "$TESTNAME FAIL - [Size < 64 bytes] $source_base -> $sinkname (Size: $bin_size)" >> "$res_file" + return 1 + fi + else + log_fail "Failed to create output file from /dev/$sinkname" + echo "$TESTNAME FAIL - [No Output File] $source_base -> $sinkname" >> "$res_file" + return 1 + fi + + echo 0 > "$sourcename/enable_source" 2>/dev/null + res=$(cat "$sourcename/enable_source" 2>/dev/null) + if [ "$res" = "0" ]; then + log_info "Source disabled successfully" + else + log_fail "Source failed to disable (Value: $res)" + echo "$TESTNAME FAIL - [Disable Error] $source_base -> $sinkname" >> "$res_file" + return 1 + fi + + return 0 +} + +reset_devices + +for sink_path in $SINK_LIST; do + sinkname=$(basename "$sink_path") + + i=1 + while [ "$i" -le "$RUNS" ]; do + log_info "--- Iteration $i for Sink: $sinkname ---" + iteration_fail=0 + + echo 1 > "$sink_path/enable_sink" 2>/dev/null + + for etm_path in $ETM_LIST; do + if ! run_trace_test "$etm_path" "$sinkname"; then + iteration_fail=1 + FAIL_COUNT=$((FAIL_COUNT + 1)) + fi + done + + echo 0 > "$sink_path/enable_sink" 2>/dev/null + + if [ "$iteration_fail" -ne 0 ]; then + log_fail "Iteration $i for Sink $sinkname encountered errors" + fi + + i=$((i + 1)) + done +done + +reset_devices +rm -rf "$TMP_DIR" + +if [ "$FAIL_COUNT" -eq 0 ]; then + log_pass "ETM Trace Enable/Disable Test Completed Successfully" + echo "$TESTNAME PASS" > "$res_file" +else + log_fail "ETM Trace Enable/Disable Test Failed ($FAIL_COUNT errors total)" + echo "$TESTNAME FAIL - Total Errors: $FAIL_COUNT" >> "$res_file" +fi + +log_info "-------------------$TESTNAME Testcase Finished----------------------------" diff --git a/Runner/suites/Kernel/DEBUG/ETM_CPU_Toggle_Composite_Base/ETM_CPU_Toggle_Composite_Base.yaml b/Runner/suites/Kernel/DEBUG/ETM_CPU_Toggle_Composite_Base/ETM_CPU_Toggle_Composite_Base.yaml new file mode 100644 index 00000000..7bd11392 --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/ETM_CPU_Toggle_Composite_Base/ETM_CPU_Toggle_Composite_Base.yaml @@ -0,0 +1,16 @@ +metadata: + name: ETM-CPU-Toggle-Composite-Base + format: "Lava-Test Test Definition 1.0" + description: "Composite stress test validating ETM stability while CPUs are dynamically offlined and onlined." + os: + - linux + scope: + - coresight + - kernel + +run: + steps: + - REPO_PATH=$PWD || true + - cd Runner/suites/Kernel/DEBUG/ETM-CPU-Toggle-Composite-Base || true + - ./run.sh 100 || true + - $REPO_PATH/Runner/utils/send-to-lava.sh ETM-CPU-Toggle-Composite-Base.res || true \ No newline at end of file diff --git a/Runner/suites/Kernel/DEBUG/ETM_CPU_Toggle_Composite_Base/README.md b/Runner/suites/Kernel/DEBUG/ETM_CPU_Toggle_Composite_Base/README.md new file mode 100644 index 00000000..19b6d43d --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/ETM_CPU_Toggle_Composite_Base/README.md @@ -0,0 +1,89 @@ +# ETM-CPU-Toggle-Composite-Base Test + +## Overview +This test performs a compostite stress validation of the Coresight ETM subsystem. It verifies that enabling/disabling trace sources and capturing data remains stable even when the system is under heavy CPU Hotplug stress (randomly offlinin/onlining cores). + +## Test Goals + +- Validate the stability of the Coresight ETM subsystem under heavy CPU hotplug stress. +- Ensure trace sources can be reliably enabled and disabled while CPU cores are dynamically offlined and onlined. +- Prevent and detect driver race conditions (e.g., "Invalid argument" or "Operation not permitted" errors). +- Ensure captured trace data remains valid and meets the minimum size threshold (>= 64 bytes) during stress. + +## Prerequisites + +- Kernel must be built with Coresight ETM and CPU Hotplug support. +- `sysfs` access to `/sys/bus/coresight/devices/` and `/sys/devices/system/cpu/`. +- Access to read from sink character devices (e.g., `/dev/tmc_etf0`). +- Root privileges (to configure Coresight devices and toggle CPU states). + +## Script Location + +``` +Runner/suites/Kernel/DEBUG/ETM_CPU_Toggle_Composite_Base/run.sh +``` + +## Files + +- `run.sh` - Main test script +- `ETM-CPU-Toggle-Composite-Base.res` - Summary result file with PASS/FAIL +- `ETM-CPU-Toggle-Composite-Base.log` - Full execution log (generated if logging is enabled) + +## How It Works + +The test uses a two-pronged approach: + +1. **Background Stress**: A background process continuously and randomly offlines and onlines available CPU cores (excluding `CPU0`). +2. **Foreground Validation**: Iterates `N` times (default: 100): + - Enables the `tmc_etf0` sink. + - Enables ETM on all currently online cores. + - Waits for 1 second to allow trace generation. + - Captures data from `/dev/tmc_etf0`. + - **Verification**: + - Ensures no "Invalid argument" or "Operation not permitted" errors occur (which often indicate driver race conditions). + - Ensures captured trace data size is >= 64 bytes. + - Disables ETM sources before the next iteration. + +## Usage + +Run the script with an optional argument for the number of stress iterations. + +```bash +./run.sh + +./run.sh 500 +``` + +## Example Output + +``` +[INFO] 2026-03-17 11:53:39 - ----------------------------------------------------------------------------------------- +[INFO] 2026-03-17 11:53:39 - -------------------Starting ETM_CPU_Toggle_Composite_Base Testcase---------------------------- +[INFO] 2026-03-17 11:53:39 - Targeting 7 cores for 100 iterations +[INFO] 2026-03-17 11:53:39 - Started CPU hotplug stress (PID: 17189) +[INFO] 2026-03-17 11:53:39 - Iteration 1/100... +[INFO] 2026-03-17 11:53:40 - Iteration 2/100... +...... +[INFO] 2026-03-17 11:55:44 - Iteration 99/100... +[INFO] 2026-03-17 11:55:45 - Iteration 100/100... +[PASS] 2026-03-17 11:55:46 - Successfully completed 100 iterations of ETM + Hotplug Stress +[INFO] 2026-03-17 11:55:46 - -------------------$TESTNAME Testcase Finished---------------------------- +``` + +## Return Code + +- `0` — All iterations completed successfully without driver errors and valid data captures +- `1` — One or more driver errors occurred, or trace captures were invalid/undersized + +## Integration in CI + +- Can be run standalone or via LAVA +- Result file ETM-CPU-Toggle-Composite-Base.res will be parsed by result_parse.sh + +## Notes + +- CPU0 is explicitly excluded from the background hotplug stress to prevent system instability or panics related to the primary boot CPU. + +## License +SPDX-License-Identifier: BSD-3-Clause-Clear +(c) Qualcomm Technologies, Inc. and/or its subsidiaries. \ No newline at end of file diff --git a/Runner/suites/Kernel/DEBUG/ETM_CPU_Toggle_Composite_Base/run.sh b/Runner/suites/Kernel/DEBUG/ETM_CPU_Toggle_Composite_Base/run.sh new file mode 100755 index 00000000..1db86d3d --- /dev/null +++ b/Runner/suites/Kernel/DEBUG/ETM_CPU_Toggle_Composite_Base/run.sh @@ -0,0 +1,186 @@ +#!/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_CPU_Toggle_Composite_Base" +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" +CPU_BASE="/sys/devices/system/cpu" +TMP_DIR="/tmp/etm-stress" +CORES=$(grep -c "processor" /proc/cpuinfo) +RUNS=${1:-100} +FAIL_COUNT=0 +pass_count=0 + +rm -rf "$TMP_DIR" +mkdir -p "$TMP_DIR" + +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_SINK=$(find_path "tmc_etf0" "tmc_etf" "tmc_etf1" "coresight-tmc_etf" "coresight-tmc_etf0") +if [ -z "$ETF_SINK" ]; then + log_fail "TMC-ETF sink not found. Cannot proceed." + echo "$TESTNAME FAIL - Missing ETF sink" > "$res_file" + exit 1 +fi + +ETF_DEV_NAME=$(basename "$ETF_SINK") +ETF_DEV_NODE="/dev/$ETF_DEV_NAME" + +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 - No ETMs found" > "$res_file" + exit 1 +fi + +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 +} + +etm_all_cores() { + state=$1 + # shellcheck disable=SC2086 + for etm_node in $ETM_LIST; do + if [ -f "$etm_node/enable_source" ]; then + echo "$state" > "$etm_node/enable_source" 2>/dev/null + fi + done +} + +toggle_cpu() { + cpu_id=$1 + if [ "$cpu_id" -eq 0 ]; then return; fi + + online_path="$CPU_BASE/cpu$cpu_id/online" + if [ -f "$online_path" ]; then + echo 0 > "$online_path" 2>/dev/null + sleep 0.1 + echo 1 > "$online_path" 2>/dev/null + fi +} + +cpu_stress_loop() { + while true; do + rand_val=$(od -An -N2 -tu2 /dev/urandom | tr -dc '0-9') + rand_val=${rand_val:-1} + target=$(( (rand_val % (CORES - 1)) + 1 )) + toggle_cpu "$target" + sleep 0.2 + done +} + +trap cleanup EXIT + +log_info "Targeting $CORES cores for $RUNS iterations" + +reset_devices + +cpu_stress_loop & +HOTPLUG_PID=$! +log_info "Started CPU hotplug stress (PID: $HOTPLUG_PID)" + +for i in $(seq 1 "$RUNS"); do + log_info "Iteration $i/$RUNS..." + + echo 1 > "$ETF_SINK/enable_sink" 2>/dev/null + + etm_all_cores 1 + sleep 1 + + etm_all_cores 0 + echo 0 > "$ETF_SINK/enable_sink" 2>/dev/null + sleep 0.2 + + outfile="$TMP_DIR/trace_iter_$i.bin" + errfile="$TMP_DIR/err_$i.txt" + + timeout 2 cat "$ETF_DEV_NODE" > "$outfile" 2> "$errfile" + + if grep -qE "Operation not permitted|Invalid argument|No such file" "$errfile"; then + log_fail "Kernel error detected during capture in iteration $i" + FAIL_COUNT=$((FAIL_COUNT + 1)) + break + fi + + if [ -f "$outfile" ]; then + size=$(stat -c%s "$outfile") + if [ "$size" -lt 64 ]; then + log_fail "Trace data too small ($size bytes) in iteration $i" + FAIL_COUNT=$((FAIL_COUNT + 1)) + break + fi + else + log_fail "Failed to capture trace file in iteration $i" + FAIL_COUNT=$((FAIL_COUNT + 1)) + break + fi + + pass_count=$((pass_count + 1)) +done + +if [ "$FAIL_COUNT" -eq 0 ] && [ "$pass_count" -eq "$RUNS" ]; then + log_pass "Successfully completed $RUNS iterations of ETM + Hotplug Stress" + echo "$TESTNAME PASS" > "$res_file" +else + log_fail "Stress test failed: $pass_count/$RUNS iterations passed" + echo "$TESTNAME FAIL" > "$res_file" +fi + +log_info "-------------------$TESTNAME Testcase Finished----------------------------" \ No newline at end of file