aboutsummaryrefslogtreecommitdiffstats
path: root/tests/libs
diff options
context:
space:
mode:
authorDmitriy Ivanov <dimitry@google.com>2014-06-02 16:29:00 -0700
committerDmitriy Ivanov <dimitry@google.com>2014-06-17 15:08:53 -0700
commit1f5e1a3cbc564c593fe1090894ecdb070f36e20c (patch)
treee45c14c9ff5dcc7b5fb82cc3b38823edec84573d /tests/libs
parentb656410a73c4dfa2a3f8deba0a673080320f8605 (diff)
downloadandroid_bionic-1f5e1a3cbc564c593fe1090894ecdb070f36e20c.tar.gz
android_bionic-1f5e1a3cbc564c593fe1090894ecdb070f36e20c.tar.bz2
android_bionic-1f5e1a3cbc564c593fe1090894ecdb070f36e20c.zip
Move libraries for unit-tests to separate folder
Change-Id: I1653f3f2fd63ba25525369bc725c8f7438ecf021
Diffstat (limited to 'tests/libs')
-rw-r--r--tests/libs/Android.mk105
-rw-r--r--tests/libs/atexit_testlib.cpp75
-rw-r--r--tests/libs/dlext_test_library.cpp43
-rw-r--r--tests/libs/dlopen_testlib_simple.cpp23
-rw-r--r--tests/libs/empty.cpp0
5 files changed, 246 insertions, 0 deletions
diff --git a/tests/libs/Android.mk b/tests/libs/Android.mk
new file mode 100644
index 000000000..e75582dbc
--- /dev/null
+++ b/tests/libs/Android.mk
@@ -0,0 +1,105 @@
+#
+# 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.
+#
+
+LOCAL_PATH := $(call my-dir)
+TEST_PATH := $(LOCAL_PATH)/..
+
+# -----------------------------------------------------------------------------
+# Library used by dlfcn tests.
+# -----------------------------------------------------------------------------
+ifneq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),mips mips64))
+no-elf-hash-table-library_src_files := \
+ empty.cpp \
+
+no-elf-hash-table-library_ldflags := \
+ -Wl,--hash-style=gnu \
+
+module := no-elf-hash-table-library
+module_tag := optional
+build_type := target
+build_target := SHARED_LIBRARY
+include $(TEST_PATH)/Android.build.mk
+endif
+
+# -----------------------------------------------------------------------------
+# Library used by dlext tests - with GNU RELRO program header
+# -----------------------------------------------------------------------------
+libdlext_test_src_files := \
+ dlext_test_library.cpp \
+
+libdlext_test_ldflags := \
+ -Wl,-z,relro \
+
+module := libdlext_test
+module_tag := optional
+build_type := target
+build_target := SHARED_LIBRARY
+include $(TEST_PATH)/Android.build.mk
+
+# -----------------------------------------------------------------------------
+# create symlink to libdlext_test.so for symlink test
+# -----------------------------------------------------------------------------
+# Use = instead of := to defer the evaluation of $@
+$(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD = \
+ $(hide) cd $(dir $@) && ln -sf $(notdir $@) libdlext_test_v2.so
+
+ifneq ($(TARGET_2ND_ARCH),)
+# link 64 bit .so
+$(TARGET_OUT)/lib64/libdlext_test.so: PRIVATE_POST_INSTALL_CMD = \
+ $(hide) cd $(dir $@) && ln -sf $(notdir $@) libdlext_test_v2.so
+endif
+
+# -----------------------------------------------------------------------------
+# Library used by dlext tests - without GNU RELRO program header
+# -----------------------------------------------------------------------------
+libdlext_test_norelro_src_files := \
+ dlext_test_library.cpp \
+
+libdlext_test_norelro_ldflags := \
+ -Wl,-z,norelro \
+
+module := libdlext_test_norelro
+module_tag := optional
+build_type := target
+build_target := SHARED_LIBRARY
+include $(TEST_PATH)/Android.build.mk
+
+# -----------------------------------------------------------------------------
+# Library used by dlfcn tests
+# -----------------------------------------------------------------------------
+libtest_simple_src_files := \
+ dlopen_testlib_simple.cpp
+
+module := libtest_simple
+build_type := target
+build_target := SHARED_LIBRARY
+include $(TEST_PATH)/Android.build.mk
+
+
+# -----------------------------------------------------------------------------
+# Library used by atexit tests
+# -----------------------------------------------------------------------------
+
+libtest_atexit_src_files := \
+ atexit_testlib.cpp
+
+module := libtest_atexit
+build_target := SHARED_LIBRARY
+build_type := target
+include $(TEST_PATH)/Android.build.mk
+build_type := host
+include $(TEST_PATH)/Android.build.mk
+
diff --git a/tests/libs/atexit_testlib.cpp b/tests/libs/atexit_testlib.cpp
new file mode 100644
index 000000000..d35f57b74
--- /dev/null
+++ b/tests/libs/atexit_testlib.cpp
@@ -0,0 +1,75 @@
+/*
+ * 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 <stdio.h>
+#include <stdlib.h>
+
+#include <string>
+
+// use external control number from main test
+static std::string* atexit_sequence = NULL;
+static bool* atexit_valid_this_in_static_dtor = NULL;
+
+static class AtExitStaticClass {
+ public:
+ AtExitStaticClass() { expected_this = this; }
+ ~AtExitStaticClass() {
+ if (atexit_valid_this_in_static_dtor) {
+ *atexit_valid_this_in_static_dtor = (expected_this == this);
+ }
+ }
+ private:
+ static const AtExitStaticClass* expected_this;
+
+} static_obj;
+
+const AtExitStaticClass* AtExitStaticClass::expected_this = NULL;
+
+// 4
+static void atexit_handler_from_atexit_from_atexit2() {
+ *atexit_sequence += " on";
+}
+
+// 3
+static void atexit_handler_from_atexit_from_atexit1() {
+ *atexit_sequence += " sat";
+}
+
+// 2
+static void atexit_handler_from_atexit() {
+ *atexit_sequence += " Dumpty";
+ // register 2 others
+ atexit(atexit_handler_from_atexit_from_atexit2);
+ atexit(atexit_handler_from_atexit_from_atexit1);
+}
+
+// 1
+static void atexit_handler_with_atexit() {
+ *atexit_sequence += "Humpty";
+ atexit(atexit_handler_from_atexit);
+}
+
+// last
+static void atexit_handler_regular() {
+ *atexit_sequence += " a wall";
+}
+
+extern "C" void register_atexit(std::string* sequence, bool* valid_this_in_static_dtor) {
+ atexit_sequence = sequence;
+ atexit_valid_this_in_static_dtor = valid_this_in_static_dtor;
+ atexit(atexit_handler_regular);
+ atexit(atexit_handler_with_atexit);
+}
+
diff --git a/tests/libs/dlext_test_library.cpp b/tests/libs/dlext_test_library.cpp
new file mode 100644
index 000000000..5c04329ed
--- /dev/null
+++ b/tests/libs/dlext_test_library.cpp
@@ -0,0 +1,43 @@
+/*
+ * 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.
+ */
+
+class A {
+public:
+ virtual int getRandomNumber() {
+ return 4; // chosen by fair dice roll.
+ // guaranteed to be random.
+ }
+
+ virtual ~A() {}
+};
+
+A a;
+
+// nested macros to make it easy to define a large amount of read-only data
+// which will require relocation.
+#define A_16 &a, &a, &a, &a, &a, &a, &a, &a, &a, &a, &a, &a, &a, &a, &a, &a,
+#define A_128 A_16 A_16 A_16 A_16 A_16 A_16 A_16 A_16
+#define A_1024 A_128 A_128 A_128 A_128 A_128 A_128 A_128 A_128
+
+extern "C" A* const lots_of_relro[] = {
+ A_1024 A_1024 A_1024 A_1024 A_1024 A_1024 A_1024 A_1024
+};
+
+extern "C" int getRandomNumber() {
+ // access the relro section (twice, in fact, once for the pointer, and once
+ // for the vtable of A) to check it's actually there.
+ return lots_of_relro[0]->getRandomNumber();
+}
diff --git a/tests/libs/dlopen_testlib_simple.cpp b/tests/libs/dlopen_testlib_simple.cpp
new file mode 100644
index 000000000..afe54b4c0
--- /dev/null
+++ b/tests/libs/dlopen_testlib_simple.cpp
@@ -0,0 +1,23 @@
+/*
+ * 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 <stdlib.h>
+
+uint32_t dlopen_testlib_taxicab_number = 1729;
+
+bool dlopen_testlib_simple_func() {
+ return true;
+}
diff --git a/tests/libs/empty.cpp b/tests/libs/empty.cpp
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/libs/empty.cpp