adding test scripts
[csql.git] / test / execTests.ksh
blobb92a251cb77026e97bc1a07e4c975684fac52b5a
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
144 echo "Running $test"
145 echo "Running $test" >>$TEST_LOG
146 echo "Test started at : `date` "
147 echo "Test started at : `date` " >>$TEST_LOG
149 expPresent="no"
150 EXPECTED_FILE=exp.`basename ${test}`
151 ARCH=`uname -m`
152 EXP_FILE=$EXPECTED_FILE
153 if [ "$ARCH" = "x86_64" ]
154 then
155 EXP_FILE=$EXPECTED_FILE.$ARCH
158 if [ -s "${TEST_SCRIPT_DIR}/${EXP_FILE}" ]
159 then
160 expPresent="yes"
163 if [ "$expPresent" = "no" ]
164 then
165 if [ -s "${TEST_SCRIPT_DIR}/${EXPECTED_FILE}" ]
166 then
167 expPresent="yes"
168 EXP_FILE=$EXPECTED_FILE
171 echo "EXP_FILE is $EXP_FILE"
174 HANG_FLAG=No
175 trap timeout_handler USR1
176 sleep ${HANG_TIMEOUT} && kill -s USR1 $$ &
177 SLEEP_PID=$!
179 if [ "$expPresent" = "yes" ]
180 then
181 cp ${TEST_SCRIPT_DIR}/${EXP_FILE} ${TEST_EXEC_DIR}
182 ${test} > ${TEST_EXEC_DIR}/cur.${EXP_FILE} 2>/dev/null &
183 else
184 ${test} >> ${TEST_LOG} 2>/dev/null &
186 CMD_PID=$!
187 wait ${CMD_PID} 2>/dev/null
188 ret=$?
189 echo "Test Ended at : `date` "
190 echo "Test Ended at : `date` " >>$TEST_LOG
191 unset CMD_PID
192 trap "" USR1
193 kill -9 ${SLEEP_PID} 2>/dev/null
195 if [ "$HANG_FLAG" = "Yes" ]
196 then
197 echo "Test Hung. so it is killed." >>$TEST_LOG
198 echo "FAILED:Test $test failed" >>$TEST_LOG
199 #TODO::Reinitalize the database, as it may be in corrupted state.
200 CURTIME=`date +%s`
201 mv ${SERVOUT} ${SERVOUT}.${SERVER_PID}.${CURTIME}
202 restart_csqlserver
203 continue
206 HANG_FLAG=No
208 if [ $ret -eq 0 ]
209 then
210 if [ "$expPresent" = "yes" ]
211 then
212 #compare exp and current output
213 diff ${TEST_SCRIPT_DIR}/${EXP_FILE} ${TEST_EXEC_DIR}/cur.${EXP_FILE} > ${TEST_EXEC_DIR}/diff.${EXP_FILE}
214 if [ $? -eq 0 ]
215 then
217 echo "Exp and current output matched."
218 echo "Test $test passed"
219 echo "Exp and current output matched." >>$TEST_LOG
220 echo "PASSED:Test $test passed" >>$TEST_LOG
221 rm ${TEST_EXEC_DIR}/cur.${EXP_FILE}
222 rm ${TEST_EXEC_DIR}/diff.${EXP_FILE}
223 rm ${TEST_EXEC_DIR}/${EXP_FILE}
224 else
225 echo "Exp and current output not matched."
226 echo "Test $test failed"
227 echo "Exp and current output not matched." >>${TEST_LOG}
228 echo "FAILED:Test $test failed" >>$TEST_LOG
229 #TODO::Reinitalize the database, as it may be in corrupted state.
230 CURTIME=`date +%s`
231 mv ${SERVOUT} ${SERVOUT}.${SERVER_PID}.${CURTIME}
232 echo "Refer ${SERVOUT}.${SERVER_PID}.${CURTIME} file for server log" >>$TEST_LOG
233 restart_csqlserver
235 else
236 echo "Returned 0."
237 echo "Test $test passed"
238 echo "Returned 0." >>$TEST_LOG
239 echo "PASSED:Test $test passed" >>$TEST_LOG
242 else
243 echo "Returned $ret "
244 echo "Test $test failed"
245 echo "Returned $ret " >>$TEST_LOG
246 echo "FAILED:Test $test failed" >>$TEST_LOG
247 #TODO::Reinitalize the database, as it may be in corrupted state.
248 CURTIME=`date +%s`
249 mv ${SERVOUT} ${SERVOUT}.${SERVER_PID}.${CURTIME}
250 echo "Refer ${SERVOUT}.${SERVER_PID}.${CURTIME} file for server log" >>$TEST_LOG
251 restart_csqlserver
254 done
255 done < TestModules
256 #kill -9 `ps -e | grep csqlsqlserver | gawk -F" " '{ print $1 }'`
257 killcsqlsqlserver
258 kill -9 ${SERVER_PID}
259 ipcrm -M 2222 -M 3333 -M 1947
260 echo "csqlserver killed PID=${SERVER_PID}" >>${TEST_LOG}
261 rm $DBFILE/*
263 exit 0
264 #---------------------------------------------------------------------
265 #function definitions
266 dummy_restart_csqlserver() {
267 echo "Restarting the server"
268 killcsqlsqlserver
269 kill -9 ${SERVER_PID}
270 ipcrm -M 2222 -M 3333 -M 1947
271 echo "csqlserver killed PID=${SERVER_PID}" >>$TEST_LOG
272 rm $DBFILE/*
273 $CSQL_INSTALL_ROOT/bin/csqlserver >${SERVOUT} &
274 SERVER_PID=$!
275 echo "csqlserver restarted with PID=${SERVER_PID}" >>$TEST_LOG
276 echo "Restarting Server"
277 sleep 5