diff mbox

[RFC,i-g-t,v3,4/5] igt_debugfs: Make igt_crc_to_string() work with other CRC types

Message ID 20161201012448.16334-5-lyude@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Lyude Paul Dec. 1, 2016, 1:24 a.m. UTC
Intel GPUs have CRC values with 5 n_words, but the Chamelium's definitely
doesn't. So make igt_crc_to_string() a little smarter so it can handle this.

Signed-off-by: Lyude <lyude@redhat.com>
---
 lib/igt_debugfs.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
diff mbox

Patch

diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c
index 9142e3f..4809b73 100644
--- a/lib/igt_debugfs.c
+++ b/lib/igt_debugfs.c
@@ -290,11 +290,18 @@  void igt_assert_crc_equal(igt_crc_t *a, igt_crc_t *b)
 char *igt_crc_to_string(igt_crc_t *crc)
 {
 	char buf[128];
+	char *p;
+	int i, len;
+
+	for (i = 0, p = buf;
+	     i < crc->n_words;
+	     i++, p += len) {
+		snprintf(p, sizeof(buf) - (p - buf), "%08x %n",
+			 crc->crc[i], &len);
+	}
 
-	igt_assert_eq(crc->n_words, 5);
-
-	sprintf(buf, "%08x %08x %08x %08x %08x", crc->crc[0],
-		crc->crc[1], crc->crc[2], crc->crc[3], crc->crc[4]);
+	/* Strip the trailing space */
+	*strrchr(buf, ' ') = '\0';
 
 	return strdup(buf);
 }