Revert^4 "Generate a primary boot image for testing."

This reverts commit c9607e3cebb5fa942fec1d40b4a36a31ca5fb7c7.

Reason for revert: Fixed LUCI tests by not relying on any environment
variable.

Bug: 216467764
Test: Run art/tools/run-gtests.sh on Cuttlefish.
Change-Id: I20e2d27a5d7f9e0938bd09d58a2fb5b350c0c5ad
diff --git a/libartbase/base/common_art_test.cc b/libartbase/base/common_art_test.cc
index b0f1c6c..e35cb93 100644
--- a/libartbase/base/common_art_test.cc
+++ b/libartbase/base/common_art_test.cc
@@ -43,6 +43,7 @@
 #include "base/runtime_debug.h"
 #include "base/stl_util.h"
 #include "base/string_view_cpp20.h"
+#include "base/testing.h"
 #include "base/unix_file/fd_file.h"
 #include "dex/art_dex_file_loader.h"
 #include "dex/dex_file-inl.h"
@@ -427,44 +428,18 @@
   android_system_ext_.clear();
 }
 
-static std::string GetDexFileName(const std::string& jar_prefix, bool host) {
-  std::string prefix(host ? GetAndroidRoot() : "");
-  const char* apexPath = (jar_prefix == "conscrypt") ? kAndroidConscryptApexDefaultPath
-    : (jar_prefix == "core-icu4j" ? kAndroidI18nApexDefaultPath
-    : kAndroidArtApexDefaultPath);
-  return StringPrintf("%s%s/javalib/%s.jar", prefix.c_str(), apexPath, jar_prefix.c_str());
-}
-
 std::vector<std::string> CommonArtTestImpl::GetLibCoreModuleNames() const {
-  // Note: This must start with the CORE_IMG_JARS in Android.common_path.mk
-  // because that's what we use for compiling the boot.art image.
-  // It may contain additional modules from TEST_CORE_JARS.
-  return {
-      // CORE_IMG_JARS modules.
-      "core-oj",
-      "core-libart",
-      "okhttp",
-      "bouncycastle",
-      "apache-xml",
-      // Additional modules.
-      "core-icu4j",
-      "conscrypt",
-  };
+  return art::testing::GetLibCoreModuleNames();
 }
 
 std::vector<std::string> CommonArtTestImpl::GetLibCoreDexFileNames(
     const std::vector<std::string>& modules) const {
-  std::vector<std::string> result;
-  result.reserve(modules.size());
-  for (const std::string& module : modules) {
-    result.push_back(GetDexFileName(module, IsHost()));
-  }
-  return result;
+  return art::testing::GetLibCoreDexFileNames(modules);
 }
 
 std::vector<std::string> CommonArtTestImpl::GetLibCoreDexFileNames() const {
   std::vector<std::string> modules = GetLibCoreModuleNames();
-  return GetLibCoreDexFileNames(modules);
+  return art::testing::GetLibCoreDexFileNames(modules);
 }
 
 std::vector<std::string> CommonArtTestImpl::GetLibCoreDexLocations(
@@ -507,12 +482,7 @@
 std::string CommonArtTestImpl::GetTestDexFileName(const char* name) const {
   CHECK(name != nullptr);
   // The needed jar files for gtest are located next to the gtest binary itself.
-  std::string cmdline;
-  bool result = android::base::ReadFileToString("/proc/self/cmdline", &cmdline);
-  CHECK(result);
-  UniqueCPtr<char[]> executable_path(realpath(cmdline.c_str(), nullptr));
-  CHECK(executable_path != nullptr);
-  std::string executable_dir = dirname(executable_path.get());
+  std::string executable_dir = android::base::GetExecutableDirectory();
   for (auto ext : {".jar", ".dex"}) {
     std::string path = executable_dir + "/art-gtest-jars-" + name + ext;
     if (OS::FileExists(path.c_str())) {
@@ -564,7 +534,19 @@
     CHECK(host_dir != nullptr);
     return std::string(host_dir) + "/apex/art_boot_images/javalib";
   }
-  return GetPrebuiltPrimaryBootImageDir();
+  // On device, the boot image is generated by `generate-boot-image`.
+  // In a standalone test, the boot image is located next to the gtest binary itself.
+  std::string path = android::base::GetExecutableDirectory() + "/art_boot_images";
+  if (OS::DirectoryExists(path.c_str())) {
+    return path;
+  }
+  // In a chroot test, the boot image is located in a predefined location.
+  path = "/data/local/tmp/art_boot_images";
+  if (OS::DirectoryExists(path.c_str())) {
+    return path;
+  }
+  LOG(FATAL) << "Boot image not found";
+  UNREACHABLE();
 }
 
 std::string CommonArtTestImpl::GetCoreFileLocation(const char* suffix) {