#endif
}
+static void print_memcmp_data(const void *_data, size_t len)
+{
+ const unsigned char *data = _data;
+ size_t i;
+
+ for (i = 0; i < len; i++) {
+ if (data[i] >= 0x20 && data[i] < 0x7f)
+ printf("%c", data[i]);
+ else
+ printf("\\x%02X", data[i]);
+ }
+}
+
+void test_assert_failed_memcmp_idx(const char *code, const char *file, unsigned int line,
+ const void *src, const void *dst, size_t len, long long i)
+{
+ printf("%s:%u: Assert", file, line);
+ if (i == LLONG_MIN)
+ printf(" failed: %s\n", code);
+ else
+ printf("(#%lld) failed: %s\n", i, code);
+ printf(" \"");
+ print_memcmp_data(src, len);
+ printf("\" != \"");
+ print_memcmp_data(dst, len);
+ printf("\" (len == %zu)", len);
+ fflush(stdout);
+ test_success = FALSE;
+#ifdef STATIC_CHECKER
+ i_unreached();
+#endif
+}
+
void test_assert_failed_cmp_intmax_idx(const char *code, const char *file,
unsigned int line,
intmax_t src, intmax_t dst,
test_assert_strcmp_idx(s1, s2, LLONG_MIN); \
} STMT_END
-/* Same as test_assert_strcmp expect that it takes an additional i as input.
+/* Additional parameters are m1 (source) and m2 (destination) memory and len
+ * in memcmp().
+ */
+#define test_assert_memcmp(m1, m2, len) STMT_START { \
+ test_assert_memcmp_idx(m1, m2, len, LLONG_MIN); \
+ } STMT_END
+
+/* Same as test_assert_strcmp except that it takes an additional i as input.
* When i is greater than or equals 0 it is used to identify the barrage of
* tests failed like in test_assert_idx.
*/
__FILE__, __LINE__, _temp_s1, _temp_s2, i); \
} STMT_END
+/* Same as test_assert_memcmp except that it takes an additional i as input.
+ * When i is greater than or equals 0 it is used to identify the barrage of
+ * tests failed like in test_assert_idx.
+*/
+#define test_assert_memcmp_idx(_m1, _m2, _len, i) STMT_START { \
+ const void *_temp_m1 = (_m1); \
+ const void *_temp_m2 = (_m2); \
+ const size_t _temp_len = (_len); \
+ if ((memcmp(_temp_m1,_temp_m2, _temp_len) != 0)) \
+ test_assert_failed_memcmp_idx("memcmp(" #_m1 "," #_m2 "," #_len ")", \
+ __FILE__, __LINE__, _temp_m1, _temp_m2, _temp_len, i); \
+ } STMT_END
+
#define test_assert_cmp_bool(_bool_value1, _op, _value2) \
test_assert_cmp((unsigned int) _bool_value1, _op, (unsigned int _bool_value2))
void test_assert_failed_strcmp_idx(const char *code, const char *file, unsigned int line,
const char *src, const char *dst, long long i)
ATTR_STATIC_CHECKER_NORETURN;
+void test_assert_failed_memcmp_idx(const char *code, const char *file, unsigned int line,
+ const void *src, const void *dst, size_t len, long long i)
+ ATTR_STATIC_CHECKER_NORETURN;
void test_assert_failed_cmp_intmax_idx(const char *code, const char *file,
unsigned int line,
intmax_t src, intmax_t dst,