diff options
author | Dan Albert <danalbert@google.com> | 2017-05-18 00:19:55 -0700 |
---|---|---|
committer | Dan Albert <danalbert@google.com> | 2017-05-22 14:45:31 -0700 |
commit | d8e996421ff6559ce5b50f34b9437afa28bc821e (patch) | |
tree | 84ac7b116962500a365901d7dd1b00fdd088b152 /sources | |
parent | 06df0612d58fdb95d52a94326388cf5788aa7d74 (diff) | |
download | ndk-d8e996421ff6559ce5b50f34b9437afa28bc821e.tar.gz |
Remove race in gtest unit tests.
We run multiple configurations of these tests simultaneously.
FilePath::GenerateUniqueFilename has a TOCTTOU race (by design). It
takes a base path to create the directory in though, so just use the
cwd for the test data directory instead of a fixed path for all test
runs.
Test: Ran the test in the new test runner
Bug: http://b/37631288
Change-Id: I81c58885bd84a14dd5d94eb3a64299861470fea7
Diffstat (limited to 'sources')
-rw-r--r-- | sources/third_party/googletest/googletest/test/gtest-filepath_test.cc | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/sources/third_party/googletest/googletest/test/gtest-filepath_test.cc b/sources/third_party/googletest/googletest/test/gtest-filepath_test.cc index ae9f55a0c..a39faf740 100644 --- a/sources/third_party/googletest/googletest/test/gtest-filepath_test.cc +++ b/sources/third_party/googletest/googletest/test/gtest-filepath_test.cc @@ -526,7 +526,15 @@ class DirectoryCreationTest : public Test { else return std::string(temp_dir) + "\\"; #elif GTEST_OS_LINUX_ANDROID - return "/sdcard/"; + // We can't use a fixed path because we run multiple configurations of this + // test on the device simultaneously. This executable has its own directory + // though, so we can use this as the temp path. + char cwd[PATH_MAX]; + if (getcwd(cwd, sizeof(cwd)) == NULL) { + perror("getcwd"); + abort(); + } + return cwd; #else return "/tmp/"; #endif // GTEST_OS_WINDOWS_MOBILE |