Config for building smaller hftest images

The size of hftest RAM disks may be too large for boards where we can
only use a small flash partition. Add a build arg for such boards and
try to build smaller binaries. This is best effort only.

Initially the config will strip out printing of details of failed
assertions, which requires keeping around many strings that cannot be
deduplicated. This saves about 25% on primary_with_secondaries tests.

Change-Id: I7af84e4298ffeddc7fd5c9bd4976d0234adc83bf
diff --git a/test/hftest/BUILD.gn b/test/hftest/BUILD.gn
index 054a319..511026d 100644
--- a/test/hftest/BUILD.gn
+++ b/test/hftest/BUILD.gn
@@ -17,6 +17,10 @@
 
 config("hftest_config") {
   include_dirs = [ "//test/inc" ]
+
+  if (hftest_optimize_for_size == true) {
+    defines = [ "HFTEST_OPTIMIZE_FOR_SIZE" ]
+  }
 }
 
 # Testing framework for a primary VM.
diff --git a/test/hftest/args.gni b/test/hftest/args.gni
index 89bf3a6..92d102b 100644
--- a/test/hftest/args.gni
+++ b/test/hftest/args.gni
@@ -16,4 +16,8 @@
   hftest_ctrl = ":ctrl_fdt"
   hftest_device = ":device_psci"
   hftest_manifest_overlay = ""
+
+  # If set to true, will strip non-critical code, such as verbose failure
+  # logging.
+  hftest_optimize_for_size = false
 }
diff --git a/test/inc/test/hftest_impl.h b/test/inc/test/hftest_impl.h
index ed2fa91..2c997c8 100644
--- a/test/inc/test/hftest_impl.h
+++ b/test/inc/test/hftest_impl.h
@@ -237,6 +237,18 @@
 #define HFTEST_LOG_FAILURE() \
 	dlog(HFTEST_LOG_PREFIX "Failure: %s:%u\n", __FILE__, __LINE__);
 
+#ifdef HFTEST_OPTIMIZE_FOR_SIZE
+#define HFTEST_LOG_ASSERT_DETAILS(lhs, rhs, op)
+#else /* HFTEST_OPTIMIZE_FOR_SIZE */
+#define HFTEST_LOG_ASSERT_DETAILS(lhs, rhs, op)                              \
+	dlog(HFTEST_LOG_PREFIX HFTEST_LOG_INDENT "%s %s %s (%s=", #lhs, #op, \
+	     #rhs, #lhs);                                                    \
+	dlog(hftest_dlog_format(lhs), hftest_any_get(lhs_value, lhs));       \
+	dlog(", %s=", #rhs);                                                 \
+	dlog(hftest_dlog_format(rhs), hftest_any_get(rhs_value, rhs));       \
+	dlog(")\n");
+#endif /* HFTEST_OPTIMIZE_FOR_SIZE */
+
 #define HFTEST_ASSERT_OP(lhs, rhs, op, fatal)                              \
 	do {                                                               \
 		union hftest_any lhs_value;                                \
@@ -248,15 +260,7 @@
 			struct hftest_context *ctx = hftest_get_context(); \
 			++ctx->failures;                                   \
 			HFTEST_LOG_FAILURE();                              \
-			dlog(HFTEST_LOG_PREFIX HFTEST_LOG_INDENT           \
-			     "%s %s %s (%s=",                              \
-			     #lhs, #op, #rhs, #lhs);                       \
-			dlog(hftest_dlog_format(lhs),                      \
-			     hftest_any_get(lhs_value, lhs));              \
-			dlog(", %s=", #rhs);                               \
-			dlog(hftest_dlog_format(rhs),                      \
-			     hftest_any_get(rhs_value, rhs));              \
-			dlog(")\n");                                       \
+			HFTEST_LOG_ASSERT_DETAILS(lhs, rhs, op);           \
 			if (fatal) {                                       \
 				ctx->abort();                              \
 			}                                                  \