xref: /aosp_15_r20/bionic/tests/gtest_globals.cpp (revision 8d67ca893c1523eb926b9080dbe4e2ffd2a27ba1)
1*8d67ca89SAndroid Build Coastguard Worker /*
2*8d67ca89SAndroid Build Coastguard Worker  * Copyright (C) 2016 The Android Open Source Project
3*8d67ca89SAndroid Build Coastguard Worker  *
4*8d67ca89SAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*8d67ca89SAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*8d67ca89SAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*8d67ca89SAndroid Build Coastguard Worker  *
8*8d67ca89SAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*8d67ca89SAndroid Build Coastguard Worker  *
10*8d67ca89SAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*8d67ca89SAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*8d67ca89SAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*8d67ca89SAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*8d67ca89SAndroid Build Coastguard Worker  * limitations under the License.
15*8d67ca89SAndroid Build Coastguard Worker  */
16*8d67ca89SAndroid Build Coastguard Worker 
17*8d67ca89SAndroid Build Coastguard Worker #include "gtest_globals.h"
18*8d67ca89SAndroid Build Coastguard Worker 
19*8d67ca89SAndroid Build Coastguard Worker #include <gtest/gtest.h>
20*8d67ca89SAndroid Build Coastguard Worker #include "utils.h"
21*8d67ca89SAndroid Build Coastguard Worker 
22*8d67ca89SAndroid Build Coastguard Worker #include <android-base/file.h>
23*8d67ca89SAndroid Build Coastguard Worker 
24*8d67ca89SAndroid Build Coastguard Worker #include <string>
25*8d67ca89SAndroid Build Coastguard Worker 
GetTestLibRoot()26*8d67ca89SAndroid Build Coastguard Worker std::string GetTestLibRoot() {
27*8d67ca89SAndroid Build Coastguard Worker   // Typically the executable is /data/nativetest[64]/bionic-unit-tests/bionic-unit-tests, and the
28*8d67ca89SAndroid Build Coastguard Worker   // test libraries are in /data/nativetest[64]/bionic-unit-tests/bionic-loader-test-libs.
29*8d67ca89SAndroid Build Coastguard Worker   std::string path = android::base::GetExecutableDirectory();
30*8d67ca89SAndroid Build Coastguard Worker 
31*8d67ca89SAndroid Build Coastguard Worker   std::string out_path;
32*8d67ca89SAndroid Build Coastguard Worker   if (!android::base::Realpath(path.c_str(), &out_path)) {
33*8d67ca89SAndroid Build Coastguard Worker     printf("Failed to get realpath for \"%s\"\n", path.c_str());
34*8d67ca89SAndroid Build Coastguard Worker     abort();
35*8d67ca89SAndroid Build Coastguard Worker   }
36*8d67ca89SAndroid Build Coastguard Worker 
37*8d67ca89SAndroid Build Coastguard Worker   out_path += "/bionic-loader-test-libs";
38*8d67ca89SAndroid Build Coastguard Worker 
39*8d67ca89SAndroid Build Coastguard Worker   std::string real_path;
40*8d67ca89SAndroid Build Coastguard Worker   if (!android::base::Realpath(out_path, &real_path)) {
41*8d67ca89SAndroid Build Coastguard Worker     printf("\"%s\": does not exists\n", out_path.c_str());
42*8d67ca89SAndroid Build Coastguard Worker     abort();
43*8d67ca89SAndroid Build Coastguard Worker   }
44*8d67ca89SAndroid Build Coastguard Worker 
45*8d67ca89SAndroid Build Coastguard Worker   return real_path;
46*8d67ca89SAndroid Build Coastguard Worker }
47