From 82a1d55f20cc6977643f4c1e0efd55baec27f9a4 Mon Sep 17 00:00:00 2001
From: Brian Gix <brian.gix@intel.com>
Date: Tue, 7 Apr 2020 09:10:33 -0700
Subject: [PATCH] Exit test-mesh-crypto on any detected fail

Unit test would signal failures if run on commandline, but not if
run as part of a unit test sweep. This change forces an exit(1) on
any detected fail, and is caught by test suite runner.

https://github.com/bluez/bluez/commit/5fc60b2ce7c4370ff8d9bc3d3c3434b212465f40

---
 unit/test-mesh-crypto.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/unit/test-mesh-crypto.c b/unit/test-mesh-crypto.c
index 32c46a5..08b7a87 100644
--- a/unit/test-mesh-crypto.c
+++ b/unit/test-mesh-crypto.c
@@ -660,9 +660,23 @@ static const struct mesh_crypto_test s8_6_2 = {
 #define INVAL	COLOR_YELLOW "INVALID" COLOR_OFF
 
 #define EVALCMP(a, b, l)	memcmp((a), (b), (l)) ? FAIL : PASS
-#define EVALSTR(a, b)		(a) && (b) ? (strcmp((a), (b)) ? FAIL : PASS) : INVAL
-#define EVALNUM(a, b)		a == b ? PASS : FAIL
+#define EXITCMP(a, b, l)	do { if (memcmp((a), (b), (l))) \
+					exit(1); \
+				} while (0)
+
+#define EVALSTR(a, b)	(((a) && (b)) ? (strcmp((a), (b)) ? FAIL : PASS) \
+								: INVAL)
+#define EXITSTR(a, b)	do { if ((a) && (b)) { \
+					if (strcmp((a), (b))) \
+						exit(1); \
+				} else \
+					exit(1); \
+			} while (0)
+
+#define EVALNUM(a, b)	(((a) == (b)) ? PASS : FAIL)
+#define EXITNUM(a, b)	do { if (a != b) exit(1); } while (0)
 #define EVALBOOLNOTBOTH(a, b)	!(a && b) ? PASS : FAIL
+#define EXITBOOLNOTBOTH(a, b)	do { if (!!(a && b)) exit(1); } while (0)
 
 static void verify_data(const char *label, unsigned int indent,
 			const char *sample, const uint8_t *data, size_t size)
@@ -673,6 +687,7 @@ static void verify_data(const char *label, unsigned int indent,
 	l_info("%-20s =%*c%s", label, 1 + (indent * 2), ' ', sample);
 	l_info("%-20s  %*c%s => %s", "", 1 + (indent * 2), ' ', str,
 							EVALSTR(sample, str));
+        EXITSTR(sample, str);
 	l_free(str);
 }
 
@@ -684,6 +699,7 @@ static void verify_bool_not_both(const char *label, unsigned int indent,
 	l_info("%-20s  %*c%s => %s", "", 1 + (indent * 2), ' ',
 						data ? "true" : "false",
 						EVALBOOLNOTBOTH(sample, data));
+ 	EXITBOOLNOTBOTH(sample, data);
 }
 
 static void verify_uint8(const char *label, unsigned int indent,
@@ -692,6 +708,7 @@ static void verify_uint8(const char *label, unsigned int indent,
 	l_info("%-20s =%*c%02x", label, 1 + (indent * 2), ' ', sample);
 	l_info("%-20s  %*c%02x => %s", "", 1 + (indent * 2), ' ', data,
 							EVALNUM(sample, data));
+	EXITNUM(sample, data);
 }
 
 static void verify_uint16(const char *label, unsigned int indent,
@@ -700,6 +717,7 @@ static void verify_uint16(const char *label, unsigned int indent,
 	l_info("%-20s =%*c%04x", label, 1 + (indent * 2), ' ', sample);
 	l_info("%-20s  %*c%04x => %s", "", 1 + (indent * 2), ' ', data,
 							EVALNUM(sample, data));
+	EXITNUM(sample, data);
 }
 
 static void verify_uint24(const char *label, unsigned int indent,
@@ -708,6 +726,7 @@ static void verify_uint24(const char *label, unsigned int indent,
 	l_info("%-20s =%*c%06x", label, 1 + (indent * 2), ' ', sample);
 	l_info("%-20s  %*c%06x => %s", "", 1 + (indent * 2), ' ', data,
 							EVALNUM(sample, data));
+	EXITNUM(sample, data);
 }
 
 static void verify_uint32(const char *label, unsigned int indent,
@@ -716,6 +735,7 @@ static void verify_uint32(const char *label, unsigned int indent,
 	l_info("%-20s =%*c%08x", label, 1 + (indent * 2), ' ', sample);
 	l_info("%-20s  %*c%08x => %s", "", 1 + (indent * 2), ' ', data,
 							EVALNUM(sample, data));
+	EXITNUM(sample, data);
 }
 
 static void verify_uint64(const char *label, unsigned int indent,
@@ -726,6 +746,7 @@ static void verify_uint64(const char *label, unsigned int indent,
 	l_info("%-20s  %*c%16llx => %s", "", 1 + (indent * 2), ' ',
 						(long long unsigned int) data,
 						EVALNUM(sample, data));
+	EXITNUM(sample, data);
 }
 
 static void show_str(const char *label, unsigned int indent,
-- 
1.8.3.1


