[Piglit] [PATCH v3 3/4] pbo-readpixels-small: make it endian-safe

Oded Gabbay oded.gabbay at gmail.com
Thu Mar 31 20:09:53 UTC 2016


In this test we use GL_BGRA + GL_UNSIGNED_BYTE. However, the probe
function receives two 4-byte values to compare, expected and
observed. This is wrong as the correct way to compare
array_of_bytes (GL_UNSIGNED_BYTE) in an endian-safe way is by comparing
memory (and not values).

This patch fixes this bug by changing the function to receive two
pointers instead of values. It also corrects the way the expected values
are constructed to be in endian-safe way for array-of-bytes

This fixes the test in llvmpipe, softpipe and r600g in big-endian machine.

v2: Changed initialization of expected results to be more clear
v3: Changed printing of results to display individual components

Signed-off-by: Oded Gabbay <oded.gabbay at gmail.com>
Reviewed-by: Ilia Mirkin <imirkin at alum.mit.edu>
---
 tests/general/pbo-readpixels-small.c | 29 ++++++++++++++++++-----------
 1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/tests/general/pbo-readpixels-small.c b/tests/general/pbo-readpixels-small.c
index 9fec2a0..8db978d 100644
--- a/tests/general/pbo-readpixels-small.c
+++ b/tests/general/pbo-readpixels-small.c
@@ -46,12 +46,16 @@ PIGLIT_GL_TEST_CONFIG_BEGIN
 PIGLIT_GL_TEST_CONFIG_END
 
 static GLboolean
-probe(int x, int y, uint32_t expected, uint32_t observed)
+probe(int x, int y, uint8_t *expected, uint8_t *observed)
 {
-	if ((expected & 0xffffff) != (observed & 0xffffff)) {
+	if (expected[0] != observed[0] ||
+		 expected[1] != observed[1] ||
+		 expected[2] != observed[2]) {
 		printf("Probe color at (%i,%i)\n", x, y);
-		printf("  Expected: 0x%08x\n", expected);
-		printf("  Observed: 0x%08x\n", observed);
+		printf("  Expected: b = 0x%02x  g = 0x%02x  r = 0x%02x  a = 0x%02x\n",
+				expected[0], expected[1], expected[2], expected[3]);
+		printf("  Observed: b = 0x%02x  g = 0x%02x  r = 0x%02x  a = 0x%02x\n",
+				observed[0], observed[1], observed[2], observed[3]);
 
 		return GL_FALSE;
 	} else {
@@ -63,8 +67,10 @@ enum piglit_result
 piglit_display(void)
 {
 	GLboolean pass = GL_TRUE;
-	uint32_t *addr;
+	uint8_t *addr;
 	GLuint pbo;
+	static uint8_t green[] = {0x00, 0xFF, 0x00, 0x00};
+	static uint8_t blue[]  = {0xFF, 0x00, 0x00, 0x00};
 
 	glClearColor(0.0, 0.0, 0.0, 0.0);
 	glClear(GL_COLOR_BUFFER_BIT);
@@ -87,24 +93,25 @@ piglit_display(void)
 	glReadPixels(0, 0, 2, 2,
 		     GL_BGRA, GL_UNSIGNED_BYTE, (void *)(uintptr_t)0);
 	addr = glMapBufferARB(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY_ARB);
-	pass &= probe(0, 0, 0x0000ff00, addr[0]);
-	pass &= probe(1, 0, 0x0000ff00, addr[1]);
-	pass &= probe(0, 1, 0x000000ff, addr[2]);
-	pass &= probe(1, 1, 0x000000ff, addr[3]);
+
+	pass &= probe(0, 0, green, addr);
+	pass &= probe(1, 0, green, addr + 4);
+	pass &= probe(0, 1, blue,  addr + 8);
+	pass &= probe(1, 1, blue,  addr + 12);
 	glUnmapBufferARB(GL_PIXEL_PACK_BUFFER);
 
 	/* Read with an offset. */
 	glReadPixels(1, 0, 1, 1,
 		     GL_BGRA, GL_UNSIGNED_BYTE, (void *)(uintptr_t)4);
 	addr = glMapBufferARB(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY_ARB);
-	pass &= probe(1, 0, 0x0000ff00, addr[1]);
+	pass &= probe(1, 0, green, addr + 4);
 	glUnmapBufferARB(GL_PIXEL_PACK_BUFFER);
 
 	/* Read with an offset. */
 	glReadPixels(1, 1, 1, 1,
 		     GL_BGRA, GL_UNSIGNED_BYTE, (void *)(uintptr_t)4);
 	addr = glMapBufferARB(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY_ARB);
-	pass &= probe(1, 1, 0x000000ff, addr[1]);
+	pass &= probe(1, 1, blue, addr + 4);
 	glUnmapBufferARB(GL_PIXEL_PACK_BUFFER);
 
 	piglit_present_results();
-- 
2.5.5



More information about the Piglit mailing list