autotest.sh 12.1 KB
Newer Older
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
#! /bin/sh

# This script compiles Ocarina and then runs it for each *.aadl file
# recursively found in the directories provided as parameters, or
# recursively in default ${root_dirs} if no parameter has been
# provided.

# If no file named *.aadl.out is present, then the output is compared
# with the input; they must match. Else the output is compared with
# *.aadl.out; this is useful if the test is meant to fail.

# The script returns the number of errors found, and indicates the
# number of unsuccessfully handled files

echo_log () {
    echo $@ | tee -a ${logfile}
}

cat_log () {
    cat $@ | tee -a ${logfile}
}

debug () {
    if test x"${ENABLE_DEBUG=yes}" = x"yes"; then
	echo "DEBUG: $1"
    fi
}

usage () {
    cat <<EOF
     Usage : $0 [options]

     Options:
34
35
36
37
38
39
40
41
42
       --help     |-h : This help
       --tests    |-t {<test_directories>}: Do the tests (testsuite directory)
       --examples |-x {examples_directories}: Do the examples (examples directory)
       --runtimes |-r : Test the PolyORB-HI runtimes
       --projects |-p : Test the AADL projects
       --all      |-a : Test Ocarina, runtimes and projects
       --lcov     |-l: Generate html output from gcov information
       --overwrite|-o: Overwrite reference file
       --clean    |-c: Delete intermediate files
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
EOF
}

banner () {
    echo "$1 $2" | \
	awk '{printf ("%.65s %s\n", $1, $2)}' | \
	awk '{printf ("%-65s%10s\n", $1, $2)}' | \
	tee -a ${logfile}
}

ignored () {
    banner $1 IGNORED
}

passed () {
    banner $1 PASSED
}

failed () {
    banner $1 FAILED
    echo_log "--------------------------- command -----------------------------"
    echo_log "$2"
    if [ -f "$3" ]; then
	echo_log "----------------------- expected output -------------------------"
	cat_log $3
	echo_log "----------------------- actual output ---------------------------"
	cat_log $4
	echo_log "-----------------------------------------------------------------"
    elif [ -f "$4" ]; then
	echo_log "--------------------------- output ------------------------------"
	cat_log $4
	echo_log "-----------------------------------------------------------------"
    fi
}

# Clean up temporary files if interrupted manually by the user

cleanup () {
    rm -rf ${tmpdir}
    rm -f  ${actual_output}
    rm -f  ${output_file}
    rm -f  ${logfile}
}

trap '{
echo "Interrupted! Cleanup..."

cd ${workdir}
cleanup
exit 1
}' 1 2 13 15

ocarina="ocarina -q"
ocarina_generate_code="ocarina -b -x"
default_flags="-g aadl"
default_version=""
workdir="`pwd`"

separator="---------------------------------------------------------------------------"

tmpdir=${workdir}/`mktemp dir.XXXXXX`
logfile=${workdir}/`mktemp log.XXXXXX`
actual_output=${workdir}/`mktemp out.XXXXXX`
output_file=${workdir}/`mktemp file.XXXXXX`

# The default value for the path converter is 'echo'. By default, we
# do not convert paths. the user may override this value by providing
# his own path converter (such as 'cygpath -w').
path_conv="${path_conv-echo}"

113
114
115
116
117
118
119
120
121
122
case "$(uname -s)" in
    CYGWIN*)
	path_conv="cygpath -w"
	;;
    MINGW32*|MSYS*)
	echo "Unsupported build configuration"
	exit -1
	;;
esac

123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# The default value of the path separator is ':'. By default we use
# the UNIX path separator. The user may override this value by
# providing his own path separator (such as ';' for windows
# platforms).
path_sep="${path_sep-:}"

# If dos2unix is not present, we display a warning
if which dos2unix 2>&1 >/dev/null; then
    dos2unix="dos2unix"
else
    echo "%%%%%%%  WARNING: dos2unix not found  %%%%%%%%%"
    # Affect a dummy value
    dos2unix=":"
fi

scriptdir=`dirname $0`; cd ${scriptdir}; scriptdir="`pwd`"
yoogx's avatar
yoogx committed
139
140
141
142

# Set execute mode
chmod 755 ${scriptdir}/tools/compare.py

143
144
145
146
147
148
149
150
151
cd ${workdir}

failures=0
total=0
dotests="true"
doexamples="false" # disabled for now
doruntimes="false"
doprojects="false"
doall="false"
152
overwrite_output="false"
153
154
155
156
157
158
159
160
161
testfiles=""
examplefiles=""

if test  $# != 0 ; then
    case "$1" in
	--help|-h)
	    usage
	    exit 0
	    ;;
162
163
164
	--overwrite|-o)
	    overwrite_output="true"
	    ;;
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
	--all|-a)
	    doexamples="false"
	    dotests="false"
	    doruntimes="false"
	    doprojects="false"
	    doall="true"
	    ;;
	--tests|-t)
	    doexamples="false"
	    shift
	    while test $# -gt 0
	      do
	      testfiles="${testfiles} $1"
	      shift
	    done
	    ;;
	--examples|-x)
	    dotests="false"
	    shift
	    while test $# -gt 0; do
		examplefiles=${examplefiles}" $1"
		shift
	    done
	    ;;
	--runtimes|-r)
	    doruntimes="true"
	    dotests="false"
	    doexamples="false"
	    shift
	    ;;
	--projects|-p)
	    doprojects="true"
	    dotests="false"
	    doexamples="false"
	    shift
	    ;;
	--lcov|-l)
	    lcov -d . -c -o ocarina.gcov-info -t ocarina
203
	    lcov -d . --remove ocarina.gcov-info "*debug*" "*adainclude*" "*python*" "*transfo*" "*nodes*" -o ocarina.gcov-info -t ocarina
yoogx's avatar
yoogx committed
204
	    genhtml -o html -s -f ocarina.gcov-info
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
	    exit 0
	    ;;
	--clean|-c)
	    rm -f log.* dir.* file.* out.*
	    exit 0
	    ;;
	*)
	    usage
	    exit 1
    esac
fi

if test ${doruntimes} = "true" ; then
    for e in "resources/runtime/polyorb-hi-c" "resources/runtime/polyorb-hi-ada"; do
	entry=${e}
	old_dir=`pwd`
	cd ${e};

	make examples 2> /dev/null > /dev/null
	if test $? != 0 ; then
	    failed ${entry} "${command}" "" "${actual_output}"
	    failures=`expr ${failures} + 1`

	else
	    passed ${entry}
	fi;

	cd ${old_dir}
    done
fi

if test ${doprojects} = "true" ; then
    old_dir=`pwd`
    cd ../../projects

    ./build.sh 2> /dev/null > /dev/null
    if test $? != 0 ; then
	banner "Projects" FAILED
	failures=`expr ${failures} + 1`
yoogx's avatar
yoogx committed
244

245
246
247
    else
	passed ${entry}
    fi;
yoogx's avatar
yoogx committed
248

249
250
251
252
253
254
255
256
    cd ${old_dir}
fi

if test ${doall} = "true" ; then
    ./autotest.sh 2> /dev/null > /dev/null
    if test $? != 0 ; then
	banner "Ocarina_Core" FAILED
	failures=`expr ${failures} + 1`
yoogx's avatar
yoogx committed
257

258
259
260
261
262
263
264
265
    else
	banner "Ocarina_Core" PASSED
    fi;

    ./autotest.sh -r 2> /dev/null > /dev/null
    if test $? != 0 ; then
	banner "Runtimes" FAILED
	failures=`expr ${failures} + 1`
yoogx's avatar
yoogx committed
266

267
268
269
270
271
272
273
274
    else
	banner "Runtimes" PASSED
    fi;

    ./autotest.sh -p 2> /dev/null > /dev/null
    if test $? != 0 ; then
	banner "Projects" FAILED
	failures=`expr ${failures} + 1`
yoogx's avatar
yoogx committed
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
    else
	banner "Projects" PASSED
    fi;
fi


if test ${doexamples} = "true" ; then
    if test "x${examplefiles}" = "x" ; then
	if test ! -f  ${scriptdir}/examples/MANIFEST; then
	    echo "${scriptdir}/examples/MANIFEST: file not found";
	    exit 2;
	fi
	examplefiles=`cat ${scriptdir}/examples/MANIFEST | grep -v "^#"`
    fi

    for e in ${examplefiles}; do
	entry=examples/${e}
	file=${scriptdir}/${entry}
	if test ! -f ${file} ; then
	    echo "FATAL : example ${e} does not exist"
	    cleanup
	    exit 1;
	fi

	rm -f  ${output_file} >/dev/null 2>&1
	rm -f  ${actual_output} >/dev/null 2>&1
	rm -rf ${tmpdir} >/dev/null 2>&1
	mkdir  ${tmpdir}
	chmod u+rwx ${tmpdir}
	cd ${tmpdir};

	total=`expr ${total} + 1`
	command="${ocarina_generate_code} \"`${path_conv} ${file}`\""
	${ocarina_generate_code} "`${path_conv} ${file}`" > ${actual_output} 2>&1
	if test $? != 0 ; then
	    failed ${entry} "${command}" "" "${actual_output}"
	    failures=`expr ${failures} + 1`

	else
	    passed ${entry}
	fi;

	cd ..
    done
fi

if test ${dotests} = "true" ; then
    if test "x${testfiles}" = "x" ; then
	if test ! -f  ${scriptdir}/tests/MANIFEST; then
	    echo "${scriptdir}/tests/MANIFEST: file not found";
	    exit 2;
	fi
	testfiles=`cat ${scriptdir}/tests/MANIFEST | grep -v "^#"`
    fi

    for t in ${testfiles}; do
	if test ! -d ${scriptdir}/${t} && test ! -f ${scriptdir}/${t};
	then
	    echo "FATAL: tests ${t} does not exist"
	    cleanup
	    exit 1;
	fi

	rm -f  ${output_file} >/dev/null 2>&1
	rm -f  ${actual_output} >/dev/null 2>&1
	cd ${workdir}
	rm -rf ${tmpdir} >/dev/null 2>&1
	mkdir  ${tmpdir}
	chmod u+rwx ${tmpdir}
	cd ${tmpdir};

	files=`find ${scriptdir}/${t} -name '*.aadl'`;

	for file in ${files}; do
	    entry=`echo ${file} | sed "s,^${scriptdir}/,,"`
            manifest="`dirname ${file}`/MANIFEST"
	    expected_output="${file}.out"
	    test_ignored="${file}.ignore"

	    # copy REAL files if such file exists

	    real_lib_base=`dirname ${file}`
	    real_libs_nb=`ls ${real_lib_base} | grep "\.real" | wc -l` > /dev/null
yoogx's avatar
yoogx committed
359
	    if [ ${real_libs_nb} -gt 0 ]
360
361
362
363
364
365
366
367
		then
		real_lib=`dirname ${file}`/"*.real"
		cp -f ${real_lib} .
	    fi

	    flags=${default_flags}
	    version=${default_version}
            if test -r ${manifest}; then
yoogx's avatar
yoogx committed
368
		flags=`grep OCARINA_FLAGS ${manifest} | sed  's/OCARINA_FLAGS=//'`
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
		version=`grep AADL_VERSION ${manifest} | awk -F= '{print $2}'`
		flags=${flags:-${default_flags}}
		version=${version:-${default_version}}
            fi

	    if test -r ${test_ignored} ; then
		ignored "${entry}"

	    else
		touch ${output_file}
		${ocarina} ${flags} ${version} "`${path_conv} ${file}`" \
		    -o "`${path_conv} ${output_file}`" > ${actual_output} 2>&1
		if test -r ${expected_output} ; then
		    cat ${output_file} >>${actual_output}
		    ${dos2unix} ${actual_output} >/dev/null 2>&1
		    ${scriptdir}/tools/compare.py \
			${expected_output} \
			${actual_output} >/dev/null 2>&1
		    result=$?

		else
		    ${scriptdir}/tools/compare.py \
			${file} \
			${output_file} >> /dev/null 2>&1
		    result=$?
		fi

		if test  ${result} != 0 ; then
		    if test -r ${expected_output} ; then
			failed ${entry} \
			    "${ocarina} ${flags} ${version} \"`${path_conv} ${file}`\"" \
			    ${expected_output} \
			    ${actual_output}

403
404
405
406
			if test ${overwrite_output} = "true"; then
			    cp ${actual_output} ${expected_output}
			fi

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
		    else
			failed ${entry} \
			    "${ocarina} ${flags} ${version} \"`${path_conv} ${file}`\"" \
			    ${file} \
			    ${output_file}
		    fi
		    failures=`expr ${failures} + 1`

		else
		    passed ${entry}
		fi
		total=`expr ${total} + 1`
	    fi
	done

	files=`find ${scriptdir}/${t} -name '*.adb'`;

	for file in ${files}; do
	    entry=`echo ${file} | sed "s,^${scriptdir}/,,"`
	    expected_output="${file}.out"
	    ignored_output="${file}.ignore"
	    gprfile="`basename ${file} .adb`.gpr"
	    gprfile="`dirname ${file}`/${gprfile}"

	    cd ${tmpdir}

	    if test -r ${ignored_output} ; then
		ignored ${entry}

	    else
		total=`expr ${total} + 1`

439
440
441
442
443
444
445
446
447
448
449
450
451
452
		case "$(uname -s)" in

		    CYGWIN*|MINGW32*|MSYS*)
			ignored ${entry}
			;;

		    *)
			if test -r ${gprfile} ; then
			    ocarina_gpr="`ocarina-config --projects`"
			    command="gnatmake -P\"`${path_conv} ${gprfile}`\" -aP${ocarina_gpr} -XOBJ_DIR=\"`${path_conv} ${tmpdir}`\""
			    ADA_PROJECT_PATH="${ocarina_gpr}${path_sep}${ADA_PROJECT_PATH}" \
					    gnatmake -P"`${path_conv} ${gprfile}`" -aP${ocarina_gpr} \
					    -XOBJ_DIR="`${path_conv} ${tmpdir}`" \
					    >${actual_output} 2>&1
453
			else
454
455
456
			    command="gnatmake '`${path_conv} ${file}`' `ocarina-config`"
			    gnatmake "`${path_conv} ${file}`" `ocarina-config` \
				     >${actual_output} 2>&1
457
			fi
yoogx's avatar
yoogx committed
458

459
460
461
462
463
			if test $? != 0 ; then
			    failed ${entry} \
				   "${command}" \
				   "" \
				   "${actual_output}"
464
465
466
467
468
469
470

                            # We do not increase the number of
                            # failures for compiled files, as those
                            # are dependent on external conditions,
                            # e.g. enabling code coverage, etc.

			    # failures=`expr ${failures} + 1`
yoogx's avatar
yoogx committed
471

472
473
474
475
			else
			    ./`basename ${file} .adb` >${actual_output} 2>&1
			    command="./`basename ${file} .adb`"
			    result=$?
yoogx's avatar
yoogx committed
476

477
478
479
480
481
482
			    if test -r ${expected_output} ; then
				${scriptdir}/tools/compare.py \
					    ${expected_output} \
					    ${actual_output} > /dev/null
				result=$?
			    fi;
yoogx's avatar
yoogx committed
483

484
485
486
487
488
489
			    if test ${result} != 0 ; then
				if test -r ${expected_output} ; then
				    failed ${entry} \
					   "${command}" \
					   ${expected_output} \
					   ${actual_output}
yoogx's avatar
yoogx committed
490

491
492
493
494
495
				else
				    failed ${entry} \
					   "${command}"
				fi
				failures=`expr ${failure} + 1`
yoogx's avatar
yoogx committed
496

497
498
499
500
501
			    else
				passed ${entry}
			    fi
			fi;;
		esac
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
	    fi
	done
    done
fi

echo_log ${separator}
echo_log "FAILURES : ${failures} / ${total}"
echo_log ${separator}

if test ${failures} != 0; then
    echo "Result trace is stored in ${logfile}"
    cd "${workdir}"
    rm -fr "${actual_output}"
    rm -fr "${output_file}"
    rm -fr "${tmpdir}"
else
    cd "${workdir}"
    cleanup
fi

exit ${failures}