summaryrefslogtreecommitdiff
path: root/lib/torture
diff options
context:
space:
mode:
authorGünther Deschner <gd@samba.org>2013-02-06 12:25:43 +0100
committerStefan Metzmacher <metze@samba.org>2016-07-20 21:27:17 +0200
commitcde8ed20e0e71f17df3a34f1b6f132ea1f8af11e (patch)
tree01d04b5190d31d4f304e992b978184e30919f4f8 /lib/torture
parent26d2ea389bbebc66831e597b570cfdd0b2d5a6ef (diff)
downloadsamba-cde8ed20e0e71f17df3a34f1b6f132ea1f8af11e.tar.gz
torture: show the first differing byte and a dump in torture_assert_data_blob_equal().
Pair-Programmed-With: Stefan Metzmacher <metze@samba.org> Signed-off-by: Günther Deschner <gd@samba.org> Signed-off-by: Stefan Metzmacher <metze@samba.org>
Diffstat (limited to 'lib/torture')
-rw-r--r--lib/torture/torture.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/torture/torture.h b/lib/torture/torture.h
index e710873fb39..31c02f7cc24 100644
--- a/lib/torture/torture.h
+++ b/lib/torture/torture.h
@@ -349,6 +349,12 @@ void torture_result(struct torture_context *test,
} \
} while(0)
+static inline void torture_dump_data_str_cb(const char *buf, void *private_data)
+{
+ char **dump = (char **)private_data;
+ *dump = talloc_strdup_append_buffer(*dump, buf);
+}
+
#define torture_assert_data_blob_equal(torture_ctx,got,expected,cmt)\
do { const DATA_BLOB __got = (got), __expected = (expected); \
if (__got.length != __expected.length) { \
@@ -358,6 +364,36 @@ void torture_result(struct torture_context *test,
return false; \
} \
if (memcmp(__got.data, __expected.data, __got.length) != 0) { \
+ char *__dump = NULL; \
+ uint8_t __byte_a = 0x00;\
+ uint8_t __byte_b = 0x00;\
+ int __i;\
+ for (__i=0; __i < __expected.length; __i++) {\
+ __byte_a = __expected.data[__i];\
+ if (__i == __got.length) {\
+ __byte_b = 0x00;\
+ break;\
+ }\
+ __byte_b = __got.data[__i];\
+ if (__byte_a != __byte_b) {\
+ break;\
+ }\
+ }\
+ torture_warning(torture_ctx, "blobs differ at byte 0x%02X (%u)", __i, __i);\
+ torture_warning(torture_ctx, "expected byte[0x%02X] = 0x%02X got byte[0x%02X] = 0x%02X",\
+ __i, __byte_a, __i, __byte_b);\
+ __dump = talloc_strdup(torture_ctx, ""); \
+ dump_data_cb(__got.data, __got.length, true, \
+ torture_dump_data_str_cb, &__dump); \
+ torture_warning(torture_ctx, "got[0x%02X]: \n%s", \
+ (int)__got.length, __dump); \
+ TALLOC_FREE(__dump); \
+ __dump = talloc_strdup(torture_ctx, ""); \
+ dump_data_cb(__expected.data, __expected.length, true, \
+ torture_dump_data_str_cb, &__dump); \
+ torture_warning(torture_ctx, "expected[0x%02X]: \n%s", \
+ (int)__expected.length, __dump); \
+ TALLOC_FREE(__dump); \
torture_result(torture_ctx, TORTURE_FAIL, \
__location__": "#got" of len %d did not match "#expected": %s", (int)__got.length, cmt); \
return false; \