@@ -1534,47 +1534,90 @@ restore_topology() {
15341534 check_topology
15351535}
15361536
1537+ # Check aplay output for warnings
1538+ # Arguments: 1-aplay output
1539+ check_for_warnings ()
1540+ {
1541+ # dlogi "$1"
1542+ if echo " $1 " | grep -q " Warning:" ; then
1543+ dlogw " Caught warning! Look for previous logs."
1544+ return 1
1545+ fi
1546+ return 0
1547+ }
1548+
15371549# Play sound and record it
15381550# Arguments: 1-arecord options 2-aplay options
15391551play_and_record ()
15401552{
1541- dlogi " Play [aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS $2 ] and capture sound [arecord $1 ]"
1553+ dlogi " Play [aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS $2 ] and capture sound [arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS $1 ]"
1554+ arecord_log=$( mktemp)
1555+ aplay_log=$( mktemp)
1556+ errors=0
1557+
15421558 # shellcheck disable=SC2086
1543- arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS $1 & PID=$!
1559+ arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS $1 2>&1 | tee " $arecord_log " &
1560+ PID=$!
1561+ sleep 1
1562+
15441563 # shellcheck disable=SC2086
1545- aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS $2
1546- wait $PID
1564+ aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS $2 2>&1 | tee " $aplay_log "
1565+ aplay_ret=${PIPESTATUS[0]}
1566+ [ $aplay_ret -ne 0 ] && errors=$(( errors+ 1 ))
1567+
1568+ wait " $PID " || errors=$(( errors+ 1 ))
15471569 sleep 1
1570+ arecord_output=$( < " $arecord_log " )
1571+ check_for_warnings " $arecord_output " || errors=$(( errors+ 1 ))
1572+ aplay_output=$( < " $aplay_log " )
1573+ check_for_warnings " $aplay_output " || errors=$(( errors+ 1 ))
1574+
1575+ rm -f " $arecord_log " " $aplay_log "
1576+
1577+ if [ " $errors " = 0 ]; then
1578+ return 0
1579+ fi
1580+ return 1
15481581}
15491582
1550- # Analyze files to look for glitches.
1583+ # Analyze file to look for glitches.
15511584# Returns exit code 0 if there are no glitches, 1 if there are.
1552- # Arguments: the list of filenames
1585+ # Arguments: filename
15531586check_soundfile_for_glitches ()
15541587{
1555- glitched_files=0
1588+ if [ -f " $result_filename " ]; then
1589+ dlogi " Analyzing $result_filename file..."
1590+ if python3 " $SCRIPT_HOME " /tools/analyze-wav.py " $result_filename " ; then
1591+ dlogi " $result_filename file is correct"
1592+ else
1593+ dlogw " GLITCHED FILE: $result_filename "
1594+ return 1
1595+ fi
1596+ else
1597+ dlogw " MISSING FILE: $result_filename "
1598+ return 1
1599+ fi
1600+ }
1601+
1602+ # Check list of soundfiles for glitches
1603+ # Returns exit code 0 if there are no glitches, 1 if there are.
1604+ # Arguments: list of filenames
1605+ check_soundfiles_for_glitches ()
1606+ {
1607+ failures=0
15561608 # shellcheck disable=SC2154
15571609 for result_filename in " ${all_result_files[@]} "
15581610 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 ))
1611+ if ! check_soundfile_for_glitches " $result_filename " ; then
1612+ failures=$(( failures+ 1 ))
15701613 fi
15711614 done
15721615
1573- if [ $glitched_files -eq 0 ]; then
1574- dlogi " Analysis finished, no issues found "
1616+ if [ " $failures " = 0 ]; then
1617+ dlogi " All files correct "
15751618 return 0
15761619 else
1577- dlogi " $glitched_files files corrupted"
1620+ dlogw " Found $failures corrupted files "
15781621 return 1
15791622 fi
15801623}
0 commit comments