Skip to content

Commit 2561992

Browse files
committed
Add automated tests for Chrome Next Generation
Signed-off-by: Emilia Kurdybelska <emiliax.kurdybelska@intel.com>
1 parent 6007edd commit 2561992

File tree

10 files changed

+825
-0
lines changed

10 files changed

+825
-0
lines changed

case-lib/lib.sh

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,3 +1477,69 @@ restore_topology() {
14771477
sudo "$insert_script"
14781478
check_topology
14791479
}
1480+
1481+
# Play sound and record it
1482+
# Arguments: 1-arecord options 2-aplay options
1483+
play_and_record()
1484+
{
1485+
dlogi "Play [aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS $2] and capture sound [arecord $1]"
1486+
# shellcheck disable=SC2086
1487+
arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS $1 & PID=$!
1488+
# shellcheck disable=SC2086
1489+
aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS $2
1490+
wait $PID
1491+
sleep 1
1492+
}
1493+
1494+
# Analyze files to look for glitches.
1495+
# Returns exit code 0 if there are no glitches, 1 if there are.
1496+
# Arguments: the list of filenames
1497+
check_soundfile_for_glitches()
1498+
{
1499+
glitched_files=0
1500+
# shellcheck disable=SC2154
1501+
for result_filename in "${all_result_files[@]}"
1502+
do
1503+
if [ -f "$result_filename" ]; then
1504+
dlogi "Analyzing $result_filename file..."
1505+
if python3 "$SCRIPT_HOME"/tools/analyse_wav.py "$result_filename"; then
1506+
dlogi "$result_filename file is correct"
1507+
else
1508+
dlogw "Found issues in $result_filename file"
1509+
glitched_files=$((glitched_files+1))
1510+
fi
1511+
else
1512+
dlogw "$result_filename file not found, check for previous errors"
1513+
glitched_files=$((glitched_files+1))
1514+
fi
1515+
done
1516+
1517+
if [ $glitched_files -eq 0 ]; then
1518+
dlogi "Analysis finished, no issues found"
1519+
return 0
1520+
else
1521+
dlogi "$glitched_files files corrupted"
1522+
return 1
1523+
fi
1524+
}
1525+
1526+
# Analyze files to check if they contain expected number of sound fragments.
1527+
# Used for testing channels mapping.
1528+
# Returns exit code 0 if they do, 1 if the don't or file doesn't exist.
1529+
# Arguments: 1-filename, 2-expected nr of fragments
1530+
analyze_mixed_sound()
1531+
{
1532+
if [ -f "$1" ]; then
1533+
dlogi "Analyzing $1 file..."
1534+
if python3 "$SCRIPT_HOME"/tools/analyze-sound-fragments.py "$1" "$2"; then
1535+
dlogi "$1 file is correct"
1536+
return 0
1537+
else
1538+
dlogw "Found issues in $1 file"
1539+
return 1
1540+
fi
1541+
else
1542+
dlogw "$1 file not found, check for previous errors"
1543+
return 1
1544+
fi
1545+
}

python-deps.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ python3-graphviz
55
python3-construct
66
python3-pytest
77
python3-pandas
8+
python3-soundfile
9+
python3-pydub

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

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
#!/bin/bash
2+
3+
##
4+
## Case Name: check-8bit-play-rec
5+
## Preconditions:
6+
## - sox 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+
71+
generate_chirps()
72+
{
73+
dlogi "Generating chirps"
74+
sox -n --encoding unsigned-integer -b 8 -r 48000 -c 2 "$chirp_u8_filename" synth 5 sine 100+20000 norm -3
75+
sox -n --encoding a-law -b 8 -r 48000 -c 2 "$chirp_alaw_filename" synth 5 sine 100+20000 norm -3
76+
sox -n --encoding mu-law -b 8 -r 48000 -c 2 "$chirp_mulaw_filename" synth 5 sine 100+20000 norm -3
77+
sox -n --encoding signed-integer -b 32 -r 48000 -c 2 "$chirp_s32_filename" synth 5 sine 100+20000 norm -3
78+
}
79+
80+
cleanup()
81+
{
82+
if [ -f "tmp1.raw" ]; then sudo rm tmp1.raw; fi
83+
if [ -f "tmp2.raw" ]; then sudo rm tmp2.raw; fi
84+
}
85+
86+
run_tests()
87+
{
88+
generate_chirps
89+
90+
set +e
91+
play_and_record "-D$capture_dev $rec_opt $u8_play_filename" "-D$playback_dev $play_opt -t wav $chirp_u8_filename"
92+
play_and_record "-D$capture_dev $rec_opt $alaw_play_filename" "-D$playback_dev $play_opt -t raw -f A_LAW $chirp_alaw_filename"
93+
play_and_record "-D$capture_dev $rec_opt $mulaw_play_filename" "-D$playback_dev $play_opt -t raw -f MU_LAW $chirp_mulaw_filename"
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+
set -e
102+
103+
if check_soundfile_for_glitches "${all_result_files[@]}"; then
104+
dlogi "All files correct"
105+
else
106+
die "Detected corrupted files!"
107+
fi
108+
}
109+
110+
main()
111+
{
112+
init_globals
113+
114+
start_test
115+
logger_disabled || func_lib_start_log_collect
116+
117+
setup_kernel_check_point
118+
func_lib_check_sudo
119+
func_pipeline_export "$tplg" "type:any"
120+
121+
run_tests
122+
cleanup
123+
}
124+
125+
{
126+
main "$@"; exit "$?"
127+
}

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

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/bin/bash
2+
3+
##
4+
## Case Name: check-float-play-rec
5+
## Preconditions:
6+
## - sox 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+
62+
generate_chirps()
63+
{
64+
dlogi "Generating chirps"
65+
sox -n --encoding float -r 48000 -c 2 -b 32 "$chirp_float_filename" synth 5 sine 100+20000 norm -3
66+
sox -n --encoding signed-integer -L -r 48000 -c 2 -b 32 "$chirp_s32_filename" synth 5 sine 100+20000 norm -3
67+
}
68+
69+
run_tests()
70+
{
71+
generate_chirps
72+
73+
set +e
74+
play_and_record "-D$capture_dev $rec_opt -f S32_LE $rec_play_filename" "-D$playback_dev $chirp_float_filename"
75+
play_and_record "-D$capture_dev $rec_opt -f FLOAT_LE $rec_filename" "-D$playback_dev $chirp_s32_filename"
76+
set -e
77+
78+
if check_soundfile_for_glitches "${all_result_files[@]}"; then
79+
dlogi "All files correct"
80+
else
81+
die "Detected corrupted files!"
82+
fi
83+
}
84+
85+
main()
86+
{
87+
init_globals
88+
89+
start_test
90+
logger_disabled || func_lib_start_log_collect
91+
92+
setup_kernel_check_point
93+
func_lib_check_sudo
94+
func_pipeline_export "$tplg" "type:any"
95+
96+
run_tests
97+
}
98+
99+
{
100+
main "$@"; exit "$?"
101+
}

0 commit comments

Comments
 (0)