Add Android build rules for tests. am: 18318b6e47 am: 1511f6dbd6
am: 2345eed995

Change-Id: Ia2e8936bc993ddcd739dc941406c745109330495
diff --git a/Android.bp b/Android.bp
index de8ca5d..0fef460 100644
--- a/Android.bp
+++ b/Android.bp
@@ -1,5 +1,5 @@
 // This Blueprint file loosely follows the logic of cpu_features'
-// CMakeLists.txt file.
+// CMakeLists.txt and test/CMakeLists.txt files.
 
 cc_defaults {
     name: "cpu_features-defaults",
@@ -96,3 +96,226 @@
         "libcpu_features",
     ],
 }
+
+
+// Tests.
+
+cc_defaults {
+    name: "cpu_features-test-defaults",
+    host_supported: true,
+    local_include_dirs: [
+        "include",
+    ],
+    cflags: [
+        "-DCPU_FEATURES_TEST"
+    ],
+}
+
+cc_test_library {
+    name: "libcpu_features-string_view",
+    defaults: ["cpu_features-test-defaults"],
+    srcs: [
+        "src/string_view.c",
+    ],
+}
+
+cc_test_library {
+    name: "libcpu_features-filesystem_for_testing",
+    defaults: ["cpu_features-test-defaults"],
+    cflags: [
+        "-DCPU_FEATURES_MOCK_FILESYSTEM",
+        // TODO: Handle unused parameters in
+        // test/filesystem_for_testing.cc and remove this flag.
+        "-Wno-unused-parameter",
+    ],
+    srcs: [
+        "test/filesystem_for_testing.cc",
+    ],
+}
+
+cc_test_library {
+    name: "libcpu_features-hwcaps_for_testing",
+    defaults: ["cpu_features-test-defaults"],
+    cflags: [
+        "-DCPU_FEATURES_MOCK_GET_ELF_HWCAP_FROM_GETAUXVAL",
+    ],
+    srcs: [
+        "test/hwcaps_for_testing.cc",
+    ],
+    static_libs: [
+        "libcpu_features-string_view",
+        "libcpu_features-filesystem_for_testing",
+    ],
+}
+
+cc_defaults {
+    name: "stack_line_reader-defaults",
+    cflags: [
+        "-DSTACK_LINE_READER_BUFFER_SIZE=1024",
+    ],
+}
+
+cc_test_library {
+    name: "libcpu_features-stack_line_reader",
+    defaults: [
+        "cpu_features-test-defaults",
+        "stack_line_reader-defaults",
+    ],
+    srcs: [
+        "src/stack_line_reader.c",
+    ],
+    static_libs: [
+        "libcpu_features-filesystem_for_testing",
+        "libcpu_features-string_view",
+    ],
+}
+
+cc_test_library {
+    name: "libcpu_features-stack_line_reader_for_test",
+    defaults: ["cpu_features-test-defaults"],
+    cflags: [
+        "-DSTACK_LINE_READER_BUFFER_SIZE=16",
+    ],
+    srcs: [
+        "src/stack_line_reader.c",
+    ],
+    whole_static_libs: [
+        "libcpu_features-filesystem_for_testing",
+        "libcpu_features-string_view",
+    ],
+}
+
+cc_test_library {
+    name: "libcpu_features-all_libraries",
+    defaults: [
+        "cpu_features-test-defaults",
+        "stack_line_reader-defaults",
+    ],
+    srcs: [
+        "src/unix_features_aggregator.c",
+    ],
+    whole_static_libs: [
+        "libcpu_features-filesystem_for_testing",
+        "libcpu_features-hwcaps_for_testing",
+        "libcpu_features-stack_line_reader",
+        "libcpu_features-string_view",
+    ],
+}
+
+cc_test {
+    name: "cpu_features-bit_utils_test",
+    defaults: ["cpu_features-test-defaults"],
+    srcs: [
+        "test/bit_utils_test.cc"
+    ],
+}
+
+cc_test {
+    name: "cpu_features-string_view_test",
+    defaults: ["cpu_features-test-defaults"],
+    srcs: [
+        "test/string_view_test.cc",
+        "src/string_view.c",
+    ],
+    static_libs: [
+        "libcpu_features-string_view",
+    ],
+}
+
+cc_test {
+    name: "cpu_features-stack_line_reader_test",
+    defaults: [
+        "cpu_features-test-defaults",
+        "stack_line_reader-defaults",
+    ],
+    cflags: [
+        // TODO: Handle unused funtions in
+        // test/stack_line_reader_test.cc and remove this flag.
+        "-Wno-unused-function",
+    ],
+    srcs: [
+        "test/stack_line_reader_test.cc",
+    ],
+    static_libs: [
+        "libcpu_features-stack_line_reader_for_test",
+    ],
+}
+
+cc_test {
+    name: "cpu_features-unix_features_aggregator_test",
+    defaults: ["cpu_features-test-defaults"],
+    srcs: [
+        "test/unix_features_aggregator_test.cc",
+    ],
+    static_libs: [
+        "libcpu_features-all_libraries",
+    ],
+}
+
+cc_defaults {
+    name: "cpu_features-cpuinfo-test-defaults",
+    defaults: ["cpu_features-test-defaults"],
+    enabled: false,
+    static_libs: [
+        "libcpu_features-all_libraries",
+    ],
+}
+
+cc_test {
+    name: "cpu_features-cpuinfo_x86_test",
+    defaults: ["cpu_features-cpuinfo-test-defaults"],
+    arch: {
+        x86: {
+            enabled: true,
+        },
+        x86_64: {
+            enabled: true,
+        },
+    },
+    target: {
+        windows: {
+            enabled: false,
+        },
+    },
+    cflags: [
+        "-DCPU_FEATURES_MOCK_CPUID_X86",
+    ],
+    srcs: [
+        "test/cpuinfo_x86_test.cc",
+        "src/cpuinfo_x86.c",
+    ],
+}
+
+cc_test {
+    name: "cpu_features-cpuinfo_arm_test",
+    defaults: [
+        "cpu_features-cpuinfo-test-defaults",
+        "stack_line_reader-defaults",
+    ],
+    arch: {
+        arm: {
+            enabled: true,
+        },
+    },
+    srcs: [
+        "test/cpuinfo_arm_test.cc",
+        "src/cpuinfo_arm.c",
+    ],
+}
+
+cc_test {
+    name: "cpu_features-cpuinfo_aarch64_test",
+    defaults: [
+        "cpu_features-cpuinfo-test-defaults",
+        "stack_line_reader-defaults",
+    ],
+    arch: {
+        arm64: {
+            enabled: true,
+        },
+    },
+    srcs: [
+        "test/cpuinfo_aarch64_test.cc",
+        "src/cpuinfo_aarch64.c",
+    ],
+}