diff options
| author | Treehugger Robot <treehugger-gerrit@google.com> | 2020-01-09 02:10:18 +0000 |
|---|---|---|
| committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2020-01-09 02:10:18 +0000 |
| commit | ce45ee11847fc6fc94fc08cdcb6a6e66c509aa19 (patch) | |
| tree | 719492359a464d01f1b7f6991e6cb80a5d0c36bc /tests | |
| parent | 3382f346fcfddc021235bb78be395cd18d7f3200 (diff) | |
| parent | e58efb84c5b21b55ca28d8aeeeff9c41424c1a34 (diff) | |
Merge "Fix linker path for emulated architecture" into android10-tests-dev
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/dl_test.cpp | 51 |
1 files changed, 42 insertions, 9 deletions
diff --git a/tests/dl_test.cpp b/tests/dl_test.cpp index 9e463948a..c1cd6949f 100644 --- a/tests/dl_test.cpp +++ b/tests/dl_test.cpp @@ -25,6 +25,7 @@ #include <limits.h> #include <stdio.h> #include <stdint.h> +#include <sys/stat.h> #include <string> #include <iostream> @@ -85,20 +86,50 @@ TEST(dl, lib_does_not_preempt_global_protected) { #else static constexpr const char* kPathToLinker = "/system/bin/linker"; #endif + +#if defined (__aarch64__) + static constexpr const char* kAlternatePathToLinker = "/system/bin/arm64/linker64"; +#elif defined (__arm__) + static constexpr const char* kAlternatePathToLinker = "/system/bin/arm/linker"; +#elif defined (__x86_64__) + static constexpr const char* kAlternatePathToLinker = "/system/bin/x86_64/linker64"; +#elif defined (__i386__) + static constexpr const char* kAlternatePathToLinker = "/system/bin/x86/linker"; +#elif defined (__mips__) +#if defined(__LP64__) + static constexpr const char* kAlternatePathToLinker = "/system/bin/mips64/linker64"; +#else + static constexpr const char* kAlternatePathToLinker = "/system/bin/mips/linker"; +#endif +#else +#error "Unknown architecture" #endif +const char* PathToLinker() { + // On the systems with emulated architecture linker would be of different + // architecture. Try to use alternate paths first. + struct stat buffer; + if (stat(kAlternatePathToLinker, &buffer) == 0) { + return kAlternatePathToLinker; + } + return kPathToLinker; +} +#endif // defined(__BIONIC__) + TEST(dl, exec_linker) { #if defined(__BIONIC__) - std::string usage_prefix = std::string("Usage: ") + kPathToLinker; + const char* path_to_linker = PathToLinker(); + std::string usage_prefix = std::string("Usage: ") + path_to_linker; ExecTestHelper eth; - eth.SetArgs({ kPathToLinker, nullptr }); - eth.Run([&]() { execve(kPathToLinker, eth.GetArgs(), eth.GetEnv()); }, 0, nullptr); + eth.SetArgs({ path_to_linker, nullptr }); + eth.Run([&]() { execve(path_to_linker, eth.GetArgs(), eth.GetEnv()); }, 0, nullptr); ASSERT_EQ(0u, eth.GetOutput().find(usage_prefix)) << "Test output:\n" << eth.GetOutput(); #endif } TEST(dl, exec_linker_load_file) { #if defined(__BIONIC__) + const char* path_to_linker = PathToLinker(); std::string helper = GetTestlibRoot() + "/exec_linker_helper/exec_linker_helper"; std::string expected_output = @@ -107,13 +138,14 @@ TEST(dl, exec_linker_load_file) { "__progname=" + helper + "\n" + "helper_func called\n"; ExecTestHelper eth; - eth.SetArgs({ kPathToLinker, helper.c_str(), nullptr }); - eth.Run([&]() { execve(kPathToLinker, eth.GetArgs(), eth.GetEnv()); }, 0, expected_output.c_str()); + eth.SetArgs({ path_to_linker, helper.c_str(), nullptr }); + eth.Run([&]() { execve(path_to_linker, eth.GetArgs(), eth.GetEnv()); }, 0, expected_output.c_str()); #endif } TEST(dl, exec_linker_load_from_zip) { #if defined(__BIONIC__) + const char* path_to_linker = PathToLinker(); std::string helper = GetTestlibRoot() + "/libdlext_test_zip/libdlext_test_zip_zipaligned.zip!/libdir/exec_linker_helper"; std::string expected_output = @@ -122,17 +154,18 @@ TEST(dl, exec_linker_load_from_zip) { "__progname=" + helper + "\n" + "helper_func called\n"; ExecTestHelper eth; - eth.SetArgs({ kPathToLinker, helper.c_str(), nullptr }); - eth.Run([&]() { execve(kPathToLinker, eth.GetArgs(), eth.GetEnv()); }, 0, expected_output.c_str()); + eth.SetArgs({ path_to_linker, helper.c_str(), nullptr }); + eth.Run([&]() { execve(path_to_linker, eth.GetArgs(), eth.GetEnv()); }, 0, expected_output.c_str()); #endif } TEST(dl, exec_linker_load_self) { #if defined(__BIONIC__) + const char* path_to_linker = PathToLinker(); std::string error_message = "error: linker cannot load itself\n"; ExecTestHelper eth; - eth.SetArgs({ kPathToLinker, kPathToLinker, nullptr }); - eth.Run([&]() { execve(kPathToLinker, eth.GetArgs(), eth.GetEnv()); }, EXIT_FAILURE, error_message.c_str()); + eth.SetArgs({ path_to_linker, path_to_linker, nullptr }); + eth.Run([&]() { execve(path_to_linker, eth.GetArgs(), eth.GetEnv()); }, EXIT_FAILURE, error_message.c_str()); #endif } |
