test-util.sh 3.08 KB
Newer Older
1 2 3 4
#
# General test script utilities
#

Shane Snyder's avatar
Shane Snyder committed
5 6 7 8 9 10 11 12 13 14
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

15 16 17
TMPDIR=/dev/shm
export TMPDIR
mkdir -p $TMPDIR
Shane Snyder's avatar
Shane Snyder committed
18
TMPBASE=$(${MKTEMP} --tmpdir -d test-XXXXXX)
19 20 21 22 23 24 25 26 27 28 29

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

function run_to ()
{
    maxtime=${1}s
    shift
Shane Snyder's avatar
Shane Snyder committed
30
    ${TIMEOUT} --signal=9 $maxtime "$@"
31 32 33 34 35 36
}

function test_start_servers ()
{
    nservers=${1:-4}
    startwait=${2:-15}
37
    maxtime=${3:-120}
38 39

    # start daemons
40
    for i in `seq $nservers`
41
    do
42
        src/bake-mkpool -s 100M $TMPBASE/svr-$i.dat
43 44 45 46
        if [ $? -ne 0 ]; then
            exit 1
        fi

47
        run_to ${maxtime} src/bake-server-daemon -f $TMPBASE/svr-$i.addr na+sm $TMPBASE/svr-$i.dat &
48 49 50 51 52 53 54 55 56 57 58 59
        if [ $? -ne 0 ]; then
            # TODO: this doesn't actually work; can't check return code of
            # something executing in background.  We have to rely on the
            # return codes of the actual client side tests to tell if
            # everything started properly
            exit 1
        fi
    done

    # wait for servers to start
    sleep ${startwait}

60
    svr1=`cat $TMPBASE/svr-1.addr`
61
}
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129

function test_start_servers_multi_providers ()
{
    nservers=${1:-4}
    nproviders=${2:-1}
    startwait=${3:-15}
    maxtime=${4:-120}

    # start daemons
    for i in `seq $nservers`
    do
	for j in `seq $nproviders`
	do
    	    src/bake-mkpool -s 100M $TMPBASE/svr-$i-prvd-$j.dat
            if [ $? -ne 0 ]; then
                exit 1
            fi
        done

        run_to ${maxtime} src/bake-server-daemon -m providers -f $TMPBASE/svr-$i.addr na+sm $TMPBASE/svr-$i-prvd-*.dat &
        if [ $? -ne 0 ]; then
            # TODO: this doesn't actually work; can't check return code of
            # something executing in background.  We have to rely on the
            # return codes of the actual client side tests to tell if
            # everything started properly
            exit 1
        fi
    done

    # wait for servers to start
    sleep ${startwait}

    svr1=`cat $TMPBASE/svr-1.addr`
}

function test_start_servers_multi_targets ()
{
    nservers=${1:-4}
    ntargets=${2:-1}
    startwait=${3:-15}
    maxtime=${4:-120}

    # start daemons
    for i in `seq $nservers`
    do
	for j in `seq $ntargets`
	do
    	    src/bake-mkpool -s 100M $TMPBASE/svr-$i-tgt-$j.dat
            if [ $? -ne 0 ]; then
                exit 1
            fi
        done

        run_to ${maxtime} src/bake-server-daemon -m targets -f $TMPBASE/svr-$i.addr na+sm $TMPBASE/svr-$i-tgt-*.dat &
        if [ $? -ne 0 ]; then
            # TODO: this doesn't actually work; can't check return code of
            # something executing in background.  We have to rely on the
            # return codes of the actual client side tests to tell if
            # everything started properly
            exit 1
        fi
    done

    # wait for servers to start
    sleep ${startwait}

    svr1=`cat $TMPBASE/svr-1.addr`
}