diff options
author | Yabin Cui <yabinc@google.com> | 2016-12-14 17:45:49 -0800 |
---|---|---|
committer | Yabin Cui <yabinc@google.com> | 2017-02-13 15:50:56 -0800 |
commit | 57e9cea09936e7a761be7b60bbf229f6b4a1ed1d (patch) | |
tree | cab4f555e0b84e3e4a67ff4820211ce29fa01480 /base/test_utils.cpp | |
parent | 5b202c43760c5f9d833875dae70ac119a5416e97 (diff) |
libbase: fix the way to find temp dir.
Tests running in app context can't access /data/local/tmp,
so try current directory if /data/local/tmp is not accessible.
Bug: http://b/18790309
Test: run unit test in app context and shell context.
Change-Id: If66fe8f0ac3edb3a32a2a2a50a524364f818a58b
Diffstat (limited to 'base/test_utils.cpp')
-rw-r--r-- | base/test_utils.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/base/test_utils.cpp b/base/test_utils.cpp index 3b3d698ccb..636477d362 100644 --- a/base/test_utils.cpp +++ b/base/test_utils.cpp @@ -57,7 +57,13 @@ char* mkdtemp(char* template_name) { static std::string GetSystemTempDir() { #if defined(__ANDROID__) - return "/data/local/tmp"; + const char* tmpdir = "/data/local/tmp"; + if (access(tmpdir, R_OK | W_OK | X_OK) == 0) { + return tmpdir; + } + // Tests running in app context can't access /data/local/tmp, + // so try current directory if /data/local/tmp is not accessible. + return "."; #elif defined(_WIN32) char tmp_dir[MAX_PATH]; DWORD result = GetTempPathA(sizeof(tmp_dir), tmp_dir); |