ART: Use TMPDIR for test directories

Bug: 16499668

(cherry picked from commit 5a79fdecffbea657ebecd4cf19078925239eb1c3)

Change-Id: I6981f707862bf4a9cc79800db85b0416f30115af
diff --git a/runtime/common_runtime_test.cc b/runtime/common_runtime_test.cc
index 9962611..b9b7efe 100644
--- a/runtime/common_runtime_test.cc
+++ b/runtime/common_runtime_test.cc
@@ -139,7 +139,17 @@
 
 void CommonRuntimeTest::SetUpAndroidData(std::string& android_data) {
   // On target, Cannot use /mnt/sdcard because it is mounted noexec, so use subdir of dalvik-cache
-  android_data = (IsHost() ? "/tmp/art-data-XXXXXX" : "/data/dalvik-cache/art-data-XXXXXX");
+  if (IsHost()) {
+    const char* tmpdir = getenv("TMPDIR");
+    if (tmpdir != nullptr && tmpdir[0] != 0) {
+      android_data = tmpdir;
+    } else {
+      android_data = "/tmp";
+    }
+  } else {
+    android_data = "/data/dalvik-cache";
+  }
+  android_data += "/art-data-XXXXXX";
   if (mkdtemp(&android_data[0]) == nullptr) {
     PLOG(FATAL) << "mkdtemp(\"" << &android_data[0] << "\") failed";
   }