windows changes
[csql.git] / test / execTests.ksh
blob767c2708aae7d3576339706e97d888ceaae731a4
1 #!/bin/ksh
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
16 restart_csqlserver() {
17 echo "Restarting the server"
18 killcsqlsqlserver
19 kill -2 ${SERVER_PID}
20 SRVPID=`ps -ef | grep csqlserver|grep -v "grep" |tail -1| awk -F" " '{ print $2 }'`
21 if [ "$SRVPID" != "" ]
22 then
23 echo CSQL Server $SRVPID is being killed
24 kill -2 $SRVPID
25 sleep 1
26 kill -9 $SRVPID
27 ipcrm -M 2222 -M 3333 -M 1947
30 echo "csqlserver killed PID=${SERVER_PID}" >>$TEST_LOG
31 rm $DBFILE/*
32 sleep 1
33 $CSQL_INSTALL_ROOT/bin/csqlserver >${SERVOUT} &
34 SERVER_PID=$!
35 echo "csqlserver restarted with PID=${SERVER_PID}" >>$TEST_LOG
36 sleep 5
39 killcsqlsqlserver() {
40 #return;
41 while true
43 SQLPID=`ps -ef | grep csqlsqlserver|grep -v "grep" |tail -1| awk -F" " '{ print $2 }'`
44 if [ "$SQLPID" != "" ]
45 then
46 echo SQL Server $SQLPID is being killed
47 kill -2 $SQLPID
48 sleep 1
49 else break;
51 done
52 #kill checkpoint setver
53 while true
55 CHKPTPID=`ps -ef | grep csqlcheckpointserver |grep -v "grep" |tail -1| awk -F" " '{ print $2 }'`
56 if [ "$CHKPTPID" != "" ]
57 then
58 echo Checkpoint server $CHKPTPID is being killed
59 kill -2 $CHKPTPID
60 sleep 1
61 else break;
63 done
66 ##################### Test Executor main starts here ##################
67 echo MY pid is $$
68 SHELL=/bin/sh
69 #TEST_RUN_DIR should be set before running this
70 if [ ! "$TEST_RUN_ROOT" ]
71 then
72 echo "TEST_RUN_ROOT should be set before running the tests"
73 exit 1
75 if [ ! "$CSQL_INSTALL_ROOT" ]
76 then
77 echo "CSQL_INSTALL_ROOT should be set before running the tests"
78 exit 1
81 if [ ! "$CSQL_CONFIG_FILE" ]
82 then
83 echo "setupenv.ksh should be run before running the tests"
84 exit 1
86 DBFILE=/tmp/csql/db
87 CACHECONFFILE=`grep TABLE_CONFIG_FILE $CSQL_CONFIG_FILE| awk -F= '{ print $2}'`
88 rm $DBFILE/*
89 rm $CACHECONFFILE
90 touch $CACHECONFFILE
91 echo $DBFILE
92 ROOT_DIR=`pwd`
93 mkdir -p $TEST_RUN_ROOT
94 SERVOUT=$TEST_RUN_ROOT/serv.out
95 touch $SERVOUT
97 export CSQL_CONFIG_FILE=csql.conf
98 $CSQL_INSTALL_ROOT/bin/csqlserver >${SERVOUT} &
99 SERVER_PID=$!
100 echo "Starting Server"
101 sleep 5
102 while read MODULE
104 echo $MODULE | grep "#" >/dev/null
105 if [ $? -eq 0 ]
106 then
107 continue
109 echo "MODULE READ is $MODULE"
111 TEST_SCRIPT_DIR=${ROOT_DIR}/${MODULE}
112 TEST_RUN_DIR=${TEST_RUN_ROOT}/${MODULE}
113 if [ -s "$TEST_RUN_DIR" ]
114 then
115 echo "TEST_RUN_ROOT directory is not empty. Clean and try again."
116 exit 1
118 mkdir -p $TEST_RUN_DIR
120 # TODO::check whether server is running
122 TEST_LOG=$TEST_RUN_DIR/testlog
124 if [ -s "$TEST_LOG" ]
125 then
126 echo "TEST_RUN_DIR has files in it. Remove before running the tests"
127 exit 1
130 TEST_EXEC_DIR=$TEST_RUN_DIR/tests
131 mkdir $TEST_EXEC_DIR
134 echo "Test Executor log file" >$TEST_LOG
135 echo "----------------------" >>$TEST_LOG
137 TestList=`ls ${TEST_SCRIPT_DIR}/test*`
138 for test in $TestList
140 if [ "$MODULE" = "system/lock" -o "$MODULE" = "system/trans" -o "$MODULE" = "system/Allocator" ]
141 then
142 restart_csqlserver
145 if [ "$MODULE" = "dbapi/Threads" ]
146 then
147 HANG_TIMEOUT=1000
148 else
149 HANG_TIMEOUT=150
152 echo "Running $test"
153 echo "Running $test" >>$TEST_LOG
154 echo "Test started at : `date` "
155 echo "Test started at : `date` " >>$TEST_LOG
157 expPresent="no"
158 EXPECTED_FILE=exp.`basename ${test}`
159 ARCH=`uname -m`
160 EXP_FILE=$EXPECTED_FILE
161 if [ "$ARCH" = "x86_64" ]
162 then
163 EXP_FILE=$EXPECTED_FILE.$ARCH
166 if [ -s "${TEST_SCRIPT_DIR}/${EXP_FILE}" ]
167 then
168 expPresent="yes"
171 if [ "$expPresent" = "no" ]
172 then
173 if [ -s "${TEST_SCRIPT_DIR}/${EXPECTED_FILE}" ]
174 then
175 expPresent="yes"
176 EXP_FILE=$EXPECTED_FILE
179 echo "EXP_FILE is $EXP_FILE"
182 HANG_FLAG=No
183 trap timeout_handler USR1
184 sleep ${HANG_TIMEOUT} && kill -s USR1 $$ &
185 SLEEP_PID=$!
187 if [ "$expPresent" = "yes" ]
188 then
189 cp ${TEST_SCRIPT_DIR}/${EXP_FILE} ${TEST_EXEC_DIR}
190 ${test} > ${TEST_EXEC_DIR}/cur.${EXP_FILE} 2>/dev/null &
191 else
192 ${test} >> ${TEST_LOG} 2>/dev/null &
194 CMD_PID=$!
195 wait ${CMD_PID} 2>/dev/null
196 ret=$?
197 echo "Test Ended at : `date` "
198 echo "Test Ended at : `date` " >>$TEST_LOG
199 unset CMD_PID
200 trap "" USR1
201 kill -9 ${SLEEP_PID} 2>/dev/null
203 if [ "$HANG_FLAG" = "Yes" ]
204 then
205 echo "Test Hung. so it is killed." >>$TEST_LOG
206 echo "FAILED:Test $test failed" >>$TEST_LOG
207 #TODO::Reinitalize the database, as it may be in corrupted state.
208 CURTIME=`date +%s`
209 mv ${SERVOUT} ${SERVOUT}.${SERVER_PID}.${CURTIME}
210 restart_csqlserver
211 continue
214 HANG_FLAG=No
216 if [ $ret -eq 0 ]
217 then
218 if [ "$expPresent" = "yes" ]
219 then
220 #compare exp and current output
221 diff ${TEST_SCRIPT_DIR}/${EXP_FILE} ${TEST_EXEC_DIR}/cur.${EXP_FILE} > ${TEST_EXEC_DIR}/diff.${EXP_FILE}
222 if [ $? -eq 0 ]
223 then
225 echo "Exp and current output matched."
226 echo "Test $test passed"
227 echo "Exp and current output matched." >>$TEST_LOG
228 echo "PASSED:Test $test passed" >>$TEST_LOG
229 rm ${TEST_EXEC_DIR}/cur.${EXP_FILE}
230 rm ${TEST_EXEC_DIR}/diff.${EXP_FILE}
231 rm ${TEST_EXEC_DIR}/${EXP_FILE}
232 else
233 echo "Exp and current output not matched."
234 echo "Test $test failed"
235 echo "Exp and current output not matched." >>${TEST_LOG}
236 echo "FAILED:Test $test failed" >>$TEST_LOG
237 #TODO::Reinitalize the database, as it may be in corrupted state.
238 CURTIME=`date +%s`
239 mv ${SERVOUT} ${SERVOUT}.${SERVER_PID}.${CURTIME}
240 echo "Refer ${SERVOUT}.${SERVER_PID}.${CURTIME} file for server log" >>$TEST_LOG
241 restart_csqlserver
243 else
244 echo "Returned 0."
245 echo "Test $test passed"
246 echo "Returned 0." >>$TEST_LOG
247 echo "PASSED:Test $test passed" >>$TEST_LOG
250 else
251 echo "Returned $ret "
252 echo "Test $test failed"
253 echo "Returned $ret " >>$TEST_LOG
254 echo "FAILED:Test $test failed" >>$TEST_LOG
255 #TODO::Reinitalize the database, as it may be in corrupted state.
256 CURTIME=`date +%s`
257 mv ${SERVOUT} ${SERVOUT}.${SERVER_PID}.${CURTIME}
258 echo "Refer ${SERVOUT}.${SERVER_PID}.${CURTIME} file for server log" >>$TEST_LOG
259 restart_csqlserver
262 done
263 done < TestModules
264 #kill -9 `ps -e | grep csqlsqlserver | gawk -F" " '{ print $1 }'`
265 killcsqlsqlserver
266 kill -9 ${SERVER_PID}
267 ipcrm -M 2222 -M 3333 -M 1947
268 echo "csqlserver killed PID=${SERVER_PID}" >>${TEST_LOG}
269 rm $DBFILE/*
271 exit 0
272 #---------------------------------------------------------------------
273 #function definitions
274 dummy_restart_csqlserver() {
275 echo "Restarting the server"
276 killcsqlsqlserver
277 kill -9 ${SERVER_PID}
278 ipcrm -M 2222 -M 3333 -M 1947
279 echo "csqlserver killed PID=${SERVER_PID}" >>$TEST_LOG
280 rm $DBFILE/*
281 $CSQL_INSTALL_ROOT/bin/csqlserver >${SERVOUT} &
282 SERVER_PID=$!
283 echo "csqlserver restarted with PID=${SERVER_PID}" >>$TEST_LOG
284 echo "Restarting Server"
285 sleep 5