commenting failing queries
[csql.git] / test / execTests.ksh
blobfd07885c7a2f663b6e92c7744a12179459a37fbe
1 #!/bin/sh
3 ################### Settings ########################################
4 #Timeout value for the hanging scripts
5 HANG_TIMEOUT=150
7 ################### TIMEOUT HANDLER #################################
8 timeout_handler() {
9 if [ $CMD_PID != "" ]
10 then
11 HANG_FLAG=Yes
12 echo "HANG_FLAG is set here"
13 kill -9 $CMD_PID 2>/dev/null
17 ##################### Test Executor main starts here ##################
18 echo MY pid is $$
19 #TEST_RUN_DIR should be set before running this
20 if [ ! "$TEST_RUN_ROOT" ]
21 then
22 echo "TEST_RUN_ROOT should be set before running the tests"
23 exit 1
25 if [ ! "$CSQL_INSTALL_ROOT" ]
26 then
27 echo "CSQL_INSTALL_ROOT should be set before running the tests"
28 exit 1
31 if [ ! "$CSQL_CONFIG_FILE" ]
32 then
33 echo "setupenv.ksh should be run before running the tests"
34 exit 1
36 DBFILE=`grep DATABASE_FILE $CSQL_CONFIG_FILE| awk -F= '{ print $2}'`
37 CACHECONFFILE=`grep TABLE_CONFIG_FILE $CSQL_CONFIG_FILE| awk -F= '{ print $2}'`
38 rm $DBFILE
39 rm $CACHECONFFILE
40 echo $DBFILE
41 ROOT_DIR=`pwd`
42 mkdir -p $TEST_RUN_ROOT
43 SERVOUT=$TEST_RUN_ROOT/serv.out
44 touch $SERVOUT
45 $CSQL_INSTALL_ROOT/bin/csqlserver >${SERVOUT} &
46 SERVER_PID=$!
47 echo "Starting Server"
48 sleep 5
49 while read MODULE
51 echo $MODULE | grep "#" >/dev/null
52 if [ $? -eq 0 ]
53 then
54 continue
56 echo "MODULE READ is $MODULE"
58 if [ "$MODULE" = "system/lock" ]
59 then
60 echo "Restarting the server for lock module"
61 kill -9 ${SERVER_PID}
62 ipcrm -M 2222 -M 3333
63 echo "csqlserver killed PID=${SERVER_PID}" >>$TEST_LOG
64 rm $DBFILE
65 $CSQL_INSTALL_ROOT/bin/csqlserver >${SERVOUT} &
66 SERVER_PID=$!
67 echo "csqlserver restarted with PID=${SERVER_PID}" >>$TEST_LOG
68 echo "Restarting Server"
69 sleep 5
71 TEST_SCRIPT_DIR=${ROOT_DIR}/${MODULE}
72 TEST_RUN_DIR=${TEST_RUN_ROOT}/${MODULE}
73 if [ -s "$TEST_RUN_DIR" ]
74 then
75 echo "TEST_RUN_ROOT directory is not empty. Clean and try again."
76 exit 1
78 mkdir -p $TEST_RUN_DIR
80 # TODO::check whether server is running
82 TEST_LOG=$TEST_RUN_DIR/testlog
84 if [ -s "$TEST_LOG" ]
85 then
86 echo "TEST_RUN_DIR has files in it. Remove before running the tests"
87 exit 1
90 TEST_EXEC_DIR=$TEST_RUN_DIR/tests
91 mkdir $TEST_EXEC_DIR
94 echo "Test Executor log file" >$TEST_LOG
95 echo "----------------------" >>$TEST_LOG
97 TestList=`ls ${TEST_SCRIPT_DIR}/test*`
98 for test in $TestList
100 echo "Running $test"
101 echo "Running $test" >>$TEST_LOG
102 echo "Test started at : `date` "
103 echo "Test started at : `date` " >>$TEST_LOG
105 expPresent="no"
106 EXP_FILE=exp.`basename ${test}`
107 #echo "EXP_FILE is $EXP_FILE"
108 if [ -s "${TEST_SCRIPT_DIR}/${EXP_FILE}" ]
109 then
110 expPresent="yes"
113 HANG_FLAG=No
114 trap timeout_handler USR1
115 sleep ${HANG_TIMEOUT} && kill -s USR1 $$ &
116 SLEEP_PID=$!
118 if [ "$expPresent" = "yes" ]
119 then
120 cp ${TEST_SCRIPT_DIR}/${EXP_FILE} ${TEST_EXEC_DIR}
121 ${test} > ${TEST_EXEC_DIR}/cur.${EXP_FILE} 2>/dev/null &
122 else
123 ${test} >> ${TEST_LOG} 2>/dev/null &
125 CMD_PID=$!
126 wait ${CMD_PID} 2>/dev/null
127 ret=$?
128 echo "Test Ended at : `date` "
129 echo "Test Ended at : `date` " >>$TEST_LOG
130 unset CMD_PID
131 trap "" USR1
132 kill -9 ${SLEEP_PID} 2>/dev/null
134 if [ "$HANG_FLAG" = "Yes" ]
135 then
136 echo "Test Hung. so it is killed." >>$TEST_LOG
137 echo "FAILED:Test $test failed" >>$TEST_LOG
138 #TODO::Reinitalize the database, as it may be in corrupted state.
139 CURTIME=`date +%s`
140 mv ${SERVOUT} ${SERVOUT}.${SERVER_PID}.${CURTIME}
141 kill -9 ${SERVER_PID}
142 ipcrm -M 2222 -M 3333
143 echo "csqlserver killed PID=${SERVER_PID}" >>$TEST_LOG
144 $CSQL_INSTALL_ROOT/bin/csqlserver >${SERVOUT} &
145 SERVER_PID=$!
146 echo "csqlserver restarted with PID=${SERVER_PID}" >>$TEST_LOG
147 echo "Restarting Server"
148 sleep 5
149 continue
152 HANG_FLAG=No
154 if [ $ret -eq 0 ]
155 then
156 if [ "$expPresent" = "yes" ]
157 then
158 #compare exp and current output
159 diff ${TEST_SCRIPT_DIR}/${EXP_FILE} ${TEST_EXEC_DIR}/cur.${EXP_FILE} > ${TEST_EXEC_DIR}/diff.${EXP_FILE}
160 if [ $? -eq 0 ]
161 then
163 echo "Exp and current output matched."
164 echo "Test $test passed"
165 echo "Exp and current output matched." >>$TEST_LOG
166 echo "PASSED:Test $test passed" >>$TEST_LOG
167 rm ${TEST_EXEC_DIR}/cur.${EXP_FILE}
168 rm ${TEST_EXEC_DIR}/diff.${EXP_FILE}
169 rm ${TEST_EXEC_DIR}/${EXP_FILE}
170 else
171 echo "Exp and current output not matched."
172 echo "Test $test failed"
173 echo "Exp and current output not matched." >>${TEST_LOG}
174 echo "FAILED:Test $test failed" >>$TEST_LOG
175 #TODO::Reinitalize the database, as it may be in corrupted state.
176 CURTIME=`date +%s`
177 mv ${SERVOUT} ${SERVOUT}.${SERVER_PID}.${CURTIME}
178 echo "Refer ${SERVOUT}.${SERVER_PID}.${CURTIME} file for server log" >>$TEST_LOG
179 kill -9 ${SERVER_PID}
180 ipcrm -M 2222 -M 3333
181 echo "csqlserver killed PID=${SERVER_PID}" >>${TEST_LOG}
182 rm $DBFILE
183 $CSQL_INSTALL_ROOT/bin/csqlserver >${SERVOUT} &
184 SERVER_PID=$!
185 echo "csqlserver restarted with PID=${SERVER_PID}" >>${TEST_LOG}
186 echo "Restarting Server"
187 sleep 5
189 else
190 echo "Returned 0."
191 echo "Test $test passed"
192 echo "Returned 0." >>$TEST_LOG
193 echo "PASSED:Test $test passed" >>$TEST_LOG
196 else
197 echo "Returned $ret "
198 echo "Test $test failed"
199 echo "Returned $ret " >>$TEST_LOG
200 echo "FAILED:Test $test failed" >>$TEST_LOG
201 #TODO::Reinitalize the database, as it may be in corrupted state.
202 CURTIME=`date +%s`
203 mv ${SERVOUT} ${SERVOUT}.${SERVER_PID}.${CURTIME}
204 echo "Refer ${SERVOUT}.${SERVER_PID}.${CURTIME} file for server log" >>$TEST_LOG
205 kill -9 ${SERVER_PID}
206 ipcrm -M 2222 -M 3333
207 echo "csqlserver killed PID=${SERVER_PID}" >>$TEST_LOG
208 rm $DBFILE
209 $CSQL_INSTALL_ROOT/bin/csqlserver >${SERVOUT} 2>${SERVOUT} &
210 SERVER_PID=$!
211 echo "csqlserver restarted with PID=${SERVER_PID}" >>${TEST_LOG}
212 echo "Restarting Server"
213 sleep 5
216 done
217 done < TestModules
219 kill -9 ${SERVER_PID}
220 ipcrm -M 2222 -M 3333
221 echo "csqlserver killed PID=${SERVER_PID}" >>${TEST_LOG}
222 rm $DBFILE
224 exit 0