Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 49 additions & 20 deletions case-lib/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1534,47 +1534,76 @@ restore_topology() {
check_topology
}

# Check aplay output for warnings
# Arguments: 1-aplay output
check_for_aplay_warnings()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
check_for_aplay_warnings()
check_for_warnings()

{
dlogi "$1"
if echo "$1" | grep -q "Warning:"; then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dlogw "Caught aplay warning! Look for previous logs."
return 1
fi
return 0
}

# Play sound and record it
# Arguments: 1-arecord options 2-aplay options
play_and_record()
{
errors=0
dlogi "Play [aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS $2] and capture sound [arecord $1]"
# shellcheck disable=SC2086
arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS $1 & PID=$!
arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS $1 & PID=$!
# shellcheck disable=SC2086
aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS $2
wait $PID
aplay_output=$(aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS $2 2>&1) || errors=$((errors+1))
wait $PID || errors=$((errors+1))
sleep 1
check_for_aplay_warnings "$aplay_output" || errors=$((errors+1))

if [ "$errors" = 0 ]; then
return 0
fi
return 1
}

# Analyze files to look for glitches.
# Analyze file to look for glitches.
# Returns exit code 0 if there are no glitches, 1 if there are.
# Arguments: the list of filenames
# Arguments: filename
check_soundfile_for_glitches()
{
glitched_files=0
if [ -f "$result_filename" ]; then
dlogi "Analyzing $result_filename file..."
if python3 "$SCRIPT_HOME"/tools/analyze-wav.py "$result_filename"; then
dlogi "$result_filename file is correct"
else
dlogw "GLITCHED FILE: $result_filename"
return 1
fi
else
dlogw "MISSING FILE: $result_filename"
return 1
fi
}

# Check list of soundfiles for glitches
# Returns exit code 0 if there are no glitches, 1 if there are.
# Arguments: list of filenames
check_soundfiles_for_glitches()
{
failures=0
# shellcheck disable=SC2154
for result_filename in "${all_result_files[@]}"
do
if [ -f "$result_filename" ]; then
dlogi "Analyzing $result_filename file..."
if python3 "$SCRIPT_HOME"/tools/analyze-wav.py "$result_filename"; then
dlogi "$result_filename file is correct"
else
dlogw "Found issues in $result_filename file"
glitched_files=$((glitched_files+1))
fi
else
dlogw "$result_filename file not found, check for previous errors"
glitched_files=$((glitched_files+1))
if ! check_soundfile_for_glitches "$result_filename"; then
failures=$((failures+1))
fi
done

if [ $glitched_files -eq 0 ]; then
dlogi "Analysis finished, no issues found"
if [ "$failures" = 0 ]; then
dlogi "All files correct"
return 0
else
dlogi "$glitched_files files corrupted"
dlogw "Found $failures corrupted files"
return 1
fi
}
Expand Down
12 changes: 5 additions & 7 deletions test-case/check-8bit-play-rec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ source "$(dirname "${BASH_SOURCE[0]}")"/../case-lib/lib.sh
OPT_NAME['t']='tplg' OPT_DESC['t']='tplg file, default value is env TPLG: $''TPLG'
OPT_HAS_ARG['t']=1 OPT_VAL['t']="$TPLG"

OPT_NAME['p']='playback_device' OPT_DESC['p']='ALSA pcm playback device. Example: hw:0,1'
OPT_HAS_ARG['p']=1 OPT_VAL['p']=''
OPT_NAME['p']='playback_device' OPT_DESC['p']='ALSA pcm playback device. Default: hw:0,0'
OPT_HAS_ARG['p']=1 OPT_VAL['p']='hw:0,0'

OPT_NAME['c']='capture_device' OPT_DESC['c']='ALSA pcm capture device. Example: hw:0,1'
OPT_HAS_ARG['c']=1 OPT_VAL['c']=''
OPT_NAME['c']='capture_device' OPT_DESC['c']='ALSA pcm capture device. Default: hw:0,0'
OPT_HAS_ARG['c']=1 OPT_VAL['c']='hw:0,0'

OPT_NAME['s']='sof-logger' OPT_DESC['s']="Open sof-logger trace the data will store at $LOG_ROOT"
OPT_HAS_ARG['s']=0 OPT_VAL['s']=1
Expand Down Expand Up @@ -87,7 +87,6 @@ run_tests()
{
generate_chirps

set +e
play_and_record "-D$capture_dev $rec_opt $u8_play_filename" "-D$playback_dev $play_opt -t wav $chirp_u8_filename"
play_and_record "-D$capture_dev $rec_opt $alaw_play_filename" "-D$playback_dev $play_opt -t raw -f A_LAW $chirp_alaw_filename"
play_and_record "-D$capture_dev $rec_opt $mulaw_play_filename" "-D$playback_dev $play_opt -t raw -f MU_LAW $chirp_mulaw_filename"
Expand All @@ -98,9 +97,8 @@ run_tests()

sox --encoding a-law -r 48000 -c 2 tmp1.raw "$alaw_rec_filename"
sox --encoding u-law -r 48000 -c 2 tmp2.raw "$mulaw_rec_filename"
set -e

if check_soundfile_for_glitches "${all_result_files[@]}"; then
if check_soundfiles_for_glitches "${all_result_files[@]}"; then
dlogi "All files correct"
else
die "Detected corrupted files!"
Expand Down
12 changes: 5 additions & 7 deletions test-case/check-float-play-rec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ source "$(dirname "${BASH_SOURCE[0]}")"/../case-lib/lib.sh
OPT_NAME['t']='tplg' OPT_DESC['t']='tplg file, default value is env TPLG: $''TPLG'
OPT_HAS_ARG['t']=1 OPT_VAL['t']="$TPLG"

OPT_NAME['p']='playback_device' OPT_DESC['p']='ALSA pcm playback device. Example: hw:0,1'
OPT_HAS_ARG['p']=1 OPT_VAL['p']=''
OPT_NAME['p']='playback_device' OPT_DESC['p']='ALSA pcm playback device. Default: hw:0,0'
OPT_HAS_ARG['p']=1 OPT_VAL['p']='hw:0,0'

OPT_NAME['c']='capture_device' OPT_DESC['c']='ALSA pcm capture device. Example: hw:0,1'
OPT_HAS_ARG['c']=1 OPT_VAL['c']=''
OPT_NAME['c']='capture_device' OPT_DESC['c']='ALSA pcm capture device. Default: hw:0,0'
OPT_HAS_ARG['c']=1 OPT_VAL['c']='hw:0,0'

OPT_NAME['s']='sof-logger' OPT_DESC['s']="Open sof-logger trace the data will store at $LOG_ROOT"
OPT_HAS_ARG['s']=0 OPT_VAL['s']=1
Expand Down Expand Up @@ -70,12 +70,10 @@ run_tests()
{
generate_chirps

set +e
play_and_record "-D$capture_dev $rec_opt -f S32_LE $rec_play_filename" "-D$playback_dev $chirp_float_filename"
play_and_record "-D$capture_dev $rec_opt -f FLOAT_LE $rec_filename" "-D$playback_dev $chirp_s32_filename"
set -e

if check_soundfile_for_glitches "${all_result_files[@]}"; then
if check_soundfiles_for_glitches "${all_result_files[@]}"; then
dlogi "All files correct"
else
die "Detected corrupted files!"
Expand Down
17 changes: 15 additions & 2 deletions test-case/check-selector-play.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,28 @@ prepare_test_soundfiles()

run_tests()
{
failures=0
set +e
for ch_nr in "${channels_to_test[@]}"
do
test_pass=true
test_filename="$HOME/Music/${ch_nr}_channels_test.wav"
result_filename="$LOG_ROOT/rec_${ch_nr}ch.wav"
dlogi "--------------- PLAY $ch_nr CHANNELS, RECORD ON 2 channels ---------------"

play_and_record "-D$capture_dev $rec_opt -d 25 $result_filename" "-Dplug$playback_dev $test_filename"

if ! analyze_mixed_sound "$result_filename" "$ch_nr"; then
if [ $? -eq 1 ]; then
test_pass=false
dlogi "TEST $ch_nr channels FAIL: aplay/arecord failed, look for previous errors"
else
if ! analyze_mixed_sound "$result_filename" "$ch_nr"; then
test_pass=false
dlogi "TEST $ch_nr channels FAIL: Recording has incorrect nr of channels"
fi
fi
if [ "$test_pass" = true ]; then
dlogi "TEST $ch_nr channels PASS: No issues found."
else
failures=$((failures+1))
fi
done
Expand Down
49 changes: 35 additions & 14 deletions test-case/check-src-play.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ source "$(dirname "${BASH_SOURCE[0]}")"/../case-lib/lib.sh
OPT_NAME['t']='tplg' OPT_DESC['t']='tplg file, default value is env TPLG: $''TPLG'
OPT_HAS_ARG['t']=1 OPT_VAL['t']="$TPLG"

OPT_NAME['p']='playback_device' OPT_DESC['p']='ALSA pcm playback device. Example: hw:0,1'
OPT_HAS_ARG['p']=1 OPT_VAL['p']=''
OPT_NAME['p']='playback_device' OPT_DESC['p']='ALSA pcm playback device. Default: hw:0,2'
OPT_HAS_ARG['p']=1 OPT_VAL['p']='hw:0,2'

OPT_NAME['c']='capture_device' OPT_DESC['c']='ALSA pcm capture device. Example: hw:0,1'
OPT_HAS_ARG['c']=1 OPT_VAL['c']=''
OPT_NAME['c']='capture_device' OPT_DESC['c']='ALSA pcm capture device. Default: hw:0,2'
OPT_HAS_ARG['c']=1 OPT_VAL['c']='hw:0,2'

OPT_NAME['s']='sof-logger' OPT_DESC['s']="Open sof-logger trace the data will store at $LOG_ROOT"
OPT_HAS_ARG['s']=0 OPT_VAL['s']=1
Expand All @@ -55,29 +55,50 @@ init_globals()
all_result_files=()
}

prepare_test_soundfile()
{
dlogi "Generating test audio: sample rate: $sample_rate Hz, chirp rate: $chirp_rate Hz..."
mkdir -p "$HOME/Music"
test_sound_filename="$HOME/Music/${sample_rate}_Hz.wav"
ffmpeg -loglevel error -y -f lavfi -i "aevalsrc='sin($chirp_rate*t*2*PI*t)':s=$sample_rate:d=5" -ac 2 "$test_sound_filename"
}

run_tests()
{
failures=0
set +e
for i in "${!sample_rates[@]}"
do
test_pass=true
sample_rate=${sample_rates[$i]}
chirp_rate=${chirp_rates[$i]}
dlogi "--------------- TEST $((i+1)): PLAY SAMPLE RATE $sample_rate Hz, RECORD IN 48000 Hz ---------------"

test_sound_filename=$LOG_ROOT/play.wav
result_filename=$LOG_ROOT/rec_play_$sample_rate.wav
all_result_files+=("$result_filename")

dlogi "Play $sample_rate Hz chirp 0 - $chirp_rate Hz, capture as 48 kHz"
ffmpeg -y -f lavfi -i "aevalsrc='sin($chirp_rate*t*2*PI*t)':s=$sample_rate:d=5" -ac 2 "$test_sound_filename" #TODO: maybe separate dir for artifacts ??

prepare_test_soundfile
play_and_record "-D$capture_dev $rec_opt $result_filename" "-D$playback_dev $test_sound_filename"
if [ $? -eq 1 ]; then
test_pass=false
dlogi "TEST $((i+1)) FAIL: aplay/arecord failed, look for previous errors"
else
check_soundfile_for_glitches "$result_filename"
if [ $? -eq 1 ]; then
test_pass=false
dlogi "TEST $((i+1)) FAIL: Found glitch in the recording"
fi
fi
if [ "$test_pass" = true ]; then
dlogi "TEST $((i+1)) PASS: No issues found."
else
failures=$((failures+1))
fi
done
set -e
if check_soundfile_for_glitches "${all_result_files[@]}"; then
dlogi "All files correct"

if [ "$failures" = 0 ]; then
dlogi "PASS: All testcases passed"
else
die "Detected corrupted files!"
die "FAIL: $failures testcases failed"
fi
}

Expand Down
37 changes: 27 additions & 10 deletions test-case/check-src-rec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ source "$(dirname "${BASH_SOURCE[0]}")"/../case-lib/lib.sh
OPT_NAME['t']='tplg' OPT_DESC['t']='tplg file, default value is env TPLG: $''TPLG'
OPT_HAS_ARG['t']=1 OPT_VAL['t']="$TPLG"

OPT_NAME['p']='playback_device' OPT_DESC['p']='ALSA pcm playback device. Example: hw:0,1'
OPT_HAS_ARG['p']=1 OPT_VAL['p']=''
OPT_NAME['p']='playback_device' OPT_DESC['p']='ALSA pcm playback device. Default: hw:0,2'
OPT_HAS_ARG['p']=1 OPT_VAL['p']='hw:0,2'

OPT_NAME['c']='capture_device' OPT_DESC['c']='ALSA pcm capture device. Example: hw:0,1'
OPT_HAS_ARG['c']=1 OPT_VAL['c']=''
OPT_NAME['c']='capture_device' OPT_DESC['c']='ALSA pcm capture device. Default: hw:0,2'
OPT_HAS_ARG['c']=1 OPT_VAL['c']='hw:0,2'

OPT_NAME['s']='sof-logger' OPT_DESC['s']="Open sof-logger trace the data will store at $LOG_ROOT"
OPT_HAS_ARG['s']=0 OPT_VAL['s']=1
Expand All @@ -51,30 +51,47 @@ init_globals()

rec_opt="-f S16_LE -c 2 -d 7"

test_sound_filename=$LOG_ROOT/play.wav
test_sound_filename=$HOME/Music/play.wav
all_result_files=()
}

run_tests()
{
dlogi "Generate 48 kHz chirp 0 - 20 kHz"
ffmpeg -y -f lavfi -i "aevalsrc='sin(2000*t*2*PI*t)':s=48000:d=5" -ac 2 "$test_sound_filename"
ffmpeg -loglevel error -y -f lavfi -i "aevalsrc='sin(2000*t*2*PI*t)':s=48000:d=5" -ac 2 "$test_sound_filename"

failures=0
set +e
for i in "${!sample_rates[@]}"
do
test_pass=true
sample_rate=${sample_rates[$i]}
dlogi "--------------- TEST $((i+1)): PLAY SAMPLE RATE 48000 Hz, RECORD IN $sample_rate Hz ---------------"

result_filename=$LOG_ROOT/rec_$sample_rate.wav
all_result_files+=("$result_filename")
play_and_record "-D$capture_dev $rec_opt -r $sample_rate $result_filename" "-D$playback_dev $test_sound_filename"
if [ $? -eq 1 ]; then
test_pass=false
dlogi "TEST $((i+1)) FAIL: aplay/arecord failed, look for previous errors"
else
check_soundfile_for_glitches "$result_filename"
if [ $? -eq 1 ]; then
test_pass=false
dlogi "TEST $((i+1)) FAIL: Found glitch in the recording"
fi
fi
if [ "$test_pass" = true ]; then
dlogi "TEST $((i+1)) PASS: No issues found."
else
failures=$((failures+1))
fi
done
set -e

if check_soundfile_for_glitches "${all_result_files[@]}"; then
dlogi "All files correct"
if [ "$failures" = 0 ]; then
dlogi "PASS: All testcases passed"
else
die "Detected corrupted files!"
die "FAIL: $failures testcases failed"
fi
}

Expand Down
Loading