Test script for getDatabaseManager() without opening connection object
[csql.git] / test / execTests.ksh
blob2f23f574ec6f7df2fb491fb973e660728c3d8085
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
30 ROOT_DIR=`pwd`
31 mkdir -p $TEST_RUN_ROOT
32 SERVOUT=$TEST_RUN_ROOT/serv.out
33 touch $SERVOUT
34 $CSQL_INSTALL_ROOT/bin/csqlserver >${SERVOUT} &
35 SERVER_PID=$!
36 echo "Starting Server"
37 sleep 5
38 while read MODULE
40 echo $MODULE | grep "#" >/dev/null
41 if [ $? -eq 0 ]
42 then
43 continue
45 echo "MODULE READ is $MODULE"
47 if [ "$MODULE" = "system/lock" ]
48 then
49 echo "Restarting the server for lock module"
50 kill -9 ${SERVER_PID}
51 ipcrm -M 2222 -M 3333
52 echo "csqlserver killed PID=${SERVER_PID}" >>$TEST_LOG
53 $CSQL_INSTALL_ROOT/bin/csqlserver >${SERVOUT} &
54 SERVER_PID=$!
55 echo "csqlserver restarted with PID=${SERVER_PID}" >>$TEST_LOG
56 echo "Restarting Server"
57 sleep 5
59 TEST_SCRIPT_DIR=${ROOT_DIR}/${MODULE}
60 TEST_RUN_DIR=${TEST_RUN_ROOT}/${MODULE}
61 if [ -s "$TEST_RUN_DIR" ]
62 then
63 echo "TEST_RUN_ROOT directory is not empty. Clean and try again."
64 exit 1
66 mkdir -p $TEST_RUN_DIR
68 # TODO::check whether server is running
70 TEST_LOG=$TEST_RUN_DIR/testlog
72 if [ -s "$TEST_LOG" ]
73 then
74 echo "TEST_RUN_DIR has files in it. Remove before running the tests"
75 exit 1
78 TEST_EXEC_DIR=$TEST_RUN_DIR/tests
79 mkdir $TEST_EXEC_DIR
82 echo "Test Executor log file" >$TEST_LOG
83 echo "----------------------" >>$TEST_LOG
85 TestList=`ls ${TEST_SCRIPT_DIR}/test*`
86 for test in $TestList
88 echo "Running $test"
89 echo "Running $test" >>$TEST_LOG
90 echo "Test started at : `date` "
91 echo "Test started at : `date` " >>$TEST_LOG
93 expPresent="no"
94 EXP_FILE=exp.`basename ${test}`
95 #echo "EXP_FILE is $EXP_FILE"
96 if [ -s "${TEST_SCRIPT_DIR}/${EXP_FILE}" ]
97 then
98 expPresent="yes"
101 HANG_FLAG=No
102 trap timeout_handler USR1
103 sleep ${HANG_TIMEOUT} && kill -s USR1 $$ &
104 SLEEP_PID=$!
106 if [ "$expPresent" = "yes" ]
107 then
108 cp ${TEST_SCRIPT_DIR}/${EXP_FILE} ${TEST_EXEC_DIR}
109 ${test} > ${TEST_EXEC_DIR}/cur.${EXP_FILE} 2>/dev/null &
110 else
111 ${test} >> ${TEST_LOG} 2>/dev/null &
113 CMD_PID=$!
114 wait ${CMD_PID} 2>/dev/null
115 ret=$?
116 echo "Test Ended at : `date` "
117 echo "Test Ended at : `date` " >>$TEST_LOG
118 unset CMD_PID
119 trap "" USR1
120 kill -9 ${SLEEP_PID} 2>/dev/null
122 if [ "$HANG_FLAG" = "Yes" ]
123 then
124 echo "Test Hung. so it is killed." >>$TEST_LOG
125 echo "FAILED:Test $test failed" >>$TEST_LOG
126 #TODO::Reinitalize the database, as it may be in corrupted state.
127 CURTIME=`date +%s`
128 mv ${SERVOUT} ${SERVOUT}.${SERVER_PID}.${CURTIME}
129 kill -9 ${SERVER_PID}
130 ipcrm -M 2222 -M 3333
131 echo "csqlserver killed PID=${SERVER_PID}" >>$TEST_LOG
132 $CSQL_INSTALL_ROOT/bin/csqlserver >${SERVOUT} &
133 SERVER_PID=$!
134 echo "csqlserver restarted with PID=${SERVER_PID}" >>$TEST_LOG
135 echo "Restarting Server"
136 sleep 5
137 continue
140 HANG_FLAG=No
142 if [ $ret -eq 0 ]
143 then
144 if [ "$expPresent" = "yes" ]
145 then
146 #compare exp and current output
147 diff ${TEST_SCRIPT_DIR}/${EXP_FILE} ${TEST_EXEC_DIR}/cur.${EXP_FILE} > ${TEST_EXEC_DIR}/diff.${EXP_FILE}
148 if [ $? -eq 0 ]
149 then
151 echo "Exp and current output matched."
152 echo "Test $test passed"
153 echo "Exp and current output matched." >>$TEST_LOG
154 echo "PASSED:Test $test passed" >>$TEST_LOG
155 rm ${TEST_EXEC_DIR}/cur.${EXP_FILE}
156 rm ${TEST_EXEC_DIR}/diff.${EXP_FILE}
157 rm ${TEST_EXEC_DIR}/${EXP_FILE}
158 else
159 echo "Exp and current output not matched."
160 echo "Test $test failed"
161 echo "Exp and current output not matched." >>${TEST_LOG}
162 echo "FAILED:Test $test failed" >>$TEST_LOG
163 #TODO::Reinitalize the database, as it may be in corrupted state.
164 CURTIME=`date +%s`
165 mv ${SERVOUT} ${SERVOUT}.${SERVER_PID}.${CURTIME}
166 echo "Refer ${SERVOUT}.${SERVER_PID}.${CURTIME} file for server log" >>$TEST_LOG
167 kill -9 ${SERVER_PID}
168 ipcrm -M 2222 -M 3333
169 echo "csqlserver killed PID=${SERVER_PID}" >>${TEST_LOG}
170 $CSQL_INSTALL_ROOT/bin/csqlserver >${SERVOUT} &
171 SERVER_PID=$!
172 echo "csqlserver restarted with PID=${SERVER_PID}" >>${TEST_LOG}
173 echo "Restarting Server"
174 sleep 5
176 else
177 echo "Returned 0."
178 echo "Test $test passed"
179 echo "Returned 0." >>$TEST_LOG
180 echo "PASSED:Test $test passed" >>$TEST_LOG
183 else
184 echo "Returned $ret "
185 echo "Test $test failed"
186 echo "Returned $ret " >>$TEST_LOG
187 echo "FAILED:Test $test failed" >>$TEST_LOG
188 #TODO::Reinitalize the database, as it may be in corrupted state.
189 CURTIME=`date +%s`
190 mv ${SERVOUT} ${SERVOUT}.${SERVER_PID}.${CURTIME}
191 echo "Refer ${SERVOUT}.${SERVER_PID}.${CURTIME} file for server log" >>$TEST_LOG
192 kill -9 ${SERVER_PID}
193 ipcrm -M 2222 -M 3333
194 echo "csqlserver killed PID=${SERVER_PID}" >>$TEST_LOG
195 $CSQL_INSTALL_ROOT/bin/csqlserver >${SERVOUT} 2>${SERVOUT} &
196 SERVER_PID=$!
197 echo "csqlserver restarted with PID=${SERVER_PID}" >>${TEST_LOG}
198 echo "Restarting Server"
199 sleep 5
202 done
203 done < TestModules
205 kill -9 ${SERVER_PID}
206 ipcrm -M 2222 -M 3333
207 echo "csqlserver killed PID=${SERVER_PID}" >>${TEST_LOG}
209 exit 0