2 * Copyright (C) 2012 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <gtest/gtest.h>
29 extern "C" int main_global_default_serial() {
33 extern "C" int main_global_protected_serial() {
37 // The following functions are defined in DT_NEEDED
38 // libdl_preempt_test.so library.
40 // This one calls main_global_default_serial
41 extern "C" int main_global_default_get_serial();
43 // This one calls main_global_protected_serial
44 extern "C" int main_global_protected_get_serial();
46 // This one calls lib_global_default_serial
47 extern "C" int lib_global_default_get_serial();
49 // This one calls lib_global_protected_serial
50 extern "C" int lib_global_protected_get_serial();
52 // This test verifies that the global default function
53 // main_global_default_serial() is preempted by
54 // the function defined above.
55 TEST(dl, main_preempts_global_default) {
56 ASSERT_EQ(3370318, main_global_default_get_serial());
59 // This one makes sure that the global protected
60 // symbols do not get preempted
61 TEST(dl, main_does_not_preempt_global_protected) {
62 ASSERT_EQ(3370318, main_global_protected_get_serial());
65 // check same things for lib
66 TEST(dl, lib_preempts_global_default) {
67 ASSERT_EQ(3370318, lib_global_default_get_serial());
70 TEST(dl, lib_does_not_preempt_global_protected) {
71 ASSERT_EQ(3370318, lib_global_protected_get_serial());
74 TEST(dl, exec_linker) {
75 #if defined(__BIONIC__)
77 static constexpr const char* kPathToLinker = "/system/bin/linker64";
79 static constexpr const char* kPathToLinker = "/system/bin/linker";
82 std::string expected_output = std::string("This is ") + kPathToLinker +
83 ", the helper program for dynamic executables.\n";
84 eth.SetArgs( { kPathToLinker, nullptr });
85 eth.Run([&]() { execve(kPathToLinker, eth.GetArgs(), eth.GetEnv()); }, 0, expected_output.c_str());
89 // TODO: Add tests for LD_PRELOADs