Skip to content

Commit 162da73

Browse files
tests: Add debug helper for printing buffers
1 parent e9fd3df commit 162da73

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/tests.c

+19
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,25 @@ static int all_bytes_equal(const void* s, unsigned char value, size_t n) {
4444
return 1;
4545
}
4646

47+
/* Debug helper for printing arrays of unsigned char. */
48+
#define PRINT_BUF(buf, len) do { \
49+
printf("%s[%lu] = ", #buf, (unsigned long)len); \
50+
print_buf_plain(buf, len); \
51+
} while(0);
52+
static void print_buf_plain(const unsigned char *buf, size_t len) {
53+
size_t i;
54+
printf("{");
55+
for (i = 0; i < len; i++) {
56+
if (i % 8 == 0) {
57+
printf("\n ");
58+
} else {
59+
printf(" ");
60+
}
61+
printf("0x%02X,", buf[i]);
62+
}
63+
printf("\n}\n");
64+
}
65+
4766
/* TODO Use CHECK_ILLEGAL(_VOID) everywhere and get rid of the uncounting callback */
4867
/* CHECK that expr_or_stmt calls the illegal callback of ctx exactly once
4968
*

0 commit comments

Comments
 (0)