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