Home | History | Annotate | Download | only in test
      1 function usage() {
      2     echo "runs $TEST_NAME"
      3     echo "\t -h help"
      4     echo "\t -c [CLIENT64_SERVER64 | CLIENT32_SERVER32 | CLIENT64_SERVER32 | CLIENT32_SERVER64] configures whether to run 32-bit or 64-bit versions of the servers and client"
      5     echo "\t -x [/ld/library/path32] set the LD_LIBRARY_PATH for servers32 and client32"
      6     echo "\t -y [/ld/library/path64] set the LD_LIBRARY_PATH for servers64 and client64"
      7 }
      8 
      9 failed_test_cases=()
     10 
     11 function run_test() {
     12     if [ $1 -eq 32 ]; then
     13         CLIENT_PATH=$CLIENT_PATH32
     14         LD_LIB_PATH_CLIENT=$LD_LIB_PATH32
     15     else
     16         CLIENT_PATH=$CLIENT_PATH64
     17         LD_LIB_PATH_CLIENT=$LD_LIB_PATH64
     18     fi
     19 
     20     if [ $2 -eq 32 ]; then
     21         SERVER_PATH=$SERVER_PATH32
     22         LD_LIB_PATH_SERVER=$LD_LIB_PATH32
     23     else
     24         SERVER_PATH=$SERVER_PATH64
     25         LD_LIB_PATH_SERVER=$LD_LIB_PATH64
     26     fi
     27 
     28     echo "Running $1-bit client with $2-bit servers"
     29     echo "$LD_LIB_PATH_SERVER=$LD_LIB_PATH_SERVER"
     30     LD_LIBRARY_PATH=$LD_LIB_PATH_SERVER:$LD_LIBRARY_PATH $SERVER_PATH &
     31     SERVER_PID=$!
     32     LD_LIBRARY_PATH=$LD_LIB_PATH_CLIENT:$LD_LIBRARY_PATH $CLIENT_PATH
     33     if [ $? -ne 0 ]; then
     34         failed_test_cases+=("$1-bit client with $2-bit servers")
     35     fi
     36     kill $SERVER_PID
     37 }
     38 
     39 function check_env() {
     40     if [ -z ${TEST_NAME+x} ]; then
     41         echo "TEST_NAME is unset";
     42         exit 1
     43     fi
     44 
     45     if [ -z ${CLIENT_PATH32+x} ]; then
     46         echo "CLIENT_PATH32 is unset";
     47         exit 1
     48     fi
     49 
     50     if [ -z ${CLIENT_PATH64+x} ]; then
     51         echo "CLIENT_PATH64 is unset";
     52         exit 1
     53     fi
     54 
     55     if [ -z ${SERVER_PATH32+x} ]; then
     56         echo "SERVER_PATH32 is unset";
     57         exit 1
     58     fi
     59 
     60     if [ -z ${SERVER_PATH64+x} ]; then
     61         echo "SERVER_PATH64 is unset";
     62         exit 1
     63     fi
     64 }
     65 
     66 #usage: run_all_tests server_path32 server_path64 client_path32 client_path64 test_name [-h/-c config/-x lib32/-y ldlib64]
     67 function run_all_tests() {
     68     SERVER_PATH32=$1
     69     SERVER_PATH64=$2
     70     CLIENT_PATH32=$3
     71     CLIENT_PATH64=$4
     72     TEST_NAME=$5
     73     check_env
     74     shift 5
     75 
     76     while getopts hc:x:y: opt;
     77     do
     78         case $opt in
     79             h)
     80                 usage
     81                 exit 0
     82                 ;;
     83             c)
     84                 case $OPTARG in
     85                     CLIENT64_SERVER64)
     86                         run_test 64 64
     87                         ;;
     88                     CLIENT32_SERVER32)
     89                         run_test 32 32
     90                         ;;
     91                     CLIENT64_SERVER32)
     92                         run_test 64 32
     93                         ;;
     94                     CLIENT32_SERVER64)
     95                         run_test 32 64
     96                         ;;
     97                     *)
     98                         echo "Error: unknown config value \"$OPTARG\""
     99                         exit 1
    100                         ;;
    101                 esac
    102                 exit 0
    103                 ;;
    104             x)
    105                 LD_LIB_PATH32=$OPTARG
    106                 ;;
    107             y)
    108                 LD_LIB_PATH64=$OPTARG
    109                 ;;
    110             *)
    111                 echo "Error: unknown param \"$opt\""
    112                 usage
    113                 exit 1
    114                 ;;
    115         esac
    116     done
    117 
    118     for i in 32 64
    119         do
    120             for j in 32 64
    121                 do
    122                     run_test $i $j
    123                 done
    124         done
    125     count_failed_tests=${#failed_test_cases[@]}
    126     echo "*********************************************************"
    127     echo "    $TEST_NAME Final Summary:\n"
    128     if [ $count_failed_tests -gt 0 ]; then
    129         echo "    $TEST_NAME failed for the following cases:\n\t"
    130         for each in "${failed_test_cases[@]}"
    131             do
    132                 echo "\t$each"
    133             done
    134     else
    135         echo "    $TEST_NAME passed for all cases!"
    136     fi
    137     echo "*********************************************************"
    138 
    139     exit ${#failed_test_cases[@]}
    140 }
    141