diff options
author | Dmitriy Ivanov <dimitry@google.com> | 2014-05-09 09:10:14 -0700 |
---|---|---|
committer | Dmitriy Ivanov <dimitry@google.com> | 2014-05-14 15:16:35 -0700 |
commit | d59e50063ad708509f3ad83350be33f5612c4f54 (patch) | |
tree | 4179117769c38d28aff06e56427f54e72e5eed6b /linker/tests | |
parent | 6897b7b8b95beae120fd53e6fd15921d6420bea7 (diff) | |
download | bionic-d59e50063ad708509f3ad83350be33f5612c4f54.zip bionic-d59e50063ad708509f3ad83350be33f5612c4f54.tar.gz bionic-d59e50063ad708509f3ad83350be33f5612c4f54.tar.bz2 |
Improve detection of already loaded libraries
Linker is now able to resolve symlinked libraries correctly.
soinfo is extended to save the graph of dependencies during
load/unload. Dependencies are used only in CallConstructor.
Bug: 9741592
Change-Id: Id9c48a74c46aa89bcdf3d54ec2f8ba3d398130b1
Diffstat (limited to 'linker/tests')
-rw-r--r-- | linker/tests/Android.mk | 1 | ||||
-rw-r--r-- | linker/tests/linked_list_test.cpp | 97 |
2 files changed, 98 insertions, 0 deletions
diff --git a/linker/tests/Android.mk b/linker/tests/Android.mk index 600fe69..831cfcb 100644 --- a/linker/tests/Android.mk +++ b/linker/tests/Android.mk @@ -30,6 +30,7 @@ LOCAL_CFLAGS += -g -Wall -Wextra -Werror -std=gnu++11 LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../libc/ LOCAL_SRC_FILES := \ + linked_list_test.cpp \ linker_allocator_test.cpp \ ../linker_allocator.cpp diff --git a/linker/tests/linked_list_test.cpp b/linker/tests/linked_list_test.cpp new file mode 100644 index 0000000..31ec7d5 --- /dev/null +++ b/linker/tests/linked_list_test.cpp @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2013 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> +#include <string> +#include <sstream> + +#include <gtest/gtest.h> + +#include "../linked_list.h" + +namespace { + +bool alloc_called = false; +bool free_called = false; + +class LinkedListTestAllocator { + public: + typedef LinkedListEntry<const char> entry_t; + + static entry_t* alloc() { + alloc_called = true; + return reinterpret_cast<entry_t*>(::malloc(sizeof(entry_t))); + } + + static void free(entry_t* p) { + free_called = true; + ::free(p); + } + private: + DISALLOW_IMPLICIT_CONSTRUCTORS(LinkedListTestAllocator); +}; + +typedef LinkedList<const char, LinkedListTestAllocator> test_list_t; + +std::string test_list_to_string(test_list_t& list) { + std::stringstream ss; + list.for_each([&] (const char* c) { + ss << c; + }); + + return ss.str(); +} + +}; + +TEST(linked_list, simple) { + alloc_called = free_called = false; + test_list_t list; + ASSERT_EQ("", test_list_to_string(list)); + ASSERT_TRUE(!alloc_called); + ASSERT_TRUE(!free_called); + list.push_front("a"); + ASSERT_TRUE(alloc_called); + ASSERT_TRUE(!free_called); + ASSERT_EQ("a", test_list_to_string(list)); + list.push_front("b"); + ASSERT_EQ("ba", test_list_to_string(list)); + list.push_front("c"); + list.push_front("d"); + ASSERT_EQ("dcba", test_list_to_string(list)); + ASSERT_TRUE(alloc_called); + ASSERT_TRUE(!free_called); + alloc_called = free_called = false; + list.remove_if([] (const char* c) { + return *c == 'c'; + }); + + ASSERT_TRUE(!alloc_called); + ASSERT_TRUE(!free_called); + + ASSERT_EQ("dba", test_list_to_string(list)); + alloc_called = free_called = false; + list.remove_if([] (const char* c) { + return *c == '2'; + }); + ASSERT_TRUE(!alloc_called); + ASSERT_TRUE(!free_called); + ASSERT_EQ("dba", test_list_to_string(list)); + list.clear(); + ASSERT_TRUE(!alloc_called); + ASSERT_TRUE(free_called); + ASSERT_EQ("", test_list_to_string(list)); +} |