@@ -1534,47 +1534,89 @@ restore_topology() {
15341534 check_topology
15351535}
15361536
1537+ # Check aplay/arecord output for warnings
1538+ # Arguments: 1-aplay/arecord output
1539+ check_for_warnings ()
1540+ {
1541+ if printf ' %s' " $1 " | grep -q " Warning:" ; then
1542+ dlogw " Caught warning! Look for previous logs."
1543+ return 1
1544+ fi
1545+ return 0
1546+ }
1547+
15371548# Play sound and record it
15381549# Arguments: 1-arecord options 2-aplay options
15391550play_and_record ()
15401551{
1541- dlogi " Play [aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS $2 ] and capture sound [arecord $1 ]"
1552+ dlogi " Play [aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS $2 ] and capture sound [arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS $1 ]"
1553+ arecord_log=$( mktemp)
1554+ aplay_log=$( mktemp)
1555+ errors=0
1556+
15421557 # shellcheck disable=SC2086
1543- arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS $1 & PID=$!
1558+ arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS $1 2>&1 | tee " $arecord_log " &
1559+ PID=$!
1560+ sleep 1
1561+
15441562 # shellcheck disable=SC2086
1545- aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS $2
1546- wait $PID
1563+ aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS $2 2>&1 | tee " $aplay_log "
1564+ aplay_ret=${PIPESTATUS[0]}
1565+ [ " $aplay_ret " -ne 0 ] && errors=$(( errors+ 1 ))
1566+
1567+ wait " $PID " || errors=$(( errors+ 1 ))
15471568 sleep 1
1569+ arecord_output=$( < " $arecord_log " )
1570+ check_for_warnings " $arecord_output " || errors=$(( errors+ 1 ))
1571+ aplay_output=$( < " $aplay_log " )
1572+ check_for_warnings " $aplay_output " || errors=$(( errors+ 1 ))
1573+
1574+ rm -f " $arecord_log " " $aplay_log "
1575+
1576+ if [ " $errors " = 0 ]; then
1577+ return 0
1578+ fi
1579+ return 1
15481580}
15491581
1550- # Analyze files to look for glitches.
1582+ # Analyze file to look for glitches.
15511583# Returns exit code 0 if there are no glitches, 1 if there are.
1552- # Arguments: the list of filenames
1584+ # Arguments: filename
15531585check_soundfile_for_glitches ()
15541586{
1555- glitched_files=0
1587+ if [ -f " $result_filename " ]; then
1588+ dlogi " Analyzing $result_filename file..."
1589+ if python3 " $SCRIPT_HOME " /tools/analyze-wav.py " $result_filename " ; then
1590+ dlogi " $result_filename file is correct"
1591+ else
1592+ dlogw " GLITCHED FILE: $result_filename "
1593+ return 1
1594+ fi
1595+ else
1596+ dlogw " MISSING FILE: $result_filename "
1597+ return 1
1598+ fi
1599+ }
1600+
1601+ # Check list of soundfiles for glitches
1602+ # Returns exit code 0 if there are no glitches, 1 if there are.
1603+ # Arguments: list of filenames
1604+ check_soundfiles_for_glitches ()
1605+ {
1606+ failures=0
15561607 # shellcheck disable=SC2154
15571608 for result_filename in " ${all_result_files[@]} "
15581609 do
1559- if [ -f " $result_filename " ]; then
1560- dlogi " Analyzing $result_filename file..."
1561- if python3 " $SCRIPT_HOME " /tools/analyze-wav.py " $result_filename " ; then
1562- dlogi " $result_filename file is correct"
1563- else
1564- dlogw " Found issues in $result_filename file"
1565- glitched_files=$(( glitched_files+ 1 ))
1566- fi
1567- else
1568- dlogw " $result_filename file not found, check for previous errors"
1569- glitched_files=$(( glitched_files+ 1 ))
1610+ if ! check_soundfile_for_glitches " $result_filename " ; then
1611+ failures=$(( failures+ 1 ))
15701612 fi
15711613 done
15721614
1573- if [ $glitched_files -eq 0 ]; then
1574- dlogi " Analysis finished, no issues found "
1615+ if [ " $failures " = 0 ]; then
1616+ dlogi " All files correct "
15751617 return 0
15761618 else
1577- dlogi " $glitched_files files corrupted"
1619+ dlogw " Found $failures corrupted files "
15781620 return 1
15791621 fi
15801622}
0 commit comments