Skip to content

Commit 2fd7bec

Browse files
SiegeLordExSiegeLord
authored andcommitted
Add --skip_on_failure and XVFB opt-out for the test_driver.
1 parent 7a2e2c0 commit 2fd7bec

File tree

4 files changed

+53
-30
lines changed

4 files changed

+53
-30
lines changed

tests/test_backbuffer.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ hash=882edf64
5555
# source bitmap is the screen (and locking is not used).
5656

5757
[test bbsrc tint]
58+
skip_on_xvfb=true
5859
extend=test bbsrc
5960
op4=al_draw_tinted_bitmap(target, #008000, 0, 0, flags)
6061
hash=a47a96d4

tests/test_bitmaps.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,8 @@ op5=al_put_pixel(15, 17, limegreen)
340340
op6=al_draw_pixel(24.5, 27.5, red)
341341
op7=al_put_pixel(25, 27, limegreen)
342342
hash=b4d84cb9
343-
tolerance=0.0
343+
hash_hw=663b41cf
344+
sig_hw=000000000000000000000000000000000000000000000000000000000000000000000000000000000
344345

345346
[test subsub dest]
346347
op0=al_clear_to_color(tan)

tests/test_convert.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[test convert]
22
# This test relies on needing a video bitmap.
33
hw_only = true
4+
skip_on_xvfb = true
45
op0= al_clear_to_color(#554321)
56
op1= al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP)
67
op2= al_set_new_bitmap_format(ALLEGRO_PIXEL_FORMAT_RGB_565)

tests/test_driver.c

Lines changed: 49 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ int vertex_counts[MAX_POLYGONS];
6565
int num_global_bitmaps;
6666
float delay = 0.0;
6767
bool save_outputs = false;
68+
bool save_on_failure = false;
6869
bool quiet = false;
6970
bool want_display = true;
71+
bool on_xvfb = true;
7072
int verbose = 0;
7173
int total_tests = 0;
7274
int passed_tests = 0;
@@ -783,7 +785,7 @@ static bool similar_signatures(char const sig1[SIG_LEN], char const sig2[SIG_LEN
783785
return ((float)correct / SIG_LEN) > 0.95;
784786
}
785787

786-
static void check_hash(ALLEGRO_CONFIG const *cfg, char const *testname,
788+
static bool check_hash(ALLEGRO_CONFIG const *cfg, char const *testname,
787789
ALLEGRO_BITMAP *bmp, BmpType bmp_type)
788790
{
789791
char const *bt = bmp_type_to_string(bmp_type);
@@ -799,7 +801,7 @@ static void check_hash(ALLEGRO_CONFIG const *cfg, char const *testname,
799801
if (exp && streq(exp, "off")) {
800802
printf("OK %s [%s] - hash check off\n", testname, bt);
801803
passed_tests++;
802-
return;
804+
return true;
803805
}
804806

805807
sprintf(hash, "%08x", hash_bitmap(bmp));
@@ -813,13 +815,13 @@ static void check_hash(ALLEGRO_CONFIG const *cfg, char const *testname,
813815
if (!exp && !sigexp) {
814816
printf("NEW %s [%s]\n\thash=%s\n\tsig=%s\n",
815817
testname, bt, hash, sig);
816-
return;
818+
return true;
817819
}
818820

819821
if (exp && streq(hash, exp)) {
820822
printf("OK %s [%s]\n", testname, bt);
821823
passed_tests++;
822-
return;
824+
return true;
823825
}
824826

825827
if (sigexp && strlen(sigexp) != SIG_LEN) {
@@ -830,11 +832,12 @@ static void check_hash(ALLEGRO_CONFIG const *cfg, char const *testname,
830832
if (sigexp && similar_signatures(sig, sigexp)) {
831833
printf("OK %s [%s] - by signature\n", testname, bt);
832834
passed_tests++;
833-
return;
835+
return true;
834836
}
835837

836838
printf("FAIL %s [%s] - hash=%s\n", testname, bt, hash);
837839
failed_tests++;
840+
return false;
838841
}
839842

840843
static double bitmap_dissimilarity(ALLEGRO_BITMAP *bmp1, ALLEGRO_BITMAP *bmp2)
@@ -868,7 +871,7 @@ static double bitmap_dissimilarity(ALLEGRO_BITMAP *bmp1, ALLEGRO_BITMAP *bmp2)
868871
return sqrt(sqerr / (w*h*4.0));
869872
}
870873

871-
static void check_similarity(ALLEGRO_CONFIG const *cfg,
874+
static bool check_similarity(ALLEGRO_CONFIG const *cfg,
872875
char const *testname,
873876
ALLEGRO_BITMAP *bmp1, ALLEGRO_BITMAP *bmp2, BmpType bmp_type, bool reliable)
874877
{
@@ -886,7 +889,7 @@ static void check_similarity(ALLEGRO_CONFIG const *cfg,
886889
if (exp && streq(hash, exp)) {
887890
printf("OK %s [%s]\n", testname, bt);
888891
passed_tests++;
889-
return;
892+
return true;
890893
}
891894

892895
if (sigexp && strlen(sigexp) != SIG_LEN) {
@@ -899,7 +902,7 @@ static void check_similarity(ALLEGRO_CONFIG const *cfg,
899902
if (sigexp && similar_signatures(sig, sigexp)) {
900903
printf("OK %s [%s] - by signature\n", testname, bt);
901904
passed_tests++;
902-
return;
905+
return true;
903906
}
904907
}
905908

@@ -915,6 +918,7 @@ static void check_similarity(ALLEGRO_CONFIG const *cfg,
915918
else
916919
printf("OK? %s [%s]\n", testname, bt);
917920
passed_tests++;
921+
return true;
918922
}
919923
else {
920924
char const *exp = al_get_config_value(cfg, testname, "hash");
@@ -925,18 +929,19 @@ static void check_similarity(ALLEGRO_CONFIG const *cfg,
925929
if (exp && streq(hash, exp)) {
926930
printf("OK %s [%s]\n", testname, bt);
927931
passed_tests++;
928-
return;
932+
return true;
929933
}
930934

931935
printf("FAIL %s [%s] - RMS error is %g\n", testname, bt, rms);
932936
printf("hash_hw=%s\n", hash);
933937
compute_signature(bmp1, sig);
934938
printf("sig_hw=%s\n", sig);
935939
failed_tests++;
940+
return false;
936941
}
937942
}
938943

939-
static void do_test(ALLEGRO_CONFIG *cfg, char const *testname,
944+
static bool do_test(ALLEGRO_CONFIG *cfg, char const *testname,
940945
ALLEGRO_BITMAP *target, int bmp_type, bool reliable, bool do_check_hash)
941946
{
942947
#define MAXBUF 80
@@ -1520,16 +1525,17 @@ static void do_test(ALLEGRO_CONFIG *cfg, char const *testname,
15201525

15211526
al_set_new_bitmap_format(ALLEGRO_PIXEL_FORMAT_ANY_WITH_ALPHA);
15221527

1528+
bool good;
15231529
if (do_check_hash) {
1524-
check_hash(cfg, testname, target, bmp_type);
1530+
good = check_hash(cfg, testname, target, bmp_type);
15251531
}
15261532
else {
1527-
check_similarity(cfg, testname, target, membuf, bmp_type, reliable);
1533+
good = check_similarity(cfg, testname, target, membuf, bmp_type, reliable);
15281534
}
15291535

15301536
total_tests++;
15311537

1532-
if (save_outputs) {
1538+
if (save_outputs && (!save_on_failure || !good)) {
15331539
ALLEGRO_USTR *filename = al_ustr_newf("%s [%s].png", testname,
15341540
bmp_type_to_string(bmp_type));
15351541
al_save_bitmap(al_cstr(filename), target);
@@ -1565,25 +1571,30 @@ static void do_test(ALLEGRO_CONFIG *cfg, char const *testname,
15651571
transforms[i].name = NULL;
15661572
}
15671573

1574+
return good;
15681575
#undef MAXBUF
15691576
}
15701577

15711578
static void sw_hw_test(ALLEGRO_CONFIG *cfg, char const *testname)
15721579
{
1573-
int old_failed_tests = failed_tests;
1574-
bool reliable;
1580+
bool reliable = true;
15751581
char const *hw_only_str = al_get_config_value(cfg, testname, "hw_only");
15761582
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");
15771584
bool hw_only = hw_only_str && get_bool(hw_only_str);
15781585
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+
}
15791592

15801593
al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
15811594
if (!hw_only) {
1582-
do_test(cfg, testname, membuf, SW, true, true);
1595+
reliable = do_test(cfg, testname, membuf, SW, true, true);
15831596
}
15841597

1585-
reliable = (failed_tests == old_failed_tests);
1586-
15871598
if (sw_only) return;
15881599

15891600
if (display) {
@@ -1752,17 +1763,19 @@ const char* help_str =
17521763
"file, but individual TEST_NAMEs can be specified after each CONFIG_FILE.\n"
17531764
"\n"
17541765
"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";
17661779

17671780
int main(int _argc, char *_argv[])
17681781
{
@@ -1793,6 +1806,13 @@ int main(int _argc, char *_argv[])
17931806
else if (streq(opt, "-s") || streq(opt, "--save")) {
17941807
save_outputs = true;
17951808
}
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+
}
17961816
else if (streq(opt, "-q") || streq(opt, "--quiet")) {
17971817
quiet = true;
17981818
}

0 commit comments

Comments
 (0)