aboutsummaryrefslogtreecommitdiffstats
path: root/tests/gtest_main.cpp
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2015-02-04 20:53:56 -0800
committerYabin Cui <yabinc@google.com>2015-02-05 10:39:37 -0800
commitead08148bdfe880f40c457d923e6456044196fc7 (patch)
treed73b76c768a74ae50657fae0e8ff4d007eeea7a3 /tests/gtest_main.cpp
parent63826658f4bcfff4f3a87fe651f22cc9b35fe8b9 (diff)
downloadandroid_bionic-ead08148bdfe880f40c457d923e6456044196fc7.tar.gz
android_bionic-ead08148bdfe880f40c457d923e6456044196fc7.tar.bz2
android_bionic-ead08148bdfe880f40c457d923e6456044196fc7.zip
Add path separator in bionic-unit-tests program path.
Bug: 19220800 Change-Id: I4245b1270363544cd5f083fe7ea7d9b11b46cdc0
Diffstat (limited to 'tests/gtest_main.cpp')
-rw-r--r--tests/gtest_main.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/gtest_main.cpp b/tests/gtest_main.cpp
index dd3ff9ed6..86d64660d 100644
--- a/tests/gtest_main.cpp
+++ b/tests/gtest_main.cpp
@@ -16,9 +16,11 @@
#include <gtest/gtest.h>
+#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
+#include <limits.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
@@ -821,6 +823,24 @@ static size_t GetProcessorCount() {
return static_cast<size_t>(sysconf(_SC_NPROCESSORS_ONLN));
}
+static void AddPathSeparatorInTestProgramPath(std::vector<char*>& args) {
+ // To run DeathTest in threadsafe mode, gtest requires that the user must invoke the
+ // test program via a valid path that contains at least one path separator.
+ // The reason is that gtest uses clone() + execve() to run DeathTest in threadsafe mode,
+ // and execve() doesn't read environment variable PATH, so execve() will not success
+ // until we specify the absolute path or relative path of the test program directly.
+ if (strchr(args[0], '/') == NULL) {
+ char path[PATH_MAX];
+ ssize_t path_len = readlink("/proc/self/exe", path, sizeof(path));
+ if (path_len <= 0 || path_len >= static_cast<ssize_t>(sizeof(path))) {
+ perror("readlink");
+ exit(1);
+ }
+ path[path_len] = '\0';
+ args[0] = strdup(path);
+ }
+}
+
static void AddGtestFilterSynonym(std::vector<char*>& args) {
// Support --gtest-filter as a synonym for --gtest_filter.
for (size_t i = 1; i < args.size(); ++i) {
@@ -858,6 +878,7 @@ static bool PickOptions(std::vector<char*>& args, IsolationTestOptions& options)
}
}
+ AddPathSeparatorInTestProgramPath(args);
AddGtestFilterSynonym(args);
// if --bionic-selftest argument is used, only enable self tests, otherwise remove self tests.