OSDN Git Service

Fix bionic-unit-tests in some non-standard builds
authorVictor Khimenko <khim@google.com>
Tue, 24 Jan 2017 21:12:07 +0000 (22:12 +0100)
committerVictor Khimenko <khim@google.com>
Tue, 24 Jan 2017 21:20:03 +0000 (22:20 +0100)
The binary bionic-unit-tests is linked with some shared libraries
and these libraries are found in ${ORIGIN}/../bionic-loader-test-libs
directory specified by runpath.  This makes it higly unlikely that
anyone would be run these files when ${ORIGIN}/../bionic-loader-test-libs
does not include proper files.

Bug: http://b/34681268
Test: run bionic-unit-tests --gtest_filter=dl*:Dl*

Change-Id: I52fc31339fdfa232c0fdafa218eadaeaf5551a8d

tests/gtest_globals.cpp

index bb99dd6..75c08b1 100644 (file)
 #include <string>
 
 static std::string init_testlib_root() {
+  // Calculate ANDROID_DATA assuming the binary is in "$ANDROID_DATA/somedir/binary-dir/binary"
+  std::string path = get_executable_path();
+
+  path = get_dirname(path.c_str());
+  path += "/..";
+
   std::string out_path;
-  const char* data_dir = getenv("ANDROID_DATA");
-  if (data_dir == nullptr) {
-    // Calculate ANDROID_DATA assuming the binary is in "$ANDROID_DATA/somedir/binary-dir/binary"
-    std::string path = get_executable_path();
-
-    path = get_dirname(path.c_str());
-    path += "/../..";
-
-    if (!get_realpath(path.c_str(), &out_path)) {
-      printf("Failed to get realpath for \"%s\"", path.c_str());
-      abort();
-    }
-  } else {
-    out_path = data_dir;
+  if (!get_realpath(path.c_str(), &out_path)) {
+    printf("Failed to get realpath for \"%s\"", path.c_str());
+    abort();
   }
 
-  out_path = out_path + "/nativetest";
-#if defined(__LP64__)
-  out_path += "64";
-#endif
   out_path += "/bionic-loader-test-libs";
 
   std::string real_path;