testutil: always print errors on failure
[openssl.git] / test / testutil.h
index 0170a226f7141a4451579bdc3a6556deb57cab68..68d202adb15d6a6161be0fbd00b54b2b9496c67e 100644 (file)
@@ -10,6 +10,8 @@
 #ifndef HEADER_TESTUTIL_H
 # define HEADER_TESTUTIL_H
 
+#include <openssl/err.h>
+
 /*-
  * SETUP_TEST_FIXTURE and EXECUTE_TEST macros for test case functions.
  *
@@ -84,4 +86,26 @@ void add_test(const char *test_case_name, int (*test_fn) ());
 void add_all_tests(const char *test_case_name, int (*test_fn)(int idx), int num);
 int run_tests(const char *test_prog_name);
 
+/*
+ *  Test assumption verification helpers.
+ */
+
+/*
+ * Returns 1 if |s1| and |s2| are both NULL or equal.
+ * Otherwise, returns 0 and pretty-prints diagnostics using |desc|.
+ */
+int strings_equal(const char *desc, const char *s1, const char *s2);
 #endif                          /* HEADER_TESTUTIL_H */
+
+/*
+ * For "impossible" conditions such as malloc failures or bugs in test code,
+ * where continuing the test would be meaningless. Note that OPENSSL_assert
+ * is fatal, and is never compiled out.
+ */
+#define TEST_check(condition)                   \
+    do {                                        \
+        if (!(condition)) {                     \
+            ERR_print_errors_fp(stderr);        \
+            OPENSSL_assert(!#condition);        \
+        }                                       \
+    } while (0)