[igt-dev] [PATCH i-g-t v5 13/14] tests/api_intel_bb: base64 dumping code

Zbigniew Kempczyński zbigniew.kempczynski at intel.com
Fri Jul 24 18:16:27 UTC 2020


Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>
---
 tests/i915/api_intel_bb.c | 57 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 55 insertions(+), 2 deletions(-)

diff --git a/tests/i915/api_intel_bb.c b/tests/i915/api_intel_bb.c
index ca4625d5..0e8144d8 100644
--- a/tests/i915/api_intel_bb.c
+++ b/tests/i915/api_intel_bb.c
@@ -32,6 +32,8 @@
 #include <errno.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
+#include <glib.h>
+#include <zlib.h>
 #include "intel_bufops.h"
 
 #define PAGE_SIZE 4096
@@ -495,6 +497,52 @@ static int compare_bufs(struct intel_buf *buf1, struct intel_buf *buf2,
 	return ret;
 }
 
+#define LINELEN 76
+static int dump_base64(const char *name, struct intel_buf *buf)
+{
+	void *ptr;
+	int fd, ret;
+	uLongf outsize = buf->surface[0].size * 2;
+	Bytef *destbuf = malloc(outsize);
+	gchar *str, *pos;
+
+	fd = buf_ops_get_fd(buf->bops);
+
+	ptr = gem_mmap__device_coherent(fd, buf->handle, 0,
+					buf->surface[0].size, PROT_READ);
+
+	ret = compress2(destbuf, &outsize, ptr, buf->surface[0].size,
+			Z_BEST_COMPRESSION);
+	if (ret != Z_OK) {
+		igt_warn("error compressing, ret: %d\n", ret);
+	} else {
+		igt_info("compressed %u -> %lu\n",
+			 buf->surface[0].size, outsize);
+
+		igt_info("--- %s ---\n", name);
+		pos = str = g_base64_encode(destbuf, outsize);
+		outsize = strlen(str);
+		while (pos) {
+			char line[LINELEN + 1];
+			int to_copy = min(LINELEN, outsize);
+			memcpy(line, pos, to_copy);
+			line[to_copy] = 0;
+			igt_info("%s\n", line);
+			pos += LINELEN;
+			outsize -= to_copy;
+			if (outsize == 0)
+				break;
+		}
+		free(str);
+	}
+
+	munmap(ptr, buf->surface[0].size);
+	free(destbuf);
+
+	return ret;
+}
+
+
 static int __do_intel_bb_blit(struct buf_ops *bops, uint32_t tiling)
 {
 	struct intel_bb *ibb;
@@ -676,8 +724,8 @@ static void full_batch(struct buf_ops *bops)
 static int render(struct buf_ops *bops, uint32_t tiling)
 {
 	struct intel_bb *ibb;
-	const int width = 1024;
-	const int height = 1024;
+	const int width = 512;
+	const int height = 512;
 	struct intel_buf src, dst, final;
 	int i915 = buf_ops_get_fd(bops);
 	uint32_t fails = 0;
@@ -737,6 +785,11 @@ static int render(struct buf_ops *bops, uint32_t tiling)
 
 	fails = compare_bufs(&src, &final, true);
 
+	if (fails) {
+		dump_base64("src", &src);
+		dump_base64("final", &final);
+	}
+
 	intel_buf_close(bops, &src);
 	intel_buf_close(bops, &dst);
 	intel_buf_close(bops, &final);
-- 
2.26.0



More information about the igt-dev mailing list