@@ -65,8 +65,10 @@ int vertex_counts[MAX_POLYGONS];
65
65
int num_global_bitmaps ;
66
66
float delay = 0.0 ;
67
67
bool save_outputs = false;
68
+ bool save_on_failure = false;
68
69
bool quiet = false;
69
70
bool want_display = true;
71
+ bool on_xvfb = true;
70
72
int verbose = 0 ;
71
73
int total_tests = 0 ;
72
74
int passed_tests = 0 ;
@@ -783,7 +785,7 @@ static bool similar_signatures(char const sig1[SIG_LEN], char const sig2[SIG_LEN
783
785
return ((float )correct / SIG_LEN ) > 0.95 ;
784
786
}
785
787
786
- static void check_hash (ALLEGRO_CONFIG const * cfg , char const * testname ,
788
+ static bool check_hash (ALLEGRO_CONFIG const * cfg , char const * testname ,
787
789
ALLEGRO_BITMAP * bmp , BmpType bmp_type )
788
790
{
789
791
char const * bt = bmp_type_to_string (bmp_type );
@@ -799,7 +801,7 @@ static void check_hash(ALLEGRO_CONFIG const *cfg, char const *testname,
799
801
if (exp && streq (exp , "off" )) {
800
802
printf ("OK %s [%s] - hash check off\n" , testname , bt );
801
803
passed_tests ++ ;
802
- return ;
804
+ return true ;
803
805
}
804
806
805
807
sprintf (hash , "%08x" , hash_bitmap (bmp ));
@@ -813,13 +815,13 @@ static void check_hash(ALLEGRO_CONFIG const *cfg, char const *testname,
813
815
if (!exp && !sigexp ) {
814
816
printf ("NEW %s [%s]\n\thash=%s\n\tsig=%s\n" ,
815
817
testname , bt , hash , sig );
816
- return ;
818
+ return true ;
817
819
}
818
820
819
821
if (exp && streq (hash , exp )) {
820
822
printf ("OK %s [%s]\n" , testname , bt );
821
823
passed_tests ++ ;
822
- return ;
824
+ return true ;
823
825
}
824
826
825
827
if (sigexp && strlen (sigexp ) != SIG_LEN ) {
@@ -830,11 +832,12 @@ static void check_hash(ALLEGRO_CONFIG const *cfg, char const *testname,
830
832
if (sigexp && similar_signatures (sig , sigexp )) {
831
833
printf ("OK %s [%s] - by signature\n" , testname , bt );
832
834
passed_tests ++ ;
833
- return ;
835
+ return true ;
834
836
}
835
837
836
838
printf ("FAIL %s [%s] - hash=%s\n" , testname , bt , hash );
837
839
failed_tests ++ ;
840
+ return false;
838
841
}
839
842
840
843
static double bitmap_dissimilarity (ALLEGRO_BITMAP * bmp1 , ALLEGRO_BITMAP * bmp2 )
@@ -868,7 +871,7 @@ static double bitmap_dissimilarity(ALLEGRO_BITMAP *bmp1, ALLEGRO_BITMAP *bmp2)
868
871
return sqrt (sqerr / (w * h * 4.0 ));
869
872
}
870
873
871
- static void check_similarity (ALLEGRO_CONFIG const * cfg ,
874
+ static bool check_similarity (ALLEGRO_CONFIG const * cfg ,
872
875
char const * testname ,
873
876
ALLEGRO_BITMAP * bmp1 , ALLEGRO_BITMAP * bmp2 , BmpType bmp_type , bool reliable )
874
877
{
@@ -886,7 +889,7 @@ static void check_similarity(ALLEGRO_CONFIG const *cfg,
886
889
if (exp && streq (hash , exp )) {
887
890
printf ("OK %s [%s]\n" , testname , bt );
888
891
passed_tests ++ ;
889
- return ;
892
+ return true ;
890
893
}
891
894
892
895
if (sigexp && strlen (sigexp ) != SIG_LEN ) {
@@ -899,7 +902,7 @@ static void check_similarity(ALLEGRO_CONFIG const *cfg,
899
902
if (sigexp && similar_signatures (sig , sigexp )) {
900
903
printf ("OK %s [%s] - by signature\n" , testname , bt );
901
904
passed_tests ++ ;
902
- return ;
905
+ return true ;
903
906
}
904
907
}
905
908
@@ -915,6 +918,7 @@ static void check_similarity(ALLEGRO_CONFIG const *cfg,
915
918
else
916
919
printf ("OK? %s [%s]\n" , testname , bt );
917
920
passed_tests ++ ;
921
+ return true;
918
922
}
919
923
else {
920
924
char const * exp = al_get_config_value (cfg , testname , "hash" );
@@ -925,18 +929,19 @@ static void check_similarity(ALLEGRO_CONFIG const *cfg,
925
929
if (exp && streq (hash , exp )) {
926
930
printf ("OK %s [%s]\n" , testname , bt );
927
931
passed_tests ++ ;
928
- return ;
932
+ return true ;
929
933
}
930
934
931
935
printf ("FAIL %s [%s] - RMS error is %g\n" , testname , bt , rms );
932
936
printf ("hash_hw=%s\n" , hash );
933
937
compute_signature (bmp1 , sig );
934
938
printf ("sig_hw=%s\n" , sig );
935
939
failed_tests ++ ;
940
+ return false;
936
941
}
937
942
}
938
943
939
- static void do_test (ALLEGRO_CONFIG * cfg , char const * testname ,
944
+ static bool do_test (ALLEGRO_CONFIG * cfg , char const * testname ,
940
945
ALLEGRO_BITMAP * target , int bmp_type , bool reliable , bool do_check_hash )
941
946
{
942
947
#define MAXBUF 80
@@ -1520,16 +1525,17 @@ static void do_test(ALLEGRO_CONFIG *cfg, char const *testname,
1520
1525
1521
1526
al_set_new_bitmap_format (ALLEGRO_PIXEL_FORMAT_ANY_WITH_ALPHA );
1522
1527
1528
+ bool good ;
1523
1529
if (do_check_hash ) {
1524
- check_hash (cfg , testname , target , bmp_type );
1530
+ good = check_hash (cfg , testname , target , bmp_type );
1525
1531
}
1526
1532
else {
1527
- check_similarity (cfg , testname , target , membuf , bmp_type , reliable );
1533
+ good = check_similarity (cfg , testname , target , membuf , bmp_type , reliable );
1528
1534
}
1529
1535
1530
1536
total_tests ++ ;
1531
1537
1532
- if (save_outputs ) {
1538
+ if (save_outputs && (! save_on_failure || ! good ) ) {
1533
1539
ALLEGRO_USTR * filename = al_ustr_newf ("%s [%s].png" , testname ,
1534
1540
bmp_type_to_string (bmp_type ));
1535
1541
al_save_bitmap (al_cstr (filename ), target );
@@ -1565,25 +1571,30 @@ static void do_test(ALLEGRO_CONFIG *cfg, char const *testname,
1565
1571
transforms [i ].name = NULL ;
1566
1572
}
1567
1573
1574
+ return good ;
1568
1575
#undef MAXBUF
1569
1576
}
1570
1577
1571
1578
static void sw_hw_test (ALLEGRO_CONFIG * cfg , char const * testname )
1572
1579
{
1573
- int old_failed_tests = failed_tests ;
1574
- bool reliable ;
1580
+ bool reliable = true;
1575
1581
char const * hw_only_str = al_get_config_value (cfg , testname , "hw_only" );
1576
1582
char const * sw_only_str = al_get_config_value (cfg , testname , "sw_only" );
1583
+ char const * skip_on_xvfb_str = al_get_config_value (cfg , testname , "skip_on_xvfb" );
1577
1584
bool hw_only = hw_only_str && get_bool (hw_only_str );
1578
1585
bool sw_only = sw_only_str && get_bool (sw_only_str );
1586
+ bool skip_on_xvfb = skip_on_xvfb_str && get_bool (skip_on_xvfb_str );
1587
+
1588
+ if (skip_on_xvfb && on_xvfb ) {
1589
+ skipped_tests ++ ;
1590
+ return ;
1591
+ }
1579
1592
1580
1593
al_set_new_bitmap_flags (ALLEGRO_MEMORY_BITMAP );
1581
1594
if (!hw_only ) {
1582
- do_test (cfg , testname , membuf , SW , true, true);
1595
+ reliable = do_test (cfg , testname , membuf , SW , true, true);
1583
1596
}
1584
1597
1585
- reliable = (failed_tests == old_failed_tests );
1586
-
1587
1598
if (sw_only ) return ;
1588
1599
1589
1600
if (display ) {
@@ -1752,17 +1763,19 @@ const char* help_str =
1752
1763
"file, but individual TEST_NAMEs can be specified after each CONFIG_FILE.\n"
1753
1764
"\n"
1754
1765
"Options:\n"
1755
- " -d, --delay duration (in sec) to wait between tests\n"
1756
- " --force-d3d force using D3D (Windows only)\n"
1757
- " --force-opengl-1.2 force using OpenGL 1.2\n"
1758
- " --force-opengl-2.0 force using OpenGL 2.0\n"
1759
- " --force-opengl force using OpenGL\n"
1760
- " -h, --help display this message\n"
1761
- " -n, --no-display do not create a display (hardware drawing is disabled)\n"
1762
- " -s, --save save the output of each test in the current directory\n"
1763
- " --use-shaders use the programmable pipeline for drawing\n"
1764
- " -v, --verbose show additional information after each test\n"
1765
- " -q, --quiet do not draw test output to the display\n" ;
1766
+ " -d, --delay duration (in sec) to wait between tests\n"
1767
+ " --force-d3d force using D3D (Windows only)\n"
1768
+ " --force-opengl-1.2 force using OpenGL 1.2\n"
1769
+ " --force-opengl-2.0 force using OpenGL 2.0\n"
1770
+ " --force-opengl force using OpenGL\n"
1771
+ " -f, --save_on_failure save the output of failred tests in the current directory\n"
1772
+ " -h, --help display this message\n"
1773
+ " -n, --no-display do not create a display (hardware drawing is disabled)\n"
1774
+ " -s, --save save the output of each test in the current directory\n"
1775
+ " --use-shaders use the programmable pipeline for drawing\n"
1776
+ " -v, --verbose show additional information after each test\n"
1777
+ " -q, --quiet do not draw test output to the display\n"
1778
+ " --xvfb indicates that we're running on XVFB, skipping tests if necessary\n" ;
1766
1779
1767
1780
int main (int _argc , char * _argv [])
1768
1781
{
@@ -1793,6 +1806,13 @@ int main(int _argc, char *_argv[])
1793
1806
else if (streq (opt , "-s" ) || streq (opt , "--save" )) {
1794
1807
save_outputs = true;
1795
1808
}
1809
+ else if (streq (opt , "-f" ) || streq (opt , "--save_on_failure" )) {
1810
+ save_on_failure = true;
1811
+ save_outputs = true;
1812
+ }
1813
+ else if (streq (opt , "--xvfb" )) {
1814
+ on_xvfb = true;
1815
+ }
1796
1816
else if (streq (opt , "-q" ) || streq (opt , "--quiet" )) {
1797
1817
quiet = true;
1798
1818
}
0 commit comments