summaryrefslogtreecommitdiff
path: root/xmerge/java/org/openoffice/xmerge/converter/palm/palmtests/qa-wrapper/bin/run-convtest
blob: 0931ca77539dc0e33459ff69ad3c965f3826dff7 (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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
#!/bin/ksh
#*************************************************************************
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# 
# Copyright 2000, 2010 Oracle and/or its affiliates.
#
# OpenOffice.org - a multi-platform office productivity suite
#
# This file is part of OpenOffice.org.
#
# OpenOffice.org is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License version 3
# only, as published by the Free Software Foundation.
#
# OpenOffice.org 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 Lesser General Public License version 3 for more details
# (a copy is included in the LICENSE file that accompanied this code).
#
# You should have received a copy of the GNU Lesser General Public License
# version 3 along with OpenOffice.org.  If not, see
# <http://www.openoffice.org/license.html>
# for a copy of the LGPLv3 License.
#
#*************************************************************************

#set -x
umask 0

integer TOTAL_PASS=0
integer TOTAL_FAIL=0
integer TOTAL_RUN=0
integer MAX_RETRIES=5
typeset RUNNAME=`date +%Y%m%d%H%M%S`
typeset PRINTDATE=`date`
typeset PDB_INFILE_DIR
typeset PDB_OUTFILE_DIR
typeset XML_OUTFILE_DIR
typeset REPORT
typeset RESDIR
typeset LOGFILE
typeset COMPLOG
typeset TEST_COMMENTS
typeset BGCOLOR
typeset ODD_BGCOLOR='#BBBBBB'
typeset EVEN_BGCOLOR='#DCDCDC'
typeset PASS_COLOR='#00ff00'
typeset FAIL_COLOR='#ff4040'

typeset ENVFILE=""
# The following variables should be set in the env file
typeset MASTERLIST=""
typeset TESTCASEDIR=""
typeset RESULTSBASE=""
typeset XMERGE_JAR=""
typeset APORTIS_JAR=""
typeset WORDSMITH_JAR=""
typeset MINICALC_JAR=""
typeset PERL5LIB=""
typeset POSE_EXE=""
typeset POSE_PRC=""
typeset TEST_DRIVER_PL=""
typeset COMPARATOR_PL=""
typeset COMPLIST=""
typeset XML_INFILE_DIR=""
typeset PDB_BASELINE_DIR=""
typeset XML_BASELINE_DIR=""
typeset EM_SCRIPT_HOME=""
typeset QAWRAPPER_SCRIPT_HOME=""
typeset EM_ROM_FILE=""
typeset EM_SESSION_FILE=""
typeset QA_LIB_HOME=""
typeset QA_COMPARATOR_HOME=""
typeset CLASSES_DIR=""



################################################################################
Usage() {
	echo "Usage: run-convtest -env <ENVFILE> [-name RUNNAME]"
	exit 1
}


################################################################################
StartReportFile() {
	typeset line=`date`

	ReportLine "<HTML>"
	ReportLine "<HEAD>"
	ReportLine "<TITLE>XMerge Converters Test Results - ${RUNNAME}</TITLE>"
	ReportLine "</HEAD>"
	ReportLine "<BODY BGCOLOR=#ffffff>"
	ReportLine "<H1 align=center>XMerge Converters Test Results - ${RUNNAME}</H1>"
	ReportLine "<P>"
	ReportLine "Test run on: ${PRINTDATE}"
	ReportLine "<P>"
	ReportLine "<CENTER>"
	ReportLine "<TABLE WIDTH='100%' BORDER=1 CELLSPACING=0 CELLPADDING=2>"
	ReportLine "<TR BGCOLOR='#9999CC'>"
	ReportLine "<TH>Test Name</TH>"
	ReportLine "<TH>Test File</TH>"
	ReportLine "<TH>.ext</TH>"
	ReportLine "<TH>Result</TH>"
	ReportLine "<TH>Comments</TH>"
	ReportLine "</TR>"
}


################################################################################
EndReportFile() {
	# remove full path from LOGFILE (link will be to current dir)
	typeset loglink=${LOGFILE##*/}

	ReportLine "<P>"
	ReportLine "<CENTER>"
	ReportLine "<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=2>"
	ReportLine "<TR>"
	ReportLine "<TH>Total Tests PASSED</TH>"
	ReportLine "<TH>${TOTAL_PASS}</TH>"
	ReportLine "</TR>"
	ReportLine "<TR>"
	ReportLine "<TH>Total Tests FAILED</TH>"
	ReportLine "<TH>${TOTAL_FAIL}</TH>"
	ReportLine "</TR>"
	ReportLine "<TR>"
	ReportLine "<TH>Total Tests Run</TH>"
	ReportLine "<TH>${TOTAL_RUN}</TH>"
	ReportLine "</TR>"
	ReportLine "</TABLE>"
	ReportLine "</CENTER>"
	ReportLine "<P>"
	ReportLine "<A HREF=${loglink}>Full logfile for test run</A>"
	ReportLine "<P>"
	ReportLine "<CENTER>"
	ReportLine "</BODY>"
	ReportLine "</HTML>"
}

################################################################################
ReportLine() {
	echo $1 >> $REPORT
}

################################################################################
LogLine() {
	echo $1 >> $LOGFILE
}

################################################################################
ReportTestComments() {
	if [[ $TEST_COMMENTS == "" ]] ; then
		TEST_COMMENTS="&nbsp;"
	fi

	ReportLine "<TD>${TEST_COMMENTS}</TD>"
}

################################################################################
GetParams() {
	integer argc=$#
	integer i=0

	if [[ $argc -lt 1 ]] ; then
		Usage
	fi

	while (($i < $argc)) ; do
		arg=$1
		shift
    		i=i+1

		if [[ $arg == '-name' ]] ; then
			if (( $i < $argc )) ; then
				RUNNAME=$1
				echo "RUNNAME=[$RUNNAME]"
				shift
				i=i+1
			else
				Usage
			fi
		elif [[ $arg == '-env' ]] ; then
			if (( $i < $argc )) ; then
				ENVFILE=$1
				shift
				i=i+1
			else
				Usage
			fi
		else
			Usage
		fi
	done

	if [[ $ENVFILE == "" ]] ; then
		Usage
	fi
}


################################################################################
ReadEnvFile() {
	. $ENVFILE

	
	echo ""
	echo "The following values have been set from $ENVFILE:"
	echo "MASTERLIST=$MASTERLIST"
	echo "TESTCASEDIR=$TESTCASEDIR"
	echo "XMERGE_JAR=$XMERGE_JAR"
	echo "APORTIS_JAR=$APORTIS_JAR"
	echo "WORDSMITH_JAR=$WORDSMITH_JAR"
	echo "MINICALC_JAR=$MINICALC_JAR"
	echo "RESULTSBASE=$RESULTSBASE"
	echo "PERL5LIB=$PERL5LIB"
	echo "POSE_EXE=$POSE_EXE"
	echo "POSE_PRC=$POSE_PRC"
	echo "TEST_DRIVER_PL=$TEST_DRIVER_PL"
	echo "COMPARATOR_PL=$COMPARATOR_PL"
	echo "XML_INFILE_DIR=$XML_INFILE_DIR"
	echo "PDB_BASELINE_DIR=$PDB_BASELINE_DIR"
	echo "XML_BASELINE_DIR=$XML_BASELINE_DIR"
	echo "EM_SCRIPT_HOME=$EM_SCRIPT_HOME"
	echo "QAWRAPPER_SCRIPT_HOME=$QAWRAPPER_SCRIPT_HOME"
	echo "EM_ROM_FILE=$EM_ROM_FILE"
	echo "EM_SESSION_FILE=$EM_SESSION_FILE"
	echo "QA_LIB_HOME=$QA_LIB_HOME"
	echo "QA_COMPARATOR_HOME=$QA_COMPARATOR_HOME"
	echo "CLASSES_DIR=$CLASSES_DIR"
	echo "COMPLIST=$COMPLIST"
}

################################################################################
POSESetup() {
	export PERL5LIB
	export EM_SCRIPT_HOME
	export QAWRAPPER_SCRIPT_HOME
	export EM_ROM_FILE
	export EM_SESSION_FILE
	export QA_LIB_HOME
	export QA_COMPARATOR_HOME
   	export CLASSES_DIR
	
}

################################################################################
TestSetup() {
	

	POSESetup

	export ZENDEBUG=1   

	COMPLIST="${COMPLIST}/tempcomp.${RUNNAME}.list"
	# create the directories for the results of this test run
	RESDIR="${RESULTSBASE}/${RUNNAME}"
	\rm -Rf $RESDIR
	mkdir $RESDIR

	# Define the directories for the test input files,
	# test output files, working directories and baseline files
	PDB_INFILE_DIR="${RESDIR}/pdb-orig"
	mkdir "${PDB_INFILE_DIR}"
	PDB_OUTFILE_DIR="${RESDIR}/pdb-new"
	mkdir "${PDB_OUTFILE_DIR}"
	XML_OUTFILE_DIR="${RESDIR}/xml-new"
	mkdir "${XML_OUTFILE_DIR}"

	LOGFILE="${RESDIR}/logfile"
	COMPLOG="${RESDIR}/complog"
	REPORT="${RESDIR}/report.html"
	StartReportFile

	echo "Results in: $RESDIR"
	echo "Report file: $REPORT"
}

################################################################################
TestCleanup() {
	EndReportFile
}

################################################################################
TestCaseSetup() {
	# where to pick up converter classes
	export CLASSPATH=""
	export CLASSPATH=$CLASSPATH:$XMERGE_JAR
	export CLASSPATH=$CLASSPATH:$APORTIS_JAR
	export CLASSPATH=$CLASSPATH:$WORDSMITH_JAR
	export CLASSPATH=$CLASSPATH:$MINICALC_JAR
}

################################################################################
TestCaseCleanup() {
	# empty function
	a=42
}

################################################################################
RunTestCase() {
	testcase=$1

	LogLine ""
	LogLine "test_driver output:"

	# run test_driver in foreground
	$TEST_DRIVER_PL\
		-pose-prc=${POSE_PRC}\
		-pose-exe=${POSE_EXE}\
		-xml-orig=${XML_INFILE_DIR}\
		-pdb-orig=${PDB_INFILE_DIR}\
		-pdb-new=${PDB_OUTFILE_DIR}\
		-xml-new=${XML_OUTFILE_DIR}\
		-test=$testcase -merge >> $LOGFILE 2>&1

	# cleanup in case zombie POSE processes are hanging around
	pkill pose
	pkill -9 pose
}


################################################################################
ComparisonSetup() {
	typeset file=$1

	
	export CLASSPATH="$CLASSES_DIR/xerces.jar"

	# create temporary comparator list file for this test case
	echo $file > $COMPLIST
}

################################################################################
ComparisonCleanup() {
	# remove temporary comparator list file used for this test case
	\rm -f $COMPLIST
}

################################################################################
RunComparison() {
	typeset type=$1

	LogLine ""
	LogLine "Comparator output:"
	$COMPARATOR_PL\
		-xml-orig=${XML_BASELINE_DIR}\
		-pdb-orig=${PDB_BASELINE_DIR}\
		-pdb-new=${PDB_INFILE_DIR}\
		-xml-new=${XML_OUTFILE_DIR}\
		-list=$COMPLIST -log=$COMPLOG -type=$type >> $LOGFILE 2>&1
#		-list=$COMPLIST -log=$COMPLOG -type=$type | tee -a $LOGFILE 2>&1

	pass=`grep TRUE $COMPLOG | wc -l`

	LogLine ""
	LogLine "COMPLIST file:"
	cat $COMPLIST >> $LOGFILE
	LogLine ""
	LogLine "Comparator logfile:"
	cat $COMPLOG >> $LOGFILE

	if [ $pass -eq 0 ]
	then
		TEST_COMMENTS="${TEST_COMMENTS}$type comparison ERROR<BR>"
		echo "$type comparison ERROR"
		return 0
	fi

	echo "$type comparison OK"
	return 1
}

################################################################################
CheckOutput() {
	typeset xmlfile="${XML_OUTFILE_DIR}/$1"
	typeset pdbfile="${PDB_INFILE_DIR}/$2"

	if [ ! -f $pdbfile ] ; then
		TEST_COMMENTS="${TEST_COMMENTS}[$pdbfile] does not exist<BR>"
		LogLine "ERROR: $pdbfile does not exist"
		echo "ERROR: $pdbfile does not exist"
		return 0
	fi

	if [ ! -f $xmlfile ] ; then
		TEST_COMMENTS="${TEST_COMMENTS}[$xmlfile] does not exist<BR>"
		LogLine "ERROR: $xmlfile does not exist"
		echo "ERROR: $xmlfile does not exist"
		return 0
	fi

	return 1
}

################################################################################
RunTest() {
	typeset testcasename
	typeset testcase
	typeset testfile
	typeset pdbfile
	typeset xmlfile
	typeset ext
	integer try
	integer finished_with_test
	integer test_pass

	TestSetup

	BGCOLOR=$ODD_BGCOLOR

	while read line ; do
		# get chars up to 1st space
		testcasename=${line%% *}
		testcase="${TESTCASEDIR}/$testcasename"

		# get 2nd word
		testfile=${line#* }
		testfile=${testfile%% *}

		# get last word
		ext=${line##* }

		LogLine "############################################"
		LogLine "Starting the following testcase"
		LogLine "testcase = $testcase"
		LogLine "testfile = $testfile"
		LogLine "ext = $ext"

		ReportLine "<TR BGCOLOR='${BGCOLOR}'>"
		ReportLine "<TD valign=top>$testcasename</TD>"
		ReportLine "<TD valign=top>$testfile</TD>"
		ReportLine "<TD valign=top>$ext</TD>"

		echo ""
		echo "testcase = $testcase"
		echo "testfile = $testfile"
		echo "ext = $ext"

		try=1
		finished_with_test=0
		TEST_COMMENTS=""

		while (($finished_with_test == 0)) ; do

			TestCaseSetup
			RunTestCase $testcase
			TestCaseCleanup

			xmlfile="${testfile}.${ext}"

			if [[ $ext == "sxc" ]] ; then
				pdbfile="${testfile}-Sheet1.pdb"
			else
				pdbfile="${testfile}.pdb"
			fi

			CheckOutput $xmlfile $pdbfile
			res=$?

			if [[ $res -eq 1 ]] ; then
				ComparisonSetup $pdbfile
				RunComparison pdb
				res=$?
# ignore result until pdb comparator is fixed...
res=1
				ComparisonCleanup
			fi

			if [[ $res -eq 1 ]] ; then
				ComparisonSetup $xmlfile
				RunComparison xml
				res=$?
				ComparisonCleanup
			fi

			if [[ $res -eq 1 ]] ; then
				TOTAL_PASS=TOTAL_PASS+1
				ReportLine "<TD valign=top BGCOLOR='${PASS_COLOR}'>PASS</TD>"
				ReportTestComments
				ReportLine "</TR>"
				LogLine "Test PASSED (on try $try)"
				echo "Test PASSED (on try $try)"
				finished_with_test=1
			else
				TEST_COMMENTS="${TEST_COMMENTS}error on try ${try}<BR>"
				LogLine "TEST FAILED (on try $try)"
				echo "TEST FAILED (on try $try)"

				if [[ $try -eq $MAX_RETRIES ]] ; then
					TOTAL_FAIL=TOTAL_FAIL+1
					ReportLine "<TD valign=top BGCOLOR='${FAIL_COLOR}'>FAIL</TD>"
					ReportTestComments
					ReportLine "</TR>"
					finished_with_test=1
				fi
			fi

			try=try+1
		done

		TOTAL_RUN=TOTAL_RUN+1

		# toggle BGCOLOR for next report line
		if [[ $BGCOLOR == $ODD_BGCOLOR ]] ; then
			BGCOLOR=$EVEN_BGCOLOR
		else
			BGCOLOR=$ODD_BGCOLOR
		fi

	done < $MASTERLIST

	ReportLine "</TABLE>"
	ReportLine "</CENTER>"

	TestCleanup

	echo "Total Tests PASSED: "${TOTAL_PASS}
	echo "Total Tests FAILED: "${TOTAL_FAIL}
	echo "Total Tests RUN: "${TOTAL_RUN}
	echo "Results in: $RESDIR"
	echo "Report file: $REPORT"
}

################################################################################
################################################################################
# main
################################################################################
################################################################################

GetParams $@
ReadEnvFile
RunTest

exit 0