Dimitry Ivanov | 927877c | 2016-09-21 11:17:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 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 |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 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. |
| 15 | */ |
| 16 | |
| 17 | #include "gtest_globals.h" |
| 18 | |
| 19 | #include <gtest/gtest.h> |
| 20 | #include "utils.h" |
| 21 | |
| 22 | #include <string> |
| 23 | |
Dimitry Ivanov | d0b5c3a | 2016-11-25 12:23:11 -0800 | [diff] [blame] | 24 | static std::string init_testlib_root() { |
Dimitry Ivanov | 927877c | 2016-09-21 11:17:13 -0700 | [diff] [blame] | 25 | std::string out_path; |
| 26 | const char* data_dir = getenv("ANDROID_DATA"); |
| 27 | if (data_dir == nullptr) { |
Dimitry Ivanov | d0b5c3a | 2016-11-25 12:23:11 -0800 | [diff] [blame] | 28 | // Calculate ANDROID_DATA assuming the binary is in "$ANDROID_DATA/somedir/binary-dir/binary" |
| 29 | std::string path = get_executable_path(); |
| 30 | |
| 31 | path = get_dirname(path.c_str()); |
| 32 | path += "/../.."; |
| 33 | |
| 34 | if (!get_realpath(path.c_str(), &out_path)) { |
| 35 | printf("Failed to get realpath for \"%s\"", path.c_str()); |
| 36 | abort(); |
| 37 | } |
Dimitry Ivanov | 927877c | 2016-09-21 11:17:13 -0700 | [diff] [blame] | 38 | } else { |
| 39 | out_path = data_dir; |
| 40 | } |
| 41 | |
| 42 | out_path = out_path + "/nativetest"; |
| 43 | #if defined(__LP64__) |
| 44 | out_path += "64"; |
| 45 | #endif |
| 46 | out_path += "/bionic-loader-test-libs"; |
Dimitry Ivanov | d0b5c3a | 2016-11-25 12:23:11 -0800 | [diff] [blame] | 47 | |
Dimitry Ivanov | 927877c | 2016-09-21 11:17:13 -0700 | [diff] [blame] | 48 | std::string real_path; |
| 49 | if (!get_realpath(out_path, &real_path)) { |
Dimitry Ivanov | d0b5c3a | 2016-11-25 12:23:11 -0800 | [diff] [blame] | 50 | printf("\"%s\": does not exists", out_path.c_str()); |
Dimitry Ivanov | 927877c | 2016-09-21 11:17:13 -0700 | [diff] [blame] | 51 | abort(); |
| 52 | } |
| 53 | |
| 54 | return real_path; |
| 55 | } |
| 56 | |
Dimitry Ivanov | d0b5c3a | 2016-11-25 12:23:11 -0800 | [diff] [blame] | 57 | const std::string& get_testlib_root() { |
| 58 | static const std::string testlib_root = init_testlib_root(); |
| 59 | return testlib_root; |
| 60 | } |
| 61 | |