Skip to content

Commit c31d838

Browse files
committed
Add automated ALOS tests
Signed-off-by: Emilia Kurdybelska <emiliax.kurdybelska@intel.com>
1 parent 98c37cb commit c31d838

File tree

6 files changed

+607
-0
lines changed

6 files changed

+607
-0
lines changed

case-lib/lib.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,3 +1352,27 @@ reboot_wrapper()
13521352
echo "Reboot command" && sleep 5
13531353
sudo reboot now
13541354
}
1355+
1356+
# Play sound and record it
1357+
# Parameters: 1-arecord options 2-aplay options
1358+
play_and_record()
1359+
{
1360+
dlogi "Play [aplay $2] and capture sound [arecord $1]"
1361+
arecord $1 & PID=$!
1362+
sleep 1
1363+
aplay $2
1364+
wait $PID
1365+
sleep 1
1366+
}
1367+
1368+
# Play sound with speaker-test and record it
1369+
# Parameters: 1-arecord options 2-speaker-test options
1370+
play_on_speakers_and_record()
1371+
{
1372+
dlogi "Play [speaker-test $2] and capture sound [arecord $1]"
1373+
arecord $1 & PID=$!
1374+
sleep 1
1375+
speaker-test $2
1376+
wait $PID
1377+
sleep 1
1378+
}

test-case/check-8bit-play-rec.sh

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
#!/bin/bash
2+
3+
##
4+
## Case Name: check-8bit-play-rec
5+
## Preconditions:
6+
## ffmpeg installed
7+
## Description:
8+
## This test verifies 8-bit audio playback and recording functionality using ALSA devices.
9+
## It generates test chirp signals in multiple 8-bit formats (unsigned 8-bit, A-LAW, MU-LAW), plays them back, records the output,
10+
## and checks the integrity of the recorded files. The test ensures that the pipeline correctly handles 8-bit audio data for both playback and capture.
11+
## Case steps:
12+
## 1. Generate chirp signals in unsigned 8-bit, A-LAW, MU-LAW, and S32_LE formats using sox.
13+
## 2. Play each chirp file and record the output using arecord and aplay with the specified ALSA devices.
14+
## 3. Convert raw recordings to WAV format for analysis.
15+
## 4. Analyze the recorded files for integrity.
16+
## Expected results:
17+
## - All chirp files are played and recorded without errors.
18+
## - The recorded files are successfully generated and converted.
19+
## - No failures are reported during analysis.
20+
##
21+
22+
set -e
23+
24+
# It is pointless to perf component in HDMI pipeline, so filter out HDMI pipelines
25+
# shellcheck disable=SC2034
26+
NO_HDMI_MODE=true
27+
28+
# shellcheck source=case-lib/lib.sh
29+
source "$(dirname "${BASH_SOURCE[0]}")"/../case-lib/lib.sh
30+
31+
OPT_NAME['t']='tplg' OPT_DESC['t']='tplg file, default value is env TPLG: $''TPLG'
32+
OPT_HAS_ARG['t']=1 OPT_VAL['t']="$TPLG"
33+
34+
OPT_NAME['p']='playback_device' OPT_DESC['p']='ALSA pcm playback device. Example: hw:0,1'
35+
OPT_HAS_ARG['p']=1 OPT_VAL['p']=''
36+
37+
OPT_NAME['c']='capture_device' OPT_DESC['c']='ALSA pcm capture device. Example: hw:0,1'
38+
OPT_HAS_ARG['c']=1 OPT_VAL['c']=''
39+
40+
OPT_NAME['s']='sof-logger' OPT_DESC['s']="Open sof-logger trace the data will store at $LOG_ROOT"
41+
OPT_HAS_ARG['s']=0 OPT_VAL['s']=1
42+
43+
func_opt_parse_option "$@"
44+
45+
init_globals()
46+
{
47+
tplg=${OPT_VAL['t']}
48+
playback_dev=${OPT_VAL['p']}
49+
capture_dev=${OPT_VAL['c']}
50+
51+
rec8_opt="-c 2 -r 48000 -d 7"
52+
rec_opt="-f S32_LE -c 2 -r 48000 -d 7"
53+
play_opt="-c 2 -r 48000"
54+
55+
chirp_u8_filename="$LOG_ROOT/chirp_u8.wav"
56+
chirp_alaw_filename="$LOG_ROOT/chirp_alaw.raw"
57+
chirp_mulaw_filename="$LOG_ROOT/chirp_mulaw.raw"
58+
chirp_s32_filename="$LOG_ROOT/chirp_s32.wav"
59+
60+
u8_play_filename="$LOG_ROOT/rec_play_u8.wav"
61+
alaw_play_filename="$LOG_ROOT/rec_play_alaw.wav"
62+
mulaw_play_filename="$LOG_ROOT/rec_play_mulaw.wav"
63+
64+
u8_rec_filename="$LOG_ROOT/rec_u8.wav"
65+
alaw_rec_filename="$LOG_ROOT/rec_alaw.wav"
66+
mulaw_rec_filename="$LOG_ROOT/rec_mulaw.wav"
67+
68+
all_result_files=($u8_play_filename $alaw_play_filename $mulaw_play_filename $u8_rec_filename $alaw_rec_filename $mulaw_rec_filename)
69+
70+
failures=0
71+
}
72+
73+
generate_chirps()
74+
{
75+
dlogi "Generating chirps"
76+
sox -n --encoding unsigned-integer -b 8 -r 48000 -c 2 $chirp_u8_filename synth 5 sine 100+20000 norm -3
77+
sox -n --encoding a-law -b 8 -r 48000 -c 2 $chirp_alaw_filename synth 5 sine 100+20000 norm -3
78+
sox -n --encoding mu-law -b 8 -r 48000 -c 2 $chirp_mulaw_filename synth 5 sine 100+20000 norm -3
79+
sox -n --encoding signed-integer -b 32 -r 48000 -c 2 $chirp_s32_filename synth 5 sine 100+20000 norm -3
80+
}
81+
82+
cleanup()
83+
{
84+
rm tmp1.raw tmp2.raw
85+
}
86+
87+
run_tests()
88+
{
89+
generate_chirps
90+
91+
play_and_record "-D$capture_dev $rec_opt -t wav" "-D$playback_dev $play_opt $chirp_u8_filename"
92+
play_and_record "-D$capture_dev $rec_opt -t raw -f A_LAW" "-D$playback_dev $play_opt $chirp_alaw"
93+
play_and_record "-D$capture_dev $rec_opt -t raw -f MU_LAW" "-D$playback_dev $play_opt $chirp_mulaw"
94+
95+
play_and_record "-D$capture_dev $rec8_opt -f U8 $u8_rec_filename" "-D$playback_dev $chirp_s32_filename"
96+
play_and_record "-D$capture_dev $rec8_opt -f A_LAW -t raw tmp1.raw" "-D$playback_dev $chirp_s32_filename"
97+
play_and_record "-D$capture_dev $rec8_opt -f MU_LAW -t raw tmp2.raw" "-D$playback_dev $chirp_s32_filename"
98+
99+
sox --encoding a-law -r 48000 -c 2 tmp1.raw $alaw_rec_filename
100+
sox --encoding u-law -r 48000 -c 2 tmp2.raw $mulaw_rec_filename
101+
102+
103+
for filename in "${all_result_files[@]}"
104+
do
105+
dlogi "Analyzing $filename file..."
106+
#TODO: Actually analyze the result
107+
if [ $? -eq 0 ]; then
108+
dlogi "$filename file is correct"
109+
else
110+
dlogw "Found issues in $filename file"
111+
failures=$((failures+1))
112+
fi
113+
done
114+
}
115+
116+
main()
117+
{
118+
init_globals
119+
120+
start_test
121+
logger_disabled || func_lib_start_log_collect
122+
123+
setup_kernel_check_point
124+
func_lib_check_sudo
125+
func_pipeline_export "$tplg" "type:any"
126+
127+
run_tests
128+
cleanup
129+
130+
if [ $failures -eq 0 ]; then
131+
dlogi "All tests passed"
132+
else
133+
die "$failures tests failed"
134+
fi
135+
}
136+
137+
{
138+
main "$@"; exit "$?"
139+
}

test-case/check-float-play-rec.sh

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#!/bin/bash
2+
3+
##
4+
## Case Name: check-float-play-rec
5+
## Preconditions:
6+
## ffmpeg installed
7+
## Description:
8+
## Verify float audio playback and capture using ALSA devices. The test generates a float-encoded chirp and a 32-bit signed integer chirp,
9+
## plays one while recording the other format and vice versa. This validates that the audio pipeline correctly handles FLOAT and S32_LE sample formats
10+
## and that sample conversion between formats works as expected.
11+
## Case steps:
12+
## 1. Generate a 48 kHz stereo chirp in 32-bit float and 32-bit signed integer formats using sox.
13+
## 2. Use arecord/aplay to play the float chirp and record with S32_LE format, then play the S32_LE chirp and record with FLOAT_LE format.
14+
## 3. Save both recorded files into the log directory for later analysis.
15+
## 4. Analyze the recorded files for integrity and correct format.
16+
## Expected results:
17+
## - Both playback and recording complete without errors.
18+
## - The recorded files are created in the log directory and match expected sample formats.
19+
## - No failures are reported during analysis.
20+
##
21+
22+
set -e
23+
24+
# It is pointless to perf component in HDMI pipeline, so filter out HDMI pipelines
25+
# shellcheck disable=SC2034
26+
NO_HDMI_MODE=true
27+
28+
# shellcheck source=case-lib/lib.sh
29+
source "$(dirname "${BASH_SOURCE[0]}")"/../case-lib/lib.sh
30+
31+
OPT_NAME['t']='tplg' OPT_DESC['t']='tplg file, default value is env TPLG: $''TPLG'
32+
OPT_HAS_ARG['t']=1 OPT_VAL['t']="$TPLG"
33+
34+
OPT_NAME['p']='playback_device' OPT_DESC['p']='ALSA pcm playback device. Example: hw:0,1'
35+
OPT_HAS_ARG['p']=1 OPT_VAL['p']=''
36+
37+
OPT_NAME['c']='capture_device' OPT_DESC['c']='ALSA pcm capture device. Example: hw:0,1'
38+
OPT_HAS_ARG['c']=1 OPT_VAL['c']=''
39+
40+
OPT_NAME['s']='sof-logger' OPT_DESC['s']="Open sof-logger trace the data will store at $LOG_ROOT"
41+
OPT_HAS_ARG['s']=0 OPT_VAL['s']=1
42+
43+
func_opt_parse_option "$@"
44+
45+
init_globals()
46+
{
47+
tplg=${OPT_VAL['t']}
48+
playback_dev=${OPT_VAL['p']}
49+
capture_dev=${OPT_VAL['c']}
50+
51+
rec_opt="-c 2 -r 48000 -d 7"
52+
53+
chirp_float_filename="$LOG_ROOT/chirp_float_48k.wav"
54+
chirp_s32_filename="$LOG_ROOT/chirp_s32_48k.wav"
55+
56+
rec_play_filename="$LOG_ROOT/rec_play_float.wav"
57+
rec_filename="$LOG_ROOT/rec_float.wav"
58+
59+
all_result_files=($rec_play_filename $rec_filename)
60+
61+
failures=0
62+
}
63+
64+
generate_chirps()
65+
{
66+
dlogi "Generating chirps"
67+
sox -n --encoding float -r 48000 -c 2 -b 32 $chirp_float_filename synth 5 sine 100+20000 norm -3
68+
sox -n --encoding signed-integer -L -r 48000 -c 2 -b 32 $chirp_s32_filename synth 5 sine 100+20000 norm -3
69+
}
70+
71+
run_tests()
72+
{
73+
generate_chirps
74+
75+
play_and_record "-D$capture_dev $rec_opt -f S32_LE $rec_play_filename" "-D$playback_dev $chirp_float_filename"
76+
play_and_record "-D$capture_dev $rec_opt -f FLOAT_LE $rec_filename" "-D$playback_dev $chirp_s32_filename"
77+
78+
for filename in "${all_result_files[@]}"
79+
do
80+
dlogi "Analyzing $filename file..."
81+
#TODO: Actually analyze the result
82+
if [ $? -eq 0 ]; then
83+
dlogi "$filename file is correct"
84+
else
85+
dlogw "Found issues in $filename file"
86+
failures=$((failures+1))
87+
fi
88+
done
89+
}
90+
91+
main()
92+
{
93+
init_globals
94+
95+
start_test
96+
logger_disabled || func_lib_start_log_collect
97+
98+
setup_kernel_check_point
99+
func_lib_check_sudo
100+
func_pipeline_export "$tplg" "type:any"
101+
102+
run_tests
103+
104+
if [ $failures -eq 0 ]; then
105+
dlogi "All tests passed"
106+
else
107+
die "$failures tests failed"
108+
fi
109+
}
110+
111+
{
112+
main "$@"; exit "$?"
113+
}

0 commit comments

Comments
 (0)