feat: print file and line number if `expect` fails

This makes debugging a failed expect easier.

Change-Id: I53a2b3cd1866c14f3983a2e36b94707a94f12ef3
Signed-off-by: Karl Meakin <karl.meakin@arm.com>
diff --git a/spm/common/sp_helpers.c b/spm/common/sp_helpers.c
index eeb0d19..96a7d1e 100644
--- a/spm/common/sp_helpers.c
+++ b/spm/common/sp_helpers.c
@@ -30,15 +30,6 @@
  * Test framework helpers
  ******************************************************************************/
 
-void expect(int expr, int expected)
-{
-	if (expr != expected) {
-		ERROR("Expected value %i, got %i\n", expected, expr);
-		while (1)
-			continue;
-	}
-}
-
 void announce_test_section_start(const char *test_sect_desc)
 {
 	INFO("========================================\n");
diff --git a/spm/common/sp_helpers.h b/spm/common/sp_helpers.h
index a82924b..e0e749d 100644
--- a/spm/common/sp_helpers.h
+++ b/spm/common/sp_helpers.h
@@ -51,7 +51,20 @@
  * Check that expr == expected.
  * If not, loop forever.
  */
-void expect(int expr, int expected);
+#define EXPECT(lhs, rhs)                                                  \
+	do {                                                              \
+		int lhs_value = (lhs);                                    \
+		int rhs_value = (rhs);                                    \
+		if (lhs_value != rhs_value) {                             \
+			ERROR("%s:%d: Assertion failed: `%s == %s`\n",    \
+			      __FILE__, __LINE__, #lhs, #rhs);            \
+			ERROR("lhs = %d (0x%x)\n", lhs_value, lhs_value); \
+			ERROR("rhs = %d (0x%x)\n", rhs_value, rhs_value); \
+			while (1) {                                       \
+				continue;                                 \
+			}                                                 \
+		}                                                         \
+	} while (0)
 
 /*
  * Test framework functions
diff --git a/spm/common/sp_tests/sp_test_ffa.c b/spm/common/sp_tests/sp_test_ffa.c
index 9a32891..e8905a2 100644
--- a/spm/common/sp_tests/sp_test_ffa.c
+++ b/spm/common/sp_tests/sp_test_ffa.c
@@ -108,8 +108,8 @@
 
 	VERBOSE("%s: test request wrong UUID.\n", __func__);
 
-	expect(ffa_func_id(ret), FFA_ERROR);
-	expect(ffa_error_code(ret), FFA_ERROR_INVALID_PARAMETER);
+	EXPECT(ffa_func_id(ret), FFA_ERROR);
+	EXPECT(ffa_error_code(ret), FFA_ERROR_INVALID_PARAMETER);
 }
 
 static void ffa_partition_info_get_regs_test(void)
@@ -132,13 +132,13 @@
 		return;
 	}
 
-	expect(ffa_partition_info_regs_helper(sp_uuids[3],
+	EXPECT(ffa_partition_info_regs_helper(sp_uuids[3],
 		&ffa_expected_partition_info[3], 1), true);
-	expect(ffa_partition_info_regs_helper(sp_uuids[2],
+	EXPECT(ffa_partition_info_regs_helper(sp_uuids[2],
 		&ffa_expected_partition_info[2], 1), true);
-	expect(ffa_partition_info_regs_helper(sp_uuids[1],
+	EXPECT(ffa_partition_info_regs_helper(sp_uuids[1],
 		&ffa_expected_partition_info[1], 1), true);
-	expect(ffa_partition_info_regs_helper(sp_uuids[0],
+	EXPECT(ffa_partition_info_regs_helper(sp_uuids[0],
 		&ffa_expected_partition_info[0], 1), true);
 
 	/*
@@ -156,13 +156,13 @@
 	    (ffa_error_code(ret) == FFA_ERROR_INVALID_PARAMETER))) {
 		INFO("Skipping register based EL3 SPMD Logical partition"
 				" discovery\n");
-		expect(ffa_partition_info_regs_helper(NULL_UUID,
+		EXPECT(ffa_partition_info_regs_helper(NULL_UUID,
 			ffa_expected_partition_info,
 			(ARRAY_SIZE(ffa_expected_partition_info) - 1)), true);
 	} else {
-		expect(ffa_partition_info_regs_helper(sp_uuids[4],
+		EXPECT(ffa_partition_info_regs_helper(sp_uuids[4],
 			&ffa_expected_partition_info[4], 1), true);
-		expect(ffa_partition_info_regs_helper(NULL_UUID,
+		EXPECT(ffa_partition_info_regs_helper(NULL_UUID,
 			ffa_expected_partition_info,
 			ARRAY_SIZE(ffa_expected_partition_info)), true);
 	}
@@ -172,13 +172,13 @@
 {
 	INFO("Test FFA_PARTITION_INFO_GET.\n");
 
-	expect(ffa_partition_info_helper(mb, sp_uuids[2],
+	EXPECT(ffa_partition_info_helper(mb, sp_uuids[2],
 		&ffa_expected_partition_info[2], 1), true);
 
-	expect(ffa_partition_info_helper(mb, sp_uuids[1],
+	EXPECT(ffa_partition_info_helper(mb, sp_uuids[1],
 		&ffa_expected_partition_info[1], 1), true);
 
-	expect(ffa_partition_info_helper(mb, sp_uuids[0],
+	EXPECT(ffa_partition_info_helper(mb, sp_uuids[0],
 		&ffa_expected_partition_info[0], 1), true);
 
 	/*
@@ -188,7 +188,7 @@
 	 * uses the rx/tx buffer and the SPMD does not support the use of
 	 * rx/tx buffer to return SPMD logical partition information.
 	 */
-	expect(ffa_partition_info_helper(mb, NULL_UUID,
+	EXPECT(ffa_partition_info_helper(mb, NULL_UUID,
 		ffa_expected_partition_info,
 		(ARRAY_SIZE(ffa_expected_partition_info) - 1)), true);
 
@@ -211,7 +211,7 @@
 		spm_version & FFA_VERSION_MINOR_MASK,
 		(int)ffa_version_compatible);
 
-	expect((int)ffa_version_compatible, (int)true);
+	EXPECT((int)ffa_version_compatible, (int)true);
 }
 
 void ffa_spm_id_get_test(void)
@@ -219,7 +219,7 @@
 	if (spm_version >= MAKE_FFA_VERSION(1, 1)) {
 		struct ffa_value ret = ffa_spm_id_get();
 
-		expect(ffa_func_id(ret), FFA_SUCCESS_SMC32);
+		EXPECT(ffa_func_id(ret), FFA_SUCCESS_SMC32);
 
 		ffa_id_t spm_id = ffa_endpoint_id(ret);
 
@@ -229,7 +229,7 @@
 		 * Check the SPMC value given in the fvp_spmc_manifest
 		 * is returned.
 		 */
-		expect(spm_id, SPMC_ID);
+		EXPECT(spm_id, SPMC_ID);
 	} else {
 		INFO("FFA_SPM_ID_GET not supported in this version of FF-A."
 			" Test skipped.\n");