Removing unnecessary DSN=myodbc3 lines from conf files
[csql.git] / test / execCacheTests.ksh
blob3b02c794bf5254de5e18e95498d38d2b3de2edf2
1 #!/bin/sh
3 # First argument is the data source name to be used
4 # Second argument is the target database name
5 # valid names: MYSQL, PSQL, ORACLE
7 ################### Settings ########################################
8 #Timeout value for the hanging scripts
9 HANG_TIMEOUT=150
11 ################### TIMEOUT HANDLER #################################
12 timeout_handler() {
13 if [ $CMD_PID != "" ]
14 then
15 HANG_FLAG=Yes
16 echo "HANG_FLAG is set here"
17 kill -9 $CMD_PID 2>/dev/null
21 ##################### Test Executor main starts here ##################
22 echo MY pid is $$
23 if [ ! "$CSQL_CONFIG_FILE" ]
24 then
25 echo "setupenv.ksh script is not run"
26 exit 1
28 #TEST_RUN_DIR should be set before running this
29 if [ ! "$TEST_RUN_ROOT" ]
30 then
31 echo "TEST_RUN_ROOT should be set before running the tests"
32 exit 1
34 if [ ! "$CSQL_INSTALL_ROOT" ]
35 then
36 echo "CSQL_INSTALL_ROOT should be set before running the tests"
37 exit 1
39 export DSN=$1
40 export TDB=$2
41 echo "First argument is " $1
42 isql $1 </dev/null >/dev/null 2>/dev/null
43 if [ $? -ne 0 ]
44 then
45 echo "Unable to connect to data source"
46 exit 1
49 cp $CSQL_CONFIG_FILE /tmp/csql.conf
50 echo DSN=$1 >>$CSQL_CONFIG_FILE
52 ROOT_DIR=`pwd`
53 mkdir -p $TEST_RUN_ROOT
54 SERVOUT=$TEST_RUN_ROOT/serv.out
55 touch $SERVOUT
56 $CSQL_INSTALL_ROOT/bin/csqlserver >${SERVOUT} &
57 SERVER_PID=$!
58 echo "Starting Server"
59 sleep 5
60 while read MODULE
62 echo $MODULE | grep "#" >/dev/null
63 if [ $? -eq 0 ]
64 then
65 continue
67 echo "MODULE READ is $MODULE"
69 TEST_SCRIPT_DIR=${ROOT_DIR}/${MODULE}
70 TEST_RUN_DIR=${TEST_RUN_ROOT}/${MODULE}
71 if [ -s "$TEST_RUN_DIR" ]
72 then
73 echo "TEST_RUN_ROOT directory is not empty. Clean and try again."
74 exit 1
76 mkdir -p $TEST_RUN_DIR
78 # TODO::check whether server is running
80 TEST_LOG=$TEST_RUN_DIR/testlog
82 if [ -s "$TEST_LOG" ]
83 then
84 echo "TEST_RUN_DIR has files in it. Remove before running the tests"
85 exit 1
88 TEST_EXEC_DIR=$TEST_RUN_DIR/tests
89 mkdir $TEST_EXEC_DIR
92 echo "Test Executor log file" >$TEST_LOG
93 echo "----------------------" >>$TEST_LOG
95 TestList=`ls ${TEST_SCRIPT_DIR}/test*`
96 for test in $TestList
98 echo "Running $test"
99 echo "Running $test" >>$TEST_LOG
100 echo "Test started at : `date` "
101 echo "Test started at : `date` " >>$TEST_LOG
103 expPresent="no"
104 EXP_FILE=exp.`basename ${test}`
105 #echo "EXP_FILE is $EXP_FILE"
106 if [ -s "${TEST_SCRIPT_DIR}/${EXP_FILE}" ]
107 then
108 expPresent="yes"
111 HANG_FLAG=No
112 trap timeout_handler USR1
113 sleep ${HANG_TIMEOUT} && kill -s USR1 $$ &
114 SLEEP_PID=$!
116 if [ "$expPresent" = "yes" ]
117 then
118 cp ${TEST_SCRIPT_DIR}/${EXP_FILE} ${TEST_EXEC_DIR}
119 ${test} > ${TEST_EXEC_DIR}/cur.${EXP_FILE} 2>/dev/null &
120 else
121 ${test} >> ${TEST_LOG} 2>/dev/null &
123 CMD_PID=$!
124 wait ${CMD_PID} 2>/dev/null
125 ret=$?
126 echo "Test Ended at : `date` "
127 echo "Test Ended at : `date` " >>$TEST_LOG
128 unset CMD_PID
129 trap "" USR1
130 kill -9 ${SLEEP_PID} 2>/dev/null
132 if [ "$HANG_FLAG" = "Yes" ]
133 then
134 echo "Test Hung. so it is killed." >>$TEST_LOG
135 echo "FAILED:Test $test failed" >>$TEST_LOG
136 #TODO::Reinitalize the database, as it may be in corrupted state.
137 CURTIME=`date +%s`
138 mv ${SERVOUT} ${SERVOUT}.${SERVER_PID}.${CURTIME}
139 kill -9 ${SERVER_PID}
140 ipcrm -M 2222 -M 3333
141 echo "csqlserver killed PID=${SERVER_PID}" >>$TEST_LOG
142 $CSQL_INSTALL_ROOT/bin/csqlserver >${SERVOUT} &
143 SERVER_PID=$!
144 echo "csqlserver restarted with PID=${SERVER_PID}" >>$TEST_LOG
145 echo "Restarting Server"
146 sleep 5
147 continue
150 HANG_FLAG=No
152 if [ $ret -eq 0 ]
153 then
154 if [ "$expPresent" = "yes" ]
155 then
156 #compare exp and current output
157 diff ${TEST_SCRIPT_DIR}/${EXP_FILE} ${TEST_EXEC_DIR}/cur.${EXP_FILE} > ${TEST_EXEC_DIR}/diff.${EXP_FILE}
158 if [ $? -eq 0 ]
159 then
161 echo "Exp and current output matched."
162 echo "Test $test passed"
163 echo "Exp and current output matched." >>$TEST_LOG
164 echo "PASSED:Test $test passed" >>$TEST_LOG
165 rm ${TEST_EXEC_DIR}/cur.${EXP_FILE}
166 rm ${TEST_EXEC_DIR}/diff.${EXP_FILE}
167 rm ${TEST_EXEC_DIR}/${EXP_FILE}
168 else
169 echo "Exp and current output not matched."
170 echo "Test $test failed"
171 echo "Exp and current output not matched." >>${TEST_LOG}
172 echo "FAILED:Test $test failed" >>$TEST_LOG
173 #TODO::Reinitalize the database, as it may be in corrupted state.
174 CURTIME=`date +%s`
175 mv ${SERVOUT} ${SERVOUT}.${SERVER_PID}.${CURTIME}
176 echo "Refer ${SERVOUT}.${SERVER_PID}.${CURTIME} file for server log" >>$TEST_LOG
177 kill -9 ${SERVER_PID}
178 ipcrm -M 2222 -M 3333
179 echo "csqlserver killed PID=${SERVER_PID}" >>${TEST_LOG}
180 $CSQL_INSTALL_ROOT/bin/csqlserver >${SERVOUT} &
181 SERVER_PID=$!
182 echo "csqlserver restarted with PID=${SERVER_PID}" >>${TEST_LOG}
183 echo "Restarting Server"
184 sleep 5
186 else
187 echo "Returned 0."
188 echo "Test $test passed"
189 echo "Returned 0." >>$TEST_LOG
190 echo "PASSED:Test $test passed" >>$TEST_LOG
193 else
194 echo "Returned $ret "
195 echo "Test $test failed"
196 echo "Returned $ret " >>$TEST_LOG
197 echo "FAILED:Test $test failed" >>$TEST_LOG
198 #TODO::Reinitalize the database, as it may be in corrupted state.
199 CURTIME=`date +%s`
200 mv ${SERVOUT} ${SERVOUT}.${SERVER_PID}.${CURTIME}
201 echo "Refer ${SERVOUT}.${SERVER_PID}.${CURTIME} file for server log" >>$TEST_LOG
202 kill -9 ${SERVER_PID}
203 ipcrm -M 2222 -M 3333
204 echo "csqlserver killed PID=${SERVER_PID}" >>$TEST_LOG
205 $CSQL_INSTALL_ROOT/bin/csqlserver >${SERVOUT} 2>${SERVOUT} &
206 SERVER_PID=$!
207 echo "csqlserver restarted with PID=${SERVER_PID}" >>${TEST_LOG}
208 echo "Restarting Server"
209 sleep 5
212 done
213 done < CacheTestModules
215 kill -9 ${SERVER_PID}
216 ipcrm -M 2222 -M 3333
217 echo "csqlserver killed PID=${SERVER_PID}" >>${TEST_LOG}
218 cp /tmp/csql.conf $CSQL_CONFIG_FILE
219 exit 0