diff options
author | Lennart Poettering <lennart@poettering.net> | 2014-03-14 21:11:31 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2014-03-14 21:17:14 +0100 |
commit | 29bfbcd675d750c0af4d7dae217722932249e435 (patch) | |
tree | 333eebd589a7106ae35ad0278e1652402ca85ec3 /src/test/test-util.c | |
parent | edb2935c5c5b95c42b8679086f60da5eafad74cb (diff) |
util: add hexdump() call to create pretty hexdumps of data
This is very useful when debugging sd-bus to look at messages.
Diffstat (limited to 'src/test/test-util.c')
-rw-r--r-- | src/test/test-util.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/test/test-util.c b/src/test/test-util.c index 229f492889..6297182e0b 100644 --- a/src/test/test-util.c +++ b/src/test/test-util.c @@ -626,6 +626,25 @@ static void test_writing_tmpfile(void) { assert(streq(contents, "abc\n" ALPHANUMERICAL "\n")); } +static void test_hexdump(void) { + uint8_t data[146]; + unsigned i; + + hexdump(stdout, NULL, 0); + hexdump(stdout, "", 0); + hexdump(stdout, "", 1); + hexdump(stdout, "x", 1); + hexdump(stdout, "x", 2); + hexdump(stdout, "foobar", 7); + hexdump(stdout, "f\nobar", 7); + hexdump(stdout, "xxxxxxxxxxxxxxxxxxxxyz", 23); + + for (i = 0; i < ELEMENTSOF(data); i++) + data[i] = i*2; + + hexdump(stdout, data, sizeof(data)); +} + int main(int argc, char *argv[]) { log_parse_environment(); log_open(); @@ -667,6 +686,7 @@ int main(int argc, char *argv[]) { test_get_files_in_directory(); test_in_set(); test_writing_tmpfile(); + test_hexdump(); return 0; } |