@@ -41,6 +41,7 @@ flag_testing_programs=
41
41
flag_additional_test_name_info=
42
42
43
43
44
+
44
45
C_RED=$( printf " \e[1;31m" )
45
46
C_GREEN=$( printf " \e[1;32m" )
46
47
C_BLUE=$( printf " \e[1;34m" )
@@ -99,6 +100,7 @@ function print_help {
99
100
printf " All available [test_flags] are:\n"
100
101
printf " --ttools <tools> - set additional debug tools\n"
101
102
printf " Tools is the coma-separated array of tools names. Tools names can be as the following:\n"
103
+ printf " * size - prints the size of input file in bytes.\n"
102
104
printf " * time - prints time statistic using Unix time command.\n"
103
105
printf " * stime - measures time using bash date command (not as precise as time tool).\n"
104
106
printf " * vmemcheck - uses valgrind memcheck tools to search for application leaks.\n"
@@ -142,8 +144,24 @@ function print_help {
142
144
}
143
145
144
146
147
+ function prepare_input {
148
+ if [[ -f $param_dir ]]; then
149
+ folder_loc=${param_dir%% .* }
150
+ if [[ ! -d " $folder_loc " ]]; then
151
+ printf " ${B_INFO} Test input is zip file -- needs unzipping...${E_INFO} \n"
152
+ printf " ${B_INFO} This may take a while...${E_INFO} \n"
153
+ mkdir " $folder_loc "
154
+ unzip -q " $param_dir " -d " $folder_loc "
155
+ fi
156
+ flag_good_err_path=" ${flag_good_err_path// $param_dir / $folder_loc } "
157
+ flag_good_out_path=" ${flag_good_out_path// $param_dir / $folder_loc } "
158
+ param_dir=" $folder_loc "
159
+ fi
160
+ }
145
161
146
162
function verify_args {
163
+ printf " ${B_BOLD} --- utest.sh VERSION ${VERSION} v ---${E_BOLD} \n\n"
164
+
147
165
if [[ ${flag_force} = ' false' ]]; then
148
166
149
167
prog_use_autodetect=false
@@ -320,6 +338,7 @@ function count_input_files {
320
338
321
339
322
340
function print_summary {
341
+ printf " \n"
323
342
if [[ $flag_minimal = ' false' ]]; then
324
343
if [[ " $not_exists_index " != " 0" ]]; then
325
344
printf " ${B_WARN} $not_exists_index output files do not exits ${E_WARN} \n"
@@ -427,28 +446,107 @@ function test_err {
427
446
428
447
429
448
449
+
450
+
451
+
452
+
453
+
454
+
455
+
456
+
457
+
458
+ message_accumulator=" "
459
+ message_last_file_head=" "
460
+ message_tooling_data_accumulator=" "
461
+
462
+ function push_test_message_with_head {
463
+ message_accumulator_head=" "
464
+ message_accumulator_file_head=" "
465
+
466
+ if [[ " $message_accumulator " = " " ]]; then
467
+ message_accumulator_head=" ${B_DEBUG} [$file_index /$file_count ]${E_DEBUG} $input_file "
468
+ if [ $flag_testing_programs_len -gt 1 ]; then
469
+ message_accumulator=" ${message_accumulator} \n${message_accumulator_head} \n"
470
+ message_accumulator_head=" "
471
+ fi
472
+ fi
473
+
474
+ message_accumulator_file_head=" $flag_additional_test_name_info "
475
+ if [[ " $message_accumulator_file_head " = " $message_last_file_head " ]]; then
476
+ message_accumulator_file_head=" "
477
+ else
478
+ message_last_file_head=" $message_accumulator_file_head "
479
+ fi
480
+
481
+ tooling_data=" ${message_tooling_data_accumulator} "
482
+ if [[ " $1 " = " " ]]; then
483
+ message_accumulator_line=$( printf " %s%s%s\n" " ${message_accumulator_head}${message_accumulator_file_head} " " $2 " " " )
484
+ else
485
+ message_accumulator_line=$( printf " %-30s%-30s%s\n" " ${message_accumulator_head}${message_accumulator_file_head} " " $1 " " ${tooling_data} " )
486
+ fi
487
+
488
+ # printf "{PUSH TO ACCUMULATOR ${message_accumulator_line}}"
489
+ message_accumulator=" ${message_accumulator} \n${message_accumulator_line} "
490
+ }
491
+
492
+ function push_test_message_error {
493
+ push_test_message_with_head " ${B_ERR} $1 ${E_ERR} "
494
+ }
495
+
496
+ function push_test_message_error_details {
497
+ lineprefix=$( printf " %-20s" " " )
498
+ err_message=$( echo -en " $1 " | sed " s/^/${lineprefix}${B_ERR} \|${E_ERR} /g" )
499
+ push_test_message_with_head " " " ${B_ERR}${err_message}${E_ERR} "
500
+ }
501
+
502
+ function push_test_message_good {
503
+ push_test_message_with_head " ${B_OK} [OK]${E_OK} " " "
504
+ }
505
+
506
+ function push_test_message_tooling_info {
507
+ message_tooling_data_accumulator=" ${message_tooling_data_accumulator} ${B_INFO} [$1 ]${E_INFO} "
508
+ }
509
+
510
+ function push_test_message_next_program {
511
+ message_tooling_data_accumulator=" "
512
+ }
513
+
514
+ function flush_test_messages {
515
+ echo -en " ${message_accumulator} "
516
+ message_accumulator=" "
517
+ message_last_file_head=" "
518
+ message_tooling_data_accumulator=" "
519
+ }
520
+
521
+
522
+
523
+
524
+
525
+
526
+
527
+
528
+
529
+
530
+
531
+
430
532
function flush_err_messages {
431
533
if [[ " $print_error_by_default " = " true" ]]; then
432
534
err_index=$(( err_index+ 1 ))
433
535
err_message=$( cat " $err_path " )
434
- printf " ${B_INFO} i Provided error message: [${err_message} ]${B_INFO} \n"
435
536
if [[ $flag_extreamely_minimalistic = ' true' ]]; then
436
- printf " ${B_ERR} $ input_file${E_ERR} \n "
537
+ push_test_message_error " $ input_file"
437
538
else
438
539
if [[ $flag_very_minimal = ' true' ]]; then
439
- printf " %-35s %s\n " " ${B_DEBUG} [ $file_index / $file_count ] ${E_DEBUG} $input_file $flag_additional_test_name_info " " ${B_ERR} [ERR] Error at stderr${E_ERR} "
540
+ push_test_message_error " Error at stderr"
440
541
else
441
- printf " %-35s %s\n" " ${B_DEBUG} [$file_index /$file_count ]${E_DEBUG} $input_file $flag_additional_test_name_info " " ${B_ERR} [ERR] Error at stderr${E_ERR} "
442
- err_message=$( echo -en " $err_message " | sed " s/^/ $B_ERR \|$E_ERR /g" )
443
- printf " $err_message \n"
542
+ push_test_message_error " Error at stderr"
543
+ push_test_message_error_details " $err_message \n"
444
544
fi
445
545
fi
446
546
fi
447
547
clean_temp_content
448
548
}
449
549
450
-
451
-
452
550
function abort_if_too_many_errors {
453
551
if [[ " $err_index " -gt 5 ]]; then
454
552
if [[ $flag_always_continue = ' false' ]]; then
@@ -469,24 +567,23 @@ function check_out_script {
469
567
if [[ $ok != ' true' ]]; then
470
568
err_index=$(( err_index+ 1 ))
471
569
err_message=$diff
472
- err_message=$( echo -en " $err_message " | sed " s/^/ $B_ERR \|$E_ERR /g" )
473
570
if [[ $flag_extreamely_minimalistic = ' false' ]]; then
474
- printf " %-35s %s\n " " ${B_DEBUG} [ $file_index / $file_count ] ${E_DEBUG} $input_file $flag_additional_test_name_info " " ${B_ERR} [ERR] Invalid tester answer${E_ERR} "
571
+ push_test_message_error " Invalid tester answer"
475
572
else
476
- printf " ${B_ERR} $ input_file${E_ERR} \n "
573
+ push_test_message_error " $ input_file"
477
574
fi
478
575
if [[ $flag_very_minimal = ' false' ]]; then
479
576
# We dont want this
480
577
if [[ ' true' = ' false' ]]; then
481
- printf " \n ${B_ERR} _ ${E_ERR} \n$err_message \n ${B_ERR} |_${E_ERR} \n"
578
+ push_test_message_error " \n$err_message \n ${B_ERR} |_${E_ERR} \n"
482
579
else
483
- printf " $err_message \n"
580
+ push_test_message_error_details " $err_message \n"
484
581
fi
485
582
fi
486
583
else
487
584
ok_index=$(( ok_index+ 1 ))
488
585
if [[ $flag_skip_ok = ' false' ]]; then
489
- printf " %-35s %s\n " " ${B_DEBUG} [ $file_index / $file_count ] ${E_DEBUG} $input_file $flag_additional_test_name_info " " ${B_OK} [OK] ${E_OK} "
586
+ push_test_message_good
490
587
fi
491
588
rm -f $err_path
492
589
fi
@@ -504,18 +601,17 @@ function check_out_script_err {
504
601
print_error_by_default=false
505
602
err_index=$(( err_index+ 1 ))
506
603
err_message=$diff
507
- err_message=$( echo -en " $err_message " | sed " s/^/ $B_ERR \|$E_ERR /g" )
508
604
if [[ $flag_extreamely_minimalistic = ' false' ]]; then
509
- printf " %-35s %s\n " " ${B_DEBUG} [ $file_index / $file_count ] ${E_DEBUG} $err_path $flag_additional_test_name_info " " ${B_ERR} [ERR] Invalid tester answer for stderr${E_ERR} "
605
+ push_test_message_error " Invalid tester answer for stderr"
510
606
else
511
- printf " ${B_ERR} $ err_path${E_ERR} \n "
607
+ push_test_message_erro " $ err_path"
512
608
fi
513
609
if [[ $flag_very_minimal = ' false' ]]; then
514
610
# We dont want this
515
611
if [[ ' true' = ' false' ]]; then
516
- printf " \n ${B_ERR} _ ${E_ERR} \n$err_message \n ${B_ERR} |_${E_ERR} \n"
612
+ push_test_message_error_details " \n$err_message \n ${B_ERR} |_${E_ERR} \n"
517
613
else
518
- printf " $err_message \n"
614
+ push_test_message_error_details " $err_message \n"
519
615
fi
520
616
fi
521
617
fi
@@ -525,27 +621,26 @@ function check_out_diff {
525
621
if [[ $diff != ' ' ]]; then
526
622
err_index=$(( err_index+ 1 ))
527
623
err_message=$diff
528
- err_message=$( echo -en " $err_message " | sed " s/^/ $B_ERR \|$E_ERR /g" )
529
624
530
625
if [[ $flag_extreamely_minimalistic = ' false' ]]; then
531
- printf " %-35s %s\n " " ${B_DEBUG} [ $file_index / $file_count ] ${E_DEBUG} $input_file $flag_additional_test_name_info " " ${B_ERR} [ERR] Non matching output${E_ERR} "
626
+ push_test_message_error " Non matching output"
532
627
else
533
- printf " ${B_ERR} $ input_file${E_ERR} \n"
628
+ push_test_message_error " $ input_file \n"
534
629
fi
535
630
536
631
if [[ $flag_very_minimal = ' false' ]]; then
537
632
# We dont want this
538
633
if [[ ' true' = ' false' ]]; then
539
- printf " \n ${B_ERR} _ ${E_ERR} \n$err_message \n ${B_ERR} |_${E_ERR} \n"
634
+ push_test_message_error_details " \n$err_message \n ${B_ERR} |_${E_ERR} \n"
540
635
else
541
- printf " $err_message \n"
636
+ push_test_message_error_details " $err_message \n"
542
637
fi
543
638
fi
544
639
545
640
else
546
641
ok_index=$(( ok_index+ 1 ))
547
642
if [[ $flag_skip_ok = ' false' ]]; then
548
- printf " %-35s %s\n " " ${B_DEBUG} [ $file_index / $file_count ] ${E_DEBUG} $input_file $flag_additional_test_name_info " " ${B_OK} [OK] ${E_OK} "
643
+ push_test_message_good
549
644
fi
550
645
rm -f $err_path
551
646
@@ -664,34 +759,46 @@ function run_program {
664
759
665
760
if [[ $flag_tools_use_stime = ' true' ]]; then
666
761
tool_time_data_stime_end=` date +%s%3N`
667
- tooling_additional_test_info=" ${tooling_additional_test_info} Execution time (script dependent): $(( tool_time_data_stime_end- tool_time_data_stime_start)) ms\n"
762
+ push_test_message_tooling_info " $(( tool_time_data_stime_end- tool_time_data_stime_start)) ms"
763
+ # tooling_additional_test_info="${tooling_additional_test_info}Execution time (script dependent): $((tool_time_data_stime_end-tool_time_data_stime_start)) ms\n"
668
764
fi
669
765
670
766
if [[ $flag_tools_use_time = ' true' ]]; then
671
767
# r=$($param_prog $input_prog_flag_acc < $input_file_path 1> $out_path 2> $err_path)
672
768
timeOut=$( { time $param_prog $input_prog_flag_acc < $input_file_path 1> /dev/null 2> /dev/null ; } 2>&1 )
673
769
timeOut=" $( echo -e " ${timeOut} " | sed ' /./,$!d' ) "
674
- tooling_additional_test_info=" ${tooling_additional_test_info}${timeOut} \n"
770
+ # tooling_additional_test_info="${tooling_additional_test_info}${timeOut}\n"
771
+ timeReal=$( echo " ${timeOut} " | grep real | sed -e ' s/real//' )
772
+ timeReal=" $( echo -e " ${timeReal} " | tr -d ' [:space:]' ) "
773
+ push_test_message_tooling_info " ${timeReal} "
675
774
fi
676
775
677
776
if [[ $flag_tools_use_vmassif = ' true' ]]; then
678
777
{ valgrind --tool=massif --pages-as-heap=yes --massif-out-file=massif.out $param_prog $input_prog_flag_acc < $input_file_path 1> /dev/null 2> /dev/null ; } > /dev/null 2>&1
679
778
memUsage=$( grep mem_heap_B massif.out | sed -e ' s/mem_heap_B=\(.*\)/\1/' | sort -g | tail -n 1)
680
779
memUsage=$( echo " scale=5; $memUsage /1000000" | bc)
681
- tooling_additional_test_info=" ${tooling_additional_test_info} Peak memory usage: ${memUsage} MB\n"
780
+ # tooling_additional_test_info="${tooling_additional_test_info}Peak memory usage: ${memUsage}MB\n"
781
+ push_test_message_tooling_info " ${memUsage} MB"
682
782
rm ./massif.out
683
783
fi
684
784
685
785
if [[ $flag_tools_use_vmemcheck = ' true' ]]; then
686
786
{ valgrind --tool=memcheck $param_prog $input_prog_flag_acc < $input_file_path > /dev/null ; } 2> ./memcheck.out
687
787
leaksReport=$( sed ' s/==.*== //' ./memcheck.out | sed -n -e ' /LEAK SUMMARY:/,$p' | sed ' s/LEAK SUMMARY://' | head -5)
688
788
if [[ $leaksReport != ' ' ]]; then
689
- tooling_additional_test_info=" ${tooling_additional_test_info} Leaks detected / Report:\n${leaksReport} \n"
789
+ # tooling_additional_test_info="${tooling_additional_test_info}Leaks detected / Report:\n${leaksReport}\n"
790
+ push_test_message_tooling_info " Leaks!"
690
791
else
691
- tooling_additional_test_info=" ${tooling_additional_test_info} No leaks possible.\n"
792
+ # tooling_additional_test_info="${tooling_additional_test_info}No leaks possible.\n"
793
+ push_test_message_tooling_info " No leaks"
692
794
fi
693
795
rm ./memcheck.out
694
796
fi
797
+
798
+ if [[ $flag_tools_use_size = ' true' ]]; then
799
+ inputFileSize=$( stat -c%s " ${input_file_path} " )
800
+ push_test_message_tooling_info " <${inputFileSize} bytes"
801
+ fi
695
802
696
803
697
804
}
786
893
787
894
788
895
set_format
896
+ prepare_input
789
897
verify_args
790
898
clean_out_err_paths
791
899
collect_testing_programs
809
917
prog=${flag_testing_programs[${prog_iter}]}
810
918
# echo "|===> Prog ${prog}"
811
919
if [ $flag_testing_programs_len -gt 1 ]; then
812
- flag_additional_test_name_info=" ( ${B_INFO} ${prog} ${E_INFO} ) "
920
+ flag_additional_test_name_info=" ${B_INFO} ${prog} ${E_INFO} "
813
921
else
814
922
flag_additional_test_name_info=" "
815
923
fi
835
943
test_out
836
944
print_tooling_additional_test_info
837
945
fi
838
- file_index=$(( file_index+ 1 ))
839
946
fi
840
947
clean_temp_content
841
948
prog_iter=$(( prog_iter+ 1 ))
949
+ push_test_message_next_program
842
950
done
951
+
952
+ file_index=$(( file_index+ 1 ))
953
+ flush_test_messages
843
954
done
844
955
845
956
0 commit comments