Skip to content
Merged
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
71 changes: 66 additions & 5 deletions test-case/check-suspend-resume.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,28 +74,89 @@ else
done
fi

save_initial_stats()
{
printf '\n\n'

INITIAL_DBG_SOURCES="$LOG_ROOT"/initial_wakeup_sources.txt
sudo cat /sys/kernel/debug/wakeup_sources | sudo tee "$INITIAL_DBG_SOURCES"

INITIAL_STATS="$LOG_ROOT"/initial_suspend_stats.txt
grep ^ /sys/power/suspend_stats/*fail* |
sudo tee "$INITIAL_STATS" > /dev/null

if grep -E ':[[:digit:]]+$' "$INITIAL_STATS" | grep -q -v ':0$'; then
dlogw "Starting test with earlier suspend failures!"
fi
printf '\n'

find /sys/devices -wholename '*/power/wakeup' -print0 |
xargs --null grep -H 'enabled'; printf '\n'
dlogi "Note many of the devices above are typically buses, not actual devices"
dlogi "https://docs.kernel.org/driver-api/pm/devices.html#sys-devices-power-wakeup-files"
printf '\n'
lspci; printf '\n'
lsusb -t; printf '\n\n'
}

check_suspend_fails()
{
diff -u "$INITIAL_STATS" <(grep ^ /sys/power/suspend_stats/*fail*)
}

dump_stats()
{
printf '\n'
grep ^ /sys/power/suspend_stats/*
printf '\n'
sudo cat /sys/kernel/debug/wakeup_sources | head -n 1
diff -u "$INITIAL_DBG_SOURCES" <(sudo cat /sys/kernel/debug/wakeup_sources) ||
true
printf '\n'
}

dump_and_die()
{
dump_stats
die "$@"
}

# This is used to workaround https://github.com/thesofproject/sof-test/issues/650,
# which may be caused by kernel issue or unstable network connection.
# TODO: remove this after issue fixed.
sleep 1

expected_wakeup_count=$(cat /sys/power/wakeup_count)
expected_stats_success=$(cat /sys/power/suspend_stats/success)
save_initial_stats
for i in $(seq 1 $loop_count)
do
dlogi "===== Round($i/$loop_count) ====="
# set up checkpoint for each iteration
setup_kernel_check_point
sleep_count=$(cat /sys/power/wakeup_count)
expected_wakeup_count=$((expected_wakeup_count+1))
expected_stats_success=$((expected_stats_success+1))
dlogc "Run the command: rtcwake -m mem -s ${sleep_lst[$i]}"
sudo rtcwake -m mem -s "${sleep_lst[$i]}" ||
die "rtcwake returned $?"
dump_and_die "rtcwake returned $?"
dlogc "sleep for ${wait_lst[$i]}"
sleep ${wait_lst[$i]}
dlogi "Check for the kernel log status"
# check kernel log for each iteration to catch issues
sof-kernel-log-check.sh "$KERNEL_CHECKPOINT" || die "Caught error in kernel log"
sof-kernel-log-check.sh "$KERNEL_CHECKPOINT" || dump_and_die "Caught error in kernel log"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should line 146 be split across two lines as well?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

93 characters so this is over the traditional 80 limit but below Linux' new, official 100 characters limit...

# check wakeup count correct
wake_count=$(cat /sys/power/wakeup_count)
dlogi "Check for the wakeup_count"
[[ $wake_count -ge $sleep_count ]] || die "suspend/resume didn't happen, because /sys/power/wakeup_count does not increase"
stats_success=$(cat /sys/power/suspend_stats/success)
dlogi "Check for wakeup_count and suspend_stats"
[ "$wake_count" -eq "$expected_wakeup_count" ] || {
dump_stats
dlogw "/sys/power/wakeup_count is $wake_count, expected $expected_wakeup_count"
printf '\n'
expected_wakeup_count=${wake_count}
}
[ "$stats_success" -eq "$expected_stats_success" ] ||
dump_and_die "/sys/power/suspend_stats/success is $stats_success, expected $expected_stats_success"
check_suspend_fails || dump_and_die "some failure counts have changed"

done