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,88 @@
Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
SPDX-License-Identifier: BSD-3-Clause

# SoC_Infra_GPU_Clock_Rate_Validation

Checks that every GPU clock rate exposed by the Linux clock framework in debugfs
(`/sys/kernel/debug/clk/gpu*/clk_rate`) is a valid integer.

## Prerequisites

- Root access, because debugfs is readable by root only.
- debugfs mounted at `/sys/kernel/debug` (or `/debug`) with the clock tree under
`<debugfs>/clk`, which needs `CONFIG_DEBUG_FS`. The test does not mount it.
debugfs is optional on production images, so the test skips when it is not
available. A GPU clock controller in the device tree does not change that.
- The GPU clock controller driver loaded on platforms that have one.
- Base utilities: `find`, `grep`, `cat`, `tr`, `readlink`, `dirname`, `basename`, `mktemp`.
The test never installs packages. It skips when a utility is missing.

The test only reads files. It changes no module, service, mount or setting, so
there is nothing to clean up on the device.

## Applicability

The runtime device tree decides whether the platform has a GPU clock controller:
an enabled node whose compatible string contains `-gpucc`, for example
`qcom,sm8550-gpucc`.

## Usage

The suite has no command-line options and no environment overrides.

```sh
cd Runner
./run-test.sh SoC_Infra_GPU_Clock_Rate_Validation
```

It can also be run directly:

```sh
cd Runner/suites/Kernel/Baseport/SoC_Infra_GPU_Clock_Rate_Validation
./run.sh
```

## Results and logs

All files are written to the directory the test is started from. That is the suite
directory when the test runs through `run-test.sh`, the LAVA definition, or
`./run.sh` inside the suite directory:

| File | Content |
|---|---|
| `SoC_Infra_GPU_Clock_Rate_Validation.res` | Final verdict: `PASS`, `FAIL` or `SKIP` |
| `gpu_clk_rates.log` | One `<clock> <rate>` line per clock; a bad value shows as `NOT_INTEGER(<value>)` and an unreadable file as `READ_ERROR` |
| `SoC_Infra_GPU_Clock_Rate_Validation_stdout_<time>.log` | Captured console output of the run |

These files are runtime output and must not be committed.

## PASS, FAIL and SKIP

| Verdict | Condition |
|---|---|
| PASS | At least one `gpu*` clock exists and each `clk_rate` file holds exactly one non-negative integer. A rate of `0` is valid, because a gated clock reports zero. |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The clock core can retain a nonzero cached rate for a gated clock or return zero for an unresolved parent. Please replace the gated-clock explanation with: zero is accepted by this readability/format check, which does not establish the physical frequency or clock enable state.

| FAIL | A `gpu*` clock rate is not a single integer (for example `12 34`, which is not merged into `1234`) or cannot be read. |
| FAIL | debugfs and `<debugfs>/clk` are available and the device tree has a GPU clock controller, but no `gpu*` clock is registered. This points to a missing or failed GPU clock driver. |
| SKIP | debugfs is not mounted or not readable, whatever the device tree says. |
| SKIP | `<debugfs>/clk` is not available, whatever the device tree says. |
| SKIP | debugfs and `<debugfs>/clk` are available, no `gpu*` clock is registered, and the device tree has no GPU clock controller. |
| SKIP | A required base utility is missing. |

Each `clk_rate` value is validated with `is_unsigned_number` exactly as read. Only
the trailing newline is dropped, so embedded whitespace makes the value invalid.

## LAVA publication

The LAVA definition publishes the result with
`send-to-lava.sh SoC_Infra_GPU_Clock_Rate_Validation.res --strict --expected-testcase-id SoC_Infra_GPU_Clock_Rate_Validation`.
If `run.sh` exits early and leaves no valid result, the publish step fails instead
of reporting nothing. The step is the last one in the definition, so its failure
status is kept.

## Shared helpers

The suite uses two helpers added to `Runner/utils/functestlib.sh`:

- `socinfra_debugfs_root` prints the mounted debugfs root.
- `socinfra_check_clk_rates` reads `clk_rate` for a clock name prefix and checks
the value with `is_unsigned_number`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
metadata:
name: soc-infra-gpu-clock-rate-validation
format: "Lava-Test Test Definition 1.0"
description: "Validate that every GPU clock rate exposed in debugfs is a valid integer"
os:
- linux
scope:
- functional

run:
steps:
- REPO_PATH=$PWD
- cd Runner/suites/Kernel/Baseport/SoC_Infra_GPU_Clock_Rate_Validation
- ./run.sh || true
- $REPO_PATH/Runner/utils/send-to-lava.sh SoC_Infra_GPU_Clock_Rate_Validation.res --strict --expected-testcase-id SoC_Infra_GPU_Clock_Rate_Validation
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/bin/sh

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

# ---------- Repo env + helpers ----------
SCRIPT_DIR="$(
cd "$(dirname "$0")" || exit 1
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 once (idempotent)
# NOTE: We intentionally **do not export** any new vars. They stay local to this shell.
if [ -z "${__INIT_ENV_LOADED:-}" ]; then
# shellcheck disable=SC1090
. "$INIT_ENV"
__INIT_ENV_LOADED=1
fi

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

TESTNAME="SoC_Infra_GPU_Clock_Rate_Validation"
RES_FILE="./$TESTNAME.res"
test_result_init "$TESTNAME" "$RES_FILE" || exit 1

CLK_PREFIX="gpu"
GPUCC_ERE='(^|[[:space:]])qcom,[[:alnum:]_-]+-gpucc([[:space:]]|$)'
REPORT_FILE="./gpu_clk_rates.log"

log_info "--------------------------------------------------------------------------"
log_info "Starting $TESTNAME"

# Never install packages on the target; skip when a base utility is missing.
if ! CHECK_DEPS_RECOVER=0 CHECK_DEPS_NO_EXIT=1 check_dependencies find grep cat tr readlink dirname basename mktemp; then
test_result_finish "SKIP" "$TESTNAME SKIP: required base utilities are unavailable"
fi

# debugfs is a prerequisite of its own. It needs CONFIG_DEBUG_FS and a mount, and
# the clk/ tree exists only when the clock framework registered its debugfs
# files. A GPU clock controller in the device tree guarantees none of that, so an
# unavailable interface is a SKIP, not a FAIL. FAIL is kept below for the cases
# where the interface is present and the clocks are still broken.
if ! debugfs_root=$(socinfra_debugfs_root); then
test_result_finish "SKIP" "$TESTNAME SKIP: debugfs is not mounted or not readable, so the clock tree is unavailable (mount -t debugfs debugfs /sys/kernel/debug, run as root)"
fi
if [ ! -d "$debugfs_root/clk" ] || [ ! -r "$debugfs_root/clk" ] || [ ! -x "$debugfs_root/clk" ]; then
test_result_finish "SKIP" "$TESTNAME SKIP: $debugfs_root/clk is not available, the kernel does not expose the clock tree in debugfs"
fi

# The interface is usable. The device tree now decides whether the platform has
# a GPU clock controller, so having no GPU clocks on such a platform is a failure
# and not a skip.
gpucc_in_dt=0
if dt_list_compatible_nodes "$GPUCC_ERE" regex >/dev/null 2>&1; then
gpucc_in_dt=1
fi
log_info "GPU clock controller (*-gpucc) in the device tree: $gpucc_in_dt"
log_info "Checking $debugfs_root/clk/${CLK_PREFIX}*/clk_rate"

socinfra_check_clk_rates "$debugfs_root" "$CLK_PREFIX" "$REPORT_FILE"
clk_rc=$?
log_info "Clocks checked: total=$SOCINFRA_CLK_TOTAL invalid=$SOCINFRA_CLK_BAD (details: $REPORT_FILE)"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Job 619157 reports PASS for 18 clocks, but stdout contains none of their names or rates. Replay $REPORT_FILE using the existing log_file_with_label after saving clk_rc, label the values as Hz, and retain the report file.


case "$clk_rc" in
0)
test_result_record "PASS" "All $SOCINFRA_CLK_TOTAL ${CLK_PREFIX}* clock rates are integers"
;;
2)
if [ "$gpucc_in_dt" -eq 1 ]; then
test_result_finish "FAIL" "$TESTNAME FAIL: the device tree has a GPU clock controller but no ${CLK_PREFIX}* clocks are registered under $debugfs_root/clk; check the GPU clock driver"
fi
test_result_finish "SKIP" "$TESTNAME SKIP: no ${CLK_PREFIX}* clocks under $debugfs_root/clk and no GPU clock controller in the device tree"
;;
*)
grep -E 'NOT_INTEGER|READ_ERROR' "$REPORT_FILE" | while IFS= read -r bad_line; do
log_fail "Invalid clock rate: $bad_line"
done
test_result_record "FAIL" "$SOCINFRA_CLK_BAD of $SOCINFRA_CLK_TOTAL ${CLK_PREFIX}* clock rates are not valid integers or cannot be read"
;;
esac

test_result_finish
53 changes: 53 additions & 0 deletions Runner/utils/functestlib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4986,6 +4986,59 @@ interconnect_debugfs_dir() {
return 1
}

# ---------------------------------------------------------------------------
# SoC Infra helpers
# ---------------------------------------------------------------------------

# socinfra_debugfs_root
# Prints the mounted debugfs root (/sys/kernel/debug or /debug).
# Returns: 0 when found, 1 when debugfs is not mounted or not readable.
socinfra_debugfs_root() {
for sdr_root in /sys/kernel/debug /debug; do
if [ -d "$sdr_root" ] && [ -r "$sdr_root" ] &&
grep -q " $sdr_root debugfs " /proc/mounts 2>/dev/null; then
printf '%s\n' "$sdr_root"
return 0
fi
done
return 1
}

# socinfra_check_clk_rates <debugfs_root> <clock_name_prefix> <report_file>
# Reads <debugfs_root>/clk/<prefix>*/clk_rate and checks that every file holds
# exactly one non-negative integer. The content is validated as read, so a value
# with embedded whitespace such as "12 34" is rejected and not merged into 1234.
# One line per clock is written to <report_file>: "<clock> <value>", or
# "<clock> NOT_INTEGER(<value>)" / "<clock> READ_ERROR" for a bad clock.
# Sets SOCINFRA_CLK_TOTAL and SOCINFRA_CLK_BAD.
# Returns: 0 all values are integers, 1 at least one value is not an integer or
# cannot be read, 2 no clock matched the prefix.
socinfra_check_clk_rates() {
SOCINFRA_CLK_TOTAL=0
SOCINFRA_CLK_BAD=0
: >"$3"
for scr_file in "$1/clk/$2"*/clk_rate; do
[ -e "$scr_file" ] || continue
scr_name=$(basename "$(dirname "$scr_file")")
SOCINFRA_CLK_TOTAL=$((SOCINFRA_CLK_TOTAL + 1))
# Command substitution drops only the trailing newline of the value.
if ! scr_val=$(cat "$scr_file" 2>/dev/null); then
SOCINFRA_CLK_BAD=$((SOCINFRA_CLK_BAD + 1))
printf '%s READ_ERROR\n' "$scr_name" >>"$3"
elif is_unsigned_number "$scr_val"; then
printf '%s %s\n' "$scr_name" "$scr_val" >>"$3"
else
SOCINFRA_CLK_BAD=$((SOCINFRA_CLK_BAD + 1))
# Keep the report to one line per clock, whatever the file held.
scr_shown=$(printf '%s' "$scr_val" | tr -c '[:print:]' '?')
printf '%s NOT_INTEGER(%s)\n' "$scr_name" "$scr_shown" >>"$3"
fi
done
[ "$SOCINFRA_CLK_TOTAL" -gt 0 ] || return 2
[ "$SOCINFRA_CLK_BAD" -eq 0 ]
}


###############################################################################
# dt_node_has_property <node-dir> <property>
# Returns 0 if the exact DT property file exists, otherwise 1. The function
Expand Down
Loading