From daa3980a96e47960fb8f9fc4ed31b2b9e5e1d7d2 Mon Sep 17 00:00:00 2001 From: Srikanth Muppandam Date: Sat, 14 Feb 2026 23:04:36 +0530 Subject: [PATCH 1/4] lib_sensors: add DT-free helper library for discovery and test runners - add lib_sensors.sh helpers to: - gate on ADSP remoteproc state and firmware presence - dump ssc_sensor_info inventory to file (avoid huge stdout) - parse AVAILABLE=true sensor TYPE list - run see_workhorse / ssc_drva_test with progress + log-based PASS/FAIL parsing - keep ShellCheck clean and deterministic argv handling Signed-off-by: Srikanth Muppandam --- Runner/utils/lib_sensors.sh | 254 ++++++++++++++++++++++++++++++++++++ 1 file changed, 254 insertions(+) create mode 100755 Runner/utils/lib_sensors.sh diff --git a/Runner/utils/lib_sensors.sh b/Runner/utils/lib_sensors.sh new file mode 100755 index 00000000..a76ee0cc --- /dev/null +++ b/Runner/utils/lib_sensors.sh @@ -0,0 +1,254 @@ +#!/bin/sh +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. +# SPDX-License-Identifier: BSD-3-Clause-Clear +# Sensor helpers (DT-free): discovery via ssc_sensor_info, run see_workhorse/ssc_drva_test, parse PASS/FAIL. + +# Global outputs set by sensors_check_adsp_remoteproc() +SENSORS_ADSP_FW="" +SENSORS_ADSP_RPROC_PATH="" +SENSORS_ADSP_STATE="" + +sensors__trim_ws() { + # usage: sensors__trim_ws " abc " -> prints "abc" + # shellcheck disable=SC2001 + echo "$1" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//' +} + +# Append a line to a newline-separated list if it doesn't already exist. +# usage: new_list="$(sensors_append_unique_line "$list" "accel")" +sensors_append_unique_line() { + list="$1" + line="$2" + + [ -z "$line" ] && { printf '%s\n' "$list"; return 0; } + + if [ -z "$list" ]; then + printf '%s\n' "$line" + return 0 + fi + + printf '%s\n' "$list" | grep -Fxq "$line" 2>/dev/null && { + printf '%s\n' "$list" + return 0 + } + + printf '%s\n%s\n' "$list" "$line" +} + +sensors__firmware_exists_quick() { + fw="$1" + [ -z "$fw" ] && return 1 + # quick/cheap checks only (avoid heavy find): + [ -f "/lib/firmware/$fw" ] && return 0 + [ -f "/lib/firmware/qcom/$fw" ] && return 0 + [ -f "/lib/firmware/qcom/qcs6490/$fw" ] && return 0 + [ -f "/vendor/firmware/$fw" ] && return 0 + [ -f "/vendor/firmware_mnt/image/$fw" ] && return 0 + return 1 +} + +# Return codes: +# 0 = running +# 1 = remoteproc found but not running +# 2 = remoteproc not running and firmware missing +# 3 = remoteproc not found (by firmware mapping) +sensors_check_adsp_remoteproc() { + fw="${1:-adsp.mbn}" + + # NOTE: these are intentionally "output variables" for the caller (run.sh) + # shellcheck disable=SC2034 + SENSORS_ADSP_FW="$fw" + # shellcheck disable=SC2034 + SENSORS_ADSP_RPROC_PATH="" + SENSORS_ADSP_STATE="" + + if ! command -v get_remoteproc_path_by_firmware >/dev/null 2>&1; then + return 3 + fi + + rpath="$(get_remoteproc_path_by_firmware "$fw" 2>/dev/null || true)" + if [ -z "$rpath" ] || [ ! -d "$rpath" ]; then + return 3 + fi + + # shellcheck disable=SC2034 + SENSORS_ADSP_RPROC_PATH="$rpath" + + if command -v get_remoteproc_state >/dev/null 2>&1; then + SENSORS_ADSP_STATE="$(get_remoteproc_state "$rpath" 2>/dev/null || true)" + SENSORS_ADSP_STATE="$(sensors__trim_ws "$SENSORS_ADSP_STATE")" + else + if [ -r "$rpath/state" ]; then + SENSORS_ADSP_STATE="$(cat "$rpath/state" 2>/dev/null || true)" + SENSORS_ADSP_STATE="$(sensors__trim_ws "$SENSORS_ADSP_STATE")" + fi + fi + + [ "$SENSORS_ADSP_STATE" = "running" ] && return 0 + + if sensors__firmware_exists_quick "$fw"; then + return 1 + fi + return 2 +} + +sensors_dump_ssc_sensor_info() { + out_file="$1" + : >"$out_file" 2>/dev/null || true + ssc_sensor_info >"$out_file" 2>&1 + return $? +} + +sensors_types_from_ssc_file() { + f="$1" + [ -r "$f" ] || return 1 + + awk ' + function trim(s) { sub(/^[ \t\r\n]+/, "", s); sub(/[ \t\r\n]+$/, "", s); return s } + /^TYPE[[:space:]]*=/ { + type = $0 + sub(/^TYPE[[:space:]]*=[[:space:]]*/, "", type) + type = trim(type) + } + /^AVAILABLE[[:space:]]*=/ { + avail = $0 + sub(/^AVAILABLE[[:space:]]*=[[:space:]]*/, "", avail) + avail = trim(avail) + } + /^PHYSICAL_SENSOR[[:space:]]*=/ { + phys = $0 + sub(/^PHYSICAL_SENSOR[[:space:]]*=[[:space:]]*/, "", phys) + phys = trim(phys) + } + /^$/ { + if (type != "" && avail == "true") { + if (phys == "" || phys == "true") print type + } + type=""; avail=""; phys="" + } + END { + if (type != "" && avail == "true") { + if (phys == "" || phys == "true") print type + } + } + ' "$f" 2>/dev/null | sort -u +} + +sensors_type_present() { + types_nl="$1" + needle="$2" + printf '%s\n' "$types_nl" | grep -Fxq "$needle" 2>/dev/null +} + +# Run a command in background, redirect all output to logfile, and print a heartbeat. +# sensors_run_cmd_with_progress