Skip to content

Commit 5edc97f

Browse files
committed
Fix: AudioPlayback no longer requires network when clips exist
Resolves #229 Problem: AudioPlayback test was forcing network connections even when audio files were already present locally, causing tests to fail in offline environments. Solution: - Add --enable-network-download flag (opt-in, default: disabled) - Add audio_check_clips_available() to check files before network ops - Implement smart network gating: only connect if files missing AND flag enabled - Auto-enable network download when WiFi credentials provided via CLI Signed-off-by: Teja Swaroop Moida <tmoida@qti.qualcomm.com>
1 parent 1e8a4e4 commit 5edc97f

File tree

5 files changed

+266
-98
lines changed

5 files changed

+266
-98
lines changed
Lines changed: 123 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,148 @@
11
#!/bin/sh
2-
32
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
43
# SPDX-License-Identifier: BSD-3-Clause-Clear
4+
# Probe failure / deferred probe detector using kernel logs + devices_deferred
55

6-
# Robustly source init_env and functestlib.sh
7-
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
6+
# ---------- Repo env + helpers ----------
7+
SCRIPT_DIR="$(
8+
cd "$(dirname "$0")" || exit 1
9+
pwd
10+
)"
811
INIT_ENV=""
912
SEARCH="$SCRIPT_DIR"
13+
1014
while [ "$SEARCH" != "/" ]; do
11-
if [ -f "$SEARCH/init_env" ]; then
12-
INIT_ENV="$SEARCH/init_env"
13-
break
14-
fi
15-
SEARCH=$(dirname "$SEARCH")
15+
if [ -f "$SEARCH/init_env" ]; then
16+
INIT_ENV="$SEARCH/init_env"
17+
break
18+
fi
19+
SEARCH=$(dirname "$SEARCH")
1620
done
1721

1822
if [ -z "$INIT_ENV" ]; then
19-
echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2
20-
exit 1
23+
echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2
24+
exit 1
2125
fi
2226

23-
if [ -z "$__INIT_ENV_LOADED" ]; then
24-
# shellcheck disable=SC1090
25-
. "$INIT_ENV"
27+
# Only source once (idempotent)
28+
# NOTE: We intentionally **do not export** any new vars. They stay local to this shell.
29+
if [ -z "${__INIT_ENV_LOADED:-}" ]; then
30+
# shellcheck disable=SC1090
31+
. "$INIT_ENV"
32+
__INIT_ENV_LOADED=1
2633
fi
2734

35+
# Keep combined suppression for consistency across repo
2836
# shellcheck disable=SC1090,SC1091
2937
. "$TOOLS/functestlib.sh"
3038

3139
TESTNAME="Probe_Failure_Check"
40+
RESULT_FILE="$TESTNAME.res"
41+
LOG_FILE="probe_failures.log"
42+
43+
# Move into testcase directory (so .res and logs land in the right place)
3244
test_path=$(find_test_case_by_name "$TESTNAME")
3345
cd "$test_path" || exit 1
3446

35-
res_file="./$TESTNAME.res"
36-
log_file="./probe_failures.log"
37-
38-
log_info "-----------------------------------------------------------------------------------------"
47+
log_info "----------------------------------------------------------------------------"
3948
log_info "------------------- Starting $TESTNAME Testcase ----------------------------"
4049

41-
rm -f "$res_file" "$log_file"
42-
{
43-
echo "Probe Failure Report - $(date)"
44-
echo "--------------------------------------------------"
45-
} > "$log_file"
46-
47-
if get_kernel_log 2>/dev/null | \
48-
grep -iE '([[:alnum:]_.-]+:)?[[:space:]]*(probe failed|failed to probe|probe error)' \
49-
>> "$log_file"; then
50-
log_error "Probe failures detected; see $log_file"
51-
log_fail "$TESTNAME : Probe failures found"
52-
echo "$TESTNAME FAIL" > "$res_file"
53-
exit 1
50+
rm -f "$RESULT_FILE" "$LOG_FILE"
51+
: >"$LOG_FILE"
52+
53+
# --- Get kernel log snapshot ---
54+
if command -v get_kernel_log >/dev/null 2>&1; then
55+
KERNEL_LOG="$(get_kernel_log 2>/dev/null)"
56+
else
57+
log_warn "'get_kernel_log' not found, falling back to 'dmesg -T'"
58+
KERNEL_LOG="$(dmesg -T 2>/dev/null)"
59+
fi
60+
61+
# --- SKIP when unable to collect kernel logs ---
62+
if [ -z "$KERNEL_LOG" ]; then
63+
if command -v log_skip >/dev/null 2>&1; then
64+
log_skip "$TESTNAME : Unable to collect kernel logs, skipping probe failure check"
65+
else
66+
log_warn "$TESTNAME : Unable to collect kernel logs, treating as SKIP"
67+
fi
68+
echo "$TESTNAME SKIP" >"$RESULT_FILE"
69+
rm -f "$LOG_FILE"
70+
exit 0
71+
fi
72+
73+
# --- Probe / firmware / bind failure patterns ---
74+
# Intentionally broad but targeted at realistic driver init / teardown problems.
75+
# Built as a concatenation of single-quoted segments to avoid stray backslashes.
76+
FAIL_PATTERN='(failed to (probe|instantiate)|'\
77+
'probe of .* failed|probe with driver .* failed|deferred probe timeout, ignoring dependency|'\
78+
'Direct firmware load .* failed|tplg firmware loading .* failed|ASoC error|'\
79+
'unprobe failed|failed to remove .* driver|component bind error|component unbind error|'\
80+
'Driver .* failed|cannot register device driver|register_component error|'\
81+
'sound: ASoC: failed|load_firmware failed|request_firmware failed|device_add failed|'\
82+
'platform device_add failed|Cannot register component|bind failed|'\
83+
'lookup_component error|failed to add machine driver)'
84+
85+
# Pull out matched lines
86+
MATCHES=$(printf '%s\n' "$KERNEL_LOG" | grep -Ei "$FAIL_PATTERN" || true)
87+
88+
# --- Optional: report devices still in deferred-probe list (debugfs) ---
89+
DEFERRED_FILE="/sys/kernel/debug/devices_deferred"
90+
if [ -r "$DEFERRED_FILE" ]; then
91+
DEFERRED_CONTENT=$(cat "$DEFERRED_FILE" 2>/dev/null || true)
92+
if [ -n "$DEFERRED_CONTENT" ]; then
93+
log_warn "Devices still listed in $DEFERRED_FILE (deferred probe not resolved):"
94+
printf '%s\n' "$DEFERRED_CONTENT" >>"$LOG_FILE"
95+
printf '%s\n' "$DEFERRED_CONTENT" | while IFS= read -r line; do
96+
[ -n "$line" ] || continue
97+
log_warn "DEFERRED: $line"
98+
done
99+
else
100+
log_info "No entries in $DEFERRED_FILE (no outstanding deferred probes)."
101+
fi
54102
else
55-
rm -f "$log_file"
56-
log_pass "$TESTNAME : No probe failures found"
57-
echo "$TESTNAME PASS" > "$res_file"
58-
exit 0
103+
log_info "$DEFERRED_FILE not available (no deferred-probe debugfs support)."
104+
fi
105+
106+
# --- Evaluate matches and report to CI ---
107+
if [ -n "$MATCHES" ]; then
108+
# Save full match set to log file for post-mortem
109+
printf '%s\n' "$MATCHES" >>"$LOG_FILE"
110+
111+
MATCH_COUNT=$(printf '%s\n' "$MATCHES" | wc -l | awk '{print $1}')
112+
# Extract the latest leading [timestamp] if present, e.g. "[ 10.471969]"
113+
LATEST_TS=$(
114+
printf '%s\n' "$MATCHES" \
115+
| sed -n 's/^\(\[[^]]*]\).*/\1/p' \
116+
| tail -n 1
117+
)
118+
119+
log_fail "$TESTNAME : Kernel probe/unprobe/firmware-related errors found (see $LOG_FILE)"
120+
log_info "Total matched lines: $MATCH_COUNT"
121+
if [ -n "$LATEST_TS" ]; then
122+
log_info "Latest timestamp among matches: $LATEST_TS"
123+
else
124+
log_info "Latest timestamp among matches: Not Available"
125+
fi
126+
127+
# Print a few representative lines to stdout for CI log visibility
128+
printf '%s\n' "$MATCHES" | head -n 10 | while IFS= read -r line; do
129+
[ -n "$line" ] || continue
130+
echo "CI-HINT: $line"
131+
done
132+
133+
# Dump entire LOG_FILE for easy inspection in LAVA logs
134+
if [ -s "$LOG_FILE" ]; then
135+
echo "================ $LOG_FILE (full contents) ================"
136+
cat "$LOG_FILE"
137+
echo "================ end of $LOG_FILE ========================="
138+
fi
139+
140+
echo "$TESTNAME FAIL" >"$RESULT_FILE"
141+
# Convention: exit 0, result is driven by .res file
142+
exit 0
59143
fi
144+
145+
log_pass "$TESTNAME : No probe/firmware/bind errors found in kernel log snapshot"
146+
echo "$TESTNAME PASS" >"$RESULT_FILE"
147+
rm -f "$LOG_FILE"
148+
exit 0

Runner/suites/Multimedia/Audio/AudioPlayback/AudioPlayback.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ params:
1818
DMESG_SCAN: 1 # Scan dmesg for errors after playback, default: 1
1919
VERBOSE: 0 # Enable verbose logging, default: 0
2020
EXTRACT_AUDIO_ASSETS: true # Download/extract audio assets if missing, default: true
21+
ENABLE_NETWORK_DOWNLOAD: false # Enable network download of missing audio files, default: false
2122
SSID: "" # Wi-Fi SSID for network connection, default: unset
2223
PASSWORD: "" # Wi-Fi password for network connection, default: unset
2324
NET_PROBE_ROUTE_IP: "1.1.1.1" # IP used for route probing, default: 1.1.1.1
@@ -27,5 +28,10 @@ run:
2728
steps:
2829
- REPO_PATH=$PWD
2930
- cd Runner/suites/Multimedia/Audio/AudioPlayback/
30-
- ./run.sh --backend "${AUDIO_BACKEND}" --sink "${SINK_CHOICE}" --format "${FORMAT}" --durations "${DURATIONS}" --loops "${LOOPS}" --timeout "${TIMEOUT}" --strict "${STRICT}" --ssid "${SSID}" --password "${PASSWORD}" || true
31-
- $REPO_PATH/Runner/utils/send-to-lava.sh AudioPlayback.res || true
31+
- |
32+
if [ "${ENABLE_NETWORK_DOWNLOAD}" = "true" ]; then
33+
./run.sh --backend "${AUDIO_BACKEND}" --sink "${SINK_CHOICE}" --formats "${FORMATS}" --durations "${DURATIONS}" --loops "${LOOPS}" --timeout "${TIMEOUT}" --enable-network-download --ssid "${SSID}" --password "${PASSWORD}" || true
34+
else
35+
./run.sh --backend "${AUDIO_BACKEND}" --sink "${SINK_CHOICE}" --formats "${FORMATS}" --durations "${DURATIONS}" --loops "${LOOPS}" --timeout "${TIMEOUT}" --ssid "${SSID}" --password "${PASSWORD}" || true
36+
fi
37+
- $REPO_PATH/Runner/utils/send-to-lava.sh AudioPlayback.res || true

Runner/suites/Multimedia/Audio/AudioPlayback/Read_me.md

Lines changed: 50 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This suite automates the validation of audio playback capabilities on Qualcomm L
99

1010
- Supports **PipeWire** and **PulseAudio** backends
1111
- Plays audio clips with configurable format, duration, and loop count
12+
- **Network operations are optional**: By default, no network connection is attempted. Use `--enable-network-download` to enable downloading missing audio files
1213
- Automatically downloads and extracts audio assets if missing
1314
- Validates playback using multiple evidence sources:
1415
- PipeWire/PulseAudio streaming state
@@ -91,6 +92,18 @@ SSID="MyNetwork" PASSWORD="MyPassword" ./run-test.sh AudioPlayback
9192
# Override network probe targets (useful in restricted networks)
9293
NET_PROBE_ROUTE_IP=192.168.1.1 NET_PING_HOST=192.168.1.254 ./run-test.sh AudioPlayback
9394
95+
# Run without network (requires local clips)
96+
./run.sh
97+
98+
# Enable network download for missing clips
99+
./run.sh --enable-network-download
100+
101+
# Provide WiFi credentials (auto-enables download)
102+
./run.sh --ssid "MyNetwork" --password "MyPassword"
103+
104+
# Offline mode with local clips only
105+
./run.sh --no-extract-assets
106+
94107
95108
**Directly from Test Directory**
96109
cd Runner/suites/Multimedia/Audio/AudioPlayback
@@ -112,38 +125,41 @@ cd Runner/suites/Multimedia/Audio/AudioPlayback
112125
113126
114127
Environment Variables:
115-
Variable Description Default
116-
AUDIO_BACKEND Selects backend: pipewire or pulseaudio auto-detect
117-
SINK_CHOICE Playback sink: speakers or null speakers
118-
FORMATS Audio formats: e.g. wav wav
119-
DURATIONS Playback durations: short, medium, long short
120-
LOOPS Number of playback loops 1
121-
TIMEOUT Playback timeout per loop (e.g., 15s, 0=none) 0
122-
STRICT Enable strict mode (fail on any error) 0
123-
DMESG_SCAN Scan dmesg for errors after playback 1
124-
VERBOSE Enable verbose logging 0
125-
EXTRACT_AUDIO_ASSETS Download/extract audio assets if missing true
126-
JUNIT_OUT Path to write JUnit XML output unset
127-
SSID Wi-Fi SSID for network connection unset
128-
PASSWORD Wi-Fi password for network connection unset
129-
NET_PROBE_ROUTE_IP IP used for route probing (default: 1.1.1.1) 1.1.1.1
130-
NET_PING_HOST Host used for ping reachability check 8.8.8.8
128+
Variable Description Default
129+
AUDIO_BACKEND Selects backend: pipewire or pulseaudio auto-detect
130+
SINK_CHOICE Playback sink: speakers or null speakers
131+
FORMATS Audio formats: e.g. wav wav
132+
DURATIONS Playback durations: short, medium, long short
133+
LOOPS Number of playback loops 1
134+
TIMEOUT Playback timeout per loop (e.g., 15s, 0=none) 0
135+
STRICT Enable strict mode (fail on any error) 0
136+
DMESG_SCAN Scan dmesg for errors after playback 1
137+
VERBOSE Enable verbose logging 0
138+
EXTRACT_AUDIO_ASSETS Download/extract audio assets if missing true
139+
ENABLE_NETWORK_DOWNLOAD Enable network download of missing audio files false
140+
141+
JUNIT_OUT Path to write JUnit XML output unset
142+
SSID Wi-Fi SSID for network connection unset
143+
PASSWORD Wi-Fi password for network connection unset
144+
NET_PROBE_ROUTE_IP IP used for route probing (default: 1.1.1.1) 1.1.1.1
145+
NET_PING_HOST Host used for ping reachability check 8.8.8.8
131146
132147
133148
CLI Options
134-
Option Description
135-
--backend Select backend: pipewire or pulseaudio
136-
--sink Playback sink: speakers or null
137-
--formats Audio formats (space/comma separated): e.g. wav
138-
--durations Playback durations: short, medium, long
139-
--loops Number of playback loops
140-
--timeout Playback timeout per loop (e.g., 15s)
141-
--strict Enable strict mode
142-
--no-dmesg Disable dmesg scan
143-
--no-extract-assets Disable asset extraction
144-
--junit <file.xml> Write JUnit XML output
145-
--verbose Enable verbose logging
146-
--help Show usage instructions
149+
Option Description
150+
--backend Select backend: pipewire or pulseaudio
151+
--sink Playback sink: speakers or null
152+
--formats Audio formats (space/comma separated): e.g. wav
153+
--durations Playback durations: short, medium, long
154+
--loops Number of playback loops
155+
--timeout Playback timeout per loop (e.g., 15s)
156+
--strict Enable strict mode
157+
--no-dmesg Disable dmesg scan
158+
--no-extract-assets Disable asset extraction entirely (skips all asset operations)
159+
--enable-network-download Enable network operations to download missing audio files (default: disabled)
160+
--junit <file.xml> Write JUnit XML output
161+
--verbose Enable verbose logging
162+
--help Show usage instructions
147163
148164
```
149165

@@ -178,8 +194,10 @@ Diagnostic logs: dmesg snapshots, mixer dumps, playback logs per test case
178194
- The script validates the presence of required tools before executing tests; missing tools result in SKIP.
179195
- If any critical tool is missing, the script exits with an error message.
180196
- Logs include dmesg snapshots, mixer dumps, and playback logs.
181-
- Asset download requires network connectivity.
182-
- Pass Wi-Fi credentials via SSID and PASSWORD environment variables to enable network access for asset downloads and playback validation.
197+
- **Network operations are disabled by default**. Use `--enable-network-download` to download missing audio files.
198+
- Pass Wi-Fi credentials via `--ssid` and `--password` CLI flags (or SSID/PASSWORD environment variables) to auto-enable network download.
199+
- If audio clips are present locally, the test runs without any network operations (offline-capable).
200+
- If clips are missing and network download is disabled, the test will SKIP with a helpful message.
183201
- You can override default network probe targets using NET_PROBE_ROUTE_IP and NET_PING_HOST to avoid connectivity-related failures in restricted environments.
184202
- Evidence-based PASS/FAIL logic ensures reliability even if backend quirks occur.
185203

@@ -188,3 +206,4 @@ Diagnostic logs: dmesg snapshots, mixer dumps, playback logs per test case
188206
SPDX-License-Identifier: BSD-3-Clause-Clear
189207
(C) Qualcomm Technologies, Inc. and/or its subsidiaries.
190208

209+

0 commit comments

Comments
 (0)