diff options
| -rw-r--r-- | runtime/gc/space/image_space.cc | 13 | ||||
| -rw-r--r-- | runtime/gc/space/image_space_test.cc | 42 |
2 files changed, 48 insertions, 7 deletions
diff --git a/runtime/gc/space/image_space.cc b/runtime/gc/space/image_space.cc index eebb1035cb..2a4803ab14 100644 --- a/runtime/gc/space/image_space.cc +++ b/runtime/gc/space/image_space.cc @@ -1454,6 +1454,7 @@ class ImageSpace::BootImageLoader { has_system_(false), has_cache_(false), is_global_cache_(true), + dalvik_cache_exists_(false), dalvik_cache_(), cache_filename_() { } @@ -1462,33 +1463,30 @@ class ImageSpace::BootImageLoader { void FindImageFiles() { std::string system_filename; - bool dalvik_cache_exists = false; bool found_image = FindImageFilenameImpl(image_location_.c_str(), image_isa_, &has_system_, &system_filename, - &dalvik_cache_exists, + &dalvik_cache_exists_, &dalvik_cache_, &is_global_cache_, &has_cache_, &cache_filename_); - DCHECK_EQ(dalvik_cache_exists, !dalvik_cache_.empty()); + DCHECK(!dalvik_cache_exists_ || !dalvik_cache_.empty()); DCHECK_EQ(found_image, has_system_ || has_cache_); } bool HasSystem() const { return has_system_; } bool HasCache() const { return has_cache_; } - bool DalvikCacheExists() const { return !dalvik_cache_.empty(); } + bool DalvikCacheExists() const { return dalvik_cache_exists_; } bool IsGlobalCache() const { return is_global_cache_; } const std::string& GetDalvikCache() const { - DCHECK(DalvikCacheExists()); return dalvik_cache_; } const std::string& GetCacheFilename() const { - DCHECK(DalvikCacheExists()); return cache_filename_; } @@ -1617,6 +1615,7 @@ class ImageSpace::BootImageLoader { bool has_system_; bool has_cache_; bool is_global_cache_; + bool dalvik_cache_exists_; std::string dalvik_cache_; std::string cache_filename_; }; @@ -1769,7 +1768,7 @@ bool ImageSpace::LoadBootImage( // Step 3: We do not have an existing image in /system, // so generate an image into the dalvik cache. - if (!loader.HasSystem()) { + if (!loader.HasSystem() && loader.DalvikCacheExists()) { std::string local_error_msg; if (!dex2oat_enabled) { local_error_msg = "Image compilation disabled."; diff --git a/runtime/gc/space/image_space_test.cc b/runtime/gc/space/image_space_test.cc index f202a43be9..a1ffa067d0 100644 --- a/runtime/gc/space/image_space_test.cc +++ b/runtime/gc/space/image_space_test.cc @@ -150,6 +150,48 @@ TEST_F(ImageSpaceNoRelocateNoDex2oatNoPatchoatTest, Test) { EXPECT_FALSE(Runtime::Current()->GetHeap()->GetBootImageSpaces().empty()); } +class NoAccessAndroidDataTest : public ImageSpaceLoadingTest<false, true, false, true> { + protected: + void SetUpRuntimeOptions(RuntimeOptions* options) OVERRIDE { + const char* android_data = getenv("ANDROID_DATA"); + CHECK(android_data != nullptr); + old_android_data_ = android_data; + bad_android_data_ = old_android_data_ + "/no-android-data"; + int result = setenv("ANDROID_DATA", bad_android_data_.c_str(), /* replace */ 1); + CHECK_EQ(result, 0) << strerror(errno); + result = mkdir(bad_android_data_.c_str(), /* mode */ 0700); + CHECK_EQ(result, 0) << strerror(errno); + // Create a regular file "dalvik_cache". GetDalvikCache() shall get EEXIST + // when trying to create a directory with the same name and creating a + // subdirectory for a particular architecture shall fail. + bad_dalvik_cache_ = bad_android_data_ + "/dalvik-cache"; + int fd = creat(bad_dalvik_cache_.c_str(), /* mode */ 0); + CHECK_NE(fd, -1) << strerror(errno); + result = close(fd); + CHECK_EQ(result, 0) << strerror(errno); + ImageSpaceLoadingTest<false, true, false, true>::SetUpRuntimeOptions(options); + } + + void TearDown() OVERRIDE { + int result = unlink(bad_dalvik_cache_.c_str()); + CHECK_EQ(result, 0) << strerror(errno); + result = rmdir(bad_android_data_.c_str()); + CHECK_EQ(result, 0) << strerror(errno); + result = setenv("ANDROID_DATA", old_android_data_.c_str(), /* replace */ 1); + CHECK_EQ(result, 0) << strerror(errno); + ImageSpaceLoadingTest<false, true, false, true>::TearDown(); + } + + private: + std::string old_android_data_; + std::string bad_android_data_; + std::string bad_dalvik_cache_; +}; + +TEST_F(NoAccessAndroidDataTest, Test) { + EXPECT_TRUE(Runtime::Current()->GetHeap()->GetBootImageSpaces().empty()); +} + } // namespace space } // namespace gc } // namespace art |