Skip to content

Commit f0b4313

Browse files
committed
AudioPlayback: Add optional network download with smart asset management
- Add --enable-network-download flag (default: disabled) for offline-first operation - Implement smart network gating: only connect when clips missing AND download enabled - Add audio_check_clips_available() to validate clips before any network operations - Remove duplicate asset fetch logic from per-test loop (single download at startup) - Add --audio-clips-path flag for CI workflows with pre-staged clips - Add SSID/PASSWORD parameters for network authentication when download enabled This allows tests to run offline when clips are present, while providing network download capability when explicitly enabled with proper credentials. Resolves qualcomm-linux#229 Signed-off-by: Teja Swaroop Moida <tmoida@qti.qualcomm.com>
1 parent 0feb6ac commit f0b4313

4 files changed

Lines changed: 160 additions & 69 deletions

File tree

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ 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
22+
AUDIO_CLIPS_BASE_DIR: "" # Custom path to pre-staged audio clips (for CI), default: unset
2123
SSID: "" # Wi-Fi SSID for network connection, default: unset
2224
PASSWORD: "" # Wi-Fi password for network connection, default: unset
2325
NET_PROBE_ROUTE_IP: "1.1.1.1" # IP used for route probing, default: 1.1.1.1
@@ -27,5 +29,5 @@ run:
2729
steps:
2830
- REPO_PATH=$PWD
2931
- 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
32+
- ./run.sh --backend "${AUDIO_BACKEND}" --sink "${SINK_CHOICE}" --formats "${FORMATS}" --durations "${DURATIONS}" --loops "${LOOPS}" --timeout "${TIMEOUT}" --strict "${STRICT}" --audio-clips-path "${AUDIO_CLIPS_BASE_DIR}" --ssid "${SSID}" --password "${PASSWORD}" || true
33+
- $REPO_PATH/Runner/utils/send-to-lava.sh AudioPlayback.res || true

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

Lines changed: 56 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,23 @@ 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+
107+
# CI workflow: Use pre-staged clips at custom location
108+
./run.sh --audio-clips-path /tmp/ci-audio-staging/AudioClips
109+
110+
# CI workflow: Via environment variable
111+
AUDIO_CLIPS_BASE_DIR="/tmp/ci-audio-staging/AudioClips" ./run-test.sh AudioPlayback
94112
95113
**Directly from Test Directory**
96114
cd Runner/suites/Multimedia/Audio/AudioPlayback
@@ -112,38 +130,42 @@ cd Runner/suites/Multimedia/Audio/AudioPlayback
112130
113131
114132
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
133+
Variable Description Default
134+
AUDIO_BACKEND Selects backend: pipewire or pulseaudio auto-detect
135+
SINK_CHOICE Playback sink: speakers or null speakers
136+
FORMATS Audio formats: e.g. wav wav
137+
DURATIONS Playback durations: short, medium, long short
138+
LOOPS Number of playback loops 1
139+
TIMEOUT Playback timeout per loop (e.g., 15s, 0=none) 0
140+
STRICT Enable strict mode (fail on any error) 0
141+
DMESG_SCAN Scan dmesg for errors after playback 1
142+
VERBOSE Enable verbose logging 0
143+
EXTRACT_AUDIO_ASSETS Download/extract audio assets if missing true
144+
ENABLE_NETWORK_DOWNLOAD Enable network download of missing audio files false
145+
AUDIO_CLIPS_BASE_DIR Custom path to pre-staged audio clips (CI use) unset
146+
JUNIT_OUT Path to write JUnit XML output unset
147+
SSID Wi-Fi SSID for network connection unset
148+
PASSWORD Wi-Fi password for network connection unset
149+
NET_PROBE_ROUTE_IP IP used for route probing (default: 1.1.1.1) 1.1.1.1
150+
NET_PING_HOST Host used for ping reachability check 8.8.8.8
131151
132152
133153
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
154+
Option Description
155+
--backend Select backend: pipewire or pulseaudio
156+
--sink Playback sink: speakers or null
157+
--formats Audio formats (space/comma separated): e.g. wav
158+
--durations Playback durations: short, medium, long
159+
--loops Number of playback loops
160+
--timeout Playback timeout per loop (e.g., 15s)
161+
--strict Enable strict mode
162+
--no-dmesg Disable dmesg scan
163+
--no-extract-assets Disable asset extraction entirely (skips all asset operations)
164+
--enable-network-download Enable network operations to download missing audio files (default: disabled)
165+
--audio-clips-path <path> Custom location for audio clips (for CI with pre-staged clips)
166+
--junit <file.xml> Write JUnit XML output
167+
--verbose Enable verbose logging
168+
--help Show usage instructions
147169
148170
```
149171

@@ -178,8 +200,10 @@ Diagnostic logs: dmesg snapshots, mixer dumps, playback logs per test case
178200
- The script validates the presence of required tools before executing tests; missing tools result in SKIP.
179201
- If any critical tool is missing, the script exits with an error message.
180202
- 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.
203+
- **Network operations are disabled by default**. Use `--enable-network-download` to download missing audio files.
204+
- Pass Wi-Fi credentials via `--ssid` and `--password` CLI flags (or SSID/PASSWORD environment variables) to auto-enable network download.
205+
- If audio clips are present locally, the test runs without any network operations (offline-capable).
206+
- If clips are missing and network download is disabled, the test will SKIP with a helpful message.
183207
- You can override default network probe targets using NET_PROBE_ROUTE_IP and NET_PING_HOST to avoid connectivity-related failures in restricted environments.
184208
- Evidence-based PASS/FAIL logic ensures reliability even if backend quirks occur.
185209

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

215+

Runner/suites/Multimedia/Audio/AudioPlayback/run.sh

Lines changed: 79 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ STRICT="${STRICT:-0}"
6767
DMESG_SCAN="${DMESG_SCAN:-1}"
6868
VERBOSE=0
6969
EXTRACT_AUDIO_ASSETS="${EXTRACT_AUDIO_ASSETS:-true}"
70+
ENABLE_NETWORK_DOWNLOAD="${ENABLE_NETWORK_DOWNLOAD:-false}" # Default: no network operations
71+
AUDIO_CLIPS_BASE_DIR="${AUDIO_CLIPS_BASE_DIR:-}" # Custom path for audio clips (CI use)
7072

7173
# Network bring-up knobs (match video behavior)
7274
if [ -z "${NET_STABILIZE_SLEEP:-}" ]; then
@@ -88,6 +90,8 @@ Usage: $0 [options]
8890
--durations "short|short medium|short medium long"
8991
--loops N
9092
--timeout SECS # set 0 to disable watchdog
93+
--enable-network-download
94+
--audio-clips-path PATH # Custom location for audio clips (CI use)
9195
--strict
9296
--no-dmesg
9397
--no-extract-assets
@@ -136,6 +140,14 @@ while [ $# -gt 0 ]; do
136140
EXTRACT_AUDIO_ASSETS=false
137141
shift
138142
;;
143+
--enable-network-download)
144+
ENABLE_NETWORK_DOWNLOAD=true
145+
shift
146+
;;
147+
--audio-clips-path)
148+
AUDIO_CLIPS_BASE_DIR="$2"
149+
shift 2
150+
;;
139151
--ssid)
140152
# shellcheck disable=SC2034
141153
SSID="$2"
@@ -161,6 +173,12 @@ while [ $# -gt 0 ]; do
161173
esac
162174
done
163175

176+
# Auto-enable network download if WiFi credentials provided
177+
if [ -n "$SSID" ] && [ -n "$PASSWORD" ]; then
178+
log_info "WiFi credentials provided, auto-enabling network download"
179+
ENABLE_NETWORK_DOWNLOAD=true
180+
fi
181+
164182
# Ensure we run from the testcase dir
165183
test_path="$(find_test_case_by_name "$TESTNAME" 2>/dev/null || echo "$SCRIPT_DIR")"
166184
if ! cd "$test_path"; then
@@ -178,7 +196,13 @@ else
178196
log_info "Platform Details: unknown"
179197
fi
180198

181-
log_info "Args: backend=${AUDIO_BACKEND:-auto} sink=$SINK_CHOICE loops=$LOOPS timeout=$TIMEOUT formats='$FORMATS' durations='$DURATIONS' strict=$STRICT dmesg=$DMESG_SCAN extract=$EXTRACT_AUDIO_ASSETS"
199+
# Export AUDIO_CLIPS_BASE_DIR for use by resolve_clip() in audio_common.sh
200+
if [ -n "$AUDIO_CLIPS_BASE_DIR" ]; then
201+
export AUDIO_CLIPS_BASE_DIR
202+
log_info "Using custom audio clips path: $AUDIO_CLIPS_BASE_DIR"
203+
fi
204+
205+
log_info "Args: backend=${AUDIO_BACKEND:-auto} sink=$SINK_CHOICE loops=$LOOPS timeout=$TIMEOUT formats='$FORMATS' durations='$DURATIONS' strict=$STRICT dmesg=$DMESG_SCAN extract=$EXTRACT_AUDIO_ASSETS network_download=$ENABLE_NETWORK_DOWNLOAD clips_path=${AUDIO_CLIPS_BASE_DIR:-default}"
182206

183207
# --- Rootfs minimum size check (mirror video policy) ---
184208
if [ "$TOP_LEVEL_RUN" -eq 1 ]; then
@@ -187,25 +211,51 @@ else
187211
log_info "Sub-run: skipping rootfs size check (already performed)."
188212
fi
189213

190-
# --- Network preflight identical to video gating ---
214+
# --- Smart network gating: only connect if needed ---
191215
if [ "$TOP_LEVEL_RUN" -eq 1 ]; then
192216
if [ "${EXTRACT_AUDIO_ASSETS}" = "true" ]; then
193-
NET_RC="1"
194-
195-
if command -v check_network_status_rc >/dev/null 2>&1; then
196-
check_network_status_rc
197-
NET_RC="$?"
198-
elif command -v check_network_status >/dev/null 2>&1; then
199-
check_network_status >/dev/null 2>&1
200-
NET_RC="$?"
201-
fi
202-
203-
if [ "$NET_RC" -ne 0 ]; then
204-
video_step "" "Bring network online (Wi-Fi credentials if provided)"
205-
ensure_network_online || true
206-
sleep "${NET_STABILIZE_SLEEP}"
217+
# First check: Do we have all files we need?
218+
if audio_check_clips_available "$FORMATS" "$DURATIONS"; then
219+
log_info "All required audio clips present locally, skipping all network operations"
207220
else
208-
sleep "${NET_STABILIZE_SLEEP}"
221+
# Files missing - check if network download is enabled
222+
if [ "${ENABLE_NETWORK_DOWNLOAD}" = "true" ]; then
223+
log_info "Audio clips missing, network download enabled - bringing network online"
224+
# Now check network status and bring up if needed
225+
NET_RC="1"
226+
if command -v check_network_status_rc >/dev/null 2>&1; then
227+
check_network_status_rc
228+
NET_RC="$?"
229+
elif command -v check_network_status >/dev/null 2>&1; then
230+
check_network_status >/dev/null 2>&1
231+
NET_RC="$?"
232+
fi
233+
234+
if [ "$NET_RC" -ne 0 ]; then
235+
video_step "" "Bring network online (Wi-Fi credentials if provided)"
236+
ensure_network_online || true
237+
sleep "${NET_STABILIZE_SLEEP}"
238+
else
239+
sleep "${NET_STABILIZE_SLEEP}"
240+
fi
241+
242+
# Download and extract audio clips tarball
243+
log_info "Downloading audio clips from: $AUDIO_TAR_URL"
244+
if audio_fetch_assets_from_url "$AUDIO_TAR_URL"; then
245+
log_info "Audio clips downloaded and extracted successfully"
246+
else
247+
log_error "Failed to download or extract audio clips from: $AUDIO_TAR_URL"
248+
log_skip "$TESTNAME SKIP - Audio clips download failed"
249+
echo "$TESTNAME SKIP" >"$RES_FILE"
250+
exit 0
251+
fi
252+
else
253+
log_skip "$TESTNAME SKIP - Required audio clips not found locally and network download disabled"
254+
log_info "To download audio clips, run with: --enable-network-download"
255+
log_info "Or manually download from: $AUDIO_TAR_URL"
256+
echo "$TESTNAME SKIP" >"$RES_FILE"
257+
exit 0
258+
fi
209259
fi
210260
fi
211261
else
@@ -323,28 +373,22 @@ for fmt in $FORMATS; do
323373
continue
324374
fi
325375

376+
# Check if clip is available (should have been downloaded at top level if needed)
326377
if [ "${EXTRACT_AUDIO_ASSETS}" = "true" ]; then
327-
if [ -f "$clip" ] && [ -s "$clip" ]; then
378+
if [ -s "$clip" ]; then
328379
CLIP_BYTES="$(wc -c < "$clip" 2>/dev/null || echo 0)"
329-
log_info "[$case_name] Clip already present: $clip (${CLIP_BYTES} bytes) — skipping fetch/extract."
380+
log_info "[$case_name] Using clip: $clip (${CLIP_BYTES} bytes)"
330381
else
331-
log_info "[$case_name] Preparing assets for clip: $clip (not found locally)"
332-
log_info "[$case_name] Attempting fetch/extract from: $AUDIO_TAR_URL"
333-
334-
audio_ensure_clip_ready "$clip" "$AUDIO_TAR_URL"
335-
rc=$?
336-
337-
if [ "$rc" -eq 0 ] && [ -f "$clip" ]; then
338-
CLIP_BYTES="$(wc -c < "$clip" 2>/dev/null || echo 0)"
339-
log_info "[$case_name] Clip ready: $clip (${CLIP_BYTES} bytes)"
340-
fi
341-
342-
if [ "$rc" -eq 2 ] || [ "$rc" -eq 1 ]; then
343-
log_skip "[$case_name] SKIP: Required clip missing and network unavailable or fetch failed."
344-
echo "$case_name SKIP (clip missing)" >> "$LOGDIR/summary.txt"
345-
skip=$((skip + 1))
346-
continue
382+
# Clip missing or empty - this shouldn't happen if top-level download succeeded
383+
log_skip "[$case_name] SKIP: Clip not available: $clip"
384+
if [ "${ENABLE_NETWORK_DOWNLOAD}" = "true" ]; then
385+
log_info "[$case_name] Hint: Clip should have been downloaded at test startup"
386+
else
387+
log_info "[$case_name] Hint: Run with --enable-network-download to download clips"
347388
fi
389+
echo "$case_name SKIP (clip unavailable)" >> "$LOGDIR/summary.txt"
390+
skip=$((skip + 1))
391+
continue
348392
fi
349393
fi
350394

Runner/utils/audio_common.sh

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ check_audio_daemon() {
3030

3131
# ---------- Assets / clips ----------
3232
resolve_clip() {
33-
fmt="$1"; dur="$2"; base="AudioClips"
33+
fmt="$1"; dur="$2"
34+
base="${AUDIO_CLIPS_BASE_DIR:-AudioClips}"
3435
case "$fmt:$dur" in
3536
wav:short|wav:medium|wav:long) printf '%s\n' "$base/yesterday_48KHz.wav" ;;
3637
*) printf '%s\n' "" ;;
@@ -735,3 +736,22 @@ alsa_pick_virtual_pcm() {
735736
done
736737
return 1
737738
}
739+
740+
741+
# Check if all required audio clips are available locally
742+
# Usage: audio_check_clips_available "$FORMATS" "$DURATIONS"
743+
# Returns: 0 if all clips present and non-empty, 1 if any clip missing or empty
744+
audio_check_clips_available() {
745+
formats="$1"
746+
durations="$2"
747+
748+
for fmt in $formats; do
749+
for dur in $durations; do
750+
clip="$(resolve_clip "$fmt" "$dur")"
751+
if [ -n "$clip" ] && [ ! -s "$clip" ]; then
752+
return 1 # At least one clip missing or empty
753+
fi
754+
done
755+
done
756+
return 0 # All clips present and non-empty
757+
}

0 commit comments

Comments
 (0)