[Intel-gfx] [PATCH i-g-t v4 5/7] lib/igt_debugfs: Add extended helper to format crc to string
Paul Kocialkowski
paul.kocialkowski at linux.intel.com
Wed Jul 12 14:50:29 UTC 2017
This introduces a igt_crc_to_string_extended helper that allows
formatting a crc to a string with a given delimiter and size to print
per crc word.
Signed-off-by: Paul Kocialkowski <paul.kocialkowski at linux.intel.com>
---
lib/igt_debugfs.c | 28 ++++++++++++++++++++++++----
lib/igt_debugfs.h | 1 +
2 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c
index 78c22e67..005f99b1 100644
--- a/lib/igt_debugfs.c
+++ b/lib/igt_debugfs.c
@@ -348,26 +348,46 @@ bool igt_check_crc_equal(const igt_crc_t *a, const igt_crc_t *b)
}
/**
- * igt_crc_to_string:
+ * igt_crc_to_string_extended:
* @crc: pipe CRC value to print
+ * @delimiter: The delimiter to use between crc words
+ * @crc_size: the number of bytes to print per crc word (either 4 or 2)
*
- * This formats @crc into a string buffer which is owned by igt_crc_to_string().
+ * This formats @crc into a string buffer, depending on @delimiter and @crc_size
+ * which is owned by igt_crc_to_string_extended().
* The next call will override the buffer again, which makes this multithreading
* unsafe.
*
* This should only ever be used for diagnostic debug output.
*/
-char *igt_crc_to_string(igt_crc_t *crc)
+char *igt_crc_to_string_extended(igt_crc_t *crc, char delimiter, int crc_size)
{
int i;
char buf[128] = { 0 };
+ const char *format[2] = { "%08x%c", "%04x%c" };
for (i = 0; i < crc->n_words; i++)
- sprintf(buf + strlen(buf), "%08x ", crc->crc[i]);
+ sprintf(buf + strlen(buf), format[crc_size == 2], crc->crc[i],
+ i == (crc->n_words - 1) ? '\0' : delimiter);
return strdup(buf);
}
+/**
+ * igt_crc_to_string:
+ * @crc: pipe CRC value to print
+ *
+ * This formats @crc into a string buffer which is owned by igt_crc_to_string().
+ * The next call will override the buffer again, which makes this multithreading
+ * unsafe.
+ *
+ * This should only ever be used for diagnostic debug output.
+ */
+char *igt_crc_to_string(igt_crc_t *crc)
+{
+ return igt_crc_to_string_extended(crc, ' ', 4);
+}
+
#define MAX_CRC_ENTRIES 10
#define MAX_LINE_LEN (10 + 11 * MAX_CRC_ENTRIES + 1)
diff --git a/lib/igt_debugfs.h b/lib/igt_debugfs.h
index fe355919..f1a76406 100644
--- a/lib/igt_debugfs.h
+++ b/lib/igt_debugfs.h
@@ -115,6 +115,7 @@ enum intel_pipe_crc_source {
void igt_assert_crc_equal(const igt_crc_t *a, const igt_crc_t *b);
bool igt_check_crc_equal(const igt_crc_t *a, const igt_crc_t *b);
+char *igt_crc_to_string_extended(igt_crc_t *crc, char delimiter, int crc_size);
char *igt_crc_to_string(igt_crc_t *crc);
void igt_require_pipe_crc(int fd);
--
2.13.2
More information about the Intel-gfx
mailing list