-
Notifications
You must be signed in to change notification settings - Fork 15
/
make_tests.sh
executable file
·1582 lines (1319 loc) · 37.7 KB
/
make_tests.sh
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
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#for user doc, check scripts/00-template
base_args=""
GNU_TIME=/usr/bin/time
GNU_DATE=date
GNU_TIMEOUT=timeout
#GNU_SED=sed
DIFF=diff
GCOV=gcov
READLINK=readlink
UNBUFFER="${UNBUFFER:-}"
EXTERNAL_MEDIA_AVAILABLE=1
platform=`uname -s`
if [ $platform = "Darwin" ] ; then
GNU_TIME=gtime
GNU_DATE=gdate
GNU_TIMEOUT=gtimeout
READLINK=greadlink
fi
#if the script in launched from elsewhere, main_dir still needs to be the script directory
main_dir="$(dirname $($READLINK -f $0))"
cd $main_dir
#if launched from an absolute path, set all paths as absolute (will break on cygwin)
rel_main_dir="."
if [[ "$0" = /* ]]; then
rel_main_dir=$main_dir
fi
generate_hash=0
global_test_ui=0
log_after_fail=0
verbose=0
enable_timeout=0
skip_next_hash_test=0
do_playback=0
do_clean=0
quiet=0
do_clean_hash=0
check_only=0
disable_hash=0
strict_mode=0
track_stack=0
speed=1
single_test_name=""
keep_temp_dir=0
store_video=0
quick_mode=0
gpac_profile=""
skip_all_tests=0
dump_js=0
current_script=""
DEF_DUMP_DUR=10
DEF_DUMP_SIZE="200x200"
DEF_TIMEOUT=20
echo "" > all_tests.js
#remote location of resource files: all media files, hash files and generated videos
REFERENCE_DIR="https://download.tsi.telecom-paristech.fr/gpac/gpac_test_suite/resources"
#dir where all external media are stored
EXTERNAL_MEDIA_DIR="$rel_main_dir/external_media"
#dir where all hashes are stored
HASH_DIR="$rel_main_dir/hash_refs"
#dir where all specific test rules (override of defaults, positive tests, ...) are stored
RULES_DIR="$rel_main_dir/rules"
#dir where all referenced videos are stored
SCRIPTS_DIR="$rel_main_dir/scripts"
#dir where all referenced videos are stored
VIDEO_DIR_REF="$rel_main_dir/external_videos_refs"
#dir where all local media data (ie from git repo) is stored
MEDIA_DIR="$rel_main_dir/media"
#local dir where all data will be generated (except hashes and referenced videos)
LOCAL_OUT_DIR="$rel_main_dir/results"
#dir where all test videos are generated
VIDEO_DIR="$LOCAL_OUT_DIR/videos"
#dir where all logs are generated
LOGS_DIR="$LOCAL_OUT_DIR/logs"
#temp dir for any test
INTERN_TEMP_DIR="$LOCAL_OUT_DIR/temp"
TEMP_DIR=$INTERN_TEMP_DIR
HAS_GPAC_NODE="no"
ALL_REPORTS="$LOCAL_OUT_DIR/all_results.xml"
ALL_LOGS="$LOCAL_OUT_DIR/all_logs.txt"
TEST_ERR_FILE="$TEMP_DIR/err_exit"
rm -f "$TEST_ERR_FILE" 2> /dev/null
rm -f "$LOGS_DIR/*.sh" 2> /dev/null
if [ ! -e $LOCAL_OUT_DIR ] ; then
mkdir $LOCAL_OUT_DIR
fi
if [ ! -e $HASH_DIR ] ; then
mkdir $HASH_DIR
fi
if [ ! -e $VIDEO_DIR ] ; then
mkdir $VIDEO_DIR
fi
if [ ! -e $VIDEO_DIR_REF ] ; then
mkdir $VIDEO_DIR_REF
fi
if [ ! -e $LOGS_DIR ] ; then
mkdir $LOGS_DIR
fi
if [ ! -e $RULES_DIR ] ; then
mkdir $RULES_DIR
fi
if [ ! -e $INTERN_TEMP_DIR ] ; then
mkdir $INTERN_TEMP_DIR
fi
L_ERR=1
L_WAR=2
L_INF=3
L_DEB=4
log()
{
if [ $quiet = 1 ]; then
return;
fi
if [ $TERM = "cygwin" ]; then
if [ $1 = $L_ERR ]; then
echo -ne "\033[31m"
elif [ $1 = $L_WAR ]; then
echo -ne "\033[32m"
elif [ $1 = $L_INF ]; then
echo -ne "\033[34m"
elif [ $verbose = 0 ]; then
echo -ne "\033[0m"
return
fi
echo $2
echo -ne "\033[0m"
else
if [ $1 = $L_ERR ]; then
tput setaf 1
elif [ $1 = $L_WAR ]; then
tput setaf 2
elif [ $1 = $L_INF ]; then
tput setaf 3
elif [ $verbose = 0 ]; then
tput sgr0
return
fi
echo $2
tput sgr0
fi
}
print_usage ()
{
echo "GPAC Test Suite Usage: $0 [<options>] [<SCRIPTS>]"
echo ""
echo "*** Test suite validation options"
echo " -clean [ARG]: removes all results (logs, stat cache and video). If ARG is specified, only clean tests generated by scripts ARG."
echo " -no-hash: runs test suite without hash checking."
echo ""
echo "*** Test suite generation options"
echo " -clean-hash [ARG]: removes all generated hash, logs, stat cache and videos. If ARG is specified, only clean tests generated by scripts ARG."
echo " -hash: regenerate tests with missing hash files."
echo " -uirec: generates UI event traces."
echo " -uiplay: replays all recorded UI event traces."
echo " -speed=N: sets playback speed for -uiplay. Default is 1."
echo ""
echo "*** General options"
echo " -strict: stops at the first failed test"
echo " -warn: dump logs after each failed test (used for travisCI)"
echo " -videos: stores all videos from playback tests in $VIDEO_DIR"
echo " -keep-tmp or -tmp: keeps tmp folder used in tests (erased by default)"
echo " -sync-hash: syncs all remote reference hashes with local base"
echo " -git-hash: syncs all remote reference hashes from git with local base"
echo " -sync-media: syncs all remote media with local base (warning this can be long)"
echo " -sync-refs: syncs all remote reference videos with local base (warning this can be long)"
echo " -sync-before: syncs all remote resources with local base (warning this can be long) before running the tests"
echo " -check: check test suites (names of each test is unique)"
echo " -track-stack: track stack in malloc and turns on -warn option"
echo " -play: executes playback tests (not all tests use playback tests)"
echo " -p=NAME: sets execution profile of all gpac apps to NAME. Use '-p=0' to disable profiles from local storage (eg for parallel executions of test suite)"
echo " -test=NAME only executes given test"
echo " -precommit alias for -sync-before -git-hash -warn. Before commit/push, you should run ./make_tests -precommit"
echo " -quick only executes the first test of each script"
echo " -timeout=SECONDS sets the timeout for each test command (default: 20)"
echo " SCRIPTS only runs the scripts provided as arguments, by default runs everything in $SCRIPTS_DIR"
echo " -v: set verbose output"
echo " -quiet: only print each test result"
echo " -h: print this help"
}
#performs mirroring of media and references hash & videos
sync_media ()
{
log $L_INF "- Mirroring $REFERENCE_DIR/media/ to $EXTERNAL_MEDIA_DIR"
if [ ! -e $EXTERNAL_MEDIA_DIR ] ; then
mkdir $EXTERNAL_MEDIA_DIR
fi
cd $EXTERNAL_MEDIA_DIR
wget -q -m -nH --no-parent --cut-dirs=4 --reject "*.gif" --reject "index.html*" --restrict-file-names=nocontrol "$REFERENCE_DIR/media/"
cd "$main_dir"
}
sync_hash ()
{
return 0
log $L_INF "- Mirroring reference hashes from from github to $HASH_DIR"
cd $HASH_DIR
if [ ! -d ".git" ]; then
rm -f *
git clone https://github.com/gpac/gpac-test-hash.git .
else
git fetch origin
git reset --hard origin/master
fi
cd "$main_dir"
}
#performs mirroring of media and references hash & videos
sync_refs ()
{
log $L_INF "- Mirroring reference videos from $REFERENCE_DIR to $VIDEO_DIR_REF"
cd $VIDEO_DIR_REF
wget -q -m -nH --no-parent --cut-dirs=4 --reject "*.gif" "$REFERENCE_DIR/video_refs/"
cd "$main_dir"
}
url_arg=()
#Parse arguments
for i in $* ; do
case $i in
"-hash")
generate_hash=1;;
"-play-all")
;;
"-clean")
do_clean=1;;
"-clean-hash")
do_clean_hash=1;;
"-uirec")
global_test_ui=1;;
"-uiplay")
global_test_ui=2;;
-speed*)
speed="${i#-speed=}"
;;
"-keep-avi")
;;
"-videos")
store_video=1;;
"-keep-tmp")
keep_temp_dir=1;;
"-tmp")
keep_temp_dir=1;;
"-no-hash")
disable_hash=1;;
"-strict")
strict_mode=1;;
"-sync-hash")
sync_hash
exit;;
"-git-hash")
sync_hash;;
"-sync-media")
sync_media;;
"-sync-refs")
sync_refs
exit;;
"-sync-before")
sync_media;;
"-check")
check_only=1;;
"-warn")
log_after_fail=1;;
"-track-stack")
track_stack=1;;
"-noplay")
;;
"-play")
do_playback=1;;
"-quick")
quick_mode=1;;
"-quiet")
quiet=1;;
-test*)
single_test_name="${i#-test=}"
;;
"-v")
verbose=1;;
-p=*)
gpac_profile="${i#-p=}"
;;
"-precommit")
sync_media
sync_hash
log_after_fail=1
;;
-timeout=*)
DEF_TIMEOUT="${i#-timeout=}"
;;
"-h")
print_usage
exit;;
-*)
log $L_ERR "Unknown Option \"$i\" - check usage (-h)"
exit;;
*)
url_arg+=("$i")
;;
esac
done
if [ $check_only != 0 ] ; then
do_clean_hash=0
do_clean=0
global_test_ui=0
fi
#Clean all hashes and reference videos
if [ $do_clean_hash != 0 ] ; then
#force cleaning as well
do_clean=1
#when using specific scripts, cleanup will be done in test_begin()
if [ "${#url_arg[@]}" -eq 0 ] ; then
read -p "This will remove all referenced videos and hashes. Are you sure (y/n)?" choice
if [ $choice != "y" ] ; then
log $L_ERR "Canceled"
exit
fi
log $L_INF "Deleting SHA-1 Hashes"
rm -rf $HASH_DIR/* 2> /dev/null
rm -rf $VIDEO_DIR_REF/* 2> /dev/null
fi
fi
#Clean all cached results and generated videos
if [ $do_clean != 0 ] ; then
rm -f $ALL_REPORTS > /dev/null
rm -f $ALL_LOGS > /dev/null
rm -rf $INTERN_TEMP_DIR/* 2> /dev/null
if [ "${#url_arg[@]}" -eq 0 ] ; then
echo "Deleting cache (logs, stats and videos)"
find "$main_dir/$LOGS_DIR/" -mindepth 1 -delete > /dev/null
rm -rf $VIDEO_DIR/* 2> /dev/null
exit
fi
fi
log $L_INF "Checking test suite config"
if [ $generate_hash = 0 ] ; then
log $L_INF "- Enabling hash tests"
fi
if [ ! -e $EXTERNAL_MEDIA_DIR ] ; then
EXTERNAL_MEDIA_AVAILABLE=0
elif [ ! -e $EXTERNAL_MEDIA_DIR/counter ] ; then
EXTERNAL_MEDIA_AVAILABLE=0
fi
if [ $EXTERNAL_MEDIA_AVAILABLE = 0 ] ; then
log $L_WAR "- External media dir unavailable - you may sync it using -sync-media"
else
log $L_INF "- External media dir available"
fi
#test for GNU time
$GNU_TIME ls > /dev/null 2>&1
res=$?
if [ $res != 0 ] ; then
log $L_ERR "GNU time not found (ret $res) - exiting"
exit 1
fi
#test for GNU date
$GNU_DATE > /dev/null 2>&1
res=$?
if [ $res != 0 ] ; then
log $L_ERR "GNU date not found (ret $res) - exiting"
exit 1
fi
#test for timeout
$GNU_TIMEOUT 1.0 ls > /dev/null 2>&1
res=$?
if [ $res != 0 ] ; then
log $L_ERR "GNU timeout not found (ret $res) - some tests may hang forever ..."
enable_timeout=0
else
enable_timeout=1
fi
node -v > /dev/null 2>&1
res=$?
if [ $res = 0 ] ; then
TMPFILE=$(mktemp)
cat <<EOF > $TMPFILE
const gpac = require('gpac');
console.log("Welcome to GPAC NodeJS !\nVersion: " + gpac.version);
EOF
node $TMPFILE > /dev/null 2>&1
node_res=$?
rm $TMPFILE
if [ $node_res = 0 ] ; then
HAS_GPAC_NODE="yes"
fi
fi
if [ $check_only = 0 ] ; then
#check MP4Box and gpac (use default args, not custom ones because of -mem-track)
MP4Box -h > /dev/null 2>&1
res=$?
if [ $res != 0 ] ; then
log $L_ERR "MP4Box not found (ret $res) - exiting"
exit 1
fi
GPAC_OSTYPE="unknown"
gpac -p=0 -h > /dev/null 2>&1
res=$?
if [ $res != 0 ] ; then
log $L_ERR "gpac not found (ret $res) - exiting"
#exit 1
else
bininfo=`gpac -h bin 2>&1`
config=`echo $bininfo | grep GPAC_64`
if [ -z "$config" ] ; then
bits=32
else
bits=64
fi
config=`echo $bininfo | grep GPAC_CONFIG_LINUX`
if [ -n "$config" ] ; then
GPAC_OSTYPE="lin$bits"
else
config=`echo $bininfo | grep GPAC_CONFIG_DARWIN`
if [ -n "$config" ] ; then
GPAC_OSTYPE="osx$bits"
else
config=`echo $bininfo | grep GPAC_CONFIG_WIN`
if [ -n "$config" ] ; then
GPAC_OSTYPE="win$bits"
fi
fi
fi
fi
#check mem tracking is supported
res=`MP4Box -mem-track -h 2>&1 | grep "WARNING"`
if [ -n "$res" ]; then
log $L_WAR "- GPAC not compiled with memory tracking"
else
log $L_INF "- Enabling memory tracking"
if [ $track_stack = 1 ]; then
base_args="$base_args -mem-track-stack"
log_after_fail=1
else
base_args="$base_args -mem-track"
fi
fi
#set check-props by default if supported
has_props=`gpac -hh core | grep check-props`
if [ "$has_props" != "" ] ; then
base_args="$base_args -check-props"
log $L_INF "- Enabling property checking"
fi
fi
#end check_only
echo ""
#reassign our default programs
MP4BOX="MP4Box -noprog -for-test -old-arch $base_args"
GPAC="gpac $base_args -noprog -for-test -old-arch -no-reassign "
if [ "$gpac_profile" != "" ] ; then
log $L_INF "GPAC profile: $gpac_profile"
MP4BOX="$MP4BOX -p=$gpac_profile"
GPAC="$GPAC -p=$gpac_profile"
fi
$MP4BOX -version 2> $INTERN_TEMP_DIR/version.txt
VERSION="`head -1 $INTERN_TEMP_DIR/version.txt | cut -d ' ' -f 5-` "
rm $INTERN_TEMP_DIR/version.txt
log $L_INF "GPAC version: $VERSION"
log $L_INF ""
#reset all the possible return values
reset_stat ()
{
EXECUTION_STATUS="N/A"
RETURN_VALUE="N/A"
MEM_TOTAL_AVG="N/A"
MEM_RESIDENT_AVG="N/A"
MEM_RESIDENT_MAX="N/A"
CPU_PERCENT="N/A"
CPU_ELAPSED_TIME="N/A"
CPU_USER_TIME="N/A"
CPU_KERNEL_TIME="N/A"
PAGE_FAULTS="N/A"
FILE_INPUTS="N/A"
SOCKET_MSG_REC="N/A"
SOCKET_MSG_SENT="N/A"
}
test_start_ts=0
#begin a test with name $1 and using hashes called $1-$2 ... $1-$N
test_begin ()
{
if [ $# -gt 1 ] ; then
log $L_ERR "> in script $current_script line $BASH_LINENO"
log $L_ERR " @test_begin takes only two arguments - wrong call (first arg is $1)"
fi
if [ $dump_js = 1 ] ; then
test_skip=0
echo '{ "name": "'$1'", "tests": [' >> all_tests.js
return
fi
test_skip=0
result=""
TEST_NAME=$1
reference_hash_valid="$HASH_DIR/$TEST_NAME-valid-hash"
log $L_DEB "Starting test $TEST_NAME"
TEMP_DIR=$INTERN_TEMP_DIR
report="$TEMP_DIR/$TEST_NAME-temp.txt"
LOGS="$LOGS_DIR/$TEST_NAME-logs.txt-new"
final_report="$LOGS_DIR/$TEST_NAME-passed.xml"
test_ui=0
test_start_ts=`$GNU_DATE +%s%N`
if [ $do_clean != 0 ] ; then
if [ $do_clean_hash != 0 ] ; then
rm -rf $HASH_DIR/$TEST_NAME* 2> /dev/null
rm -rf $VIDEO_DIR_REF/$TEST_NAME* 2> /dev/null
rm -rf $reference_hash_valid 2> /dev/null
fi
rm -rf $LOGS_DIR/$TEST_NAME* > /dev/null
rm -rf $VIDEO_DIR/$TEST_NAME* 2> /dev/null
test_skip=1
return
fi
if [ $quick_mode != 0 ] ; then
if [ $skip_all_tests != 0 ] ; then
test_skip=1
return
fi
skip_all_tests=1
fi
if [ $check_only != 0 ] ; then
test_ui=0
report="$TEMP_DIR/$TEST_NAME.test"
if [ -f $report ] ; then
log $L_ERR "Test $TEST_NAME already exists - please fix ($current_script)"
rm -rf $TEMP_DIR/* 2> /dev/null
exit
fi
echo "" > $report
test_skip=1
return
fi
if [ $keep_temp_dir != 0 ] ; then
TEMP_DIR="$INTERN_TEMP_DIR/$TEST_NAME"
if [ ! -e $TEMP_DIR ] ; then
mkdir $TEMP_DIR
fi
fi
#reset defaults
dump_dur=$DEF_DUMP_DUR
dump_size=$DEF_DUMP_SIZE
test_timeout=$DEF_TIMEOUT
test_skip=0
single_test=0
test_args="$@"
test_nb_args=$#
skip_play_hash=0
subtest_idx=0
nb_subtests=0
test_ui=$global_test_ui
test_stats="$LOGS_DIR/$TEST_NAME-stats.sh"
#if error in strict mode, mark the test as skippable using value 2
if [ $strict_mode = 1 ] ; then
if [ -f $TEST_ERR_FILE ] ; then
test_skip=2
fi
fi
if [ $generate_hash = 1 ] ; then
#skip test only if reference hash is marked as valid
if [ -f "$reference_hash_valid" ] ; then
log $L_DEB "Reference hash found for test $TEST_NAME - skipping hash generation"
test_skip=1
fi
elif [ $test_ui != 0 ] ; then
test_skip=0
elif [ $test_skip = 0 ] ; then
#skip test only if final report is present (whether we generate hashes or not)
if [ -f "$final_report" ] ; then
if [ -f "$test_stats" ] ; then
log $L_DEB "$TEST_NAME already passed - skipping"
test_skip=1
else
log $L_WAR "$TEST_NAME already passed but missing stats.sh - regenerating"
fi
fi
fi
if [ "$single_test_name" != "" ] && [ "$single_test_name" != "$TEST_NAME" ] ; then
test_ui=0
test_skip=1
fi
if [ $test_skip != 0 ] ; then
#stats.sh may be missing when generating hashes and that's not an error
if [ -f "$test_stats" ] ; then
has_skip=`grep -w "TEST_SKIP" $test_stats`
if [ "$has_skip" = "" ]; then
echo "TEST_SKIP=$test_skip" >> $test_stats
fi
fi
test_skip=1
elif [ $test_ui != 0 ] ; then
#in UI test mode don't check cache status, always run the tests
test_skip=1
else
echo "*** $TEST_NAME logs (GPAC version $VERSION) - test date $(date '+%d/%m/%Y %H:%M:%S') ***" > $LOGS
echo "" >> $LOGS
fi
rules_sh=$RULES_DIR/$TEST_NAME.sh
if [ -f $rules_sh ] ; then
source $rules_sh
fi
if [ $test_skip != 0 ] ; then
TEMP_DIR=$INTERN_TEMP_DIR
fi
}
mark_test_error ()
{
if [ $strict_mode = 1 ] ; then
echo "" > $TEST_ERR_FILE
log $L_ERR "Error test $TEST_NAME subtest $SUBTEST_NAME - aborting"
fi
}
test_end_ts=0
#ends test - gather all logs/stats produced and generate report
test_end ()
{
#wait for all sub-tests to complete (some may use subshells)
wait
test_end_ts=`$GNU_DATE +%s%N`
test_runtime=$((test_end_ts-test_start_ts))
test_runtime=$(($test_runtime / 1000000))
if [ $dump_js = 1 ] ; then
test_skip=0
echo '{}]},' >> all_tests.js
return
fi
TEMP_DIR=$INTERN_TEMP_DIR
if [ $# -gt 0 ] ; then
log $L_ERR "> in test $TEST_NAME in script $current_script line $BASH_LINENO"
log $L_ERR " @test_end takes no argument - wrong call"
fi
if [ $test_skip = 1 ] ; then
return
fi
test_stats="$LOGS_DIR/$TEST_NAME-stats.sh"
echo "" > $test_stats
stat_xml_temp="$TEMP_DIR/$TEST_NAME-statstemp.xml"
echo "" > $stat_xml_temp
test_fail=0
test_leak=0
test_exec_na=0
nb_subtests=0
nb_test_hash=0
nb_hash_fail=0
nb_hash_missing=0
if [ "$result" != "" ] ; then
test_fail=1
fi
# makes glob on non existing files to expand to null
# enabling loops on nonexisting* to be empty
shopt -s nullglob
#gather all stats per subtests
for i in $TEMP_DIR/$TEST_NAME-stats-*.sh ; do
reset_stat
RETURN_VALUE=0
SUBTEST_NAME=""
COMMAND_LINE=""
SUBTEST_IDX=0
nb_subtests=$((nb_subtests + 1))
source $i
echo " <stat subtest=\"$SUBTEST_NAME\" execution_status=\"$EXECUTION_STATUS\" return_status=\"$RETURN_STATUS\" mem_total_avg=\"$MEM_TOTAL_AVG\" mem_resident_avg=\"$MEM_RESIDENT_AVG\" mem_resident_max=\"$MEM_RESIDENT_MAX\" cpu_percent=\"$CPU_PERCENT\" cpu_elapsed_time=\"$CPU_ELAPSED_TIME\" cpu_user_time=\"$CPU_USER_TIME\" cpu_kernel_time=\"$CPU_KERNEL_TIME\" page_faults=\"$PAGE_FAULTS\" file_inputs=\"$FILE_INPUTS\" socket_msg_rec=\"$SOCKET_MSG_REC\" socket_msg_sent=\"$SOCKET_MSG_SENT\" return_value=\"$RETURN_VALUE\">" >> $stat_xml_temp
echo " <command_line>$COMMAND_LINE</command_line>" >> $stat_xml_temp
echo " </stat>" >> $stat_xml_temp
test_ok=1
if [ $RETURN_VALUE -eq 1 ] ; then
result="$SUBTEST_NAME:Fail $result"
test_ok=0
test_fail=$((test_fail + 1))
elif [ $RETURN_VALUE -eq 2 ] ; then
result="$SUBTEST_NAME:MemLeak $result"
test_ok=0
test_leak=$((test_leak + 1))
elif [ $RETURN_VALUE != 0 ] ; then
if [ $enable_timeout != 0 ] && [ $RETURN_VALUE = 124 ] ; then
result="$SUBTEST_NAME:Timeout $result"
else
result="$SUBTEST_NAME:Fail(ret code $RETURN_VALUE) $result"
fi
test_ok=0
test_fail=$((test_fail + 1))
fi
if [ $log_after_fail = 1 ] ; then
if [ $test_ok = 0 ] ; then
sublog=$LOGS_DIR/$TEST_NAME-logs-$SUBTEST_IDX-$SUBTEST_NAME.txt
if [ -f $sublog ] ; then
cat $sublog 2> stderr
fi
fi
fi
rm -f $i > /dev/null
done
# list all logs files
for i in $LOGS_DIR/$TEST_NAME-logs-*.txt; do
wa=`grep "Wrong argument value" $i`
#exception for this test where we test bad formatting for coverage
if [ "$wa" != "" ] && [ "$TEST_NAME" != "gpac-filter-dump_props" ] ; then
result="$result CMDLINE_INVALID"
if [ $test_ok != 0 ] ; then
test_ok=0
test_fail=$((test_fail + 1))
fi
fi
cat $i >> $LOGS
done
rm -f $LOGS_DIR/$TEST_NAME-logs-*.txt > /dev/null
#gather all hashes for this test
for i in $TEMP_DIR/$TEST_NAME-stathash-*.sh ; do
if [ -f $i ] ; then
HASH_TEST=""
HASH_NOT_FOUND=0
HASH_FAIL=0
SRC_NOT_FOUND=0
source $i
nb_test_hash=$((nb_test_hash + 1))
if [ $HASH_NOT_FOUND -eq 1 ] ; then
result="$HASH_TEST:HashNotFound $result"
nb_hash_missing=$((nb_hash_missing + 1))
test_exec_na=$((test_exec_na + 1))
elif [ $SRC_NOT_FOUND -eq 1 ] ; then
result="$HASH_TEST:HashSourceNotFound $result"
test_ok=0
nb_hash_fail=$((nb_hash_fail + 1))
test_exec_na=$((test_exec_na + 1))
elif [ $HASH_FAIL -eq 1 ] ; then
result="$HASH_TEST:HashFail $result"
test_ok=0
nb_hash_fail=$((nb_hash_fail + 1))
test_exec_na=$((test_exec_na + 1))
fi
fi
rm -f $i > /dev/null
done
if [ "$result" = "" ] ; then
result="OK"
fi
if [ ! -f $TEST_ERR_FILE ] ; then
if [ $generate_hash = 1 ] ; then
log $L_DEB "Test $TEST_NAME $nb_subtests subtests and $nb_test_hash hashes"
nb_hashes=$((nb_test_hash + nb_test_hash))
#only allow no hash if only one subtest
if [ $subtest_idx -gt 1 ] && [ $nb_hashes -lt $subtest_idx ] ; then
log $L_ERR "Test $TEST_NAME has too few hash tests: $nb_hashes for $nb_subtests subtests - please fix"
result="NOT ENOUGH HASHES"
else
echo "ok" > $reference_hash_valid
fi
# if [ $nb_test_hash -gt 15 ] ; then
# log $L_WAR "Test $TEST_NAME has too many subtests with hashes ($nb_test_hash), not efficient for hash generation - consider rewriting $current_script"
# fi
fi
fi
echo " <test name=\"$TEST_NAME\" result=\"$result\" date=\"$(date '+%d/%m/%Y %H:%M:%S')\" runtime=\"$test_runtime\">" > $report
cat $stat_xml_temp >> $report
rm -f $stat_xml_temp > /dev/null
echo " </test>" >> $report
echo "TEST_FAIL=$test_fail" >> $test_stats
echo "TEST_EXEC_NA=$test_exec_na" >> $test_stats
echo "SUBTESTS_LEAK=$test_leak" >> $test_stats
echo "NB_HASH_SUBTESTS=$nb_test_hash" >> $test_stats
echo "NB_HASH_SUBTESTS_MISSING=$nb_hash_missing" >> $test_stats
echo "NB_HASH_SUBTESTS_FAIL=$nb_hash_fail" >> $test_stats
echo "NB_SUBTESTS=$nb_subtests" >> $test_stats
if [ "$result" == "OK" ] ; then
mv $report "$LOGS_DIR/$TEST_NAME-passed-new.xml"
echo "$TEST_NAME: $result"
else
mv $report "$LOGS_DIR/$TEST_NAME-failed.xml"
mark_test_error
log $L_ERR "$TEST_NAME: $result"
fi
shopt -u nullglob
}
#@do_test execute the command line given $1 using GNU time and store stats with return value, command line ($1) and subtest name ($2)
ret=0
do_test ()
{
skip_next_hash_test=0
if [ $dump_js = 1 ] ; then
test_skip=0
echo '{ "subtest": "'$2'", "cmd": "'$1'"},' >> all_tests.js
return
fi
if [ $# -gt 2 ] ; then
log $L_ERR "> in test $TEST_NAME in script $current_script line $BASH_LINENO"
log $L_ERR " @do_test takes only two arguments - wrong call (first arg $1)"
fi
if [ $strict_mode = 1 ] ; then
if [ -f $TEST_ERR_FILE ] ; then
return
fi
fi
if [ $test_skip = 1 ] ; then
return
fi
log L_DEB "executing $1"
subtest_idx=$((subtest_idx + 1))
log_subtest="$LOGS_DIR/$TEST_NAME-logs-$subtest_idx-$2.txt"
stat_subtest="$INTERN_TEMP_DIR/$TEST_NAME-stats-$subtest_idx-$2.sh"
SUBTEST_NAME=$2
echo "" > $log_subtest
echo "*** Subtest \"$2\": executing \"$1\" ***" >> $log_subtest
timeout_args=""
if [ $enable_timeout != 0 ] ; then
timeout_args="$GNU_TIMEOUT $test_timeout"
fi
$UNBUFFER $timeout_args $GNU_TIME -o $stat_subtest -f ' EXECUTION_STATUS="OK"\n RETURN_STATUS=%x\n MEM_TOTAL_AVG=%K\n MEM_RESIDENT_AVG=%t\n MEM_RESIDENT_MAX=%M\n CPU_PERCENT=%P\n CPU_ELAPSED_TIME=%E\n CPU_USER_TIME=%U\n CPU_KERNEL_TIME=%S\n PAGE_FAULTS=%F\n FILE_INPUTS=%I\n SOCKET_MSG_REC=%r\n SOCKET_MSG_SENT=%s' $1 >> $log_subtest 2>&1
rv=$?
echo "SUBTEST_NAME=$2" >> $stat_subtest
echo "SUBTEST_IDX=$subtest_idx" >> $stat_subtest
#regular error, check if this is a negative test.
if [ $rv -eq 1 ] ; then
if [ $single_test = 1 ] ; then
negative_test_stderr=$RULES_DIR/$TEST_NAME-stderr.txt
else
negative_test_stderr=$RULES_DIR/$TEST_NAME-$2-stderr.txt
fi
if [ -f $negative_test_stderr ] ; then
#look for all lines in -stderr file, if one found consider this a success
while read line ; do
res_err=`grep -o "$line" $log_subtest`
if [ -n "$res_err" ]; then
echo "Negative test detected, reverting to success (found \"$res_err\" in stderr)" >> $log_subtest
rv=0
skip_next_hash_test=1
echo "" > $stat_subtest
break
fi
#remove windows style endlines as they may cause some problems
#also remove empty lines otherwise grep always matches
done < <(tr -d '\r' <$negative_test_stderr | sed '/^$/d' )
fi
fi
#override generated stats if error, since gtime may put undesired lines in output file which would break sourcing
if [ $rv != 0 ] ; then
echo "SUBTEST_NAME=$2" > $stat_subtest
echo "SUBTEST_IDX=$subtest_idx" >> $stat_subtest
mark_test_error
fi
echo "RETURN_VALUE=$rv" >> $stat_subtest
echo "COMMAND_LINE=\"$1\"" >> $stat_subtest
echo "" >> $log_subtest
ret=$rv
}
#end do_test
#do_play_test: playback the input video (arg2) and audio (arg3) to vout/aout, and produces the MP4 file for these files
do_play_test ()
{
if [ $# -gt 3 ] ; then
log $L_ERR "> in test $TEST_NAME in script $current_script line $BASH_LINENO"
log $L_ERR " @do_play_test takes only 3 arguments - wrong call (first arg $1)"
return
fi
name=$1