test-util.sh 1.23 KB
Newer Older
Matthieu Dorier's avatar
Matthieu Dorier committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
#
# General test script utilities
#

if [ -z "$TIMEOUT" ] ; then
    echo expected TIMEOUT variable defined to its respective command
    exit 1
fi

if [ -z "$MKTEMP" ] ; then
    echo expected MKTEMP variable defined to its respective command
    exit 1
fi

TMPDIR=/dev/shm
export TMPDIR
mkdir -p $TMPDIR
TMPBASE=$(${MKTEMP} --tmpdir -d test-XXXXXX)

if [ ! -d $TMPBASE ];
then
  echo "Temp directory doesn't exist: $TMPBASE"
  exit 3
fi

function run_to ()
{
    maxtime=${1}s
    shift
    ${TIMEOUT} --signal=9 $maxtime "$@"
}

function test_start_server ()
{
    startwait=${1:-15}
    maxtime=${2:-120}

Matthieu Dorier's avatar
Matthieu Dorier committed
38
    run_to ${maxtime} bin/sdskv-server-daemon -f $TMPBASE/sdskv.addr na+sm ${@:3} &
Matthieu Dorier's avatar
Matthieu Dorier committed
39 40 41 42 43 44
    # wait for server to start
    sleep ${startwait}

    svr_addr=`cat $TMPBASE/sdskv.addr`
}

45 46 47 48 49 50 51 52 53 54 55 56
function test_start_custom_server ()
{
    startwait=${1:-15}
    maxtime=${2:-120}

    run_to ${maxtime} test/sdskv-custom-server-daemon -f $TMPBASE/sdskv.addr na+sm ${@:3} &
    # wait for server to start
    sleep ${startwait}

    svr_addr=`cat $TMPBASE/sdskv.addr`
}

57 58
function find_db_name ()
{
59
    test_db_name=$TMPBASE/${SDSKV_TEST_DB_NAME:-"sdskv-test-db"}
60 61 62
    test_db_type=${SDSKV_TEST_DB_TYPE:-"map"}
    test_db_full="${test_db_name}:${test_db_type}"
}