Device gtests: Use boot.art instead of core.art.
They are essentially the same. We can use boot.art to run gtests
since it is already part of the apex, including the jar files.
This will make it easier to run the tests in atest, since we
will not have to worry about copying core.art to the device.
The long-term goal is to avoid generating core.art altogether.
Couple of tests also require "alternate" image which has no
compiled code. The tests now generate it on-demand in code.
The host gtests still use core.art for now (as there is no
boot.art on host). The plan is to add it in future CLs.
Test: m test-art-host-gtest
Test: ./art/tools/run-gtests.sh
Bug: 147817606
Change-Id: I3a750bb8e60eea0b4a7df1491285feffd5a0161c
diff --git a/libartbase/base/common_art_test.cc b/libartbase/base/common_art_test.cc
index 7101ca4..978f69c 100644
--- a/libartbase/base/common_art_test.cc
+++ b/libartbase/base/common_art_test.cc
@@ -19,6 +19,7 @@
#include <dirent.h>
#include <dlfcn.h>
#include <fcntl.h>
+#include <ftw.h>
#include <stdlib.h>
#include <unistd.h>
#include <cstdio>
@@ -51,6 +52,29 @@
using android::base::StringPrintf;
+ScratchDir::ScratchDir() {
+ // ANDROID_DATA needs to be set
+ CHECK_NE(static_cast<char*>(nullptr), getenv("ANDROID_DATA")) <<
+ "Are you subclassing RuntimeTest?";
+ path_ = getenv("ANDROID_DATA");
+ path_ += "/tmp-XXXXXX";
+ bool ok = (mkdtemp(&path_[0]) != nullptr);
+ CHECK(ok) << strerror(errno) << " for " << path_;
+ path_ += "/";
+}
+
+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);
+}
+
ScratchFile::ScratchFile() {
// ANDROID_DATA needs to be set
CHECK_NE(static_cast<char*>(nullptr), getenv("ANDROID_DATA")) <<
@@ -364,13 +388,13 @@
}
static std::string GetDexFileName(const std::string& jar_prefix, bool host) {
- std::string path = GetAndroidRoot();
-
- std::string suffix = host
- ? "-hostdex" // The host version.
- : "-testdex"; // The unstripped target version.
-
- return StringPrintf("%s/framework/%s%s.jar", path.c_str(), jar_prefix.c_str(), suffix.c_str());
+ if (host) {
+ std::string path = GetAndroidRoot();
+ return StringPrintf("%s/framework/%s-hostdex.jar", path.c_str(), jar_prefix.c_str());
+ } else {
+ const char* apex = (jar_prefix == "conscrypt") ? "com.android.conscrypt" : "com.android.art";
+ return StringPrintf("/apex/%s/javalib/%s.jar", apex, jar_prefix.c_str());
+ }
}
std::vector<std::string> CommonArtTestImpl::GetLibCoreModuleNames() const {
@@ -504,7 +528,7 @@
std::string host_dir = GetAndroidRoot();
location = StringPrintf("%s/framework/core.%s", host_dir.c_str(), suffix);
} else {
- location = StringPrintf("/data/art-test/core.%s", suffix);
+ location = StringPrintf("/apex/com.android.art/javalib/boot.%s", suffix);
}
return location;