torture: show the first differing byte and a dump in torture_assert_data_blob_equal().
authorGünther Deschner <gd@samba.org>
Wed, 6 Feb 2013 11:25:43 +0000 (12:25 +0100)
committerStefan Metzmacher <metze@samba.org>
Wed, 20 Jul 2016 19:27:17 +0000 (21:27 +0200)
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>
lib/torture/torture.h

index e710873fb39423c7297192eca7cf558eeaa366eb..31c02f7cc24f5ffa4c7759335300bbaf9eaca79d 100644 (file)
@@ -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; \