blob: 538a5345669ef57d7c8e395de6e20f7589571ef8 [file] [log] [blame]
Dimitry Ivanov927877c2016-09-21 11:17:13 -07001/*
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
Dimitry Ivanov5b2cd3a2017-03-16 11:34:13 -070022#include <android-base/file.h>
23
Dimitry Ivanov927877c2016-09-21 11:17:13 -070024#include <string>
25
Dimitry Ivanovd0b5c3a2016-11-25 12:23:11 -080026static std::string init_testlib_root() {
Victor Khimenko65273fb2017-01-24 22:12:07 +010027 // Calculate ANDROID_DATA assuming the binary is in "$ANDROID_DATA/somedir/binary-dir/binary"
28 std::string path = get_executable_path();
29
Dimitry Ivanov5b2cd3a2017-03-16 11:34:13 -070030 path = android::base::Dirname(path);
Victor Khimenko65273fb2017-01-24 22:12:07 +010031 path += "/..";
32
Dimitry Ivanov927877c2016-09-21 11:17:13 -070033 std::string out_path;
Dimitry Ivanov5b2cd3a2017-03-16 11:34:13 -070034 if (!android::base::Realpath(path.c_str(), &out_path)) {
Victor Khimenko65273fb2017-01-24 22:12:07 +010035 printf("Failed to get realpath for \"%s\"", path.c_str());
36 abort();
Dimitry Ivanov927877c2016-09-21 11:17:13 -070037 }
38
Dimitry Ivanov927877c2016-09-21 11:17:13 -070039 out_path += "/bionic-loader-test-libs";
Dimitry Ivanovd0b5c3a2016-11-25 12:23:11 -080040
Dimitry Ivanov927877c2016-09-21 11:17:13 -070041 std::string real_path;
Dimitry Ivanov5b2cd3a2017-03-16 11:34:13 -070042 if (!android::base::Realpath(out_path, &real_path)) {
Dimitry Ivanovd0b5c3a2016-11-25 12:23:11 -080043 printf("\"%s\": does not exists", out_path.c_str());
Dimitry Ivanov927877c2016-09-21 11:17:13 -070044 abort();
45 }
46
47 return real_path;
48}
49
Dimitry Ivanovd0b5c3a2016-11-25 12:23:11 -080050const std::string& get_testlib_root() {
51 static const std::string testlib_root = init_testlib_root();
52 return testlib_root;
53}
54