From aa336eced6b0c805e4a52653878fc1d06f3ed7c1 Mon Sep 17 00:00:00 2001 From: Niklas Haas Date: Wed, 29 May 2024 13:55:57 +0200 Subject: [PATCH] tests: also highlight errors in memdump using plaintext For copying terminal output. --- src/tests/tests.h | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/tests/tests.h b/src/tests/tests.h index a33a0de5..dc67404f 100644 --- a/src/tests/tests.h +++ b/src/tests/tests.h @@ -131,16 +131,27 @@ static inline pl_log pl_test_logger(void) static inline void log_array(const uint8_t *a, const uint8_t *ref, size_t off, size_t size) { + const int width = 16; + unsigned errors = 0; for (size_t n = 0; n < size; n++) { const char *prefix = "", *suffix = ""; - char terminator = ' '; + bool newline = false; + int idx = n % width; if (a[n + off] != ref[n + off]) { prefix = "\033[31;1m"; suffix = "\033[0m"; + errors |= 1 << idx; + } + if (n + 1 == size || idx == width - 1) + newline = true; + fprintf(stderr, "%s%02"PRIx8"%s%c", prefix, a[n + off], suffix, newline ? '\n' : ' '); + if (newline && errors) { + for (int i = 0; i <= idx; i++) { + const char mark = errors & (1 << i) ? '^' : ' '; + fprintf(stderr, "%c%c%c", mark, mark, i == idx ? '\n' : ' '); + } + errors = 0; } - if (n+1 == size || n % 16 == 15) - terminator = '\n'; - fprintf(stderr, "%s%02"PRIx8"%s%c", prefix, a[n + off], suffix, terminator); } }