Add static variant of hwasan_test

Test: atest hwasan_test hwasan_test_static
Change-Id: I2cd93e4d7e8c76dceffea4a287c1645cb22f4e3f
diff --git a/tests/Android.bp b/tests/Android.bp
index deb2843..d1ca78f 100644
--- a/tests/Android.bp
+++ b/tests/Android.bp
@@ -1083,8 +1083,8 @@
     ],
 }
 
-cc_test {
-    name: "hwasan_test",
+cc_defaults {
+    name: "hwasan_test_defaults",
     enabled: false,
     // This does not use bionic_tests_defaults because it is not supported on
     // host.
@@ -1099,9 +1099,6 @@
     srcs: [
         "hwasan_test.cpp",
     ],
-    shared_libs: [
-        "libbase",
-    ],
     data_libs: [
         "libtest_simple_hwasan",
         "libtest_simple_hwasan_nohwasan",
@@ -1111,6 +1108,24 @@
 }
 
 cc_test {
+    name: "hwasan_test",
+    defaults: ["hwasan_test_defaults"],
+    shared_libs: [
+        "libbase",
+    ],
+}
+
+cc_test {
+    name: "hwasan_test_static",
+    defaults: ["hwasan_test_defaults"],
+    static_libs: [
+        "libbase",
+    ],
+    static_executable: true,
+    cflags: ["-DHWASAN_TEST_STATIC"],
+}
+
+cc_test {
     name: "memtag_stack_dlopen_test",
     enabled: false,
     // This does not use bionic_tests_defaults because it is not supported on
diff --git a/tests/hwasan_test.cpp b/tests/hwasan_test.cpp
index e32534e..ddf84cb 100644
--- a/tests/hwasan_test.cpp
+++ b/tests/hwasan_test.cpp
@@ -36,7 +36,18 @@
 
 using HwasanDeathTest = SilentDeathTest;
 
-TEST_F(HwasanDeathTest, UseAfterFree) {
+
+#ifdef HWASAN_TEST_STATIC
+#define MAYBE_DlopenAbsolutePath DISABLED_DlopenAbsolutePath
+// TODO(fmayer): figure out why uaf is misclassified as out of bounds for
+// static executables.
+#define MAYBE_UseAfterFree DISABLED_UseAfterFree
+#else
+#define MAYBE_DlopenAbsolutePath DlopenAbsolutePath
+#define MAYBE_UseAfterFree UseAfterFree
+#endif
+
+TEST_F(HwasanDeathTest, MAYBE_UseAfterFree) {
   EXPECT_DEATH(
       {
         void* m = malloc(1);
@@ -59,7 +70,7 @@
 }
 
 // Check whether dlopen of /foo/bar.so checks /foo/hwasan/bar.so first.
-TEST(HwasanTest, DlopenAbsolutePath) {
+TEST(HwasanTest, MAYBE_DlopenAbsolutePath) {
   std::string path = android::base::GetExecutableDirectory() + "/libtest_simple_hwasan.so";
   ASSERT_EQ(0, access(path.c_str(), F_OK));  // Verify test setup.
   std::string hwasan_path =