From 65df89dfe657ea3464fffa18d1dedd4c65fd2539 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 29 Sep 2023 12:52:17 +0100 Subject: [PATCH 1/3] SDLTest_CompareSurfaces: Log better messages if NULL or different sizes Signed-off-by: Simon McVittie --- src/test/SDL_test_compare.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/test/SDL_test_compare.c b/src/test/SDL_test_compare.c index 023723de3bdbb..c65b75c72a442 100644 --- a/src/test/SDL_test_compare.c +++ b/src/test/SDL_test_compare.c @@ -67,12 +67,19 @@ int SDLTest_CompareSurfaces(SDL_Surface *surface, SDL_Surface *referenceSurface, char referenceFilename[FILENAME_SIZE]; /* Validate input surfaces */ - if (surface == NULL || referenceSurface == NULL) { + if (surface == NULL) { + SDLTest_LogError("Cannot compare NULL surface"); + return -1; + } + + if (referenceSurface == NULL) { + SDLTest_LogError("Cannot compare NULL reference surface"); return -1; } /* Make sure surface size is the same. */ if ((surface->w != referenceSurface->w) || (surface->h != referenceSurface->h)) { + SDLTest_LogError("Expected %dx%d surface, got %dx%d", referenceSurface->w, referenceSurface->h, surface->w, surface->h); return -2; } From 2acbc479b0719e2fc46a3e74461e859ad5f2e508 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 29 Sep 2023 12:52:32 +0100 Subject: [PATCH 2/3] SDLTest_CompareSurfaces: If surfaces differ, log their formats Signed-off-by: Simon McVittie --- src/test/SDL_test_compare.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/test/SDL_test_compare.c b/src/test/SDL_test_compare.c index c65b75c72a442..8101d0aae55de 100644 --- a/src/test/SDL_test_compare.c +++ b/src/test/SDL_test_compare.c @@ -52,6 +52,16 @@ GetPixel(Uint8 *p, size_t bytes_per_pixel) return ret; } +static void +LogErrorFormat(const char *name, const SDL_PixelFormat *format) +{ + SDLTest_LogError("%s: %08" SDL_PRIx32 " %s, %u bits/%u bytes per pixel", name, format->format, SDL_GetPixelFormatName(format->format), format->BitsPerPixel, format->BytesPerPixel); + SDLTest_LogError("%s: R mask %08" SDL_PRIx32 ", loss %u, shift %u", name, format->Rmask, format->Rloss, format->Rshift); + SDLTest_LogError("%s: G mask %08" SDL_PRIx32 ", loss %u, shift %u", name, format->Gmask, format->Gloss, format->Gshift); + SDLTest_LogError("%s: B mask %08" SDL_PRIx32 ", loss %u, shift %u", name, format->Bmask, format->Bloss, format->Bshift); + SDLTest_LogError("%s: A mask %08" SDL_PRIx32 ", loss %u, shift %u", name, format->Amask, format->Aloss, format->Ashift); +} + /* Compare surfaces */ int SDLTest_CompareSurfaces(SDL_Surface *surface, SDL_Surface *referenceSurface, int allowable_error) { @@ -130,6 +140,8 @@ int SDLTest_CompareSurfaces(SDL_Surface *surface, SDL_Surface *referenceSurface, _CompareSurfaceCount++; if (ret != 0) { SDLTest_LogError("Comparison of pixels with allowable error of %i failed %i times.", allowable_error, ret); + LogErrorFormat("Reference surface format", referenceSurface->format); + LogErrorFormat("Actual surface format ", surface->format); SDLTest_LogError("First detected occurrence at position %i,%i with a squared RGB-difference of %i.", sampleErrorX, sampleErrorY, sampleDist); (void)SDL_snprintf(imageFilename, FILENAME_SIZE - 1, "CompareSurfaces%04d_TestOutput.bmp", _CompareSurfaceCount); SDL_SaveBMP(surface, imageFilename); From e5b600975d551bca83e530fcf5fdbc06b9135de2 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 29 Sep 2023 13:00:43 +0100 Subject: [PATCH 3/3] SDLTest_CompareSurfaces: Output RGBA values of first differing pixel Signed-off-by: Simon McVittie --- src/test/SDL_test_compare.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/test/SDL_test_compare.c b/src/test/SDL_test_compare.c index 8101d0aae55de..bc3c484bdb9c1 100644 --- a/src/test/SDL_test_compare.c +++ b/src/test/SDL_test_compare.c @@ -71,6 +71,8 @@ int SDLTest_CompareSurfaces(SDL_Surface *surface, SDL_Surface *referenceSurface, Uint8 *p, *p_reference; int dist; int sampleErrorX = 0, sampleErrorY = 0, sampleDist = 0; + SDL_Color sampleReference = { 0, 0, 0, 0 }; + SDL_Color sampleActual = { 0, 0, 0, 0 }; Uint8 R, G, B, A; Uint8 Rd, Gd, Bd, Ad; char imageFilename[FILENAME_SIZE]; @@ -128,6 +130,14 @@ int SDLTest_CompareSurfaces(SDL_Surface *surface, SDL_Surface *referenceSurface, sampleErrorX = i; sampleErrorY = j; sampleDist = dist; + sampleReference.r = Rd; + sampleReference.g = Gd; + sampleReference.b = Bd; + sampleReference.a = Ad; + sampleActual.r = R; + sampleActual.g = G; + sampleActual.b = B; + sampleActual.a = A; } } } @@ -143,6 +153,8 @@ int SDLTest_CompareSurfaces(SDL_Surface *surface, SDL_Surface *referenceSurface, LogErrorFormat("Reference surface format", referenceSurface->format); LogErrorFormat("Actual surface format ", surface->format); SDLTest_LogError("First detected occurrence at position %i,%i with a squared RGB-difference of %i.", sampleErrorX, sampleErrorY, sampleDist); + SDLTest_LogError("Reference pixel: R=%u G=%u B=%u A=%u", sampleReference.r, sampleReference.g, sampleReference.b, sampleReference.a); + SDLTest_LogError("Actual pixel : R=%u G=%u B=%u A=%u", sampleActual.r, sampleActual.g, sampleActual.b, sampleActual.a); (void)SDL_snprintf(imageFilename, FILENAME_SIZE - 1, "CompareSurfaces%04d_TestOutput.bmp", _CompareSurfaceCount); SDL_SaveBMP(surface, imageFilename); (void)SDL_snprintf(referenceFilename, FILENAME_SIZE - 1, "CompareSurfaces%04d_Reference.bmp", _CompareSurfaceCount);