Skip to content

Commit 1998094

Browse files
committed
Updated the Audio test scripts to include support for PulseAudio and PipeWire
Signed-off-by: Teja Swaroop Moida <[email protected]>
1 parent 2e80ef4 commit 1998094

File tree

4 files changed

+129
-39
lines changed

4 files changed

+129
-39
lines changed

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

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,20 @@ This script automates the validation of audio playback capabilities on the Qualc
66

77
## Features
88

9-
- Decoding PCM clip
10-
- Compatible with Yocto-based root filesystem
9+
- Plays a test audio clip using either `paplay` or `pw-play`
10+
- Supports configurable playback volume, timeout, and loop count
11+
- Automatically downloads and extracts audio clip if not present
12+
- Captures kernel logs before and after playback
13+
- Scans dmesg logs for audio-related errors
14+
- Validates presence of required daemons and binaries
1115

1216
## Prerequisites
1317

1418
Ensure the following components are present in the target Yocto build:
1519

1620
- `paplay` binary (for PulseAudio)
17-
- `pw-play` binary (for PipeWire)
18-
- `pgrep`, `grep`, `timeout` utilities
21+
- `pw-play`, `pgrep`, `timeout`, `grep` (for PipeWire)
22+
- `pulseaudio` or `pipewire` daemon must be running depending on backend
1923

2024
## Directory Structure
2125

@@ -53,20 +57,31 @@ cd <Path in device>/Runner
5357
AUDIO_BACKEND=pulseaudio ./run-test.sh AudioPlayback
5458
**Run with PipeWire**
5559
AUDIO_BACKEND=pipewire ./run-test.sh AudioPlayback
60+
61+
Environment Variables:
62+
You can customize playback behavior using the following environment variables:
63+
AUDIO_BACKEND: Selects the audio backend (pulseaudio or pipewire). Default is pulseaudio.
64+
PLAYBACK_TIMEOUT: Timeout duration for playback (e.g., 15s). Default is 15s.
65+
PLAYBACK_LOOPS: Number of times to repeat playback. Default is 1.
66+
PLAYBACK_VOLUME: Playback volume.
67+
For paplay: Range is 0–65536 (default: 65536)
68+
For pw-play: Range is 0.0–1.0 (default: 1.0)
5669
```
5770
Sample Output:
5871
```
59-
[Executing test case: AudioPlayback] 2025-05-28 19:01:59 -
60-
[INFO] 2025-05-28 19:01:59 - ------------------------------------------------------------
61-
[INFO] 2025-05-28 19:01:59 - ------------------- Starting AudioPlayback Testcase ------------
62-
[INFO] 2025-05-28 19:01:59 - Using audio backend: pipewire
63-
[INFO] 2025-05-28 19:01:59 - Checking if dependency binary is available
64-
[INFO] 2025-05-28 19:01:59 - Playback clip present: AudioClips/yesterday_48KHz.wav
65-
[PASS] 2025-05-28 19:02:14 - Playback completed or timed out (ret=124) as expected.
66-
[PASS] 2025-05-28 19:02:14 - AudioPlayback : Test Passed
67-
[INFO] 2025-05-28 19:02:14 - See results/audioplayback/playback_stdout.log, dmesg_before/after.log for debug details
68-
[INFO] 2025-05-28 19:02:14 - ------------------- Completed AudioPlayback Testcase -------------
69-
[PASS] 2025-05-28 19:02:14 - AudioPlayback passed
72+
sh-5.2# AUDIO_BACKEND=pipewire ./run-test.sh AudioPlayback
73+
[Executing test case: AudioPlayback] 2025-08-14 10:17:35 -
74+
[INFO] 2025-08-14 10:17:35 - ------------------------------------------------------------
75+
[INFO] 2025-08-14 10:17:35 - ------------------- Starting AudioPlayback Testcase ------------
76+
[INFO] 2025-08-14 10:17:35 - Using audio backend: pipewire
77+
[INFO] 2025-08-14 10:17:35 - Checking if dependency binary is available
78+
[INFO] 2025-08-14 10:17:35 - Playback clip present: AudioClips/yesterday_48KHz.wav
79+
[INFO] 2025-08-14 10:17:51 - Scanning dmesg for audio: errors & success patterns
80+
[INFO] 2025-08-14 10:17:51 - No audio-related errors found (no OK pattern requested)
81+
[PASS] 2025-08-14 10:17:51 - Playback completed or timed out (ret=124) as expected.
82+
[PASS] 2025-08-14 10:17:51 - AudioPlayback : Test Passed
83+
[PASS] 2025-08-14 10:17:51 - AudioPlayback passed
84+
[INFO] 2025-08-14 10:17:51 - ========== Test Summary ==========
7085
```
7186
3. Results will be available in the `Runner/suites/Multimedia/Audio/AudioPlayback/AudioPlayback.res` directory.
7287

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

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,28 @@ RESULT_FILE="$TESTNAME.res"
3838
# Determine backend and binary
3939
AUDIO_BACKEND="${AUDIO_BACKEND:-pulseaudio}" # Default to pulseaudio if not set
4040

41+
# PLAYBACK_VOLUME: 0-65536 for paplay, 0.0-1.0 for pw-play
42+
# PLAYBACK_TIMEOUT: seconds (default: 15)
43+
# PLAYBACK_LOOPS: number of times to repeat playback
44+
PLAYBACK_TIMEOUT="${PLAYBACK_TIMEOUT:-15s}"
45+
PLAYBACK_LOOPS="${PLAYBACK_LOOPS:-1}"
46+
# Set default volume based on backend
47+
# paplay volume range: 0–65536
48+
# pw-play volume range: 0.0–1.0
49+
if [ "$AUDIO_BACKEND" = "pulseaudio" ]; then
50+
PLAYBACK_VOLUME="${PLAYBACK_VOLUME:-65536}"
51+
elif [ "$AUDIO_BACKEND" = "pipewire" ]; then
52+
PLAYBACK_VOLUME="${PLAYBACK_VOLUME:-1.0}"
53+
fi
54+
4155
case "$AUDIO_BACKEND" in
4256
pulseaudio)
4357
TESTBINARY="paplay"
44-
PLAY_CMD="paplay \"$PLAYBACK_CLIP\" -d \"$AUDIO_DEVICE\""
58+
PLAY_CMD="paplay --volume=$PLAYBACK_VOLUME \"$PLAYBACK_CLIP\" -d \"$AUDIO_DEVICE\""
4559
;;
4660
pipewire)
4761
TESTBINARY="pw-play"
48-
PLAY_CMD="pw-play \"$PLAYBACK_CLIP\""
62+
PLAY_CMD="pw-play --volume=$PLAYBACK_VOLUME \"$PLAYBACK_CLIP\""
4963
;;
5064
*)
5165
log_fail "Invalid AUDIO_BACKEND specified: $AUDIO_BACKEND. Use 'pulseaudio' or 'pipewire'."
@@ -64,6 +78,15 @@ log_info "------------------------------------------------------------"
6478
log_info "------------------- Starting $TESTNAME Testcase ------------"
6579
log_info "Using audio backend: $AUDIO_BACKEND"
6680

81+
# Daemon check
82+
if [ "$AUDIO_BACKEND" = "pulseaudio" ]; then
83+
if ! pgrep pulseaudio > /dev/null && ! pgrep pipewire-pulse > /dev/null; then
84+
log_skip_exit "$TESTNAME" "Neither PulseAudio nor pipewire-pulse daemon is running"
85+
fi
86+
elif [ "$AUDIO_BACKEND" = "pipewire" ]; then
87+
pgrep pipewire > /dev/null || log_skip_exit "$TESTNAME" "PipeWire daemon not running"
88+
fi
89+
6790
log_info "Checking if dependency binary is available"
6891
check_dependencies "$TESTBINARY" pgrep grep timeout
6992
# Download/extract audio if not present
@@ -83,13 +106,19 @@ if [ ! -f "$PLAYBACK_CLIP" ]; then
83106
fi
84107

85108
log_info "Playback clip present: $PLAYBACK_CLIP"
109+
86110
# --- Capture logs BEFORE playback (for debugging) ---
87-
dmesg > "$LOGDIR/dmesg_before.log"
111+
get_kernel_log > "$LOGDIR/dmesg_before.log"
112+
88113
# --- Start the Playback, capture output ---
89-
eval "timeout 15s $PLAY_CMD" > "$LOGDIR/playback_stdout.log" 2>&1
114+
for i in $(seq 1 "$PLAYBACK_LOOPS"); do
115+
timeout "$PLAYBACK_TIMEOUT" sh -c "$PLAY_CMD" >> "$LOGDIR/playback_stdout.log" 2>&1
116+
done
90117
ret=$?
118+
91119
# --- Capture logs AFTER playback (for debugging) ---
92-
dmesg > "$LOGDIR/dmesg_after.log"
120+
get_kernel_log > "$LOGDIR/dmesg_after.log"
121+
scan_dmesg_errors "audio" "$LOGDIR"
93122

94123
if [ "$ret" -eq 0 ] || [ "$ret" -eq 124 ]; then
95124
log_pass "Playback completed or timed out (ret=$ret) as expected."

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

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,20 @@ This script automates the validation of audio recording capabilities on the Qual
99
- Records PCM audio to '/tmp/rec1.wav' using either `parec` or `pw-record`
1010
- Automatically detects and sets PipeWire source ID if PipeWire is used
1111
- Uses `AUDIO_BACKEND` environment variable to select backend (default: pulseaudio)
12+
- Captures kernel logs before and after recording
13+
- Scans dmesg logs for audio-related errors
14+
- Supports configurable timeout and loop count for recording
15+
- Validates presence of required daemons and binaries
1216
- Compatible with Yocto-based root filesystem
1317

1418
## Prerequisites
1519

1620
Ensure the following components are present in the target Yocto build:
1721

1822
- `parec` binary (for PulseAudio)
19-
- `pw-record`, `wpctl`, `grep`, `sed` (for PipeWire)
23+
- `pw-record`, `wpctl`, `grep`, `sed`, `timeout`, `pgrep` (for PipeWire)
24+
- `pulseaudio` or `pipewire` daemon must be running depending on backend
25+
2026

2127
## Directory Structure
2228

@@ -54,20 +60,28 @@ cd <Path in device>Runner
5460
AUDIO_BACKEND=pulseaudio ./run-test.sh AudioRecord
5561
**Run with PipeWire**
5662
AUDIO_BACKEND=pipewire ./run-test.sh AudioRecord
63+
64+
Environment Variables:
65+
You can customize recording behavior using the following environment variables:
66+
AUDIO_BACKEND: Selects the audio backend (pulseaudio or pipewire). Default is pulseaudio.
67+
RECORD_TIMEOUT: Timeout duration for recording (e.g., 12s). Default is 12s.
68+
RECORD_LOOPS: Number of times to repeat recording. Default is 1.
5769
```
5870

5971
Sample Output:
6072
```
61-
[Executing test case: AudioRecord] 2025-05-28 19:03:33 -
62-
[INFO] 2025-05-28 19:03:33 - ------------------------------------------------------------
63-
[INFO] 2025-05-28 19:03:33 - ------------------- Starting AudioRecord Testcase ------------
64-
[INFO] 2025-05-28 19:03:33 - Using audio backend: pulseaudio
65-
[INFO] 2025-05-28 19:03:33 - Checking if dependency binary is available
66-
[PASS] 2025-05-28 19:03:45 - Recording completed or timed out (ret=124) as expected and output file exists.
67-
[PASS] 2025-05-28 19:03:45 - AudioRecord : Test Passed
68-
[INFO] 2025-05-28 19:03:45 - See results/audiorecord/parec_stdout.log or pw-record_stdout.log, dmesg_before/after.log, syslog_before/after.log for debug details
69-
[INFO] 2025-05-28 19:03:45 - ------------------- Completed AudioRecord Testcase -------------
70-
[PASS] 2025-05-28 19:03:45 - AudioRecord passed
73+
sh-5.2# AUDIO_BACKEND=pipewire ./run-test.sh AudioRecord
74+
[Executing test case: AudioRecord] 2025-08-14 10:35:43 -
75+
[INFO] 2025-08-14 10:35:43 - ------------------------------------------------------------
76+
[INFO] 2025-08-14 10:35:43 - ------------------- Starting AudioRecord Testcase ------------
77+
[INFO] 2025-08-14 10:35:43 - Using audio backend: pipewire
78+
[INFO] 2025-08-14 10:35:43 - Checking if dependency binary is available
79+
[INFO] 2025-08-14 10:35:43 - Detected PipeWire source ID: 50
80+
[INFO] 2025-08-14 10:35:55 - Scanning dmesg for audio: errors & success patterns
81+
[INFO] 2025-08-14 10:35:55 - No audio-related errors found (no OK pattern requested)
82+
[PASS] 2025-08-14 10:35:55 - Recording completed or timed out (ret=124) as expected and output file exists.
83+
[PASS] 2025-08-14 10:35:55 - AudioRecord : Test Passed
84+
[PASS] 2025-08-14 10:35:55 - AudioRecord passed
7185
```
7286

7387
3. Results will be available in the `Runner/suites/Multimedia/Audio/AudioRecord/AudioRecord.res` directory.

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

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,24 @@ AUDIO_DEVICE="regular0"
3434
LOGDIR="results/audiorecord"
3535
RESULT_FILE="$TESTNAME.res"
3636

37-
AUDIO_BACKEND="${AUDIO_BACKEND:-pulseaudio}" # Default to pulseaudio
37+
# Determine backend and binary
38+
AUDIO_BACKEND="${AUDIO_BACKEND:-pulseaudio}" # Default to pulseaudio if not set
39+
40+
# RECORD_TIMEOUT: seconds (default: 12s)
41+
# RECORD_LOOPS: number of times to repeat recording
42+
RECORD_TIMEOUT="${RECORD_TIMEOUT:-12s}"
43+
RECORD_LOOPS="${RECORD_LOOPS:-1}"
44+
45+
# Set test binary and command
46+
if [ "$AUDIO_BACKEND" = "pulseaudio" ]; then
47+
TESTBINARY="parec"
48+
elif [ "$AUDIO_BACKEND" = "pipewire" ]; then
49+
TESTBINARY="pw-record"
50+
else
51+
log_fail "Invalid AUDIO_BACKEND specified: $AUDIO_BACKEND. Use 'pulseaudio' or 'pipewire'."
52+
echo "$TESTNAME FAIL" > "$RESULT_FILE"
53+
exit 1
54+
fi
3855

3956
test_path=$(find_test_case_by_name "$TESTNAME")
4057
cd "$test_path" || exit 1
@@ -45,12 +62,21 @@ log_info "------------------------------------------------------------"
4562
log_info "------------------- Starting $TESTNAME Testcase ------------"
4663
log_info "Using audio backend: $AUDIO_BACKEND"
4764

65+
# Daemon check
66+
if [ "$AUDIO_BACKEND" = "pulseaudio" ]; then
67+
if ! pgrep pulseaudio > /dev/null && ! pgrep pipewire-pulse > /dev/null; then
68+
log_skip_exit "$TESTNAME" "Neither PulseAudio nor pipewire-pulse daemon is running"
69+
fi
70+
elif [ "$AUDIO_BACKEND" = "pipewire" ]; then
71+
pgrep pipewire > /dev/null || log_skip_exit "$TESTNAME" "PipeWire daemon not running"
72+
fi
73+
74+
log_info "Checking if dependency binary is available"
4875
if [ "$AUDIO_BACKEND" = "pulseaudio" ]; then
49-
TESTBINARY="parec"
50-
RECORD_CMD="$TESTBINARY --rate=48000 --format=s16le --channels=1 --file-format=wav \"$RECORD_FILE\" -d \"$AUDIO_DEVICE\""
5176
check_dependencies "$TESTBINARY" pgrep timeout
77+
RECORD_CMD="$TESTBINARY --rate=48000 --format=s16le --channels=1 --file-format=wav \"$RECORD_FILE\" -d \"$AUDIO_DEVICE\""
5278
else
53-
TESTBINARY="pw-record"
79+
5480
check_dependencies "$TESTBINARY" wpctl grep sed timeout
5581

5682
# Extract source ID using sed
@@ -66,13 +92,19 @@ else
6692
RECORD_CMD="$TESTBINARY \"$RECORD_FILE\" -v"
6793
fi
6894

69-
dmesg > "$LOGDIR/dmesg_before.log"
95+
# --- Capture logs BEFORE recording (for debugging) ---
96+
get_kernel_log > "$LOGDIR/dmesg_before.log"
7097
rm -f "$RECORD_FILE"
7198

72-
eval "timeout 12s $RECORD_CMD" > "$LOGDIR/${TESTBINARY}_stdout.log" 2>&1
99+
# --- Start the Recording, capture output ---
100+
for i in $(seq 1 "$RECORD_LOOPS"); do
101+
timeout "$RECORD_TIMEOUT" sh -c "$RECORD_CMD" >> "$LOGDIR/${TESTBINARY}_stdout.log" 2>&1
102+
done
73103
ret=$?
74104

75-
dmesg > "$LOGDIR/dmesg_after.log"
105+
# --- Capture logs AFTER recording (for debugging) ---
106+
get_kernel_log > "$LOGDIR/dmesg_after.log"
107+
scan_dmesg_errors "audio" "$LOGDIR"
76108

77109
if ([ "$ret" -eq 0 ] || [ "$ret" -eq 124 ]) && [ -s "$RECORD_FILE" ]; then
78110
log_pass "Recording completed or timed out (ret=$ret) as expected and output file exists."
@@ -86,6 +118,6 @@ else
86118
exit 1
87119
fi
88120

89-
log_info "See $LOGDIR/${TESTBINARY}_stdout.log, dmesg_before/after.log, syslog_before/after.log for debug details"
121+
log_info "See $LOGDIR/${TESTBINARY}_stdout.log, dmesg_before/after.log for debug details"
90122
log_info "------------------- Completed $TESTNAME Testcase -------------"
91123
exit 0

0 commit comments

Comments
 (0)