From 75c50d03422eb6a74f462419015a697f371468d6 Mon Sep 17 00:00:00 2001 From: Danylo Piliaiev Date: Mon, 30 Dec 2019 15:51:12 +0200 Subject: [PATCH] osmesa/tests: Cover OSMESA_RGB GL_UNSIGNED_BYTE case Signed-off-by: Danylo Piliaiev Reviewed-by: Eric Anholt Part-of: --- src/gallium/targets/osmesa/test-render.cpp | 26 +++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/gallium/targets/osmesa/test-render.cpp b/src/gallium/targets/osmesa/test-render.cpp index b31789abcd5..ab11f665f10 100644 --- a/src/gallium/targets/osmesa/test-render.cpp +++ b/src/gallium/targets/osmesa/test-render.cpp @@ -56,17 +56,27 @@ name_params(const testing::TestParamInfo params) { TEST_P(OSMesaRenderTestFixture, Render) { auto params = GetParam(); - uint32_t pixel = 0; + const int w = 2, h = 2; + uint8_t pixels[w * h * 4] = { 0 }; uint32_t expected; // This should be green for the given color model - int w = 1, h = 1; std::unique_ptr ctx{ OSMesaCreateContext(params[0], NULL), &OSMesaDestroyContext}; ASSERT_TRUE(ctx); - auto ret = OSMesaMakeCurrent(ctx.get(), &pixel, params[1], w, h); + auto ret = OSMesaMakeCurrent(ctx.get(), &pixels, params[1], w, h); ASSERT_EQ(ret, GL_TRUE); + int bpp = 4; + switch (params[0]) { + case OSMESA_RGB: + bpp = 3; + break; + case OSMESA_RGB_565: + bpp = 2; + break; + } + switch (params[0]) { case OSMESA_RGBA: case OSMESA_BGRA: @@ -86,7 +96,12 @@ TEST_P(OSMesaRenderTestFixture, Render) glClear(GL_COLOR_BUFFER_BIT); glFinish(); - ASSERT_EQ(expected, pixel); + for (unsigned i = 0; i < w * h; i++) { + uint32_t color = 0; + memcpy(&color, &pixels[i * bpp], bpp); + + ASSERT_EQ(expected, color); + } } INSTANTIATE_TEST_CASE_P( @@ -95,7 +110,8 @@ INSTANTIATE_TEST_CASE_P( testing::Values( Params{ OSMESA_RGBA, GL_UNSIGNED_BYTE }, Params{ OSMESA_BGRA, GL_UNSIGNED_BYTE }, - Params{ OSMESA_ARGB, GL_UNSIGNED_BYTE } + Params{ OSMESA_ARGB, GL_UNSIGNED_BYTE }, + Params{ OSMESA_RGB, GL_UNSIGNED_BYTE } ), name_params ); -- 2.30.2