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@xxxxxxxxxxxxxxx> --- lib/igt_debugfs.c | 27 +++++++++++++++++++++++---- lib/igt_debugfs.h | 1 + 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c index ef05dc77..2aa33586 100644 --- a/lib/igt_debugfs.c +++ b/lib/igt_debugfs.c @@ -348,28 +348,47 @@ 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 function allocates a string and formats @crc into it. + * This function allocates a string and formats @crc into it, depending on + * @delimiter and @crc_size. * The caller is responsible for freeing the string. * * 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 = calloc(128, sizeof(char)); + const char *format[2] = { "%08x%c", "%04x%c" }; if (!buf) return NULL; 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 buf; } +/** + * igt_crc_to_string: + * @crc: pipe CRC value to print + * + * This function allocates a string and formats @crc into it. + * The caller is responsible for freeing the string. + * + * 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 _______________________________________________ Intel-gfx mailing list Intel-gfx@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/intel-gfx