Force malloc_debug_unit_tests to use _FORTIFY_SOURCE=2

We plan to make _FORTIFY_SOURCE=3 global on device.
malloc_debug_unit_test uses malloc_usable_size and this particular case
does not work with _FORTIFY_SOURCE=3. We isolated the file and forced
this cc test to use _FORTIFY_SOURCE=2.

Bug: 291762537
Test:
 - m malloc_debug_unit_tests
 - m malloc_debug_system_record_unit_tests
 - atest malloc_debug_system_record_unit_tests
 - atest malloc_debug_unit_tests
Change-Id: I97d671c6241eb845b1c805001fa2bbf658b6a0da
diff --git a/libc/malloc_debug/Android.bp b/libc/malloc_debug/Android.bp
index 50f24f6..408a046 100644
--- a/libc/malloc_debug/Android.bp
+++ b/libc/malloc_debug/Android.bp
@@ -125,18 +125,12 @@
 // ==============================================================
 // Unit Tests
 // ==============================================================
-cc_test {
-    name: "malloc_debug_unit_tests",
-    test_suites: ["device-tests"],
-    isolated: true,
+cc_defaults {
+    name: "malloc_debug_tests",
 
     srcs: [
-        "tests/backtrace_fake.cpp",
         "tests/log_fake.cpp",
         "tests/libc_fake.cpp",
-        "tests/malloc_debug_config_tests.cpp",
-        "tests/malloc_debug_record_data_tests.cpp",
-        "tests/malloc_debug_unit_tests.cpp",
     ],
 
     local_include_dirs: ["tests"],
@@ -149,16 +143,15 @@
         "bionic_libc_platform_headers",
     ],
 
-    static_libs: [
-        "libc_malloc_debug",
-        "libtinyxml2",
-    ],
-
     shared_libs: [
         "libbase",
         "libunwindstack",
     ],
 
+    static_libs: [
+        "libc_malloc_debug",
+    ],
+
     cflags: [
         "-Wall",
         "-Werror",
@@ -167,6 +160,41 @@
     ],
 }
 
+cc_test {
+    name: "malloc_debug_system_record_unit_tests",
+    defaults: ["malloc_debug_tests"],
+    test_suites: ["device-tests"],
+    isolated: true,
+
+    srcs: [
+        "tests/malloc_debug_config_tests.cpp",
+        "tests/malloc_debug_record_data_tests.cpp",
+    ],
+}
+
+cc_test {
+    name: "malloc_debug_unit_tests",
+    defaults: ["malloc_debug_tests"],
+    test_suites: ["device-tests"],
+    isolated: true,
+
+    srcs: [
+        "tests/backtrace_fake.cpp",
+        "tests/malloc_debug_unit_tests.cpp",
+    ],
+
+    static_libs: [
+        "libtinyxml2",
+    ],
+
+    cflags: [
+        // This code uses malloc_usable_size(),
+        // and thus can't be built with _FORTIFY_SOURCE=3.
+        "-U_FORTIFY_SOURCE",
+        "-D_FORTIFY_SOURCE=2",
+    ],
+}
+
 // ==============================================================
 // System Tests
 // ==============================================================