Skip to content
Merged
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
188 changes: 109 additions & 79 deletions Runner/suites/Multimedia/Camera/Camera_NHX/run.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
# SPDX-License-Identifier: BSD-3-Clause#
# SPDX-License-Identifier: BSD-3-Clause
# Camera NHX validation

TESTNAME="Camera_NHX"
Expand Down Expand Up @@ -51,10 +51,8 @@ RUN_LOG="$LOG_DIR/${TESTNAME}_${TS}.log"
SUMMARY_TXT="$OUT_DIR/${TESTNAME}_summary_${TS}.txt"
DMESG_DIR="$LOG_DIR/dmesg_${TS}"

# NHX helper output directory (IMPORTANT: lib_camera.sh expects a directory, not a file)
NHX_OUTDIR="$OUT_DIR/nhx_${TS}"

# dump list & checksum artifacts (produced by dump validation helper)
DUMPS_LIST="$NHX_OUTDIR/nhx_dumps.list"
CHECKSUMS_TXT="$NHX_OUTDIR/nhx_checksums.txt"
CHECKSUMS_PREV="$OUT_DIR/${TESTNAME}_checksums.prev.txt"
Expand All @@ -65,13 +63,26 @@ if [ -z "$MARKER" ]; then
: >"$MARKER" 2>/dev/null || true
fi

cleanup() { rm -f "$MARKER" 2>/dev/null || true; }
trap cleanup EXIT INT TERM
CAM_SERVER_PRESENT=0
CAM_SERVER_STOPPED_FOR_TEST=0

# shellcheck disable=SC2317
cleanup() {
if [ "$CAM_SERVER_STOPPED_FOR_TEST" -eq 1 ] && [ "$CAM_SERVER_PRESENT" -eq 1 ]; then
systemd_service_start_safe "cam-server" >/dev/null 2>&1 || true
fi

if [ -n "${MARKER:-}" ]; then
rm -f "$MARKER"
fi
}

trap 'cleanup' EXIT INT TERM

# -----------------------------------------------------------------------------
# Deps check (functestlib.sh provides check_dependencies)
# Deps check
# -----------------------------------------------------------------------------
deps_list="date awk sed grep tee wc ls find stat rm tr head tail dmesg sort opkg fdtdump mkfifo sha256sum md5sum cksum diff cp"
deps_list="date awk sed grep tee wc ls find stat rm tr head tail dmesg sort fdtdump mkfifo sha256sum md5sum cksum diff cp"
if ! check_dependencies "$deps_list"; then
log_skip "$TESTNAME SKIP missing one or more dependencies: $deps_list"
echo "$TESTNAME SKIP" >"$RES_FILE"
Expand All @@ -86,18 +97,9 @@ fi

# -----------------------------------------------------------------------------
# CAMX prechecks
# Sequence:
# 1) DT check
# 2) fdtdump camera nodes sample
# 3) driver load checks
# 4) packages present
# 5) sensor presence warn-only
# -----------------------------------------------------------------------------
log_info "Checking CAMX proprietary prerequisites before running NHX"

# -----------------------------
# 1) DT check
# -----------------------------
log_info "DT check"

PATTERNS="qcom,cam qcom,camera camera_kt cam-req-mgr cam-cpas cam-jpeg cam-ife cam-icp cam-sensor camera0-thermal"
Expand All @@ -110,7 +112,6 @@ for pat in $PATTERNS; do
printf '%s\n' "$out"
found_any=1
else
# Explicit append logic (reviewer-friendly; avoids &&/|| ambiguity)
if [ -n "$missing_list" ]; then
missing_list="$missing_list, $pat"
else
Expand All @@ -125,12 +126,9 @@ if [ "$found_any" -ne 1 ]; then
exit 0
fi

# -----------------------------
# 2) fdtdump camera nodes sample
# -----------------------------
log_info "fdtdump camera nodes sample"

FDT_MATCHES="$(camx_fdtdump_has_cam_nodes 2>/dev/null || true)"
FDT_MATCHES="$(camx_fdtdump_has_cam_nodes 2>/dev/null)"
rc=$?
if [ "$rc" -ne 0 ]; then
if [ "$rc" -eq 2 ]; then
Expand All @@ -143,37 +141,31 @@ if [ "$rc" -ne 0 ]; then
fi

printf '%s\n' "$FDT_MATCHES" | while IFS= read -r l; do
[ -n "$l" ] && log_info " $l"
if [ -n "$l" ]; then
log_info " $l"
fi
done

# -----------------------------
# 3) driver load checks
# -----------------------------
log_info "driver load checks"

CAM_MOD=""

if command -v lsmod >/dev/null 2>&1; then
CAM_MOD="$(lsmod 2>/dev/null | awk '{print $1}' \
| grep -E '^(camera_qc|camera_qcm|camera_qcs)' \
| head -n 1 || true)"
if command -v camx_pick_camera_module >/dev/null 2>&1; then
CAM_MOD="$(camx_pick_camera_module 2>/dev/null || true)"
fi

if [ -z "$CAM_MOD" ]; then
kver="$(uname -r 2>/dev/null || true)"
if [ -n "$kver" ] && [ -d "/lib/modules/$kver" ]; then
ko="$(find "/lib/modules/$kver" -type f \( -name 'camera_qc*.ko' -o -name 'camera_qcm*.ko' -o -name 'camera_qcs*.ko' \) \
2>/dev/null | head -n 1 || true)"
CAM_MOD="$(basename "${ko:-}" .ko)"
fi
if [ -z "$CAM_MOD" ] && command -v lsmod >/dev/null 2>&1; then
CAM_MOD="$(lsmod 2>/dev/null | awk '{print $1}' | grep -E '^(camera_qc|camera_qcm|camera_qcs)' | head -n 1 || true)"
fi

if [ -z "$CAM_MOD" ]; then
log_skip "$TESTNAME SKIP could not determine camera module name"
log_skip "$TESTNAME SKIP could not determine board-specific camera module"
echo "$TESTNAME SKIP" >"$RES_FILE"
exit 0
fi

log_info "Board-specific camera module selected $CAM_MOD"

CAM_KO="$(find_kernel_module "$CAM_MOD" 2>/dev/null || true)"
if [ -z "$CAM_KO" ] || [ ! -f "$CAM_KO" ]; then
log_skip "$TESTNAME SKIP camera module artifact not found ${CAM_MOD}.ko"
Expand All @@ -197,7 +189,6 @@ if [ -z "$ICP_FW" ] || [ ! -f "$ICP_FW" ]; then
fi
log_info "ICP firmware found $ICP_FW"

# dmesg collection and error scan
module_regex='CAM_(ERR|WARN|FATAL)'
exclude_regex='dummy regulator|supply [^ ]+ not found|using dummy regulator'

Expand All @@ -216,12 +207,10 @@ FW_DL_OK=0
FW_DONE_OK=0

if [ -n "$FW_BASENAME" ] && [ -r "$DM_SNAP" ]; then
if grep -F "CAM_INFO: CAM-ICP: cam_a5_download_fw" "$DM_SNAP" 2>/dev/null \
| grep -F "$FW_BASENAME" >/dev/null 2>&1; then
if grep -F "CAM_INFO: CAM-ICP: cam_a5_download_fw" "$DM_SNAP" 2>/dev/null | grep -F "$FW_BASENAME" >/dev/null 2>&1; then
FW_DL_OK=1
fi
if grep -F "CAM_INFO: CAM-ICP: cam_icp_mgr_hw_open" "$DM_SNAP" 2>/dev/null \
| grep -F "FW download done successfully" >/dev/null 2>&1; then
if grep -F "CAM_INFO: CAM-ICP: cam_icp_mgr_hw_open" "$DM_SNAP" 2>/dev/null | grep -F "FW download done successfully" >/dev/null 2>&1; then
FW_DONE_OK=1
fi
fi
Expand All @@ -238,19 +227,17 @@ fi
bind_cnt=0
if [ -r "$DM_SNAP" ]; then
bind_cnt="$(grep -ciE 'cam_req_mgr.*bound|bound.*cam_req_mgr' "$DM_SNAP" 2>/dev/null || echo 0)"
case "$bind_cnt" in ''|*[!0-9]*) bind_cnt=0 ;; esac
case "$bind_cnt" in
''|*[!0-9]*) bind_cnt=0 ;;
esac
fi

if [ "$bind_cnt" -lt 5 ]; then
log_skip "$TESTNAME SKIP CAMX bind graph not observed"
echo "$TESTNAME SKIP" >"$RES_FILE"
exit 0
if [ "$bind_cnt" -lt 1 ]; then
log_warn "CAMX bind graph not observed in pre-NHX dmesg snapshot"
else
log_info "CAMX bind graph observed in pre-NHX dmesg snapshot count=$bind_cnt"
fi
log_info "CAMX bind graph observed"

# -----------------------------
# 4) packages present
# -----------------------------
log_info "packages present"

CAMX_PKGS="$(camx_opkg_list_camx 2>/dev/null || true)"
Expand All @@ -262,24 +249,22 @@ fi

log_info "CAMX packages detected"
printf '%s\n' "$CAMX_PKGS" | while IFS= read -r l; do
[ -n "$l" ] && log_info " $l"
if [ -n "$l" ]; then
log_info " $l"
fi
done

# -----------------------------
# 5) sensor presence warn-only
# -----------------------------
log_info "sensor presence warn-only NHX may still work without cam sensors"

SENSOR_COUNT="$(libcam_list_sensors_count 2>/dev/null || true)"
case "$SENSOR_COUNT" in ''|*[!0-9]*) SENSOR_COUNT=0 ;; esac
case "$SENSOR_COUNT" in
''|*[!0-9]*) SENSOR_COUNT=0 ;;
esac
log_info "cam list detected $SENSOR_COUNT cameras"
if [ "$SENSOR_COUNT" -lt 1 ]; then
log_warn "No sensors reported by cam list continuing"
fi

# -----------------------------------------------------------------------------
# Pick checksum tool (prefer helper in lib_camera.sh)
# -----------------------------------------------------------------------------
CKSUM_TOOL=""
if command -v nhx_pick_cksum_tool >/dev/null 2>&1; then
CKSUM_TOOL="$(nhx_pick_cksum_tool)"
Expand All @@ -299,6 +284,39 @@ log_info "DUMP_DIR=$DUMP_DIR"
log_info "NHX_OUTDIR=$NHX_OUTDIR"
log_info "CKSUM_TOOL=${CKSUM_TOOL:-none}"

# -----------------------------------------------------------------------------
# cam-server stop before NHX
# -----------------------------------------------------------------------------
if systemd_service_exists "cam-server"; then
CAM_SERVER_PRESENT=1

CAM_SERVER_TS_BEFORE_STOP='5 minutes ago'

log_info "cam-server status before stop"
systemd_service_status_log "cam-server BEFORE stop (status only)" "$RUN_LOG" "cam-server" || true

log_info "cam-server stdout before stop"
systemd_service_stdout_since "cam-server BEFORE stop (stdout recent)" \
"$RUN_LOG" "$CAM_SERVER_TS_BEFORE_STOP" "cam-server.service" || true

log_info "Stopping cam-server before nhx.sh"
if systemd_service_stop_safe "cam-server"; then
CAM_SERVER_STOPPED_FOR_TEST=1
CAM_SERVER_TS_AFTER_STOP="$(date '+%Y-%m-%d %H:%M:%S')"

log_info "cam-server status after stop"
systemd_service_status_log "cam-server AFTER stop (status only)" "$RUN_LOG" "cam-server" || true

log_info "cam-server stdout after stop"
systemd_service_stdout_since "cam-server AFTER stop (stdout since stop marker)" \
"$RUN_LOG" "$CAM_SERVER_TS_AFTER_STOP" "cam-server.service" || true
else
log_warn "Failed to stop cam-server before nhx.sh"
fi
else
log_info "cam-server service not present, continuing"
fi

# -----------------------------------------------------------------------------
# Run NHX
# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -329,21 +347,38 @@ else
fi

# -----------------------------------------------------------------------------
# Dump validation (delegate to lib_camera.sh helper)
# IMPORTANT: helper expects an output DIRECTORY, not a file path.
# cam-server start after NHX
# -----------------------------------------------------------------------------
if [ "$CAM_SERVER_STOPPED_FOR_TEST" -eq 1 ]; then
log_info "Starting cam-server after nhx.sh"
if systemd_service_start_safe "cam-server"; then
CAM_SERVER_STOPPED_FOR_TEST=0
CAM_SERVER_TS_AFTER_START="$(date '+%Y-%m-%d %H:%M:%S')"

log_info "cam-server status after start"
systemd_service_status_log "cam-server AFTER start (status only)" "$RUN_LOG" "cam-server" || true

log_info "cam-server stdout after start"
systemd_service_stdout_since "cam-server AFTER start (stdout since start marker)" \
"$RUN_LOG" "$CAM_SERVER_TS_AFTER_START" "cam-server.service" || true
else
log_warn "Failed to start cam-server after nhx.sh"
fi
else
log_info "cam-server was not stopped for test, skipping restart"
fi
# -----------------------------------------------------------------------------
# Dump validation
# -----------------------------------------------------------------------------
DUMP_VALIDATION_FAIL=0

# Ensure output directory exists regardless of helper/fallback
mkdir -p "$NHX_OUTDIR" 2>/dev/null || true

if command -v nhx_validate_dumps_and_checksums >/dev/null 2>&1; then
# nhx_validate_dumps_and_checksums <dump_dir> <marker_file> <out_dir> <out_checksums> <prev_checksums>
if ! nhx_validate_dumps_and_checksums "$DUMP_DIR" "$MARKER" "$NHX_OUTDIR" "$CHECKSUMS_TXT" "$CHECKSUMS_PREV"; then
DUMP_VALIDATION_FAIL=1
fi

# If helper generated a different list name, keep our expected path working.
if [ ! -s "$DUMPS_LIST" ]; then
if [ -s "$NHX_OUTDIR/nhx_dumps.list" ]; then
DUMPS_LIST="$NHX_OUTDIR/nhx_dumps.list"
Expand All @@ -354,7 +389,6 @@ if command -v nhx_validate_dumps_and_checksums >/dev/null 2>&1; then
fi
fi
else
# fallback: old behavior
: >"$DUMPS_LIST" 2>/dev/null || true

grep -F "Saving image to file:" "$RUN_LOG" \
Expand All @@ -363,7 +397,9 @@ else
| sort -u >"$DUMPS_LIST" 2>/dev/null || true

DUMP_COUNT="$(wc -l <"$DUMPS_LIST" 2>/dev/null | awk '{print $1}')"
[ -n "$DUMP_COUNT" ] || DUMP_COUNT=0
if [ -z "$DUMP_COUNT" ]; then
DUMP_COUNT=0
fi

if [ "$DUMP_COUNT" -eq 0 ]; then
log_info "No dump paths found in log scanning dump dir for new files"
Expand All @@ -373,15 +409,11 @@ else
fi
fi

# -----------------------------------------------------------------------------
# Compute dump count (based on DUMPS_LIST produced by helper/fallback)
# -----------------------------------------------------------------------------
DUMP_COUNT="$(wc -l <"$DUMPS_LIST" 2>/dev/null | awk '{print $1}')"
[ -n "$DUMP_COUNT" ] || DUMP_COUNT=0
if [ -z "$DUMP_COUNT" ]; then
DUMP_COUNT=0
fi

# -----------------------------------------------------------------------------
# Validate dumps (summary-side size scan; checksum is already done by helper)
# -----------------------------------------------------------------------------
ZERO_OR_MISSING=0
TOTAL_BYTES=0

Expand Down Expand Up @@ -410,7 +442,6 @@ if [ "$DUMP_COUNT" -gt 0 ]; then
} >>"$SUMMARY_TXT"

while IFS= read -r f; do
# Clear, reviewer-friendly empty-line skip
[ -z "$f" ] && continue

if [ ! -f "$f" ]; then
Expand All @@ -419,11 +450,10 @@ if [ "$DUMP_COUNT" -gt 0 ]; then
continue
fi

SZ="$(stat -c %s "$f" 2>/dev/null)"
if [ -z "$SZ" ]; then
SZ="$(wc -c <"$f" 2>/dev/null | awk '{print $1}')"
fi
[ -n "$SZ" ] || SZ=0
SZ="$(nhx_dump_size_bytes "$f" 2>/dev/null || printf '%s\n' "0")"
case "$SZ" in
''|*[!0-9]*) SZ=0 ;;
esac

if [ "$SZ" -le 0 ]; then
ZERO_OR_MISSING=$((ZERO_OR_MISSING + 1))
Expand Down
Loading
Loading