Revert "Revert "Ensure dex file are extracted and verified at load time""
The issue was caused by running device-gtests as root (which will always
have full write access everywhere).
For now, disable the tests that rely on file permissions when running as
root.
Test: m test-art-target-gtest-oat_file_assistant_test
Bug: 36605597
Bug: 36824842
This reverts commit 9bfc6bb1f44797aec19a151e47c0902ef2516095.
Change-Id: I60e8c3d602ca40b1f1e12e8808055effcbb8dcc6
diff --git a/runtime/dexopt_test.cc b/runtime/dexopt_test.cc
index 24b1abb..3c8243a 100644
--- a/runtime/dexopt_test.cc
+++ b/runtime/dexopt_test.cc
@@ -45,18 +45,23 @@
}
void DexoptTest::GenerateOatForTest(const std::string& dex_location,
- const std::string& oat_location,
- CompilerFilter::Filter filter,
- bool relocate,
- bool pic,
- bool with_alternate_image) {
+ const std::string& oat_location_in,
+ CompilerFilter::Filter filter,
+ bool relocate,
+ bool pic,
+ bool with_alternate_image) {
std::string dalvik_cache = GetDalvikCache(GetInstructionSetString(kRuntimeISA));
std::string dalvik_cache_tmp = dalvik_cache + ".redirected";
-
+ std::string oat_location = oat_location_in;
if (!relocate) {
// Temporarily redirect the dalvik cache so dex2oat doesn't find the
// relocated image file.
ASSERT_EQ(0, rename(dalvik_cache.c_str(), dalvik_cache_tmp.c_str())) << strerror(errno);
+ // If the oat location is in dalvik cache, replace the cache path with the temporary one.
+ size_t pos = oat_location.find(dalvik_cache);
+ if (pos != std::string::npos) {
+ oat_location = oat_location.replace(pos, dalvik_cache.length(), dalvik_cache_tmp);
+ }
}
std::vector<std::string> args;
@@ -90,6 +95,7 @@
if (!relocate) {
// Restore the dalvik cache if needed.
ASSERT_EQ(0, rename(dalvik_cache_tmp.c_str(), dalvik_cache.c_str())) << strerror(errno);
+ oat_location = oat_location_in;
}
// Verify the odex file was generated as expected.