Add some extra dexanalyze tests
Based on dexdump tests, test for:
- Missing arguments
- Invalid input
- Using core dex as input
Test: test-art-host-gtest-dexanalyze_test
Bug: 77721545
Change-Id: I8ce0607b6d3d60171de00a83047536195a81e26f
diff --git a/build/Android.gtest.mk b/build/Android.gtest.mk
index 3daaf01..b481352 100644
--- a/build/Android.gtest.mk
+++ b/build/Android.gtest.mk
@@ -277,6 +277,16 @@
$(TARGET_CORE_IMAGE_DEFAULT_32) \
dexdump2-target
+# The dexanalyze test requires an image and the dexanalyze utility.
+ART_GTEST_dexanalyze_test_HOST_DEPS := \
+ $(HOST_CORE_IMAGE_DEFAULT_64) \
+ $(HOST_CORE_IMAGE_DEFAULT_32) \
+ dexanalyze-host
+ART_GTEST_dexanalyze_test_TARGET_DEPS := \
+ $(TARGET_CORE_IMAGE_DEFAULT_64) \
+ $(TARGET_CORE_IMAGE_DEFAULT_32) \
+ dexanalyze-target
+
# The dexlayout test requires an image and the dexlayout utility.
# TODO: rename into dexdump when migration completes
ART_GTEST_dexlayout_test_HOST_DEPS := \
diff --git a/tools/dexanalyze/dexanalyze.cc b/tools/dexanalyze/dexanalyze.cc
index c4aebc6..a21b9dc 100644
--- a/tools/dexanalyze/dexanalyze.cc
+++ b/tools/dexanalyze/dexanalyze.cc
@@ -130,7 +130,7 @@
// TODO: once added, use an api to android::base to read a std::vector<uint8_t>.
if (!android::base::ReadFileToString(filename.c_str(), &content)) {
LOG(ERROR) << "ReadFileToString failed for " + filename << std::endl;
- continue;
+ return 2;
}
std::vector<std::unique_ptr<const DexFile>> dex_files;
const DexFileLoader dex_file_loader;
@@ -142,14 +142,14 @@
&error_msg,
&dex_files)) {
LOG(ERROR) << "OpenAll failed for " + filename << " with " << error_msg << std::endl;
- continue;
+ return 3;
}
for (std::unique_ptr<const DexFile>& dex_file : dex_files) {
if (options.dump_per_input_dex_) {
Analysis current(&options);
if (!current.ProcessDexFile(*dex_file)) {
LOG(ERROR) << "Failed to process " << filename << " with error " << error_msg;
- continue;
+ return 4;
}
LOG(INFO) << "Analysis for " << dex_file->GetLocation() << std::endl;
current.Dump(LOG_STREAM(INFO));
diff --git a/tools/dexanalyze/dexanalyze_test.cc b/tools/dexanalyze/dexanalyze_test.cc
index c9b8f53..96be3f9 100644
--- a/tools/dexanalyze/dexanalyze_test.cc
+++ b/tools/dexanalyze/dexanalyze_test.cc
@@ -36,10 +36,22 @@
}
};
+TEST_F(DexAnalyzeTest, NoInputFileGiven) {
+ DexAnalyzeExec({ "-a" }, /*expect_success*/ false);
+}
+
+TEST_F(DexAnalyzeTest, CantOpenInput) {
+ DexAnalyzeExec({ "-a", "/non/existent/path" }, /*expect_success*/ false);
+}
+
TEST_F(DexAnalyzeTest, TestAnalyzeMultidex) {
DexAnalyzeExec({ "-a", GetTestDexFileName("MultiDex") }, /*expect_success*/ true);
}
+TEST_F(DexAnalyzeTest, TestAnalizeCoreDex) {
+ DexAnalyzeExec({ "-a", GetLibCoreDexFileNames()[0] }, /*expect_success*/ true);
+}
+
TEST_F(DexAnalyzeTest, TestInvalidArg) {
DexAnalyzeExec({ "-invalid-option" }, /*expect_success*/ false);
}