run_exec_autotests.bash 7.06 KB
Newer Older
1 2
#!/bin/bash

3 4
if [ -s $OPENAIR_DIR/cmake_targets/tools/build_helper ] ; then
   source $OPENAIR_DIR/cmake_targets/tools/build_helper
5 6 7 8 9
else
   echo "Error: no file in the file tree: is OPENAIR_DIR variable set?"
   exit 1
fi

10
source $OPENAIR_DIR/cmake_targets/tools/test_helper
guptar's avatar
guptar committed
11

12
#SUDO="sudo -E "
guptar's avatar
guptar committed
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
tdir=$OPENAIR_DIR/cmake_targets/autotests
mkdir -p $tdir/bin $tdir/log
results_file="$tdir/log/execution_autotests.xml"

updated=$(svn st -q $OPENAIR_DIR)
if [ "$updated" != "" ] ; then
	echo "some files are not in svn:\n $updated"
fi

cd $tdir 


#\param $1 -> name of test case
#\param $2 -> name of compilation program
#\param $3 -> arguments for compilation program
#\param $4 -> name of pre-executable to install kernel modules, etc
#\param $5 -> arguments of pre-executable
#\param $6 -> name of executable
#\param $7 -> arguments for running the program
#\param $8 -> search expression
33 34
#\param $9 -> search expression which should NOT be found (for ex. segmentation fault) 
#\param $10 -> number of runs
guptar's avatar
guptar committed
35 36 37

test_compile_and_run() {
    xUnit_start
38
    test_case_name=$1.$2
guptar's avatar
guptar committed
39 40 41 42 43 44 45 46
    log_dir=$tdir/log
    log_file=$tdir/log/test.$1.txt
    compile_prog=$2
    compile_args=$3
    pre_exec_file=$4
    pre_exec_args=$5
    exec_args=$7
    search_expr=$8
47 48
    search_expr_negative=$9
    nruns=${10}
guptar's avatar
guptar committed
49 50 51 52 53 54 55 56 57 58 59
    build_dir=$tdir/$1/build
    exec_file=$build_dir/$6
    
    #Temporary log file where execution log is stored.
    temp_exec_log=$log_dir/temp_log.txt
    
    echo "Compiling test case $test_case_name. Log file = $log_file"

    rm -fr $build_dir
    mkdir -p $build_dir

60 61 62 63 64 65 66
    #echo "log_dir = $log_dir"
    #echo "log_file = $log_file"
    #echo "exec_file = $exec_file"
    #echo "args = $args"
    #echo "search_expr = $search_expr"
    #echo "pre_exec_file = $pre_exec_file"
    #echo "nruns = $nruns"
guptar's avatar
guptar committed
67
    
68 69 70

 

guptar's avatar
guptar committed
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
    echo "<COMPILATION LOG>" > $log_file
    cd $build_dir
    {
        cmake ..
        #rm -fv $exec_file
        make -j`nproc` $compile_prog
    }>> $log_file 2>&1
    echo "</COMPILATION LOG>" >> $log_file 2>&1

    for (( run_index=1; run_index <= $nruns; run_index++ ))
     do

     echo "Executing test case $test_case_name, Run Index = $run_index, Log file = $log_file"

     echo "-----------------------------------------------------------------------------" >> $log_file  2>&1
     echo "<EXECUTION LOG Run = $run_index >" >> $log_file  2>&1
 
88 89 90 91 92 93 94
     if [ -n "$pre_exec_file" ]; then
       { source $pre_exec_file $pre_exec_args; } >> $log_file  2>&1
     fi

     { $exec_file $exec_args ;} > $temp_exec_log  2>&1


guptar's avatar
guptar committed
95 96 97 98

     cat $temp_exec_log >> $log_file  2>&1
     echo "</EXECUTION LOG Run = $run_index >" >> $log_file  2>&1

99 100
     search_result=`grep -E "$search_expr" $temp_exec_log`
     test_case_result=""
guptar's avatar
guptar committed
101
     if [ -z "$search_result" ]; then
102
        test_case_result="FAIL"
guptar's avatar
guptar committed
103
     else
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
        test_case_result="PASS"
     fi
    
     #If we find a negative search result then there is crash of program and test case is failed even if above condition is true

     search_result=`grep -iE "$search_expr_negative" $temp_exec_log`
     if [ -n "$search_result" ]; then
        test_case_result="FAIL"
     fi
     
     if [ "$test_case_result" == "FAIL" ]; then
        echo_error "execution $test_case_name  FAIL $run_index"
        xUnit_fail "execution" "$test_case_name" "FAIL" "$run_index"
     fi

     if [ "$test_case_result" == "PASS" ]; then
        echo_success "execution $test_case_name  PASS $run_index"
	xUnit_success "execution" "$test_case_name" "PASS" "$run_index"        
guptar's avatar
guptar committed
122 123 124 125 126 127 128
     fi

# End of for loop
    done

}

129 130 131 132 133 134 135
dbin=$OPENAIR_DIR/cmake_targets/autotests/bin
dlog=$OPENAIR_DIR/cmake_targets/autotests/log

run_test() {
case=case$1; shift
cmd=$1; shift
expected=$3; shift
guptar's avatar
guptar committed
136 137 138
echo "expected = $expected"
exit

139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
$cmd > $dlog/$case.txt 2>&1
if [ $expected = "true" ] ; then	 
  if $* $dlog/$case.txt; then
    echo_success "test $case, command: $cmd ok"
  else
    echo_error "test $case, command: $cmd Failed"
  fi
else 
  if $* $dlog/$case.txt; then
    echo_error "test $case, command: $cmd Failed"
  else
    echo_success "test $case, command: $cmd ok"
  fi
fi
}

guptar's avatar
guptar committed
155 156 157 158 159 160 161
#$1 -> name of test case
#$2 -> name of compilation program
#$3 -> arguments for compilation program
#$4 -> name of pre-executable to install kernel modules, etc
#$5 -> arguments of pre-executable
#$6 -> name of executable
#$7 -> arguments for running the program
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
#$8 -> search expression which needs to be found
#$9 -> search expression which should NOT be found (for ex. segmentation fault) 
#$10 -> number of runs

#oaisim tests
test_compile_and_run 0200 "oaisim_nos1" "" "$OPENAIR_DIR/cmake_targets/tools/init_nas_nos1" "" "oaisim_nos1" " -O $OPENAIR_TARGETS/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.generic.oaisim.local_no_mme.conf -b1 -u1 -n1000" "RRC_CONN" "segmentation fault|assertion" 3

test_compile_and_run 0201 "oaisim_nos1" "" "$OPENAIR_DIR/cmake_targets/tools/init_nas_nos1" "" "oaisim_nos1" " -O $OPENAIR_TARGETS/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.generic.oaisim.local_no_mme.conf -b1 -u1 -a -n1000" "RRC_CONN" "segmentation fault|assertion" 3

#PHY unitary simulations for secuirity tests

test_compile_and_run 0300 "test_aes128_cmac_encrypt" "" "" "" "test_aes128_cmac_encrypt" " --verbose" "finished with 0 errors" "segmentation fault|assertion" 3

test_compile_and_run 0301 "test_aes128_ctr_decrypt" "" "" "" "test_aes128_ctr_decrypt" " --verbose" "finished with 0 errors" "segmentation fault|assertion" 3

test_compile_and_run 0302 "test_aes128_ctr_encrypt" "" "" "" "test_aes128_ctr_encrypt" " --verbose" "finished with 0 errors" "segmentation fault|assertion" 3

test_compile_and_run 0303 "test_secu_kenb" "" "" "" "test_secu_kenb" " --verbose" "finished with 0 errors" "segmentation fault|assertion" 3

test_compile_and_run 0304 "test_secu_knas" "" "" "" "test_secu_knas" " --verbose" "finished with 0 errors" "segmentation fault|assertion" 3

test_compile_and_run 0305 "test_secu_knas_encrypt_eea1" "" "" "" "test_secu_knas_encrypt_eea1" " --verbose" "finished with 0 errors" "segmentation fault|assertion"  3

test_compile_and_run 0306 "test_secu_knas_encrypt_eea2" "" "" "" "test_secu_knas_encrypt_eea2" " --verbose" "finished with 0 errors" "segmentation fault|assertion"  3

test_compile_and_run 0307 "test_secu_knas_encrypt_eia1" "" "" "" "test_secu_knas_encrypt_eia1" " --verbose" "finished with 0 errors" "segmentation fault|assertion"  3
guptar's avatar
guptar committed
188

189
test_compile_and_run 0308 "test_secu_knas_encrypt_eia2" "" "" "" "test_secu_knas_encrypt_eia2" " --verbose" "finished with 0 errors" "segmentation fault|assertion"  3
guptar's avatar
guptar committed
190

191
test_compile_and_run 0309 "test_kdf" "" "" "" "test_kdf" " --verbose" "finished with 0 errors" "segmentation fault|assertion" 3
guptar's avatar
guptar committed
192 193 194 195 196 197 198 199 200 201

#test_compile_and_run 0200 "oaisim_nos1" "" "$OPENAIR_DIR/cmake_targets/tools/init_nas_nos1" "" "oaisim_nos1" " -O /home/calisson/rohit/oai_snav/taets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.generic.oaisim.local_no_mme.conf -b1 -u1 -a " "RRC_CONN" 3

#run_test 0200 "$dbin/oaisim.r8 -a -A AWGN -n 100" false grep -q '(Segmentation.fault)|(Exiting)|(FATAL)'

#run_test 0201 "$dbin/oaisim.r8 -a -A AWGN -n 100" false fgrep -q '[E]'

# write the test results into a file

xUnit_write "$results_file"
202

guptar's avatar
guptar committed
203
echo "Test Results are written to $results_file"
204