Move more test code to CommonArtTest

Complete migration of libdexfile and libartbase to CommonArtTest.
(libprofile and clients remain on CommonRuntimeTest because of required
refactorings.)

Bug: 78651010
Bug: 72216369
Test: make -j 40 test-art-host-gtest
      make -j 2 test-art-target-gtest

Change-Id: Id10d8fc9002e0ad9451730627dfd848f5761c90c
diff --git a/dexdump/Android.bp b/dexdump/Android.bp
index 2f0962c..ac9a9a2 100644
--- a/dexdump/Android.bp
+++ b/dexdump/Android.bp
@@ -23,10 +23,6 @@
         "dexdump.cc",
     ],
     cflags: ["-Wall", "-Werror"],
-    // TODO: fix b/72216369 and remove the need for this.
-    include_dirs: [
-        "art/runtime"  // dex utils.
-    ],
 }
 
 art_cc_binary {
diff --git a/libartbase/base/common_art_test.cc b/libartbase/base/common_art_test.cc
index 0d798f3..67413eb 100644
--- a/libartbase/base/common_art_test.cc
+++ b/libartbase/base/common_art_test.cc
@@ -355,17 +355,18 @@
   return filename;
 }
 
-std::vector<std::unique_ptr<const DexFile>> CommonArtTestImpl::OpenTestDexFiles(const char* name) {
-  std::string filename = GetTestDexFileName(name);
+std::vector<std::unique_ptr<const DexFile>> CommonArtTestImpl::OpenDexFiles(const char* filename) {
+  static constexpr bool kVerify = true;
   static constexpr bool kVerifyChecksum = true;
   std::string error_msg;
   const ArtDexFileLoader dex_file_loader;
   std::vector<std::unique_ptr<const DexFile>> dex_files;
-  bool success = dex_file_loader.Open(filename.c_str(),
-                                      filename.c_str(),
-                                      /* verify */ true,
+  bool success = dex_file_loader.Open(filename,
+                                      filename,
+                                      kVerify,
                                       kVerifyChecksum,
-                                      &error_msg, &dex_files);
+                                      &error_msg,
+                                      &dex_files);
   CHECK(success) << "Failed to open '" << filename << "': " << error_msg;
   for (auto& dex_file : dex_files) {
     CHECK_EQ(PROT_READ, dex_file->GetPermissions());
@@ -374,6 +375,11 @@
   return dex_files;
 }
 
+std::vector<std::unique_ptr<const DexFile>> CommonArtTestImpl::OpenTestDexFiles(
+    const char* name) {
+  return OpenDexFiles(GetTestDexFileName(name).c_str());
+}
+
 std::unique_ptr<const DexFile> CommonArtTestImpl::OpenTestDexFile(const char* name) {
   std::vector<std::unique_ptr<const DexFile>> vector = OpenTestDexFiles(name);
   EXPECT_EQ(1U, vector.size());
diff --git a/libartbase/base/common_art_test.h b/libartbase/base/common_art_test.h
index a4764c2..3998be5 100644
--- a/libartbase/base/common_art_test.h
+++ b/libartbase/base/common_art_test.h
@@ -148,6 +148,9 @@
 
   std::string GetTestAndroidRoot();
 
+  // Open a file (allows reading of framework jars).
+  std::vector<std::unique_ptr<const DexFile>> OpenDexFiles(const char* filename);
+  // Open a test file (art-gtest-*.jar).
   std::vector<std::unique_ptr<const DexFile>> OpenTestDexFiles(const char* name);
 
   std::unique_ptr<const DexFile> OpenTestDexFile(const char* name);
diff --git a/libartbase/base/file_utils_test.cc b/libartbase/base/file_utils_test.cc
index e74dfe5..56d1c44 100644
--- a/libartbase/base/file_utils_test.cc
+++ b/libartbase/base/file_utils_test.cc
@@ -20,11 +20,11 @@
 #include <stdlib.h>
 
 #include "base/stl_util.h"
-#include "common_runtime_test.h"
+#include "common_art_test.h"
 
 namespace art {
 
-class FileUtilsTest : public CommonRuntimeTest {};
+class FileUtilsTest : public CommonArtTest {};
 
 TEST_F(FileUtilsTest, GetDalvikCacheFilename) {
   std::string name;
@@ -63,7 +63,7 @@
 
   // We don't expect null returns for most cases, so don't check and let std::string crash.
 
-  // CommonRuntimeTest sets ANDROID_ROOT, so expect this to be the same.
+  // CommonArtTest sets ANDROID_ROOT, so expect this to be the same.
   std::string android_root = GetAndroidRootSafe(&error_msg);
   std::string android_root_env = getenv("ANDROID_ROOT");
   EXPECT_EQ(android_root, android_root_env);
@@ -78,7 +78,7 @@
 
   // Set a bogus value for ANDROID_ROOT. This should be an error.
   ASSERT_EQ(0, setenv("ANDROID_ROOT", "/this/is/obviously/bogus", 1 /* overwrite */));
-  EXPECT_TRUE(GetAndroidRootSafe(&error_msg) == nullptr);
+  EXPECT_EQ(GetAndroidRootSafe(&error_msg), "");
 
   // Unset ANDROID_ROOT and see that it still returns something (as libart code is running).
   ASSERT_EQ(0, unsetenv("ANDROID_ROOT"));
diff --git a/libdexfile/dex/art_dex_file_loader_test.cc b/libdexfile/dex/art_dex_file_loader_test.cc
index d353c26..5f3fc026 100644
--- a/libdexfile/dex/art_dex_file_loader_test.cc
+++ b/libdexfile/dex/art_dex_file_loader_test.cc
@@ -14,26 +14,25 @@
  * limitations under the License.
  */
 
+#include "art_dex_file_loader.h"
+
 #include <sys/mman.h>
 
 #include <fstream>
 #include <memory>
 
-#include "art_dex_file_loader.h"
+#include "base/common_art_test.h"
 #include "base/file_utils.h"
 #include "base/mem_map.h"
 #include "base/os.h"
 #include "base/stl_util.h"
 #include "base/unix_file/fd_file.h"
-#include "common_runtime_test.h"
 #include "dex/base64_test_util.h"
 #include "dex/code_item_accessors-inl.h"
 #include "dex/descriptors_names.h"
 #include "dex/dex_file.h"
 #include "dex/dex_file-inl.h"
 #include "dex/dex_file_loader.h"
-#include "scoped_thread_state_change-inl.h"
-#include "thread-current-inl.h"
 
 namespace art {
 
@@ -43,26 +42,35 @@
   dst_stream << src_stream.rdbuf();
 }
 
-class ArtDexFileLoaderTest : public CommonRuntimeTest {};
+class ArtDexFileLoaderTest : public CommonArtTest {
+  void SetUp() OVERRIDE {
+    CommonArtTest::SetUp();
+    // Open a jar file from the boot classpath for use in basic tests of dex accessors.
+    std::vector<std::string> lib_core_dex_file_names = GetLibCoreDexFileNames();
+    CHECK_NE(lib_core_dex_file_names.size(), 0U);
+    dex_files_ = OpenDexFiles(lib_core_dex_file_names[0].c_str());
+    CHECK_NE(dex_files_.size(), 0U);
+    // Save a dex file for use by tests.
+    java_lang_dex_file_ = dex_files_[0].get();
+  }
 
-// TODO: Port OpenTestDexFile(s) need to be ported to use non-ART utilities, and
-// the tests that depend upon them should be moved to dex_file_loader_test.cc
+ protected:
+  std::vector<std::unique_ptr<const DexFile>> dex_files_;
+  const DexFile* java_lang_dex_file_;
+};
 
 TEST_F(ArtDexFileLoaderTest, Open) {
-  ScopedObjectAccess soa(Thread::Current());
   std::unique_ptr<const DexFile> dex(OpenTestDexFile("Nested"));
   ASSERT_TRUE(dex.get() != nullptr);
 }
 
 TEST_F(ArtDexFileLoaderTest, GetLocationChecksum) {
-  ScopedObjectAccess soa(Thread::Current());
   std::unique_ptr<const DexFile> raw(OpenTestDexFile("Main"));
   EXPECT_NE(raw->GetHeader().checksum_, raw->GetLocationChecksum());
 }
 
 TEST_F(ArtDexFileLoaderTest, GetChecksum) {
   std::vector<uint32_t> checksums;
-  ScopedObjectAccess soa(Thread::Current());
   std::string error_msg;
   const ArtDexFileLoader dex_file_loader;
   EXPECT_TRUE(dex_file_loader.GetMultiDexChecksums(GetLibCoreDexFileNames()[0].c_str(),
@@ -94,7 +102,6 @@
 }
 
 TEST_F(ArtDexFileLoaderTest, ClassDefs) {
-  ScopedObjectAccess soa(Thread::Current());
   std::unique_ptr<const DexFile> raw(OpenTestDexFile("Nested"));
   ASSERT_TRUE(raw.get() != nullptr);
   EXPECT_EQ(3U, raw->NumClassDefs());
@@ -110,7 +117,6 @@
 }
 
 TEST_F(ArtDexFileLoaderTest, GetMethodSignature) {
-  ScopedObjectAccess soa(Thread::Current());
   std::unique_ptr<const DexFile> raw(OpenTestDexFile("GetMethodSignature"));
   ASSERT_TRUE(raw.get() != nullptr);
   EXPECT_EQ(1U, raw->NumClassDefs());
@@ -215,7 +221,6 @@
 }
 
 TEST_F(ArtDexFileLoaderTest, FindStringId) {
-  ScopedObjectAccess soa(Thread::Current());
   std::unique_ptr<const DexFile> raw(OpenTestDexFile("GetMethodSignature"));
   ASSERT_TRUE(raw.get() != nullptr);
   EXPECT_EQ(1U, raw->NumClassDefs());