summaryrefslogtreecommitdiffstats
path: root/systemtest/testjava.sh
blob: 5e1cda79c80cd5f3bce4e28c72d0507498320abb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
#!/bin/ksh
#
# This file is part of rasdaman community.
#
# Rasdaman community is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Rasdaman community is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with rasdaman community.  If not, see <http://www.gnu.org/licenses/>.
#
# Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
# rasdaman GmbH.
#
# For more information please see <http://www.rasdaman.org>
# or contact Peter Baumann via <baumann@rasdaman.com>.
######################### testcenter.sh header ###################
#
# testcenter.sh FOR:
#   Release of RASDAMAN
#
#		
# COMMENTS: needs class examples.TestQuery
# This facility is not necessary because you can start manualy the server
#
##################################################################

TESTER=$USER
CLIENT=$HOSTNAME
SERVER=$HOSTNAME
BASENAME=RASBASE
TESTDATE=$(date +"%d.%m.%Y_%H:%M:%S")
LOGFILE=testjava.log
LOGRCS=javasession.log
INTERACTIVE="off"
SCRIPTS="off"
QUERIES="on"
PRESERVERESULTS="off"
DEBUGCOMMANDS="off"
PROTOCOL=$RMANPROTOCOL

if [[ $1 = "" ]]; then
  TESTDIR="testdata"
else
  TESTDIR=$1
fi

showOptions()
{
    clear
    echo "===================================================================="
    echo "                TEST JAVA OPTIONS:"
    echo "===================================================================="
    echo "  Date...........................: " `date`
    echo "  (T)ester...............: " $TESTER
    echo "  (C)lient name..........: " $CLIENT
    echo "  (S)erver name..........: " $SERVER
    echo "  (B)ase name............: " $BASENAME
    echo "  (L)og file.............: " $LOGFILE
    echo "  (Q)uery dir............: " $TESTDIR
    echo ""
    echo "  (I)nteractive..........: " $INTERACTIVE
    echo "  (P)reserve results.....: " $PRESERVERESULTS
    echo "  (D)ebug commands.......: " $DEBUGCOMMANDS
    echo ""
    echo "  Phase (1) Test Queries.: " $QUERIES
    echo "  Phase (2) Test Scripts.: " $SCRIPTS
    echo ""
    echo " Protocol................: " $PROTOCOL
}
setParameters()
{
  option="*"

  while [[ $option != "" ]]; do

    showOptions

    echo "  \nEnter [tcsblqipd12] to change setting or <return> to continue! \c"
    read option
    echo "\n" 

    if   [[ $option = t ]]; then
      echo "  Enter new name for tester: \c"
      read TESTER
      echo 
    elif [[ $option = c ]]; then
      echo "  Enter new client name: \c"
      read CLIENT
      echo 
    elif [[ $option = s ]]; then
      echo "  Enter new server name: \c"
      read SERVER
      echo 
    elif [[ $option = b ]]; then
      echo "  Enter new base name: \c"
      read BASENAME
      echo 
    elif [[ $option = l ]]; then
      echo "  Enter new name for the log file: \c"
      read LOGFILE
      echo 
    elif [[ $option = q ]]; then
      echo "  Enter new name for the query data directory: \c"
      read TESTDIR
      echo 
    elif [[ $option = i ]]; then
      if [[ $INTERACTIVE = "off" ]]; then
        INTERACTIVE="on"
      else
        INTERACTIVE="off"
      fi
    elif [[ $option = p ]]; then
      if [[ $PRESERVERESULTS = "off" ]]; then
        PRESERVERESULTS="on"
      else
        PRESERVERESULTS="off"
      fi
    elif [[ $option = d ]]; then
      if [[ $DEBUGCOMMANDS = "off" ]]; then
        DEBUGCOMMANDS="on"
      else
        DEBUGCOMMANDS="off"
      fi
    elif [[ $option = 1 ]]; then
      if [[ $QUERIES = "off" ]]; then
        QUERIES="on"
      else
        QUERIES="off"
      fi
    elif [[ $option = 2 ]]; then
      if [[ $SCRIPTS = "off" ]]; then
        SCRIPTS="on"
      else
        SCRIPTS="off"
      fi
    fi

  done
}



testQuery() 
{
  testFile=$1

  echo $testCnt ". Test query: " $testFile "\c"

  YesNo="y"
  if [[ $INTERACTIVE = "on" ]]; then
    echo "  Test it (y/n) ? \c"
    read YesNo
  fi

  if [[ $YesNo = "y" ]]; then
    $query $testFile -testbed > testbedOutput
    checkTestImage $testFile;
  fi
}



testScript() 
{
  testFile=$1

  echo $testCnt ". Test script: " $testFile "\c"

  YesNo="y"
  if [[ $INTERACTIVE = "on" ]]; then
    echo "  Test it (y/n) ? \c"
    read YesNo
  fi

  if [[ $YesNo = "y" ]]; then
    $testFile $SERVER $BASENAME > testbedOutput
    checkTestImage $testFile;
  fi
}



checkTestImage()
{
  returnValue="EXECUTION OK"

  # create info file
  gawk -f testOutputGen.awk testbedOutput > testbedOutputInfo

  # check for verification file
  verificationFile=$testFile".out"

  if [[ ! -a $verificationFile ]]; then
    echo FAILED
    echo "  ERROR: verification file $verificationFile does not exist"

    echo "  Do you want to see the output (y/n) ? \c"
    read YesNo
    echo "\n"

    if [[ $YesNo = y ]]; then
      echo "I. TEST FILE"
      cat $testFile 
      echo "\n\nII. OUTPUT"
      cat testbedOutputInfo
      echo "\n\n"
    fi

    echo "  Do you want to create a verification file (y/n) ? \c"
    read YesNo
    echo "\n"

    if [[ $YesNo = y ]]; then
      cp testbedOutputInfo $verificationFile
      echo "  CREATED\n"
      returnValue="VERIFICATION FILE CREATED"
    else
      echo "  NOT CREATED\n"
      returnValue="VERIFICATION FILE NOT FOUND"
    fi

  else

    diff testbedOutputInfo $verificationFile

    if [[ $? = 1 ]]; then
      echo "FAILED"
      echo "\nProgram output:"
      cat testbedOutput
      echo "\n\n"
      returnValue="EXECUTION FAILED"

      echo "  Do you want to update the verification file (y/n) ? \c"
      read YesNo
      echo "\n"

      if [[ $YesNo = y ]]; then
        co -l $verificationFile
        cp testbedOutputInfo $verificationFile
        echo "  UPDATED\n"
        ci -u -m"testcenter update" $verificationFile
        returnValue="VERIFICATION FILE UPDATED"
      fi

    else
      echo "OK"
    fi

  fi

  rm testbedOutput testbedOutputInfo
}



#
# main
#

# test programs
query="$RMANBASE/java/examples/TestQuery.class"
images="$RMANBASE/systemtest/images"

if [[ ! -a $query ]]; then
  query="$RMANBASE/java/classes/examples/TestQuery.class"
  if [[ ! -a $query ]]; then
    echo "\nTest program $query not found"
    echo "Please build the program and try again."
    return
  fi 
fi

setParameters;
query="$query -s $SERVER -d $BASENAME"
YesNo=""

if [[ -f $LOGFILE ]]; then
  echo "\nDelete log file $LOGFILE (y/n) ? \c"
  read YesNo
  echo "\n\n"
  if [[ $YesNo = y ]]; then
    rm $LOGFILE
  fi
fi


echo "----------------------------------JAVA TEST SESSION-------------------------" >> $LOGFILE
echo "- Date........ : " $TESTDATE >> $LOGFILE
echo "- Tester.......: " $TESTER >> $LOGFILE
echo "- Directory....: " $PWD/$TESTDIR >> $LOGFILE
echo "- Client name..: " $CLIENT >> $LOGFILE
echo "- Server name..: " $SERVER >> $LOGFILE
echo "- Base name....: " $BASENAME >> $LOGFILE
echo "-------------------------------------START----------------------------------" >> $LOGFILE



#
# test query files
#

if [[ $QUERIES = "on" ]]; then
  echo "\nPhase 1: Testing Query Files\n"
  
  if [[ $PRESERVERESULTS = "on" ]]; then
    if [[ $DEBUGCOMMANDS = "on" ]]; then
     echo java -Xms100m -Xmx200m -DRMANPROTOCOL=$PROTOCOL -classpath $CLASSPATH examples.TestQuery -server $SERVER -database $BASENAME -testdirectory $TESTDIR -logfile $LOGFILE -preserveresult
    else 
     java -Xms100m -Xmx200m -DRMANPROTOCOL=$PROTOCOL -classpath $CLASSPATH examples.TestQuery -server $SERVER -database $BASENAME -testdirectory $TESTDIR -logfile $LOGFILE -preserveresult
    fi
  else
    if [[ $DEBUGCOMMANDS = "on" ]]; then
     echo java -Xms100m -Xmx200m -DRMANPROTOCOL=$PROTOCOL -classpath $CLASSPATH examples.TestQuery -server $SERVER -database $BASENAME -testdirectory $TESTDIR -logfile $LOGFILE
    else 
     java -Xms100m -Xmx200m -DRMANPROTOCOL=$PROTOCOL -classpath $CLASSPATH examples.TestQuery -server $SERVER -database $BASENAME -testdirectory $TESTDIR -logfile $LOGFILE
    fi
  fi
  
fi


#
# test scripts
#

if [[ $SCRIPTS = "on" ]]; then
  echo "\nPhase 2: Testing Scripts\n"

  testCnt=1
  scriptFiles=`find scripts -name '*.sh' | sort`

  for scriptFile in $scriptFiles; do

    testScript $scriptFile

    echo "Script " $testCnt $scriptFile":" $returnValue >> $LOGFILE

    testCnt=$(($testCnt+1))
  done
fi

echo "\n-------------------------------------END------------------------------------" >> $LOGFILE
echo "\n\n" >> $LOGFILE


echo "\nTesting finnished.\n"