From 94e92916fd1f3bc138cf922955f0d43285df8c3d Mon Sep 17 00:00:00 2001 From: Bjorn Andersson Date: Wed, 7 Mar 2018 18:07:09 -0800 Subject: [PATCH] bootrr: Move common functions to bootrr Move the common functions to a helper and use this from assert_device_present. Make assert_device_present accept a fourth parameter for a timeout, which will cause the assert to wait for the given amount of time for the device to appear. Signed-off-by: Bjorn Andersson --- helpers/assert_device_present | 13 ++++++------- helpers/bootrr | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 helpers/bootrr diff --git a/helpers/assert_device_present b/helpers/assert_device_present index 18d83af..3d89f38 100755 --- a/helpers/assert_device_present +++ b/helpers/assert_device_present @@ -1,18 +1,17 @@ #!/bin/sh +source /usr/bin/bootrr + TEST_CASE_ID="$1" DRIVER="$2" DEVICE="$3" +TIMEOUT="${4:-1}" if [ -z "${TEST_CASE_ID}" -o -z "${DRIVER}" -o -z "${DEVICE}" ]; then - echo "Usage: $0 " + echo "Usage: $0 []" exit 1 fi -if [ -L /sys/bus/*/drivers/${DRIVER}/${DEVICE} ]; then - TEST_RESULT="pass" -else - TEST_RESULT="fail" -fi +timeout ${TIMEOUT} [ -L /sys/bus/*/drivers/${DRIVER}/${DEVICE} ] || test_report_exit fail -lava-test-case "${TEST_CASE_ID}" --result ${TEST_RESULT} +test_report_exit pass diff --git a/helpers/bootrr b/helpers/bootrr new file mode 100644 index 0000000..20975c4 --- /dev/null +++ b/helpers/bootrr @@ -0,0 +1,21 @@ +#!/bin/sh + +timeout() { + attempts="$1"; shift + cmd="$@" + + for i in `seq ${attempts}` + do + $cmd && return 0 + sleep 1 + done + + return 1 +} + +test_report_exit() { + TEST_RESULT=$1 + lava-test-case ${TEST_CASE_ID} --result ${TEST_RESULT} + exit 0 +} +