1 #!/bin/ksh
2 #**************************************************************
3 #
4 #  Licensed to the Apache Software Foundation (ASF) under one
5 #  or more contributor license agreements.  See the NOTICE file
6 #  distributed with this work for additional information
7 #  regarding copyright ownership.  The ASF licenses this file
8 #  to you under the Apache License, Version 2.0 (the
9 #  "License"); you may not use this file except in compliance
10 #  with the License.  You may obtain a copy of the License at
11 #
12 #    http://www.apache.org/licenses/LICENSE-2.0
13 #
14 #  Unless required by applicable law or agreed to in writing,
15 #  software distributed under the License is distributed on an
16 #  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 #  KIND, either express or implied.  See the License for the
18 #  specific language governing permissions and limitations
19 #  under the License.
20 #
21 #**************************************************************
22 
23 #set -x
24 umask 0
25 
26 integer TOTAL_PASS=0
27 integer TOTAL_FAIL=0
28 integer TOTAL_RUN=0
29 integer MAX_RETRIES=5
30 typeset RUNNAME=`date +%Y%m%d%H%M%S`
31 typeset PRINTDATE=`date`
32 typeset PDB_INFILE_DIR
33 typeset PDB_OUTFILE_DIR
34 typeset XML_OUTFILE_DIR
35 typeset REPORT
36 typeset RESDIR
37 typeset LOGFILE
38 typeset COMPLOG
39 typeset TEST_COMMENTS
40 typeset BGCOLOR
41 typeset ODD_BGCOLOR='#BBBBBB'
42 typeset EVEN_BGCOLOR='#DCDCDC'
43 typeset PASS_COLOR='#00ff00'
44 typeset FAIL_COLOR='#ff4040'
45 
46 typeset ENVFILE=""
47 # The following variables should be set in the env file
48 typeset MASTERLIST=""
49 typeset TESTCASEDIR=""
50 typeset RESULTSBASE=""
51 typeset XMERGE_JAR=""
52 typeset APORTIS_JAR=""
53 typeset WORDSMITH_JAR=""
54 typeset MINICALC_JAR=""
55 typeset PERL5LIB=""
56 typeset POSE_EXE=""
57 typeset POSE_PRC=""
58 typeset TEST_DRIVER_PL=""
59 typeset COMPARATOR_PL=""
60 typeset COMPLIST=""
61 typeset XML_INFILE_DIR=""
62 typeset PDB_BASELINE_DIR=""
63 typeset XML_BASELINE_DIR=""
64 typeset EM_SCRIPT_HOME=""
65 typeset QAWRAPPER_SCRIPT_HOME=""
66 typeset EM_ROM_FILE=""
67 typeset EM_SESSION_FILE=""
68 typeset QA_LIB_HOME=""
69 typeset QA_COMPARATOR_HOME=""
70 typeset CLASSES_DIR=""
71 
72 
73 
74 ################################################################################
75 Usage() {
76 	echo "Usage: run-convtest -env <ENVFILE> [-name RUNNAME]"
77 	exit 1
78 }
79 
80 
81 ################################################################################
82 StartReportFile() {
83 	typeset line=`date`
84 
85 	ReportLine "<HTML>"
86 	ReportLine "<HEAD>"
87 	ReportLine "<TITLE>XMerge Converters Test Results - ${RUNNAME}</TITLE>"
88 	ReportLine "</HEAD>"
89 	ReportLine "<BODY BGCOLOR=#ffffff>"
90 	ReportLine "<H1 align=center>XMerge Converters Test Results - ${RUNNAME}</H1>"
91 	ReportLine "<P>"
92 	ReportLine "Test run on: ${PRINTDATE}"
93 	ReportLine "<P>"
94 	ReportLine "<CENTER>"
95 	ReportLine "<TABLE WIDTH='100%' BORDER=1 CELLSPACING=0 CELLPADDING=2>"
96 	ReportLine "<TR BGCOLOR='#9999CC'>"
97 	ReportLine "<TH>Test Name</TH>"
98 	ReportLine "<TH>Test File</TH>"
99 	ReportLine "<TH>.ext</TH>"
100 	ReportLine "<TH>Result</TH>"
101 	ReportLine "<TH>Comments</TH>"
102 	ReportLine "</TR>"
103 }
104 
105 
106 ################################################################################
107 EndReportFile() {
108 	# remove full path from LOGFILE (link will be to current dir)
109 	typeset loglink=${LOGFILE##*/}
110 
111 	ReportLine "<P>"
112 	ReportLine "<CENTER>"
113 	ReportLine "<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=2>"
114 	ReportLine "<TR>"
115 	ReportLine "<TH>Total Tests PASSED</TH>"
116 	ReportLine "<TH>${TOTAL_PASS}</TH>"
117 	ReportLine "</TR>"
118 	ReportLine "<TR>"
119 	ReportLine "<TH>Total Tests FAILED</TH>"
120 	ReportLine "<TH>${TOTAL_FAIL}</TH>"
121 	ReportLine "</TR>"
122 	ReportLine "<TR>"
123 	ReportLine "<TH>Total Tests Run</TH>"
124 	ReportLine "<TH>${TOTAL_RUN}</TH>"
125 	ReportLine "</TR>"
126 	ReportLine "</TABLE>"
127 	ReportLine "</CENTER>"
128 	ReportLine "<P>"
129 	ReportLine "<A HREF=${loglink}>Full logfile for test run</A>"
130 	ReportLine "<P>"
131 	ReportLine "<CENTER>"
132 	ReportLine "</BODY>"
133 	ReportLine "</HTML>"
134 }
135 
136 ################################################################################
137 ReportLine() {
138 	echo $1 >> $REPORT
139 }
140 
141 ################################################################################
142 LogLine() {
143 	echo $1 >> $LOGFILE
144 }
145 
146 ################################################################################
147 ReportTestComments() {
148 	if [[ $TEST_COMMENTS == "" ]] ; then
149 		TEST_COMMENTS="&nbsp;"
150 	fi
151 
152 	ReportLine "<TD>${TEST_COMMENTS}</TD>"
153 }
154 
155 ################################################################################
156 GetParams() {
157 	integer argc=$#
158 	integer i=0
159 
160 	if [[ $argc -lt 1 ]] ; then
161 		Usage
162 	fi
163 
164 	while (($i < $argc)) ; do
165 		arg=$1
166 		shift
167     		i=i+1
168 
169 		if [[ $arg == '-name' ]] ; then
170 			if (( $i < $argc )) ; then
171 				RUNNAME=$1
172 				echo "RUNNAME=[$RUNNAME]"
173 				shift
174 				i=i+1
175 			else
176 				Usage
177 			fi
178 		elif [[ $arg == '-env' ]] ; then
179 			if (( $i < $argc )) ; then
180 				ENVFILE=$1
181 				shift
182 				i=i+1
183 			else
184 				Usage
185 			fi
186 		else
187 			Usage
188 		fi
189 	done
190 
191 	if [[ $ENVFILE == "" ]] ; then
192 		Usage
193 	fi
194 }
195 
196 
197 ################################################################################
198 ReadEnvFile() {
199 	. $ENVFILE
200 
201 
202 	echo ""
203 	echo "The following values have been set from $ENVFILE:"
204 	echo "MASTERLIST=$MASTERLIST"
205 	echo "TESTCASEDIR=$TESTCASEDIR"
206 	echo "XMERGE_JAR=$XMERGE_JAR"
207 	echo "APORTIS_JAR=$APORTIS_JAR"
208 	echo "WORDSMITH_JAR=$WORDSMITH_JAR"
209 	echo "MINICALC_JAR=$MINICALC_JAR"
210 	echo "RESULTSBASE=$RESULTSBASE"
211 	echo "PERL5LIB=$PERL5LIB"
212 	echo "POSE_EXE=$POSE_EXE"
213 	echo "POSE_PRC=$POSE_PRC"
214 	echo "TEST_DRIVER_PL=$TEST_DRIVER_PL"
215 	echo "COMPARATOR_PL=$COMPARATOR_PL"
216 	echo "XML_INFILE_DIR=$XML_INFILE_DIR"
217 	echo "PDB_BASELINE_DIR=$PDB_BASELINE_DIR"
218 	echo "XML_BASELINE_DIR=$XML_BASELINE_DIR"
219 	echo "EM_SCRIPT_HOME=$EM_SCRIPT_HOME"
220 	echo "QAWRAPPER_SCRIPT_HOME=$QAWRAPPER_SCRIPT_HOME"
221 	echo "EM_ROM_FILE=$EM_ROM_FILE"
222 	echo "EM_SESSION_FILE=$EM_SESSION_FILE"
223 	echo "QA_LIB_HOME=$QA_LIB_HOME"
224 	echo "QA_COMPARATOR_HOME=$QA_COMPARATOR_HOME"
225 	echo "CLASSES_DIR=$CLASSES_DIR"
226 	echo "COMPLIST=$COMPLIST"
227 }
228 
229 ################################################################################
230 POSESetup() {
231 	export PERL5LIB
232 	export EM_SCRIPT_HOME
233 	export QAWRAPPER_SCRIPT_HOME
234 	export EM_ROM_FILE
235 	export EM_SESSION_FILE
236 	export QA_LIB_HOME
237 	export QA_COMPARATOR_HOME
238    	export CLASSES_DIR
239 
240 }
241 
242 ################################################################################
243 TestSetup() {
244 
245 
246 	POSESetup
247 
248 	export ZENDEBUG=1
249 
250 	COMPLIST="${COMPLIST}/tempcomp.${RUNNAME}.list"
251 	# create the directories for the results of this test run
252 	RESDIR="${RESULTSBASE}/${RUNNAME}"
253 	\rm -Rf $RESDIR
254 	mkdir $RESDIR
255 
256 	# Define the directories for the test input files,
257 	# test output files, working directories and baseline files
258 	PDB_INFILE_DIR="${RESDIR}/pdb-orig"
259 	mkdir "${PDB_INFILE_DIR}"
260 	PDB_OUTFILE_DIR="${RESDIR}/pdb-new"
261 	mkdir "${PDB_OUTFILE_DIR}"
262 	XML_OUTFILE_DIR="${RESDIR}/xml-new"
263 	mkdir "${XML_OUTFILE_DIR}"
264 
265 	LOGFILE="${RESDIR}/logfile"
266 	COMPLOG="${RESDIR}/complog"
267 	REPORT="${RESDIR}/report.html"
268 	StartReportFile
269 
270 	echo "Results in: $RESDIR"
271 	echo "Report file: $REPORT"
272 }
273 
274 ################################################################################
275 TestCleanup() {
276 	EndReportFile
277 }
278 
279 ################################################################################
280 TestCaseSetup() {
281 	# where to pick up converter classes
282 	export CLASSPATH=""
283 	export CLASSPATH=$CLASSPATH:$XMERGE_JAR
284 	export CLASSPATH=$CLASSPATH:$APORTIS_JAR
285 	export CLASSPATH=$CLASSPATH:$WORDSMITH_JAR
286 	export CLASSPATH=$CLASSPATH:$MINICALC_JAR
287 }
288 
289 ################################################################################
290 TestCaseCleanup() {
291 	# empty function
292 	a=42
293 }
294 
295 ################################################################################
296 RunTestCase() {
297 	testcase=$1
298 
299 	LogLine ""
300 	LogLine "test_driver output:"
301 
302 	# run test_driver in foreground
303 	$TEST_DRIVER_PL\
304 		-pose-prc=${POSE_PRC}\
305 		-pose-exe=${POSE_EXE}\
306 		-xml-orig=${XML_INFILE_DIR}\
307 		-pdb-orig=${PDB_INFILE_DIR}\
308 		-pdb-new=${PDB_OUTFILE_DIR}\
309 		-xml-new=${XML_OUTFILE_DIR}\
310 		-test=$testcase -merge >> $LOGFILE 2>&1
311 
312 	# cleanup in case zombie POSE processes are hanging around
313 	pkill pose
314 	pkill -9 pose
315 }
316 
317 
318 ################################################################################
319 ComparisonSetup() {
320 	typeset file=$1
321 
322 
323 	export CLASSPATH="$CLASSES_DIR/xerces.jar"
324 
325 	# create temporary comparator list file for this test case
326 	echo $file > $COMPLIST
327 }
328 
329 ################################################################################
330 ComparisonCleanup() {
331 	# remove temporary comparator list file used for this test case
332 	\rm -f $COMPLIST
333 }
334 
335 ################################################################################
336 RunComparison() {
337 	typeset type=$1
338 
339 	LogLine ""
340 	LogLine "Comparator output:"
341 	$COMPARATOR_PL\
342 		-xml-orig=${XML_BASELINE_DIR}\
343 		-pdb-orig=${PDB_BASELINE_DIR}\
344 		-pdb-new=${PDB_INFILE_DIR}\
345 		-xml-new=${XML_OUTFILE_DIR}\
346 		-list=$COMPLIST -log=$COMPLOG -type=$type >> $LOGFILE 2>&1
347 #		-list=$COMPLIST -log=$COMPLOG -type=$type | tee -a $LOGFILE 2>&1
348 
349 	pass=`grep TRUE $COMPLOG | wc -l`
350 
351 	LogLine ""
352 	LogLine "COMPLIST file:"
353 	cat $COMPLIST >> $LOGFILE
354 	LogLine ""
355 	LogLine "Comparator logfile:"
356 	cat $COMPLOG >> $LOGFILE
357 
358 	if [ $pass -eq 0 ]
359 	then
360 		TEST_COMMENTS="${TEST_COMMENTS}$type comparison ERROR<BR>"
361 		echo "$type comparison ERROR"
362 		return 0
363 	fi
364 
365 	echo "$type comparison OK"
366 	return 1
367 }
368 
369 ################################################################################
370 CheckOutput() {
371 	typeset xmlfile="${XML_OUTFILE_DIR}/$1"
372 	typeset pdbfile="${PDB_INFILE_DIR}/$2"
373 
374 	if [ ! -f $pdbfile ] ; then
375 		TEST_COMMENTS="${TEST_COMMENTS}[$pdbfile] does not exist<BR>"
376 		LogLine "ERROR: $pdbfile does not exist"
377 		echo "ERROR: $pdbfile does not exist"
378 		return 0
379 	fi
380 
381 	if [ ! -f $xmlfile ] ; then
382 		TEST_COMMENTS="${TEST_COMMENTS}[$xmlfile] does not exist<BR>"
383 		LogLine "ERROR: $xmlfile does not exist"
384 		echo "ERROR: $xmlfile does not exist"
385 		return 0
386 	fi
387 
388 	return 1
389 }
390 
391 ################################################################################
392 RunTest() {
393 	typeset testcasename
394 	typeset testcase
395 	typeset testfile
396 	typeset pdbfile
397 	typeset xmlfile
398 	typeset ext
399 	integer try
400 	integer finished_with_test
401 	integer test_pass
402 
403 	TestSetup
404 
405 	BGCOLOR=$ODD_BGCOLOR
406 
407 	while read line ; do
408 		# get chars up to 1st space
409 		testcasename=${line%% *}
410 		testcase="${TESTCASEDIR}/$testcasename"
411 
412 		# get 2nd word
413 		testfile=${line#* }
414 		testfile=${testfile%% *}
415 
416 		# get last word
417 		ext=${line##* }
418 
419 		LogLine "############################################"
420 		LogLine "Starting the following testcase"
421 		LogLine "testcase = $testcase"
422 		LogLine "testfile = $testfile"
423 		LogLine "ext = $ext"
424 
425 		ReportLine "<TR BGCOLOR='${BGCOLOR}'>"
426 		ReportLine "<TD valign=top>$testcasename</TD>"
427 		ReportLine "<TD valign=top>$testfile</TD>"
428 		ReportLine "<TD valign=top>$ext</TD>"
429 
430 		echo ""
431 		echo "testcase = $testcase"
432 		echo "testfile = $testfile"
433 		echo "ext = $ext"
434 
435 		try=1
436 		finished_with_test=0
437 		TEST_COMMENTS=""
438 
439 		while (($finished_with_test == 0)) ; do
440 
441 			TestCaseSetup
442 			RunTestCase $testcase
443 			TestCaseCleanup
444 
445 			xmlfile="${testfile}.${ext}"
446 
447 			if [[ $ext == "sxc" ]] ; then
448 				pdbfile="${testfile}-Sheet1.pdb"
449 			else
450 				pdbfile="${testfile}.pdb"
451 			fi
452 
453 			CheckOutput $xmlfile $pdbfile
454 			res=$?
455 
456 			if [[ $res -eq 1 ]] ; then
457 				ComparisonSetup $pdbfile
458 				RunComparison pdb
459 				res=$?
460 # ignore result until pdb comparator is fixed...
461 res=1
462 				ComparisonCleanup
463 			fi
464 
465 			if [[ $res -eq 1 ]] ; then
466 				ComparisonSetup $xmlfile
467 				RunComparison xml
468 				res=$?
469 				ComparisonCleanup
470 			fi
471 
472 			if [[ $res -eq 1 ]] ; then
473 				TOTAL_PASS=TOTAL_PASS+1
474 				ReportLine "<TD valign=top BGCOLOR='${PASS_COLOR}'>PASS</TD>"
475 				ReportTestComments
476 				ReportLine "</TR>"
477 				LogLine "Test PASSED (on try $try)"
478 				echo "Test PASSED (on try $try)"
479 				finished_with_test=1
480 			else
481 				TEST_COMMENTS="${TEST_COMMENTS}error on try ${try}<BR>"
482 				LogLine "TEST FAILED (on try $try)"
483 				echo "TEST FAILED (on try $try)"
484 
485 				if [[ $try -eq $MAX_RETRIES ]] ; then
486 					TOTAL_FAIL=TOTAL_FAIL+1
487 					ReportLine "<TD valign=top BGCOLOR='${FAIL_COLOR}'>FAIL</TD>"
488 					ReportTestComments
489 					ReportLine "</TR>"
490 					finished_with_test=1
491 				fi
492 			fi
493 
494 			try=try+1
495 		done
496 
497 		TOTAL_RUN=TOTAL_RUN+1
498 
499 		# toggle BGCOLOR for next report line
500 		if [[ $BGCOLOR == $ODD_BGCOLOR ]] ; then
501 			BGCOLOR=$EVEN_BGCOLOR
502 		else
503 			BGCOLOR=$ODD_BGCOLOR
504 		fi
505 
506 	done < $MASTERLIST
507 
508 	ReportLine "</TABLE>"
509 	ReportLine "</CENTER>"
510 
511 	TestCleanup
512 
513 	echo "Total Tests PASSED: "${TOTAL_PASS}
514 	echo "Total Tests FAILED: "${TOTAL_FAIL}
515 	echo "Total Tests RUN: "${TOTAL_RUN}
516 	echo "Results in: $RESDIR"
517 	echo "Report file: $REPORT"
518 }
519 
520 ################################################################################
521 ################################################################################
522 # main
523 ################################################################################
524 ################################################################################
525 
526 GetParams $@
527 ReadEnvFile
528 RunTest
529 
530 exit 0
531