lock manager and chunk allocation mutex modificationsw
[csql.git] / test / execCacheTests.ksh
blob84626f750a609d59b7621d5415661e400d7ab6a2
1 #!/bin/ksh
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
6 # Third argument is user name
7 # Fourth argument is password
9 ################### Settings ########################################
10 #Timeout value for the hanging scripts
11 HANG_TIMEOUT=200
13 ################### TIMEOUT HANDLER #################################
14 timeout_handler() {
15 if [ $CMD_PID != "" ]
16 then
17 HANG_FLAG=Yes
18 echo "HANG_FLAG is set here"
19 kill -9 $CMD_PID 2>/dev/null
22 restart_csqlserver() {
23 echo "Restarting the server"
24 kill -2 ${SERVER_PID}
25 killcsqlsqlserver
26 SRVPID=`ps -ef | grep csqlserver|grep -v "grep" |tail -1| awk -F" " '{ print $2 }'`
27 if [ "$SRVPID" != "" ]
28 then
29 echo CSQL Server $SRVPID is being killed
30 kill -2 $SRVPID
31 sleep 1
32 kill -9 $SRVPID
33 ipcrm -M 2222 -M 3333 -M 1947
36 echo "csqlserver killed PID=${SERVER_PID}" >>$TEST_LOG
37 # rm -f /tmp/csql.conf
38 rm -rf /tmp/csql/*
39 mkdir /tmp/csql/log
40 mkdir /tmp/csql/db
41 cp $CSQL_SRCROOT/csql.conf /tmp/csql/csql.conf
42 export CSQL_CONFIG_FILE=/tmp/csql/csql.conf
43 echo "MMAP=false" >>/tmp/csql/csql.conf
44 echo "CSQL_SQL_SERVER=true">>/tmp/csql/csql.conf
45 # rm -rf /tmp/csql/*
46 # mkdir /tmp/csql/log
47 # mkdir /tmp/csql/db
48 touch /tmp/csql/csqltable.conf
49 touch /tmp/csql/csqlnw.conf
50 touch /tmp/csql/csqlds.conf
51 $CSQL_INSTALL_ROOT/bin/csqlds -U $DBUSER -P $PASSWORD -D $DSN -N $TDB -a
52 $CSQL_INSTALL_ROOT/bin/csqlserver >${SERVOUT} &
53 SERVER_PID=$!
54 echo "csqlserver restarted with PID=${SERVER_PID}" >>$TEST_LOG
55 sleep 5
58 killcsqlsqlserver() {
59 #return;
60 while true
62 SQLPID=`ps -ef | grep csqlsqlserver|grep -v "grep" |tail -1| awk -F" " '{ print $2 }'`
63 if [ "$SQLPID" != "" ]
64 then
65 echo SQL Server $SQLPID is being killed
66 kill -2 $SQLPID
67 sleep 1
68 else break;
70 done
71 #kill checkpoint setver
72 while true
74 CHKPTPID=`ps -ef | grep csqlcheckpointserver |grep -v "grep" |tail -1| awk -F" " '{ print $2 }'`
75 if [ "$CHKPTPID" != "" ]
76 then
77 echo Checkpoint server $CHKPTPID is being killed
78 kill -2 $CHKPTPID
79 sleep 1
80 else break;
82 done
85 ##################### Test Executor main starts here ##################
86 echo MY pid is $$
87 if [ ! "$CSQL_CONFIG_FILE" ]
88 then
89 echo "setupenv.ksh script is not run"
90 exit 1
92 SHELL=/bin/sh
93 #TEST_RUN_DIR should be set before running this
94 if [ ! "$TEST_RUN_ROOT" -a ! "$MODULE_NAME" ]
95 then
96 echo "TEST_RUN_ROOT should be set before running the tests"
97 exit 1
99 if [ ! "$CSQL_INSTALL_ROOT" ]
100 then
101 echo "CSQL_INSTALL_ROOT should be set before running the tests"
102 exit 1
105 cp $CSQL_SRCROOT/csql.conf /tmp/csql/csql.conf
106 export CSQL_CONFIG_FILE=/tmp/csql/csql.conf
107 echo "MMAP=false" >>/tmp/csql.conf
108 echo "CSQL_SQL_SERVER=true">>/tmp/csql.conf
109 export DSN=$1
110 export DBUSER=$3
111 export PASSWORD=$4
112 export TDB=$2
113 echo "First argument is " $1
114 if [ $# -ne 4 ]
115 then
116 isql $1 $3 $4 </dev/null >/dev/null 2>/dev/null
117 if [ $? -ne 0 ]
118 then
119 echo "Unable to connect to data source"
120 exit 1
122 echo DSN=$1 >>$CSQL_CONFIG_FILE
123 else
124 isql $1 $3 $4</dev/null >/dev/null 2>/dev/null
125 if [ $? -ne 0 ]
126 then
127 echo "Unable to connect to data source"
128 exit 1
130 echo DSN=$1 >>$CSQL_CONFIG_FILE
133 #setting up multiDSN
134 . ./setMultiDsn.ksh
135 if [ ! "$MYSQL_DSN" ]
136 then
137 echo "Set up needs to be done for MultiDSN by edit setMultiDsn.ksh file for all TDBs."
138 exit 1
141 ROOT_DIR=`pwd`
142 if [ ! "$MODULE_NAME" ]
143 then
145 mkdir -p $TEST_RUN_ROOT
146 SERVOUT=$TEST_RUN_ROOT/serv.out
147 touch $SERVOUT
148 $CSQL_INSTALL_ROOT/bin/csqlserver >${SERVOUT} &
149 SERVER_PID=$!
150 echo "Starting Server"
151 sleep 5
152 while read MODULE
154 echo $MODULE | grep "#" >/dev/null
155 if [ $? -eq 0 ]
156 then
157 continue
159 echo "MODULE READ is $MODULE"
160 #if [ "$MODULE" = "adapter/Connect" -o "$MODULE" = "adapter/Parameter" -o "$MODULE" = "adapter/Select" ]
161 #then
162 rm -f /tmp/csql/csqlds.conf
163 touch /tmp/csql/csqlds.conf
164 $CSQL_INSTALL_ROOT/bin/csqlds -U $DBUSER -P $PASSWORD -D $DSN -N $TDB -a
165 if [ $? -ne 0 ]
166 then
167 exit 1;
170 TEST_SCRIPT_DIR=${ROOT_DIR}/${MODULE}
171 TEST_RUN_DIR=${TEST_RUN_ROOT}/${MODULE}
172 if [ -s "$TEST_RUN_DIR" ]
173 then
174 kill -9 $SERVER_PID
175 ipcrm -M 2222 -M 3333 -M 1947
176 echo "TEST_RUN_ROOT directory is not empty. Clean and try again."
177 exit 1
179 mkdir -p $TEST_RUN_DIR
181 # TODO::check whether server is running
183 TEST_LOG=$TEST_RUN_DIR/testlog
185 if [ -s "$TEST_LOG" ]
186 then
187 echo "TEST_RUN_DIR has files in it. Remove before running the tests"
188 exit 1
191 TEST_EXEC_DIR=$TEST_RUN_DIR/tests
192 mkdir $TEST_EXEC_DIR
195 echo "Test Executor log file" >$TEST_LOG
196 echo "----------------------" >>$TEST_LOG
198 TestList=`ls ${TEST_SCRIPT_DIR}/test*`
199 for test in $TestList
201 echo "Running $test"
202 echo "Running $test" >>$TEST_LOG
203 echo "Test started at : `date` "
204 echo "Test started at : `date` " >>$TEST_LOG
206 expPresent="no"
207 arch="no"
208 os="no"
209 EXPECTED_FILE=exp.`basename ${test}`
210 ARCH=`uname -m`
211 EXP_FILE=$EXPECTED_FILE
212 if [ "$ARCH" = "x86_64" ]
213 then
214 EXP_FILE=$EXPECTED_FILE.$ARCH
215 arch="yes"
217 if [ -s "${TEST_SCRIPT_DIR}/${EXP_FILE}" -a "$arch" = "yes" ]
218 then
219 expPresent="yes"
221 OS=`uname`
222 if [ "$OS" = "SunOS" ]
223 then
224 EXP_FILE=$EXPECTED_FILE.$OS
225 os="yes"
227 if [ -s "${TEST_SCRIPT_DIR}/${EXP_FILE}" -a "$os" = "yes" ]
228 then
229 expPresent="yes"
231 if [ "$expPresent" = "no" ]
232 then
233 EXP_FILE=$EXPECTED_FILE.$DSN
235 if [ -s "${TEST_SCRIPT_DIR}/${EXP_FILE}" ]
236 then
237 expPresent="yes"
239 if [ "$expPresent" = "no" ]
240 then
241 if [ -s "${TEST_SCRIPT_DIR}/${EXPECTED_FILE}" ]
242 then
243 expPresent="yes"
244 EXP_FILE=$EXPECTED_FILE
248 echo "EXP_FILE is $EXP_FILE"
250 HANG_FLAG=No
251 trap timeout_handler USR1
252 sleep ${HANG_TIMEOUT} && kill -s USR1 $$ &
253 SLEEP_PID=$!
255 if [ "$expPresent" = "yes" ]
256 then
257 cp ${TEST_SCRIPT_DIR}/${EXP_FILE} ${TEST_EXEC_DIR}
258 ${test} > ${TEST_EXEC_DIR}/cur.${EXP_FILE} 2>/dev/null &
259 else
260 ${test} >> ${TEST_LOG} 2>/dev/null &
262 CMD_PID=$!
263 wait ${CMD_PID} 2>/dev/null
264 ret=$?
265 echo "Test Ended at : `date` "
266 echo "Test Ended at : `date` " >>$TEST_LOG
267 unset CMD_PID
268 trap "" USR1
269 kill -9 ${SLEEP_PID} 2>/dev/null
271 if [ "$HANG_FLAG" = "Yes" ]
272 then
273 echo "Test Hung. so it is killed." >>$TEST_LOG
274 echo "FAILED:Test $test failed" >>$TEST_LOG
275 #TODO::Reinitalize the database, as it may be in corrupted state.
276 CURTIME=`date +%s`
277 mv ${SERVOUT} ${SERVOUT}.${SERVER_PID}.${CURTIME}
278 restart_csqlserver
279 continue
282 HANG_FLAG=No
284 if [ $ret -eq 0 ]
285 then
286 if [ "$expPresent" = "yes" ]
287 then
288 #compare exp and current output
289 diff ${TEST_SCRIPT_DIR}/${EXP_FILE} ${TEST_EXEC_DIR}/cur.${EXP_FILE} > ${TEST_EXEC_DIR}/diff.${EXP_FILE}
290 if [ $? -eq 0 ]
291 then
293 echo "Exp and current output matched."
294 echo "Test $test passed"
295 echo "Exp and current output matched." >>$TEST_LOG
296 echo "PASSED:Test $test passed" >>$TEST_LOG
297 rm ${TEST_EXEC_DIR}/cur.${EXP_FILE}
298 rm ${TEST_EXEC_DIR}/diff.${EXP_FILE}
299 rm ${TEST_EXEC_DIR}/${EXP_FILE}
300 else
301 echo "Exp and current output not matched."
302 echo "Test $test failed"
303 echo "Exp and current output not matched." >>${TEST_LOG}
304 echo "FAILED:Test $test failed" >>$TEST_LOG
305 #TODO::Reinitalize the database, as it may be in corrupted state.
306 CURTIME=`date +%s`
307 mv ${SERVOUT} ${SERVOUT}.${SERVER_PID}.${CURTIME}
308 echo "Refer ${SERVOUT}.${SERVER_PID}.${CURTIME} file for server log" >>$TEST_LOG
309 restart_csqlserver
311 else
312 echo "Returned 0."
313 echo "Test $test passed"
314 echo "Returned 0." >>$TEST_LOG
315 echo "PASSED:Test $test passed" >>$TEST_LOG
318 else
319 echo "Returned $ret "
320 echo "Test $test failed"
321 echo "Returned $ret " >>$TEST_LOG
322 echo "FAILED:Test $test failed" >>$TEST_LOG
323 #TODO::Reinitalize the database, as it may be in corrupted state.
324 CURTIME=`date +%s`
325 mv ${SERVOUT} ${SERVOUT}.${SERVER_PID}.${CURTIME}
326 echo "Refer ${SERVOUT}.${SERVER_PID}.${CURTIME} file for server log" >>$TEST_LOG
327 restart_csqlserver
330 done
331 done < CacheTestModules
332 kill -9 ${SERVER_PID}
333 killcsqlsqlserver
334 ipcrm -M 2222 -M 3333 -M 1947
335 echo "csqlserver killed PID=${SERVER_PID}" >>${TEST_LOG}
337 else
339 #For Single Script Test
340 if [ ! "$SCRIPT_NAME" ]
341 then
342 echo "Set SCRIPT_NAME to execute single script"
343 exit 1
345 $CSQL_INSTALL_ROOT/bin/csqlserver >/dev/null 2>&1 &
346 SERVER_PID=$!
347 echo "Starting Server"
348 sleep 5
349 echo "MODULE Name is $MODULE_NAME"
350 echo "SCRIPT Name is $SCRIPT_NAME"
351 if [ "$MODULE_NAME" = "adapter/Connect" -o "$MODULE_NAME" = "adapter/Parameter" -o "$MODULE_NAME" = "adapter/Select" ]
352 then
353 rm -f /tmp/csql/csqlds.conf
354 touch /tmp/csql/csqlds.conf
355 $CSQL_INSTALL_ROOT/bin/csqlds -U $DBUSER -P $PASSWORD -D $DSN -N $TDB -a
356 if [ $? -ne 0 ]
357 then
358 exit 1;
361 test=${ROOT_DIR}/${MODULE_NAME}/${SCRIPT_NAME}
362 echo "Running $test"
363 echo "Test started at : `date` "
364 expPresent="no"
365 EXPECTED_FILE=exp.`basename ${test}`
366 EXP_FILE=$EXPECTED_FILE.$DSN
367 TEST_SCRIPT_DIR=${ROOT_DIR}/${MODULE_NAME}
368 if [ -s "${TEST_SCRIPT_DIR}/${EXP_FILE}" ]
369 then
370 expPresent="yes"
372 if [ "$expPresent" = "no" ]
373 then
374 if [ -s "${TEST_SCRIPT_DIR}/${EXPECTED_FILE}" ]
375 then
376 expPresent="yes"
377 EXP_FILE=$EXPECTED_FILE
380 echo "EXP_FILE is $EXP_FILE"
381 HANG_FLAG=No
382 trap timeout_handler USR1
383 sleep ${HANG_TIMEOUT} && kill -s USR1 $$ &
384 SLEEP_PID=$!
385 if [ "$expPresent" = "yes" ]
386 then
387 cp ${TEST_SCRIPT_DIR}/${EXP_FILE} ${ROOT_DIR}
388 ${test} >${ROOT_DIR}/cur.${EXP_FILE} 2>/dev/null &
389 else
390 ${test} 2>/dev/null &
392 CMD_PID=$!
393 wait ${CMD_PID} 2>/dev/null
394 ret=$?
395 echo "Test Ended at : `date` "
396 unset CMD_PID
397 trap "" USR1
398 kill -9 ${SLEEP_PID} 2>/dev/null
399 if [ "$HANG_FLAG" = "Yes" ]
400 then
401 CURTIME=`date +%s`
402 mv ${SERVOUT} ${SERVOUT}.${SERVER_PID}.${CURTIME}
403 kill -9 ${SERVER_PID}
404 ipcrm -M 2222 -M 3333
405 echo "csqlserver killed due to HANG_FLAG PID=${SERVER_PID}"
407 HANG_FLAG=No
408 if [ $ret -eq 0 ]
409 then
410 if [ "$expPresent" = "yes" ]
411 then
412 diff ${TEST_SCRIPT_DIR}/${EXP_FILE} ${ROOT_DIR}/cur.${EXP_FILE} > ${ROOT_DIR}/diff.${EXP_FILE}
413 if [ $? -eq 0 ]
414 then
415 echo "Exp and current output matched."
416 echo "Test $test passed"
417 rm -f ${ROOT_DIR}/cur.${EXP_FILE} ${ROOT_DIR}/diff.${EXP_FILE} ${ROOT_DIR}/${EXP_FILE}
418 else
419 echo "Exp and current output not matched."
420 echo "Test $test failed"
422 else
423 echo "Returned 0."
424 echo "Test $test passed"
426 else
427 echo "Returned $ret "
428 echo "Test $test failed"
430 kill -9 ${SERVER_PID}
431 killcsqlsqlserver
432 ipcrm -M 2222 -M 3333 -M 1947
435 exit 0