From e8534e7cdb0450af3dfaa44f6f8f646e455c1af8 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Wed, 28 Feb 2024 15:44:28 -0800 Subject: [PATCH] Update test_sdl_canvas When I run this test locally in firefox I was getting 2785 as the sum value. I believe this is because the test includes SDL1 font rendering which can depend on the system fonts you have installed. --- test/browser/test_sdl_canvas.c | 19 +++++++++---------- test/test_browser.py | 14 +++++++------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/test/browser/test_sdl_canvas.c b/test/browser/test_sdl_canvas.c index 9208c73b8f37b..5aee551488631 100644 --- a/test/browser/test_sdl_canvas.c +++ b/test/browser/test_sdl_canvas.c @@ -50,34 +50,33 @@ int main(int argc, char **argv) { SDL_Rect rect = { 200, 200, 175, 125 }; SDL_FillRect(screen, &rect, SDL_MapRGBA(screen->format, 0x22, 0x22, 0xff, 0xff)); - SDL_Flip(screen); + SDL_Flip(screen); SDL_LockSurface(screen); int width, height; emscripten_get_canvas_element_size("#canvas", &width, &height); - - if (width != 600 && height != 450) - { - printf("error: wrong width/height\n"); - abort(); - } + assert(width == 600); + assert(height == 450); int sum = 0; + int row_size = screen->w * 4; + // Sum the red components of each pixel on the diagonal. for (int i = 0; i < screen->h; i++) { - sum += *((char*)screen->pixels + i*screen->w*4 + i*4 + 0); + sum += *((char*)screen->pixels + i*row_size + i*4 + 0); } printf("Sum: %d\n", sum); printf("you should see two lines of text in different colors and a blue rectangle\n"); SDL_UnlockSurface(screen); - + SDL_Quit(); printf("done.\n"); - assert(sum > 3000 && sum < 5000); // varies a little on different browsers, font differences? + // varies a little on different browsers, font differences? + assert(sum > 2000 && sum < 5000); return 0; } diff --git a/test/test_browser.py b/test/test_browser.py index 5527899a241ae..ac89564764f17 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -838,13 +838,13 @@ def test_sdl_stb_image_cleanup(self): shutil.copyfile(test_file('screenshot.jpg'), 'screenshot.not') self.btest_exit('test_sdl_stb_image_cleanup.c', args=['-sSTB_IMAGE', '--preload-file', 'screenshot.not', '-lSDL', '-lGL', '--memoryprofiler']) - def test_sdl_canvas(self): - self.btest_exit('test_sdl_canvas.c', args=['-sLEGACY_GL_EMULATION', '-lSDL', '-lGL']) - # some extra coverage - self.clear() - self.btest_exit('test_sdl_canvas.c', args=['-sLEGACY_GL_EMULATION', '-O0', '-sSAFE_HEAP', '-lSDL', '-lGL']) - self.clear() - self.btest_exit('test_sdl_canvas.c', args=['-sLEGACY_GL_EMULATION', '-O2', '-sSAFE_HEAP', '-lSDL', '-lGL']) + @parameterized({ + '': ([],), + '_safe_heap': (['-sSAFE_HEAP'],), + '_safe_heap_O2': (['-sSAFE_HEAP', '-O2'],), + }) + def test_sdl_canvas(self, args): + self.btest_exit('test_sdl_canvas.c', args=['-sLEGACY_GL_EMULATION', '-lSDL', '-lGL'] + args) def post_manual_reftest(self): assert os.path.exists('reftest.js')