Convert more bionic tests to Android.bp

Bug: 122332847
Bug: 130734182
Test: mmm bionic/tests; same files installed before & after
Test: m cts; same files in cts before & after
Test: `objdump -x <files> | grep NEEDED` is identical
Test: `objdump -x <files> | grep RUNPATH` difference make sense
      (additional lib64 entries from soong, minimal reorder)
Test: treehugger
Change-Id: I6eea4c3f9c0040efeba64e2b47c7b573767cd386
diff --git a/tests/Android.build.mk b/tests/Android.build.mk
deleted file mode 100644
index 04fc92d..0000000
--- a/tests/Android.build.mk
+++ /dev/null
@@ -1,128 +0,0 @@
-#
-# Copyright (C) 2014 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-include $(CLEAR_VARS)
-LOCAL_ADDITIONAL_DEPENDENCIES := $(common_additional_dependencies)
-
-LOCAL_MODULE := $(module)
-LOCAL_MODULE_TAGS := $(module_tag)
-ifeq ($(build_type),host)
-  # Always make host multilib
-  LOCAL_MULTILIB := both
-endif
-
-ifneq ($(findstring LIBRARY, $(build_target)),LIBRARY)
-  LOCAL_MODULE_STEM_32 := $(module)32
-  LOCAL_MODULE_STEM_64 := $(module)64
-else
-ifneq ($($(module)_install_to_native_tests_dir),)
-  ifeq ($(build_type),host)
-    native_tests_var := HOST_OUT_NATIVE_TESTS
-  else
-    native_tests_var := TARGET_OUT_DATA_NATIVE_TESTS
-  endif
-
-  ifneq ($($(module)_install_to_native_tests_dir_32),)
-    tests_dir_32 := $($(module)_install_to_native_tests_dir_32)
-  else
-    tests_dir_32 := $($(module)_install_to_native_tests_dir)
-  endif
-
-  ifneq ($($(module)_install_to_native_tests_dir_64),)
-    tests_dir_64 := $($(module)_install_to_native_tests_dir_64)
-  else
-    tests_dir_64 := $($(module)_install_to_native_tests_dir)
-  endif
-
-  LOCAL_MODULE_PATH_32 := $($(TARGET_2ND_ARCH_VAR_PREFIX)$(native_tests_var))/$(tests_dir_32)
-  LOCAL_MODULE_PATH_64 := $($(native_tests_var))/$(tests_dir_64)
-endif
-endif
-
-LOCAL_CLANG := $($(module)_clang_$(build_type))
-
-ifneq ($($(module)_allow_asan),true)
-  LOCAL_SANITIZE := never
-endif
-
-LOCAL_FORCE_STATIC_EXECUTABLE := $($(module)_force_static_executable)
-
-LOCAL_ALLOW_UNDEFINED_SYMBOLS := $($(module)_allow_undefined_symbols)
-
-ifneq ($($(module)_multilib),)
-  LOCAL_MULTILIB := $($(module)_multilib)
-endif
-
-ifneq ($($(module)_relative_path),)
-  LOCAL_MODULE_RELATIVE_PATH := $($(module)_relative_path)
-endif
-
-LOCAL_CFLAGS := \
-    $(common_cflags) \
-    $($(module)_cflags) \
-    $($(module)_cflags_$(build_type)) \
-
-LOCAL_CONLYFLAGS += \
-    $(common_conlyflags) \
-    $($(module)_conlyflags) \
-    $($(module)_conlyflags_$(build_type)) \
-
-LOCAL_CPPFLAGS += \
-    $(common_cppflags) \
-    $($(module)_cppflags) \
-    $($(module)_cppflags_$(build_type)) \
-
-LOCAL_C_INCLUDES := \
-    $(common_c_includes) \
-    $($(module)_c_includes) \
-    $($(module)_c_includes_$(build_type)) \
-
-LOCAL_SRC_FILES := \
-    $($(module)_src_files) \
-    $($(module)_src_files_$(build_type)) \
-
-LOCAL_STATIC_LIBRARIES := \
-    $($(module)_static_libraries) \
-    $($(module)_static_libraries_$(build_type)) \
-
-LOCAL_SHARED_LIBRARIES := \
-    $($(module)_shared_libraries) \
-    $($(module)_shared_libraries_$(build_type)) \
-
-LOCAL_WHOLE_STATIC_LIBRARIES := \
-    $($(module)_whole_static_libraries) \
-    $($(module)_whole_static_libraries_$(build_type)) \
-
-LOCAL_LDFLAGS := \
-    $($(module)_ldflags) \
-    $($(module)_ldflags_$(build_type)) \
-
-LOCAL_LDLIBS := \
-    $($(module)_ldlibs) \
-    $($(module)_ldlibs_$(build_type)) \
-
-LOCAL_CXX_STL := libc++_static
-
-ifeq ($(build_type),target)
-  include $(BUILD_$(build_target))
-endif
-
-ifeq ($(build_type),host)
-  # Only build if host builds are supported.
-  ifeq ($(build_host),true)
-    include $(BUILD_HOST_$(build_target))
-  endif
-endif
diff --git a/tests/libs/Android.bp b/tests/libs/Android.bp
index 98d4f25..2ee6c86 100644
--- a/tests/libs/Android.bp
+++ b/tests/libs/Android.bp
@@ -83,21 +83,30 @@
     name: "libtest_elftls_dynamic_filler_1",
     defaults: ["bionic_testlib_defaults"],
     srcs: ["elftls_dynamic_filler.cpp"],
-    cflags: ["-fno-emulated-tls", "-DTLS_FILLER=100"],
+    cflags: [
+        "-fno-emulated-tls",
+        "-DTLS_FILLER=100",
+    ],
 }
 
 cc_test_library {
     name: "libtest_elftls_dynamic_filler_2",
     defaults: ["bionic_testlib_defaults"],
     srcs: ["elftls_dynamic_filler.cpp"],
-    cflags: ["-fno-emulated-tls", "-DTLS_FILLER=200"],
+    cflags: [
+        "-fno-emulated-tls",
+        "-DTLS_FILLER=200",
+    ],
 }
 
 cc_test_library {
     name: "libtest_elftls_dynamic_filler_3",
     defaults: ["bionic_testlib_defaults"],
     srcs: ["elftls_dynamic_filler.cpp"],
-    cflags: ["-fno-emulated-tls", "-DTLS_FILLER=300"],
+    cflags: [
+        "-fno-emulated-tls",
+        "-DTLS_FILLER=300",
+    ],
 }
 
 // -----------------------------------------------------------------------------
@@ -131,7 +140,13 @@
 // -----------------------------------------------------------------------------
 // Library used by dlext tests - with GNU RELRO program header
 // -----------------------------------------------------------------------------
-// In Android.mk to support creating symlinks
+cc_test_library {
+    name: "libdlext_test",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlext_test_library.cpp"],
+    ldflags: ["-Wl,-z,relro"],
+    shared_libs: ["libtest_simple"],
+}
 
 // -----------------------------------------------------------------------------
 // Library used by dlext tests - without GNU RELRO program header
@@ -145,19 +160,58 @@
 }
 
 // -----------------------------------------------------------------------------
+// Library used by dlext tests - recursive use of RELRO sharing
+// -----------------------------------------------------------------------------
+cc_test_library {
+    name: "libdlext_test_recursive",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlext_test_recursive_library.cpp"],
+    ldflags: ["-Wl,-z,relro"],
+    shared_libs: ["libdlext_test"],
+}
+
+// -----------------------------------------------------------------------------
 // Library used by dlext tests - different name non-default location
 // -----------------------------------------------------------------------------
-// In Android.mk to support installing to /data
+cc_test_library {
+    name: "libdlext_test_fd",
+    defaults: ["bionic_testlib_defaults"],
+    host_supported: false,
+    srcs: ["dlext_test_library.cpp"],
+    ldflags: ["-Wl,--rpath,${ORIGIN}/.."],
+    relative_install_path: "bionic-loader-test-libs/libdlext_test_fd",
+    shared_libs: ["libtest_simple"],
+}
 
 // -----------------------------------------------------------------------------
 // Libraries used by dlext tests for open from a zip-file
 // -----------------------------------------------------------------------------
-// In Android.mk to support installing to /data
+cc_test_library {
+    name: "libdlext_test_zip",
+    defaults: ["bionic_testlib_defaults"],
+    host_supported: false,
+    srcs: ["dlext_test_library.cpp"],
+    shared_libs: ["libatest_simple_zip"],
+    relative_install_path: "bionic-loader-test-libs/libdlext_test_zip",
+}
+
+cc_test_library {
+    name: "libatest_simple_zip",
+    defaults: ["bionic_testlib_defaults"],
+    host_supported: false,
+    srcs: ["dlopen_testlib_simple.cpp"],
+    relative_install_path: "bionic-loader-test-libs/libatest_simple_zip",
+}
 
 // ----------------------------------------------------------------------------
 // Library with soname which does not match filename
 // ----------------------------------------------------------------------------
-// In Android.mk to support zipped and aligned tests
+cc_test_library {
+    name: "libdlext_test_different_soname",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlext_test_library.cpp"],
+    ldflags: ["-Wl,-soname=libdlext_test_soname.so"],
+}
 
 // -----------------------------------------------------------------------------
 // Library used by dlext tests - zipped and aligned
@@ -375,39 +429,545 @@
 }
 
 // -----------------------------------------------------------------------------
-// Build DT_RUNPATH test helper libraries
+// Build test helper libraries for linker namespaces
+//
+// This set of libraries is to test isolated namespaces
+//
+// Isolated namespaces do not allow loading of the library outside of
+// the search paths.
+//
+// This library cannot be loaded in isolated namespace because one of DT_NEEDED
+// libraries is outside of the search paths.
+//
+// libnstest_root_not_isolated.so (DT_RUNPATH = $ORIGIN/../private_namespace_libs_external/)
+// +-> libnstest_public.so
+// +-> libnstest_private_external.so (located in $ORIGIN/../private_namespace_libs_external/)
+//
+// Search path: $NATIVE_TESTS/private_namespace_libs/
+//
 // -----------------------------------------------------------------------------
-// include $(LOCAL_PATH)/Android.build.dt_runpath.mk
+
+cc_test_library {
+    name: "libnstest_root_not_isolated",
+    defaults: ["bionic_testlib_defaults"],
+    host_supported: false,
+    srcs: ["namespaces_root.cpp"],
+    shared_libs: [
+        "libnstest_public",
+        "libnstest_private_external",
+    ],
+    relative_install_path: "bionic-loader-test-libs/private_namespace_libs",
+    ldflags: ["-Wl,--rpath,$ORIGIN/../private_namespace_libs_external"],
+}
+
+cc_test_library {
+    name: "libnstest_private_external",
+    defaults: ["bionic_testlib_defaults"],
+    host_supported: false,
+    srcs: ["namespaces_private.cpp"],
+    relative_install_path: "bionic-loader-test-libs/private_namespace_libs_external",
+}
+
+// -----------------------------------------------------------------------------
+// Build DT_RUNPATH test helper libraries
+//
+// Dependencies
+//
+// libtest_dt_runpath_d.so                       runpath: ${ORIGIN}/dt_runpath_b_c_x, ${ORIGIN}/dt_runpath_y/${LIB}
+// |-> dt_runpath_b_c_x/libtest_dt_runpath_b.so  runpath: ${ORIGIN}/../dt_runpath_a
+// |   |-> dt_runpath_a/libtest_dt_runpath_a.so
+// |-> dt_runpath_b_c_x/libtest_dt_runpath_c.so  runpath: ${ORIGIN}/invalid_dt_runpath
+// |   |-> libtest_dt_runpath_a.so (soname)
+// |-> dt_runpath_y/lib[64]/libtest_dt_runpath_y.so
+//
+// This one is used to test dlopen
+// dt_runpath_b_c_x/libtest_dt_runpath_x.so
+//
+// -----------------------------------------------------------------------------
+
+// A leaf library in a non-standard directory.
+cc_test_library {
+    name: "libtest_dt_runpath_a",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["empty.cpp"],
+    relative_install_path: "bionic-loader-test-libs/dt_runpath_a",
+}
+
+// Depends on library A with a DT_RUNPATH
+cc_test_library {
+    name: "libtest_dt_runpath_b",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["empty.cpp"],
+    shared_libs: ["libtest_dt_runpath_a"],
+    relative_install_path: "bionic-loader-test-libs/dt_runpath_b_c_x",
+    ldflags: ["-Wl,--rpath,${ORIGIN}/../dt_runpath_a"],
+}
+
+// Depends on library A with an incorrect DT_RUNPATH. This does not matter
+// because B is the first in the D (below) dependency order, and library A
+// is already loaded using the correct DT_RUNPATH from library B.
+cc_test_library {
+    name: "libtest_dt_runpath_c",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["empty.cpp"],
+    shared_libs: ["libtest_dt_runpath_a"],
+    relative_install_path: "bionic-loader-test-libs/dt_runpath_b_c_x",
+    ldflags: ["-Wl,--rpath,${ORIGIN}/invalid_dt_runpath"],
+}
+
+// D depends on B, C, and Y with DT_RUNPATH.
+cc_test_library {
+    name: "libtest_dt_runpath_d",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlopen_b.cpp"],
+    shared_libs: [
+        "libtest_dt_runpath_b",
+        "libtest_dt_runpath_c",
+        "libtest_dt_runpath_y",
+    ],
+    ldflags: [
+        "-Wl,--rpath,${ORIGIN}/dt_runpath_b_c_x",
+        "-Wl,--rpath,${ORIGIN}/dt_runpath_y/${LIB}",
+    ],
+}
+
+// D version for open-from-zip test with runpath
+cc_test_library {
+    name: "libtest_dt_runpath_d_zip",
+    srcs: ["dlopen_b.cpp"],
+    shared_libs: [
+        "libtest_dt_runpath_b",
+        "libtest_dt_runpath_c",
+        "libtest_dt_runpath_y",
+    ],
+    cflags: [
+        "-Wall",
+        "-Werror",
+    ],
+    gtest: false,
+    relative_install_path: "libtest_dt_runpath_d_zip",
+    ldflags: [
+        "-Wl,--rpath,${ORIGIN}/dt_runpath_b_c_x",
+        "-Wl,--rpath,${ORIGIN}/dt_runpath_y/${LIB}",
+    ],
+    sanitize: {
+        address: false,
+        fuzzer: false,
+    },
+    stl: "libc++_static",
+    target: {
+        darwin: {
+            enabled: false,
+        },
+    },
+}
+
+// A leaf library in a directory library D has DT_RUNPATH for.
+cc_test_library {
+    name: "libtest_dt_runpath_x",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["empty.cpp"],
+    relative_install_path: "bionic-loader-test-libs/dt_runpath_b_c_x",
+}
+
+// A leaf library in lib or lib64 directory
+cc_test_library {
+    name: "libtest_dt_runpath_y",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["empty.cpp"],
+
+    multilib: {
+        lib32: {
+            relative_install_path: "bionic-loader-test-libs/dt_runpath_y/lib",
+        },
+        lib64: {
+            relative_install_path: "bionic-loader-test-libs/dt_runpath_y/lib64",
+        },
+    },
+}
 
 // -----------------------------------------------------------------------------
 // Build library with two parents
+//
+// Libraries used by dlfcn tests to verify local group ref_counting
+// libtest_two_parents*.so
 // -----------------------------------------------------------------------------
-// include $(LOCAL_PATH)/Android.build.dlopen_2_parents_reloc.mk
+
+// ..._child.so - correct answer
+cc_test_library {
+    name: "libtest_two_parents_child",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlopen_2_parents_reloc_answer.cpp"],
+}
+
+// ..._parent1.so - correct answer
+cc_test_library {
+    name: "libtest_two_parents_parent1",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlopen_check_order_reloc_answer_impl.cpp"],
+    shared_libs: ["libtest_two_parents_child"],
+    cflags: ["-D__ANSWER=42"],
+}
+
+// ..._parent2.so - incorrect answer
+cc_test_library {
+    name: "libtest_two_parents_parent2",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlopen_check_order_reloc_answer_impl.cpp"],
+    shared_libs: ["libtest_two_parents_child"],
+    cflags: ["-D__ANSWER=1"],
+}
 
 // -----------------------------------------------------------------------------
 // Build libtest_check_order_dlsym.so with its dependencies.
+//
+// Libraries used by dlfcn tests to verify correct load order:
 // -----------------------------------------------------------------------------
-// include $(LOCAL_PATH)/Android.build.dlopen_check_order_dlsym.mk
+
+// libtest_check_order_2_right.so
+cc_test_library {
+    name: "libtest_check_order_dlsym_2_right",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlopen_check_order_dlsym_answer.cpp"],
+    cflags: ["-D__ANSWER=42"],
+}
+
+// libtest_check_order_a.so
+cc_test_library {
+    name: "libtest_check_order_dlsym_a",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlopen_check_order_dlsym_answer.cpp"],
+    cflags: ["-D__ANSWER=1"],
+}
+
+// libtest_check_order_b.so
+cc_test_library {
+    name: "libtest_check_order_dlsym_b",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlopen_check_order_dlsym_answer.cpp"],
+    cflags: [
+        "-D__ANSWER=2",
+        "-D__ANSWER2=43",
+    ],
+}
+
+// libtest_check_order_c.so
+cc_test_library {
+    name: "libtest_check_order_dlsym_3_c",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlopen_check_order_dlsym_answer.cpp"],
+    cflags: ["-D__ANSWER=3"],
+}
+
+// libtest_check_order_d.so
+cc_test_library {
+    name: "libtest_check_order_dlsym_d",
+    defaults: ["bionic_testlib_defaults"],
+    shared_libs: ["libtest_check_order_dlsym_b"],
+    srcs: ["dlopen_check_order_dlsym_answer.cpp"],
+    cflags: [
+        "-D__ANSWER=4",
+        "-D__ANSWER2=4",
+    ],
+}
+
+// libtest_check_order_left.so
+cc_test_library {
+    name: "libtest_check_order_dlsym_1_left",
+    defaults: ["bionic_testlib_defaults"],
+    shared_libs: [
+        "libtest_check_order_dlsym_a",
+        "libtest_check_order_dlsym_b",
+    ],
+    srcs: ["empty.cpp"],
+}
+
+// libtest_check_order.so
+cc_test_library {
+    name: "libtest_check_order_dlsym",
+    defaults: ["bionic_testlib_defaults"],
+    shared_libs: [
+        "libtest_check_order_dlsym_1_left",
+        "libtest_check_order_dlsym_2_right",
+        "libtest_check_order_dlsym_3_c",
+    ],
+    srcs: ["empty.cpp"],
+}
 
 // -----------------------------------------------------------------------------
 // Build libtest_check_order_siblings.so with its dependencies.
+//
+// Libraries used by dlfcn tests to verify correct relocation order:
+// libtest_check_order_reloc_siblings*.so
 // -----------------------------------------------------------------------------
-// include $(LOCAL_PATH)/Android.build.dlopen_check_order_reloc_siblings.mk
+
+// ..._1.so - empty
+cc_test_library {
+    name: "libtest_check_order_reloc_siblings_1",
+    defaults: ["bionic_testlib_defaults"],
+    shared_libs: [
+        "libtest_check_order_reloc_siblings_a",
+        "libtest_check_order_reloc_siblings_b",
+    ],
+    srcs: ["empty.cpp"],
+}
+
+// ..._2.so - empty
+cc_test_library {
+    name: "libtest_check_order_reloc_siblings_2",
+    defaults: ["bionic_testlib_defaults"],
+    shared_libs: [
+        "libtest_check_order_reloc_siblings_c",
+        "libtest_check_order_reloc_siblings_d",
+    ],
+    srcs: [
+        "dlopen_check_order_reloc_grandchild_answer.cpp",
+    ],
+    allow_undefined_symbols: true,
+}
+
+// ..._3.so - get_answer2();
+cc_test_library {
+    name: "libtest_check_order_reloc_siblings_3",
+    defaults: ["bionic_testlib_defaults"],
+    shared_libs: [
+        "libtest_check_order_reloc_siblings_e",
+        "libtest_check_order_reloc_siblings_f",
+    ],
+    srcs: [
+        "dlopen_check_order_reloc_nephew_answer.cpp",
+    ],
+}
+
+// ..._a.so <- correct impl
+cc_test_library {
+    name: "libtest_check_order_reloc_siblings_a",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: [
+        "dlopen_check_order_reloc_answer_impl.cpp",
+    ],
+    cflags: ["-D__ANSWER=42"],
+}
+
+// ..._b.so
+cc_test_library {
+    name: "libtest_check_order_reloc_siblings_b",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: [
+        "dlopen_check_order_reloc_answer_impl.cpp",
+    ],
+    cflags: ["-D__ANSWER=1"],
+}
+
+// ..._c.so
+cc_test_library {
+    name: "libtest_check_order_reloc_siblings_c",
+    defaults: ["bionic_testlib_defaults"],
+    shared_libs: [
+        "libtest_check_order_reloc_siblings_c_1",
+        "libtest_check_order_reloc_siblings_c_2",
+    ],
+    srcs: [
+        "dlopen_check_order_reloc_answer_impl.cpp",
+    ],
+    cflags: ["-D__ANSWER=2"],
+}
+
+// ..._d.so
+cc_test_library {
+    name: "libtest_check_order_reloc_siblings_d",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: [
+        "dlopen_check_order_reloc_answer_impl.cpp",
+    ],
+    cflags: ["-D__ANSWER=3"],
+}
+
+// ..._e.so
+cc_test_library {
+    name: "libtest_check_order_reloc_siblings_e",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: [
+        "dlopen_check_order_reloc_answer_impl.cpp",
+    ],
+    cflags: [
+        "-D__ANSWER=4",
+    ],
+}
+
+// ..._f.so <- get_answer()
+cc_test_library {
+    name: "libtest_check_order_reloc_siblings_f",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: [
+        "dlopen_check_order_reloc_answer.cpp",
+    ],
+}
+
+// ..._c_1.so
+cc_test_library {
+    name: "libtest_check_order_reloc_siblings_c_1",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: [
+        "dlopen_check_order_reloc_grandchild_answer_impl.cpp",
+    ],
+    cflags: ["-D__ANSWER=42"],
+}
+
+// ..._c_2.so
+cc_test_library {
+    name: "libtest_check_order_reloc_siblings_c_2",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: [
+        "dlopen_check_order_reloc_grandchild_answer_impl.cpp",
+    ],
+    cflags: ["-D__ANSWER=0"],
+}
+
+// libtest_check_order_reloc_siblings.so
+cc_test_library {
+    name: "libtest_check_order_reloc_siblings",
+    defaults: ["bionic_testlib_defaults"],
+    shared_libs: [
+        "libtest_check_order_reloc_siblings_1",
+        "libtest_check_order_reloc_siblings_2",
+        "libtest_check_order_reloc_siblings_3",
+    ],
+    srcs: [
+        "empty.cpp",
+    ],
+}
 
 // -----------------------------------------------------------------------------
 // Build libtest_check_order_root.so with its dependencies.
+//
+// Libraries used by dlfcn tests to verify correct relocation order:
+// libtest_check_order_reloc_root*.so
 // -----------------------------------------------------------------------------
-// include $(LOCAL_PATH)/Android.build.dlopen_check_order_reloc_main_executable.mk
+
+// ..._1.so - empty
+cc_test_library {
+    name: "libtest_check_order_reloc_root_1",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["empty.cpp"],
+}
+
+// ..._2.so - this one has the incorrect answer
+cc_test_library {
+    name: "libtest_check_order_reloc_root_2",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlopen_check_order_reloc_root_answer_impl.cpp"],
+    cflags: ["-D__ANSWER=2"],
+}
+
+// libtest_check_order_reloc_root.so <- implements get_answer3()
+cc_test_library {
+    name: "libtest_check_order_reloc_root",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlopen_check_order_reloc_root_answer.cpp"],
+    shared_libs: [
+        "libtest_check_order_reloc_root_1",
+        "libtest_check_order_reloc_root_2",
+    ],
+}
 
 // -----------------------------------------------------------------------------
 // Build libtest_versioned_lib.so with its dependencies.
+//
+// Libraries used to test versioned symbols
 // -----------------------------------------------------------------------------
-// include $(LOCAL_PATH)/Android.build.versioned_lib.mk
+
+cc_test_library {
+    name: "libtest_versioned_uselibv1",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["versioned_uselib.cpp"],
+    shared_libs: ["libtest_versioned_libv1"],
+}
+
+cc_test_library {
+    name: "libtest_versioned_uselibv2",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["versioned_uselib.cpp"],
+    shared_libs: ["libtest_versioned_libv2"],
+    version_script: "versioned_uselib.map",
+}
+
+cc_test_library {
+    name: "libtest_versioned_uselibv2_other",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["versioned_uselib.cpp"],
+    shared_libs: [
+        "libtest_versioned_otherlib_empty",
+        "libtest_versioned_libv2",
+    ],
+}
+
+cc_test_library {
+    name: "libtest_versioned_uselibv3_other",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["versioned_uselib.cpp"],
+    shared_libs: [
+        "libtest_versioned_otherlib_empty",
+        "libtest_versioned_lib",
+    ],
+}
+
+// lib v1 - this one used during static linking but never used at runtime
+// which forces libtest_versioned_uselibv1 to use function v1 from
+// libtest_versioned_lib.so
+cc_test_library {
+    name: "libtest_versioned_libv1",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["versioned_lib_v1.cpp"],
+    version_script: "versioned_lib_v1.map",
+    ldflags: ["-Wl,-soname,libtest_versioned_lib.so"],
+}
+
+// lib v2 - to make libtest_versioned_uselibv2.so use version 2 of versioned_function()
+cc_test_library {
+    name: "libtest_versioned_libv2",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["versioned_lib_v2.cpp"],
+    version_script: "versioned_lib_v2.map",
+    ldflags: ["-Wl,-soname,libtest_versioned_lib.so"],
+}
+
+// last version - this one is used at the runtime and exports 3 versions
+// of versioned_symbol().
+cc_test_library {
+    name: "libtest_versioned_lib",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["versioned_lib_v3.cpp"],
+    version_script: "versioned_lib_v3.map",
+}
+
+// This library is empty, the actual implementation will provide an unversioned
+// symbol for versioned_function().
+cc_test_library {
+    name: "libtest_versioned_otherlib_empty",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["empty.cpp"],
+    ldflags: ["-Wl,-soname,libtest_versioned_otherlib.so"],
+}
+
+cc_test_library {
+    name: "libtest_versioned_otherlib",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["versioned_lib_other.cpp"],
+    version_script: "versioned_lib_other.map",
+}
 
 // -----------------------------------------------------------------------------
 // Build libraries needed by pthread_atfork tests
+
+// This library used to test phtread_atfork handler behaviour
+// during/after dlclose.
 // -----------------------------------------------------------------------------
-// include $(LOCAL_PATH)/Android.build.pthread_atfork.mk
+cc_test_library {
+    name: "libtest_pthread_atfork",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["pthread_atfork.cpp"],
+}
 
 // -----------------------------------------------------------------------------
 // Library with dependency loop used by dlfcn tests
@@ -496,7 +1056,12 @@
 // -----------------------------------------------------------------------------
 // Library with dependency used by dlfcn tests
 // -----------------------------------------------------------------------------
-// In Android.mk to support dependency on libdlext_test
+cc_test_library {
+    name: "libtest_with_dependency",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlopen_testlib_simple.cpp"],
+    shared_libs: ["libdlext_test"],
+}
 
 // -----------------------------------------------------------------------------
 // Library used by ifunc tests
@@ -777,7 +1342,6 @@
     ],
 }
 
-
 // -----------------------------------------------------------------------------
 // Tool to use to align the shared libraries in a zip file.
 // -----------------------------------------------------------------------------
diff --git a/tests/libs/Android.build.dlopen_2_parents_reloc.mk b/tests/libs/Android.build.dlopen_2_parents_reloc.mk
deleted file mode 100644
index 29ae10d..0000000
--- a/tests/libs/Android.build.dlopen_2_parents_reloc.mk
+++ /dev/null
@@ -1,52 +0,0 @@
-#
-# Copyright (C) 2014 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-# -----------------------------------------------------------------------------
-# Libraries used by dlfcn tests to verify local group ref_counting
-# libtest_two_parents*.so
-# -----------------------------------------------------------------------------
-
-# -----------------------------------------------------------------------------
-# ..._child.so - correct answer
-# -----------------------------------------------------------------------------
-libtest_two_parents_child_src_files := \
-    dlopen_2_parents_reloc_answer.cpp
-
-module := libtest_two_parents_child
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# ..._parent1.so - correct answer
-# -----------------------------------------------------------------------------
-libtest_two_parents_parent1_src_files := \
-    dlopen_check_order_reloc_answer_impl.cpp
-
-libtest_two_parents_parent1_shared_libraries := libtest_two_parents_child
-libtest_two_parents_parent1_cflags := -D__ANSWER=42
-module := libtest_two_parents_parent1
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# ..._parent2.so - incorrect answer
-# -----------------------------------------------------------------------------
-libtest_two_parents_parent2_src_files := \
-    dlopen_check_order_reloc_answer_impl.cpp
-
-libtest_two_parents_parent2_shared_libraries := libtest_two_parents_child
-libtest_two_parents_parent2_cflags := -D__ANSWER=1
-module := libtest_two_parents_parent2
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
diff --git a/tests/libs/Android.build.dlopen_check_order_dlsym.mk b/tests/libs/Android.build.dlopen_check_order_dlsym.mk
deleted file mode 100644
index 73d8c1a..0000000
--- a/tests/libs/Android.build.dlopen_check_order_dlsym.mk
+++ /dev/null
@@ -1,90 +0,0 @@
-#
-# Copyright (C) 2012 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-# -----------------------------------------------------------------------------
-# Libraries used by dlfcn tests to verify correct load order:
-# libtest_check_order_2_right.so
-# -----------------------------------------------------------------------------
-libtest_check_order_dlsym_2_right_src_files := \
-    dlopen_check_order_dlsym_answer.cpp
-
-libtest_check_order_dlsym_2_right_cflags := -D__ANSWER=42
-module := libtest_check_order_dlsym_2_right
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# libtest_check_order_a.so
-# -----------------------------------------------------------------------------
-libtest_check_order_dlsym_a_src_files := \
-    dlopen_check_order_dlsym_answer.cpp
-
-libtest_check_order_dlsym_a_cflags := -D__ANSWER=1
-module := libtest_check_order_dlsym_a
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# libtest_check_order_b.so
-# -----------------------------------------------------------------------------
-libtest_check_order_dlsym_b_src_files := \
-    dlopen_check_order_dlsym_answer.cpp
-
-libtest_check_order_dlsym_b_cflags := -D__ANSWER=2 -D__ANSWER2=43
-module := libtest_check_order_dlsym_b
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# libtest_check_order_c.so
-# -----------------------------------------------------------------------------
-libtest_check_order_dlsym_3_c_src_files := \
-    dlopen_check_order_dlsym_answer.cpp
-
-libtest_check_order_dlsym_3_c_cflags := -D__ANSWER=3
-module := libtest_check_order_dlsym_3_c
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# libtest_check_order_d.so
-# -----------------------------------------------------------------------------
-libtest_check_order_dlsym_d_src_files := \
-   dlopen_check_order_dlsym_answer.cpp
-
-libtest_check_order_dlsym_d_shared_libraries := libtest_check_order_dlsym_b
-libtest_check_order_dlsym_d_cflags := -D__ANSWER=4 -D__ANSWER2=4
-module := libtest_check_order_dlsym_d
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# libtest_check_order_left.so
-# -----------------------------------------------------------------------------
-libtest_check_order_dlsym_1_left_src_files := \
-    empty.cpp
-
-libtest_check_order_dlsym_1_left_shared_libraries := libtest_check_order_dlsym_a libtest_check_order_dlsym_b
-
-module := libtest_check_order_dlsym_1_left
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# libtest_check_order.so
-# -----------------------------------------------------------------------------
-libtest_check_order_dlsym_src_files := \
-    empty.cpp
-
-libtest_check_order_dlsym_shared_libraries := libtest_check_order_dlsym_1_left \
-  libtest_check_order_dlsym_2_right libtest_check_order_dlsym_3_c
-
-module := libtest_check_order_dlsym
-include $(LOCAL_PATH)/Android.build.testlib.mk
diff --git a/tests/libs/Android.build.dlopen_check_order_reloc_main_executable.mk b/tests/libs/Android.build.dlopen_check_order_reloc_main_executable.mk
deleted file mode 100644
index 639696b..0000000
--- a/tests/libs/Android.build.dlopen_check_order_reloc_main_executable.mk
+++ /dev/null
@@ -1,56 +0,0 @@
-#
-# Copyright (C) 2012 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-# -----------------------------------------------------------------------------
-# Libraries used by dlfcn tests to verify correct relocation order:
-# libtest_check_order_reloc_root*.so
-# -----------------------------------------------------------------------------
-
-
-# -----------------------------------------------------------------------------
-# ..._1.so - empty
-# -----------------------------------------------------------------------------
-libtest_check_order_reloc_root_1_src_files := \
-    empty.cpp
-
-
-module := libtest_check_order_reloc_root_1
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-
-# -----------------------------------------------------------------------------
-# ..._2.so - this one has the incorrect answer
-# -----------------------------------------------------------------------------
-libtest_check_order_reloc_root_2_src_files := \
-    dlopen_check_order_reloc_root_answer_impl.cpp
-
-libtest_check_order_reloc_root_2_cflags := -D__ANSWER=2
-
-module := libtest_check_order_reloc_root_2
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# libtest_check_order_reloc_root.so <- implements get_answer3()
-# -----------------------------------------------------------------------------
-libtest_check_order_reloc_root_src_files := \
-    dlopen_check_order_reloc_root_answer.cpp
-
-libtest_check_order_reloc_root_shared_libraries := \
-    libtest_check_order_reloc_root_1 \
-    libtest_check_order_reloc_root_2
-
-module := libtest_check_order_reloc_root
-include $(LOCAL_PATH)/Android.build.testlib.mk
diff --git a/tests/libs/Android.build.dlopen_check_order_reloc_siblings.mk b/tests/libs/Android.build.dlopen_check_order_reloc_siblings.mk
deleted file mode 100644
index bd35a51..0000000
--- a/tests/libs/Android.build.dlopen_check_order_reloc_siblings.mk
+++ /dev/null
@@ -1,158 +0,0 @@
-#
-# Copyright (C) 2014 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-# -----------------------------------------------------------------------------
-# Libraries used by dlfcn tests to verify correct relocation order:
-# libtest_check_order_reloc_siblings*.so
-# -----------------------------------------------------------------------------
-
-# -----------------------------------------------------------------------------
-# ..._1.so - empty
-# -----------------------------------------------------------------------------
-libtest_check_order_reloc_siblings_1_src_files := \
-    empty.cpp
-
-libtest_check_order_reloc_siblings_1_shared_libraries := \
-    libtest_check_order_reloc_siblings_a \
-    libtest_check_order_reloc_siblings_b
-
-module := libtest_check_order_reloc_siblings_1
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-
-# -----------------------------------------------------------------------------
-# ..._2.so - empty
-# -----------------------------------------------------------------------------
-libtest_check_order_reloc_siblings_2_src_files := \
-    dlopen_check_order_reloc_grandchild_answer.cpp
-
-libtest_check_order_reloc_siblings_2_shared_libraries := \
-    libtest_check_order_reloc_siblings_c \
-    libtest_check_order_reloc_siblings_d
-
-libtest_check_order_reloc_siblings_2_allow_undefined_symbols := true
-module := libtest_check_order_reloc_siblings_2
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# ..._3.so - get_answer2();
-# -----------------------------------------------------------------------------
-libtest_check_order_reloc_siblings_3_src_files := \
-    dlopen_check_order_reloc_nephew_answer.cpp
-
-libtest_check_order_reloc_siblings_3_shared_libraries := \
-    libtest_check_order_reloc_siblings_e \
-    libtest_check_order_reloc_siblings_f
-
-module := libtest_check_order_reloc_siblings_3
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# ..._a.so <- correct impl
-# -----------------------------------------------------------------------------
-libtest_check_order_reloc_siblings_a_src_files := \
-    dlopen_check_order_reloc_answer_impl.cpp
-
-libtest_check_order_reloc_siblings_a_cflags := -D__ANSWER=42
-module := libtest_check_order_reloc_siblings_a
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# ..._b.so
-# -----------------------------------------------------------------------------
-libtest_check_order_reloc_siblings_b_src_files := \
-    dlopen_check_order_reloc_answer_impl.cpp
-
-libtest_check_order_reloc_siblings_b_cflags := -D__ANSWER=1
-module := libtest_check_order_reloc_siblings_b
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# ..._c.so
-# -----------------------------------------------------------------------------
-libtest_check_order_reloc_siblings_c_src_files := \
-    dlopen_check_order_reloc_answer_impl.cpp
-
-libtest_check_order_reloc_siblings_c_cflags := -D__ANSWER=2
-libtest_check_order_reloc_siblings_c_shared_libraries := \
-    libtest_check_order_reloc_siblings_c_1 \
-    libtest_check_order_reloc_siblings_c_2
-
-module := libtest_check_order_reloc_siblings_c
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# ..._d.so
-# -----------------------------------------------------------------------------
-libtest_check_order_reloc_siblings_d_src_files := \
-    dlopen_check_order_reloc_answer_impl.cpp
-
-libtest_check_order_reloc_siblings_d_cflags := -D__ANSWER=3
-module := libtest_check_order_reloc_siblings_d
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# ..._e.so
-# -----------------------------------------------------------------------------
-libtest_check_order_reloc_siblings_e_src_files := \
-    dlopen_check_order_reloc_answer_impl.cpp
-
-libtest_check_order_reloc_siblings_e_cflags := -D__ANSWER=4
-module := libtest_check_order_reloc_siblings_e
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# ..._f.so <- get_answer()
-# -----------------------------------------------------------------------------
-libtest_check_order_reloc_siblings_f_src_files := \
-    dlopen_check_order_reloc_answer.cpp
-
-module := libtest_check_order_reloc_siblings_f
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# ..._c_1.so
-# -----------------------------------------------------------------------------
-libtest_check_order_reloc_siblings_c_1_src_files := \
-    dlopen_check_order_reloc_grandchild_answer_impl.cpp
-
-libtest_check_order_reloc_siblings_c_1_cflags := -D__ANSWER=42
-module := libtest_check_order_reloc_siblings_c_1
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# ..._c_2.so
-# -----------------------------------------------------------------------------
-libtest_check_order_reloc_siblings_c_2_src_files := \
-    dlopen_check_order_reloc_grandchild_answer_impl.cpp
-
-libtest_check_order_reloc_siblings_c_2_cflags := -D__ANSWER=0
-module := libtest_check_order_reloc_siblings_c_2
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# libtest_check_order_reloc_siblings.so
-# -----------------------------------------------------------------------------
-libtest_check_order_reloc_siblings_src_files := \
-    empty.cpp
-
-libtest_check_order_reloc_siblings_shared_libraries := \
-    libtest_check_order_reloc_siblings_1 \
-    libtest_check_order_reloc_siblings_2 \
-    libtest_check_order_reloc_siblings_3
-
-module := libtest_check_order_reloc_siblings
-include $(LOCAL_PATH)/Android.build.testlib.mk
diff --git a/tests/libs/Android.build.dt_runpath.mk b/tests/libs/Android.build.dt_runpath.mk
deleted file mode 100644
index b0d8e4b..0000000
--- a/tests/libs/Android.build.dt_runpath.mk
+++ /dev/null
@@ -1,128 +0,0 @@
-#
-# Copyright (C) 2012 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-# -----------------------------------------------------------------------------
-# Libraries used by dt_runpath tests.
-# -----------------------------------------------------------------------------
-
-#
-# Dependencies
-#
-# libtest_dt_runpath_d.so                       runpath: ${ORIGIN}/dt_runpath_b_c_x, ${ORIGIN}/dt_runpath_y/${LIB}
-# |-> dt_runpath_b_c_x/libtest_dt_runpath_b.so  runpath: ${ORIGIN}/../dt_runpath_a
-# |   |-> dt_runpath_a/libtest_dt_runpath_a.so
-# |-> dt_runpath_b_c_x/libtest_dt_runpath_c.so  runpath: ${ORIGIN}/invalid_dt_runpath
-# |   |-> libtest_dt_runpath_a.so (soname)
-# |-> dt_runpath_y/lib[64]/libtest_dt_runpath_y.so
-#
-# This one is used to test dlopen
-# dt_runpath_b_c_x/libtest_dt_runpath_x.so
-#
-
-# A leaf library in a non-standard directory.
-libtest_dt_runpath_a_src_files := \
-    empty.cpp
-
-libtest_dt_runpath_a_relative_path := dt_runpath_a
-module := libtest_dt_runpath_a
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# Depends on library A with a DT_RUNPATH
-libtest_dt_runpath_b_src_files := \
-    empty.cpp
-
-libtest_dt_runpath_b_shared_libraries := libtest_dt_runpath_a
-libtest_dt_runpath_b_ldflags := -Wl,--rpath,\$${ORIGIN}/../dt_runpath_a -Wl,--enable-new-dtags
-libtest_dt_runpath_b_relative_path := dt_runpath_b_c_x
-module := libtest_dt_runpath_b
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# Depends on library A with an incorrect DT_RUNPATH. This does not matter
-# because B is the first in the D (below) dependency order, and library A
-# is already loaded using the correct DT_RUNPATH from library B.
-libtest_dt_runpath_c_src_files := \
-    empty.cpp
-
-libtest_dt_runpath_c_shared_libraries := libtest_dt_runpath_a
-libtest_dt_runpath_c_ldflags := -Wl,--rpath,\$${ORIGIN}/invalid_dt_runpath -Wl,--enable-new-dtags
-libtest_dt_runpath_c_relative_path := dt_runpath_b_c_x
-module := libtest_dt_runpath_c
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# D depends on B, C, and Y with DT_RUNPATH.
-libtest_dt_runpath_d_src_files := \
-    dlopen_b.cpp
-
-libtest_dt_runpath_d_shared_libraries := \
-    libtest_dt_runpath_b \
-    libtest_dt_runpath_c \
-    libtest_dt_runpath_y
-libtest_dt_runpath_d_ldflags := \
-    -Wl,--rpath,\$${ORIGIN}/dt_runpath_b_c_x \
-    -Wl,--rpath,\$${ORIGIN}/dt_runpath_y/\$${LIB} \
-    -Wl,--enable-new-dtags
-libtest_dt_runpath_d_ldlibs := -ldl
-module := libtest_dt_runpath_d
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# D version for open-from-zip test with runpath
-module := libtest_dt_runpath_d_zip
-
-libtest_dt_runpath_d_zip_src_files := \
-    dlopen_b.cpp
-
-libtest_dt_runpath_d_zip_shared_libraries := \
-    libtest_dt_runpath_b \
-    libtest_dt_runpath_c \
-    libtest_dt_runpath_y
-libtest_dt_runpath_d_zip_ldflags := \
-    -Wl,--rpath,\$${ORIGIN}/dt_runpath_b_c_x \
-    -Wl,--rpath,\$${ORIGIN}/dt_runpath_y/\$${LIB} \
-    -Wl,--enable-new-dtags
-libtest_dt_runpath_d_zip_ldlibs := -ldl
-libtest_dt_runpath_d_zip_install_to_native_tests_dir := $(module)
-
-module_tag := optional
-build_type := target
-build_target := SHARED_LIBRARY
-include $(TEST_PATH)/Android.build.mk
-
-
-# A leaf library in a directory library D has DT_RUNPATH for.
-libtest_dt_runpath_x_src_files := \
-    empty.cpp
-
-libtest_dt_runpath_x_relative_path := dt_runpath_b_c_x
-module := libtest_dt_runpath_x
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# A leaf library in lib or lib64 directory
-libtest_dt_runpath_y_src_files := \
-    empty.cpp
-
-ifeq ($(TARGET_TRANSLATE_2ND_ARCH),true)
-libtest_dt_runpath_y_install_to_native_tests_dir_32 := bionic-loader-test-libs/dt_runpath_y/lib/$(TARGET_2ND_ARCH)
-else
-libtest_dt_runpath_y_install_to_native_tests_dir_32 := bionic-loader-test-libs/dt_runpath_y/lib
-endif
-ifeq ($(TARGET_IS_64_BIT),true)
-libtest_dt_runpath_y_install_to_native_tests_dir_64 := bionic-loader-test-libs/dt_runpath_y/lib64
-else
-libtest_dt_runpath_y_install_to_native_tests_dir_64 := bionic-loader-test-libs/dt_runpath_y/lib
-endif
-
-module := libtest_dt_runpath_y
-include $(LOCAL_PATH)/Android.build.testlib.mk
diff --git a/tests/libs/Android.build.linker_namespaces.mk b/tests/libs/Android.build.linker_namespaces.mk
deleted file mode 100644
index e2b01a7..0000000
--- a/tests/libs/Android.build.linker_namespaces.mk
+++ /dev/null
@@ -1,48 +0,0 @@
-#
-# Copyright (C) 2015 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-# -----------------------------------------------------------------------------
-# This set of libraries are used to verify linker namespaces.
-# -----------------------------------------------------------------------------
-
-# -----------------------------------------------------------------------------
-# This set of libraries is to test isolated namespaces
-#
-# Isolated namespaces do not allow loading of the library outside of
-# the search paths.
-#
-# This library cannot be loaded in isolated namespace because one of DT_NEEDED
-# libraries is outside of the search paths.
-#
-# libnstest_root_not_isolated.so (DT_RUNPATH = $ORIGIN/../private_namespace_libs_external/)
-# +-> libnstest_public.so
-# +-> libnstest_private_external.so (located in $ORIGIN/../private_namespace_libs_external/)
-#
-# Search path: $NATIVE_TESTS/private_namespace_libs/
-# -----------------------------------------------------------------------------
-libnstest_root_not_isolated_src_files := namespaces_root.cpp
-libnstest_root_not_isolated_shared_libraries := libnstest_public libnstest_private_external
-libnstest_root_not_isolated_relative_install_path := private_namespace_libs
-libnstest_root_not_isolated_ldflags := -Wl,--rpath,\$$ORIGIN/../private_namespace_libs_external \
-                                       -Wl,--enable-new-dtags
-
-module := libnstest_root_not_isolated
-include $(LOCAL_PATH)/Android.build.testlib.target.mk
-
-libnstest_private_external_src_files := namespaces_private.cpp
-libnstest_private_external_relative_install_path := private_namespace_libs_external
-module := libnstest_private_external
-include $(LOCAL_PATH)/Android.build.testlib.target.mk
diff --git a/tests/libs/Android.build.pthread_atfork.mk b/tests/libs/Android.build.pthread_atfork.mk
deleted file mode 100644
index 72ffec4..0000000
--- a/tests/libs/Android.build.pthread_atfork.mk
+++ /dev/null
@@ -1,25 +0,0 @@
-#
-# Copyright (C) 2014 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-# -----------------------------------------------------------------------------
-# This library used to test phtread_atfork handler behaviour
-# during/after dlclose.
-# -----------------------------------------------------------------------------
-libtest_pthread_atfork_src_files := pthread_atfork.cpp
-
-module := libtest_pthread_atfork
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
diff --git a/tests/libs/Android.build.testlib.host.mk b/tests/libs/Android.build.testlib.host.mk
deleted file mode 100644
index 38970dc..0000000
--- a/tests/libs/Android.build.testlib.host.mk
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# Copyright (C) 2016 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-build_target := SHARED_LIBRARY
-build_type := host
-include $(LOCAL_PATH)/Android.build.testlib.internal.mk
diff --git a/tests/libs/Android.build.testlib.internal.mk b/tests/libs/Android.build.testlib.internal.mk
deleted file mode 100644
index e1fec2b..0000000
--- a/tests/libs/Android.build.testlib.internal.mk
+++ /dev/null
@@ -1,27 +0,0 @@
-#
-# Copyright (C) 2016 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-# 1. Install test libraries to $ANDROID_DATA/nativetests../bionic-loader-test-libs/
-#    by default.
-ifeq ($($(module)_relative_install_path),)
-  $(module)_install_to_native_tests_dir := bionic-loader-test-libs
-else
-  $(module)_install_to_native_tests_dir := bionic-loader-test-libs/$($(module)_relative_install_path)
-endif
-# 2. Set dt_runpath to origin to resolve dependencies
-$(module)_ldflags += -Wl,--rpath,\$${ORIGIN} -Wl,--enable-new-dtags
-
-include $(TEST_PATH)/Android.build.mk
diff --git a/tests/libs/Android.build.testlib.mk b/tests/libs/Android.build.testlib.mk
deleted file mode 100644
index a46c457..0000000
--- a/tests/libs/Android.build.testlib.mk
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# Copyright (C) 2014 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-include $(LOCAL_PATH)/Android.build.testlib.host.mk
-
-include $(LOCAL_PATH)/Android.build.testlib.target.mk
diff --git a/tests/libs/Android.build.testlib.target.mk b/tests/libs/Android.build.testlib.target.mk
deleted file mode 100644
index 5ec0d71..0000000
--- a/tests/libs/Android.build.testlib.target.mk
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# Copyright (C) 2014 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-build_target := SHARED_LIBRARY
-build_type := target
-include $(LOCAL_PATH)/Android.build.testlib.internal.mk
diff --git a/tests/libs/Android.build.versioned_lib.mk b/tests/libs/Android.build.versioned_lib.mk
deleted file mode 100644
index f3a6374..0000000
--- a/tests/libs/Android.build.versioned_lib.mk
+++ /dev/null
@@ -1,120 +0,0 @@
-#
-# Copyright (C) 2015 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-# -----------------------------------------------------------------------------
-# Libraries used to test versioned symbols
-# -----------------------------------------------------------------------------
-libtest_versioned_uselibv1_src_files := versioned_uselib.cpp
-
-libtest_versioned_uselibv1_shared_libraries := \
-    libtest_versioned_libv1
-
-module := libtest_versioned_uselibv1
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-libtest_versioned_uselibv2_src_files := \
-    versioned_uselib.cpp
-
-libtest_versioned_uselibv2_shared_libraries := \
-    libtest_versioned_libv2
-
-libtest_versioned_uselibv2_ldflags := \
-    -Wl,--version-script,$(LOCAL_PATH)/versioned_uselib.map
-
-module := libtest_versioned_uselibv2
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-libtest_versioned_uselibv2_other_src_files := \
-    versioned_uselib.cpp
-
-libtest_versioned_uselibv2_other_shared_libraries := \
-    libtest_versioned_otherlib_empty libtest_versioned_libv2
-
-module := libtest_versioned_uselibv2_other
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-libtest_versioned_uselibv3_other_src_files := \
-    versioned_uselib.cpp
-
-libtest_versioned_uselibv3_other_shared_libraries := \
-    libtest_versioned_otherlib_empty libtest_versioned_lib
-
-module := libtest_versioned_uselibv3_other
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# lib v1 - this one used during static linking but never used at runtime
-# which forces libtest_versioned_uselibv1 to use function v1 from
-# libtest_versioned_lib.so
-# -----------------------------------------------------------------------------
-libtest_versioned_libv1_src_files := \
-    versioned_lib_v1.cpp
-
-libtest_versioned_libv1_ldflags := \
-    -Wl,--version-script,$(LOCAL_PATH)/versioned_lib_v1.map \
-    -Wl,-soname,libtest_versioned_lib.so
-
-module := libtest_versioned_libv1
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# lib v2 - to make libtest_versioned_uselibv2.so use version 2 of versioned_function()
-# -----------------------------------------------------------------------------
-libtest_versioned_libv2_src_files := \
-    versioned_lib_v2.cpp
-
-libtest_versioned_libv2_ldflags := \
-    -Wl,--version-script,$(LOCAL_PATH)/versioned_lib_v2.map \
-    -Wl,-soname,libtest_versioned_lib.so
-
-module := libtest_versioned_libv2
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-
-# -----------------------------------------------------------------------------
-# last version - this one is used at the runtime and exports 3 versions
-# of versioned_symbol().
-# -----------------------------------------------------------------------------
-libtest_versioned_lib_src_files := \
-    versioned_lib_v3.cpp
-
-libtest_versioned_lib_ldflags := \
-    -Wl,--version-script,$(LOCAL_PATH)/versioned_lib_v3.map
-
-module := libtest_versioned_lib
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# This library is empty, the actual implementation will provide an unversioned
-# symbol for versioned_function().
-# -----------------------------------------------------------------------------
-libtest_versioned_otherlib_empty_src_files := empty.cpp
-
-libtest_versioned_otherlib_empty_ldflags := -Wl,-soname,libtest_versioned_otherlib.so
-module := libtest_versioned_otherlib_empty
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-libtest_versioned_otherlib_src_files := versioned_lib_other.cpp
-
-libtest_versioned_otherlib_ldflags := \
-    -Wl,--version-script,$(LOCAL_PATH)/versioned_lib_other.map
-
-module := libtest_versioned_otherlib
-include $(LOCAL_PATH)/Android.build.testlib.mk
diff --git a/tests/libs/Android.mk b/tests/libs/Android.mk
index c40277d..08416ac 100644
--- a/tests/libs/Android.mk
+++ b/tests/libs/Android.mk
@@ -15,105 +15,6 @@
 #
 
 LOCAL_PATH := $(call my-dir)
-TEST_PATH := $(LOCAL_PATH)/..
-
-common_cppflags := -Wall -Werror
-common_additional_dependencies := \
-    $(LOCAL_PATH)/Android.mk \
-    $(LOCAL_PATH)/Android.build.dt_runpath.mk \
-    $(LOCAL_PATH)/Android.build.dlext_testzip.mk \
-    $(LOCAL_PATH)/Android.build.dlopen_2_parents_reloc.mk \
-    $(LOCAL_PATH)/Android.build.dlopen_check_order_dlsym.mk \
-    $(LOCAL_PATH)/Android.build.dlopen_check_order_reloc_siblings.mk \
-    $(LOCAL_PATH)/Android.build.dlopen_check_order_reloc_main_executable.mk \
-    $(LOCAL_PATH)/Android.build.linker_namespaces.mk \
-    $(LOCAL_PATH)/Android.build.pthread_atfork.mk \
-    $(LOCAL_PATH)/Android.build.testlib.mk \
-    $(LOCAL_PATH)/Android.build.testlib.target.mk \
-    $(LOCAL_PATH)/Android.build.versioned_lib.mk \
-    $(TEST_PATH)/Android.build.mk
-
-# -----------------------------------------------------------------------------
-# Library used by dlext tests - with GNU RELRO program header
-# -----------------------------------------------------------------------------
-libdlext_test_src_files := \
-    dlext_test_library.cpp \
-
-libdlext_test_ldflags := \
-    -Wl,-z,relro \
-
-libdlext_test_shared_libraries := libtest_simple
-
-module := libdlext_test
-module_tag := optional
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# Library used by dlext tests - recursive use of RELRO sharing
-# -----------------------------------------------------------------------------
-libdlext_test_recursive_src_files := \
-    dlext_test_recursive_library.cpp \
-
-libdlext_test_recursive_ldflags := \
-    -Wl,-z,relro \
-
-libdlext_test_recursive_shared_libraries := libdlext_test
-
-module := libdlext_test_recursive
-module_tag := optional
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# Library used by dlext tests - different name non-default location
-# -----------------------------------------------------------------------------
-module := libdlext_test_fd
-
-libdlext_test_fd_src_files := \
-    dlext_test_library.cpp \
-
-libdlext_test_fd_shared_libraries := libtest_simple
-
-libdlext_test_fd_relative_install_path := $(module)
-
-libdlext_test_fd_ldflags := -Wl,--rpath,\$${ORIGIN}/.. -Wl,--enable-new-dtags
-
-module_tag := optional
-include $(LOCAL_PATH)/Android.build.testlib.target.mk
-
-
-# -----------------------------------------------------------------------------
-# Libraries used by dlext tests for open from a zip-file
-# -----------------------------------------------------------------------------
-module := libdlext_test_zip
-
-libdlext_test_zip_src_files := \
-    dlext_test_library.cpp \
-
-libdlext_test_zip_shared_libraries := libatest_simple_zip
-
-libdlext_test_zip_relative_install_path := $(module)
-module_tag := optional
-include $(LOCAL_PATH)/Android.build.testlib.target.mk
-
-module := libatest_simple_zip
-
-libatest_simple_zip_src_files := \
-    dlopen_testlib_simple.cpp
-
-libatest_simple_zip_relative_install_path := $(module)
-module_tag := optional
-include $(LOCAL_PATH)/Android.build.testlib.target.mk
-
-# ----------------------------------------------------------------------------
-# Library with soname which does not match filename
-# ----------------------------------------------------------------------------
-libdlext_test_different_soname_src_files := \
-    dlext_test_library.cpp \
-
-module := libdlext_test_different_soname
-module_tag := optional
-libdlext_test_different_soname_ldflags := -Wl,-soname=libdlext_test_soname.so
-include $(LOCAL_PATH)/Android.build.testlib.mk
 
 # -----------------------------------------------------------------------------
 # Library used by dlext tests - zipped and aligned
@@ -125,54 +26,3 @@
   bionic_2nd_arch_prefix := $(TARGET_2ND_ARCH_VAR_PREFIX)
   include $(LOCAL_PATH)/Android.build.dlext_testzip.mk
 endif
-
-# -----------------------------------------------------------------------------
-# Build test helper libraries for linker namespaces
-# -----------------------------------------------------------------------------
-include $(LOCAL_PATH)/Android.build.linker_namespaces.mk
-
-# -----------------------------------------------------------------------------
-# Build DT_RUNPATH test helper libraries
-# -----------------------------------------------------------------------------
-include $(LOCAL_PATH)/Android.build.dt_runpath.mk
-
-# -----------------------------------------------------------------------------
-# Build library with two parents
-# -----------------------------------------------------------------------------
-include $(LOCAL_PATH)/Android.build.dlopen_2_parents_reloc.mk
-
-# -----------------------------------------------------------------------------
-# Build libtest_check_order_dlsym.so with its dependencies.
-# -----------------------------------------------------------------------------
-include $(LOCAL_PATH)/Android.build.dlopen_check_order_dlsym.mk
-
-# -----------------------------------------------------------------------------
-# Build libtest_check_order_siblings.so with its dependencies.
-# -----------------------------------------------------------------------------
-include $(LOCAL_PATH)/Android.build.dlopen_check_order_reloc_siblings.mk
-
-# -----------------------------------------------------------------------------
-# Build libtest_check_order_root.so with its dependencies.
-# -----------------------------------------------------------------------------
-include $(LOCAL_PATH)/Android.build.dlopen_check_order_reloc_main_executable.mk
-
-# -----------------------------------------------------------------------------
-# Build libtest_versioned_lib.so with its dependencies.
-# -----------------------------------------------------------------------------
-include $(LOCAL_PATH)/Android.build.versioned_lib.mk
-
-# -----------------------------------------------------------------------------
-# Build libraries needed by pthread_atfork tests
-# -----------------------------------------------------------------------------
-include $(LOCAL_PATH)/Android.build.pthread_atfork.mk
-
-# -----------------------------------------------------------------------------
-# Library with dependency used by dlfcn tests
-# -----------------------------------------------------------------------------
-libtest_with_dependency_src_files := \
-    dlopen_testlib_simple.cpp
-
-libtest_with_dependency_shared_libraries := libdlext_test
-
-module := libtest_with_dependency
-include $(LOCAL_PATH)/Android.build.testlib.mk