Rewrite assembler_test_base.h

Simplify the code in preparation of move to LLVM prebuilt tools.

Bug: 147817558
Test: m test-art-host-gtest
Change-Id: Iba277235255fd7d7f0965749b0b2d4a9567ced1f
diff --git a/libartbase/base/common_art_test.cc b/libartbase/base/common_art_test.cc
index e0e44a8..043d35e 100644
--- a/libartbase/base/common_art_test.cc
+++ b/libartbase/base/common_art_test.cc
@@ -53,7 +53,7 @@
 
 using android::base::StringPrintf;
 
-ScratchDir::ScratchDir() {
+ScratchDir::ScratchDir(bool keep_files) : keep_files_(keep_files) {
   // ANDROID_DATA needs to be set
   CHECK_NE(static_cast<char*>(nullptr), getenv("ANDROID_DATA")) <<
       "Are you subclassing RuntimeTest?";
@@ -65,15 +65,17 @@
 }
 
 ScratchDir::~ScratchDir() {
-  // Recursively delete the directory and all its content.
-  nftw(path_.c_str(), [](const char* name, const struct stat*, int type, struct FTW *) {
-    if (type == FTW_F) {
-      unlink(name);
-    } else if (type == FTW_DP) {
-      rmdir(name);
-    }
-    return 0;
-  }, 256 /* max open file descriptors */, FTW_DEPTH);
+  if (!keep_files_) {
+    // Recursively delete the directory and all its content.
+    nftw(path_.c_str(), [](const char* name, const struct stat*, int type, struct FTW *) {
+      if (type == FTW_F) {
+        unlink(name);
+      } else if (type == FTW_DP) {
+        rmdir(name);
+      }
+      return 0;
+    }, 256 /* max open file descriptors */, FTW_DEPTH);
+  }
 }
 
 ScratchFile::ScratchFile() {