diff --git a/case-lib/lib.sh b/case-lib/lib.sh index 92541bd4..2798ae56 100644 --- a/case-lib/lib.sh +++ b/case-lib/lib.sh @@ -40,6 +40,41 @@ if [ ! "$SOFCARD" ]; then awk '/sof-[a-z]/ && $1 ~ /^[0-9]+$/ { $1=$1; print $1; exit 0;}') fi +# Arguments: +# +# - poll interval in secs +# - timeout in secs, rounded up to the next interval +# - command and arguments +# +poll_wait_for() +{ + test $# -ge 3 || + die "poll_wait_for() invoked with $# arguments" + + local ival="$1"; shift + local maxtime="$1"; shift + + printf "Polling '%s' every ${ival}s for ${maxtime}s\n" "$*" + + local waited=0 attempts=1 pass=true + while ! "$@"; do + if [ "$waited" -ge "$maxtime" ]; then + pass=false + break; + fi + sleep "$ival" + : $((attempts++)); waited=$((waited+ival)) + done + local timeinfo="${waited}s and ${attempts} attempts" + if $pass; then + printf "Completed '%s' after ${timeinfo}\n" "$*" + else + >&2 printf "Command '%s' timed out after ${timeinfo}\n" "$*" + fi + + $pass +} + setup_kernel_check_point() { # Make the check point $SOF_TEST_INTERVAL second(s) earlier to avoid diff --git a/test-case/check-kmod-load-unload.sh b/test-case/check-kmod-load-unload.sh index 28312df9..2e863078 100755 --- a/test-case/check-kmod-load-unload.sh +++ b/test-case/check-kmod-load-unload.sh @@ -91,7 +91,8 @@ do die "Found error(s) in kernel log after module insertion" dlogi "checking if firmware is loaded successfully" - if sof_firmware_boot_complete --since=@"$KERNEL_CHECKPOINT"; then + # Check every 1s for 10s + if poll_wait_for 1 10 sof_firmware_boot_complete --since=@"$KERNEL_CHECKPOINT"; then grep_firmware_info_in_logs --since=@"$KERNEL_CHECKPOINT" else die "Failed to load firmware after module insertion"