summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Mathieu Chartier <mathieuc@google.com> 2019-07-18 14:17:47 -0700
committer Mathieu Chartier <mathieuc@google.com> 2019-07-19 15:46:56 +0000
commit6b689ceb63b4fffaf0e617f7d363c841dd29e458 (patch)
tree0e8b554f3cc6390435c7caa05b378c47e9079be3
parentd84794d235df588814533d96f6e459b72f3a19b1 (diff)
Fix handling for invalid or missing app images
Avoid crashing when there is an invalid app image path passed to oatdump. Added regression test. Bug: 137724009 Test: test-art-host-gtest-oatdump_app_test Change-Id: I27470d0c1d844de5b9f3f3bf960e925cd8977d50
-rw-r--r--oatdump/oatdump.cc2
-rw-r--r--oatdump/oatdump_app_test.cc9
-rw-r--r--oatdump/oatdump_test.h25
3 files changed, 32 insertions, 4 deletions
diff --git a/oatdump/oatdump.cc b/oatdump/oatdump.cc
index 090e271421..ea647086b5 100644
--- a/oatdump/oatdump.cc
+++ b/oatdump/oatdump.cc
@@ -2782,12 +2782,14 @@ static int DumpImages(Runtime* runtime, OatDumperOptions* options, std::ostream*
if (space == nullptr) {
LOG(ERROR) << "Failed to open app image " << options->app_image_ << " with error "
<< error_msg;
+ return EXIT_FAILURE;
}
// Open dex files for the image.
std::vector<std::unique_ptr<const DexFile>> dex_files;
if (!runtime->GetClassLinker()->OpenImageDexFiles(space.get(), &dex_files, &error_msg)) {
LOG(ERROR) << "Failed to open app image dex files " << options->app_image_ << " with error "
<< error_msg;
+ return EXIT_FAILURE;
}
// Dump the actual image.
int result = DumpImage(space.get(), options, os);
diff --git a/oatdump/oatdump_app_test.cc b/oatdump/oatdump_app_test.cc
index 4490647d2c..b4997ba8db 100644
--- a/oatdump/oatdump_app_test.cc
+++ b/oatdump/oatdump_app_test.cc
@@ -42,4 +42,13 @@ TEST_F(OatDumpTest, TestAppImageWithBootImageStatic) {
ASSERT_TRUE(Exec(kStatic, kModeAppImage, {}, kListAndCode));
}
+TEST_F(OatDumpTest, TestAppImageInvalidPath) {
+ TEST_DISABLED_WITHOUT_BAKER_READ_BARRIERS(); // GC bug, b/126305867
+ TEST_DISABLED_FOR_NON_STATIC_HOST_BUILDS();
+ const std::string app_image_arg = "--app-image-file=" + GetAppImageName();
+ ASSERT_TRUE(GenerateAppOdexFile(kStatic, {"--runtime-arg", "-Xmx64M", app_image_arg}));
+ SetAppImageName("missing_app_image.art");
+ ASSERT_TRUE(Exec(kStatic, kModeAppImage, {}, kListAndCode, /*expect_failure=*/true));
+}
+
} // namespace art
diff --git a/oatdump/oatdump_test.h b/oatdump/oatdump_test.h
index 359b060f1f..7c5149dcda 100644
--- a/oatdump/oatdump_test.h
+++ b/oatdump/oatdump_test.h
@@ -107,8 +107,15 @@ class OatDumpTest : public CommonRuntimeTest {
return "ProfileTestMultiDex";
}
+ void SetAppImageName(const std::string& name) {
+ app_image_name_ = name;
+ }
+
std::string GetAppImageName() {
- return tmp_dir_ + "/" + GetAppBaseName() + ".art";
+ if (app_image_name_.empty()) {
+ app_image_name_ = tmp_dir_ + "/" + GetAppBaseName() + ".art";
+ }
+ return app_image_name_;
}
std::string GetAppOdexName() {
@@ -158,7 +165,8 @@ class OatDumpTest : public CommonRuntimeTest {
::testing::AssertionResult Exec(Flavor flavor,
Mode mode,
const std::vector<std::string>& args,
- Display display) {
+ Display display,
+ bool expect_failure = false) {
std::string file_path = GetExecutableFilePath(flavor, "oatdump");
if (!OS::FileExists(file_path.c_str())) {
@@ -322,8 +330,17 @@ class OatDumpTest : public CommonRuntimeTest {
if (res.stage != ForkAndExecResult::kFinished) {
return ::testing::AssertionFailure() << strerror(errno);
}
+ error_buf.push_back(0); // Make data a C string.
+
if (!res.StandardSuccess()) {
- return ::testing::AssertionFailure() << "Did not terminate successfully: " << res.status_code;
+ if (expect_failure && WIFEXITED(res.status_code)) {
+ // Avoid crash as valid exit.
+ return ::testing::AssertionSuccess();
+ }
+ return ::testing::AssertionFailure() << "Did not terminate successfully: " << res.status_code
+ << " " << error_buf.data();
+ } else if (expect_failure) {
+ return ::testing::AssertionFailure() << "Expected failure";
}
if (mode == kModeSymbolize) {
@@ -342,7 +359,6 @@ class OatDumpTest : public CommonRuntimeTest {
}
if (!result) {
oss << "Processed bytes " << total << ":" << std::endl;
- error_buf.push_back(0); // Make data a C string.
}
return result ? ::testing::AssertionSuccess()
@@ -350,6 +366,7 @@ class OatDumpTest : public CommonRuntimeTest {
}
std::string tmp_dir_;
+ std::string app_image_name_;
private:
std::string core_art_location_;