--- a/src/test/regress/regress.c
+++ b/src/test/regress/regress.c
@@ -670,6 +670,16 @@ test_atomic_flag(void)
 	pg_atomic_clear_flag(&flag);
 }
 
+#define EXPECT(result_expr, expected_expr)		\
+	do { \
+		uint32		result = (result_expr); \
+		uint32		expected = (expected_expr); \
+		if (result != expected) \
+			elog(ERROR, \
+				 "%s yielded %u, expected %s in file \"%s\" line %u", \
+				 #result_expr, result, #expected_expr, __FILE__, __LINE__); \
+	} while (0)
+
 static void
 test_atomic_uint32(void)
 {
@@ -678,17 +688,10 @@ test_atomic_uint32(void)
 	int			i;
 
 	pg_atomic_init_u32(&var, 0);
-
-	if (pg_atomic_read_u32(&var) != 0)
-		elog(ERROR, "atomic_read_u32() #1 wrong");
-
+	EXPECT(pg_atomic_read_u32(&var), 0);
 	pg_atomic_write_u32(&var, 3);
-
-	if (pg_atomic_read_u32(&var) != 3)
-		elog(ERROR, "atomic_read_u32() #2 wrong");
-
-	if (pg_atomic_fetch_add_u32(&var, pg_atomic_read_u32(&var) - 2) != 3)
-		elog(ERROR, "atomic_fetch_add_u32() #1 wrong");
+	EXPECT(pg_atomic_read_u32(&var), 3);
+	EXPECT(pg_atomic_fetch_add_u32(&var, pg_atomic_read_u32(&var) - 2), 3);
 
 	if (pg_atomic_fetch_sub_u32(&var, 1) != 4)
 		elog(ERROR, "atomic_fetch_sub_u32() #1 wrong");
