diff options
author | 2023-07-31 11:01:45 +0100 | |
---|---|---|
committer | 2023-08-02 15:18:55 +0000 | |
commit | 0187b188b3f992362dfba829dcba11205e774608 (patch) | |
tree | a27df4cc2adfed7a4cc65e62ba8d893a69a400da /oatdump/oatdump_app_test.cc | |
parent | 0e09c653ca085043e910e799358bd96ae16a0879 (diff) |
Overhaul oatdump options.
Changes:
- `--app-image` (which dumps the app image) no longer requires
`--image`. oatdump infers the boot image location when possible.
- `--app-image` now only dumps the app image, and doesn't fall through
to dumping the boot image anymore.
- `--app-oat` is now deprecated and becomes an alias of `--oat-file`.
- When `--oat-file` (which dumps the oat file) is combined with
`--app-image`, it now correctly takes `--dex-file` as an additional
flag to specify the dex filename. Before this change, oatdump ignored
`--dex-file` when `--app-image` was specified, and it only dumped the
oat header.
- Using `--oat-file` alone now brings up a runtime whenever possible.
This allows dumping more information including BSS mappings for BCP
dex files. Before this change, oat files were dumped with runtime
only if `--boot-image` was specified.
- When the dex code is missing, oatdump now always dumps the oat file
without runtime. Before this change, it tried to dump with runtime and
failed.
- `--boot-image` now accepts a non-existing path, to start the runtime
in imageless mode. This allows dumping with runtime for an oat file
that is generated without a boot image.
- oatdump now checks the BCP checksums before dumping with runtime.
Before this change, it crashed when there was a BCP mismatch.
- When `--image` (which dumps the boot image) is unexpectedly combined
with `--boot-image`, oatdump now ignores `--boot-image`. Before this
change, the behavior was controlled by `--image` but the location was
taken from `--boot-image`.
- The order of precedence of the options is clarified in the code, but
is unchanged for backward compatibility.
Bug: 293335130
Test: Manually tested the examples in the help text added by this CL.
Test: m test-art-host-gtest-art_oatdump_tests
Test: atest art_standalone_oatdump_tests
Change-Id: I3e1dcf403f6fb459bcd91b47e5f4513237813215
Diffstat (limited to 'oatdump/oatdump_app_test.cc')
-rw-r--r-- | oatdump/oatdump_app_test.cc | 142 |
1 files changed, 137 insertions, 5 deletions
diff --git a/oatdump/oatdump_app_test.cc b/oatdump/oatdump_app_test.cc index 14af024db1..03b43cef11 100644 --- a/oatdump/oatdump_app_test.cc +++ b/oatdump/oatdump_app_test.cc @@ -18,11 +18,78 @@ namespace art { -TEST_P(OatDumpTest, TestDumpOatWithBootImage) { +// Oat file compiled with a boot image. oatdump invoked with a boot image. +TEST_P(OatDumpTest, TestDumpOatWithRuntimeWithBootImage) { TEST_DISABLED_FOR_RISCV64(); ASSERT_TRUE(GenerateAppOdexFile(GetParam())); + ASSERT_TRUE(Exec(GetParam(), + kArgOatApp | kArgBootImage | kArgBcp | kArgIsa, + {}, + kExpectOat | kExpectCode | kExpectBssMappingsForBcp)); +} + +// Oat file compiled without a boot image. oatdump invoked without a boot image. +TEST_P(OatDumpTest, TestDumpOatWithRuntimeWithNoBootImage) { + TEST_DISABLED_FOR_RISCV64(); + TEST_DISABLED_FOR_DEBUG_BUILD(); // DCHECK failed. + ASSERT_TRUE(GenerateAppOdexFile(GetParam(), {"--boot-image=/nonx/boot.art"})); + ASSERT_TRUE(Exec(GetParam(), + kArgOatApp | kArgBcp | kArgIsa, + {"--boot-image=/nonx/boot.art"}, + kExpectOat | kExpectCode | kExpectBssMappingsForBcp)); +} + +// Dex code cannot be found in the vdex file, and no --dex-file is specified. Dump header only. +TEST_P(OatDumpTest, TestDumpOatTryWithRuntimeDexNotFound) { + TEST_DISABLED_FOR_RISCV64(); + ASSERT_TRUE( + GenerateAppOdexFile(GetParam(), {"--dex-location=/nonx/app.jar", "--copy-dex-files=false"})); + ASSERT_TRUE(Exec(GetParam(), kArgOatApp | kArgBootImage | kArgBcp | kArgIsa, {}, kExpectOat)); +} + +// Dex code cannot be found in the vdex file, but can be found in the specified dex file. +TEST_P(OatDumpTest, TestDumpOatWithRuntimeDexSpecified) { + TEST_DISABLED_FOR_RISCV64(); + ASSERT_TRUE( + GenerateAppOdexFile(GetParam(), {"--dex-location=/nonx/app.jar", "--copy-dex-files=false"})); + ASSERT_TRUE(Exec(GetParam(), + kArgOatApp | kArgDexApp | kArgBootImage | kArgBcp | kArgIsa, + {}, + kExpectOat | kExpectCode | kExpectBssMappingsForBcp)); +} + +// Oat file compiled with a boot image. oatdump invoked without a boot image. +TEST_P(OatDumpTest, TestDumpOatWithoutRuntimeBcpMismatch) { + TEST_DISABLED_FOR_RISCV64(); + ASSERT_TRUE(GenerateAppOdexFile(GetParam())); + ASSERT_TRUE(Exec(GetParam(), + kArgOatApp | kArgBcp | kArgIsa, + {"--boot-image=/nonx/boot.art"}, + kExpectOat | kExpectCode | kExpectBssOffsetsForBcp)); +} + +// Bootclasspath not specified. +TEST_P(OatDumpTest, TestDumpOatWithoutRuntimeNoBcp) { + TEST_DISABLED_FOR_RISCV64(); + ASSERT_TRUE(GenerateAppOdexFile(GetParam())); + ASSERT_TRUE(Exec(GetParam(), kArgOatApp, {}, kExpectOat | kExpectCode | kExpectBssOffsetsForBcp)); +} + +// Dex code cannot be found in the vdex file, and no --dex-file is specified. Dump header only. +TEST_P(OatDumpTest, TestDumpOatWithoutRuntimeDexNotFound) { + TEST_DISABLED_FOR_RISCV64(); + ASSERT_TRUE( + GenerateAppOdexFile(GetParam(), {"--dex-location=/nonx/app.jar", "--copy-dex-files=false"})); + ASSERT_TRUE(Exec(GetParam(), kArgOatApp, {}, kExpectOat)); +} + +// Dex code cannot be found in the vdex file, but can be found in the specified dex file. +TEST_P(OatDumpTest, TestDumpOatWithoutRuntimeDexSpecified) { + TEST_DISABLED_FOR_RISCV64(); + ASSERT_TRUE( + GenerateAppOdexFile(GetParam(), {"--dex-location=/nonx/app.jar", "--copy-dex-files=false"})); ASSERT_TRUE(Exec( - GetParam(), kArgOatApp | kArgBootImage | kArgBcp | kArgIsa, {}, kExpectOat | kExpectCode)); + GetParam(), kArgOatApp | kArgDexApp, {}, kExpectOat | kExpectCode | kExpectBssOffsetsForBcp)); } TEST_P(OatDumpTest, TestDumpAppImageWithBootImage) { @@ -31,9 +98,21 @@ TEST_P(OatDumpTest, TestDumpAppImageWithBootImage) { const std::string app_image_arg = "--app-image-file=" + GetAppImageName(); ASSERT_TRUE(GenerateAppOdexFile(GetParam(), {app_image_arg})); ASSERT_TRUE(Exec(GetParam(), + kArgAppImage | kArgOatApp | kArgBootImage | kArgBcp | kArgIsa, + {}, + kExpectImage | kExpectOat | kExpectCode | kExpectBssMappingsForBcp)); +} + +// Deprecated usage, but checked for compatibility. +TEST_P(OatDumpTest, TestDumpAppImageWithBootImageLegacy) { + TEST_DISABLED_FOR_RISCV64(); + TEST_DISABLED_WITHOUT_BAKER_READ_BARRIERS(); // GC bug, b/126305867 + const std::string app_image_arg = "--app-image-file=" + GetAppImageName(); + ASSERT_TRUE(GenerateAppOdexFile(GetParam(), {app_image_arg})); + ASSERT_TRUE(Exec(GetParam(), kArgAppImage | kArgImage | kArgBcp | kArgIsa, {"--app-oat=" + GetAppOdexName()}, - kExpectImage | kExpectOat | kExpectCode)); + kExpectImage | kExpectOat | kExpectCode | kExpectBssMappingsForBcp)); } TEST_P(OatDumpTest, TestDumpAppImageInvalidPath) { @@ -42,10 +121,63 @@ TEST_P(OatDumpTest, TestDumpAppImageInvalidPath) { const std::string app_image_arg = "--app-image-file=" + GetAppImageName(); ASSERT_TRUE(GenerateAppOdexFile(GetParam(), {app_image_arg})); ASSERT_TRUE(Exec(GetParam(), - kArgImage | kArgBcp | kArgIsa, - {"--app-image=missing_app_image.art", "--app-oat=" + GetAppOdexName()}, + kArgOatApp | kArgBootImage | kArgBcp | kArgIsa, + {"--app-image=missing_app_image.art"}, /*expects=*/0, /*expect_failure=*/true)); } +// The runtime can start, but the boot image check should fail. +TEST_P(OatDumpTest, TestDumpAppImageWithWrongBootImage) { + TEST_DISABLED_FOR_RISCV64(); + TEST_DISABLED_WITHOUT_BAKER_READ_BARRIERS(); // GC bug, b/126305867 + const std::string app_image_arg = "--app-image-file=" + GetAppImageName(); + ASSERT_TRUE(GenerateAppOdexFile(GetParam(), {app_image_arg})); + ASSERT_TRUE(Exec(GetParam(), + kArgAppImage | kArgOatApp | kArgBcp | kArgIsa, + {"--boot-image=/nonx/boot.art"}, + /*expects=*/0, + /*expect_failure=*/true)); +} + +// Not possible. +TEST_P(OatDumpTest, TestDumpAppImageWithoutRuntime) { + TEST_DISABLED_FOR_RISCV64(); + TEST_DISABLED_WITHOUT_BAKER_READ_BARRIERS(); // GC bug, b/126305867 + const std::string app_image_arg = "--app-image-file=" + GetAppImageName(); + ASSERT_TRUE(GenerateAppOdexFile(GetParam(), {app_image_arg})); + ASSERT_TRUE(Exec(GetParam(), + kArgAppImage | kArgOatApp, + {}, + /*expects=*/0, + /*expect_failure=*/true)); +} + +// Dex code cannot be found in the vdex file, and no --dex-file is specified. Cannot dump app image. +TEST_P(OatDumpTest, TestDumpAppImageDexNotFound) { + TEST_DISABLED_FOR_RISCV64(); + TEST_DISABLED_WITHOUT_BAKER_READ_BARRIERS(); // GC bug, b/126305867 + const std::string app_image_arg = "--app-image-file=" + GetAppImageName(); + ASSERT_TRUE(GenerateAppOdexFile( + GetParam(), {app_image_arg, "--dex-location=/nonx/app.jar", "--copy-dex-files=false"})); + ASSERT_TRUE(Exec(GetParam(), + kArgAppImage | kArgOatApp | kArgBootImage | kArgBcp | kArgIsa, + {}, + /*expects=*/0, + /*expect_failure=*/true)); +} + +// Dex code cannot be found in the vdex file, but can be found in the specified dex file. +TEST_P(OatDumpTest, TestDumpAppImageDexSpecified) { + TEST_DISABLED_FOR_RISCV64(); + TEST_DISABLED_WITHOUT_BAKER_READ_BARRIERS(); // GC bug, b/126305867 + const std::string app_image_arg = "--app-image-file=" + GetAppImageName(); + ASSERT_TRUE(GenerateAppOdexFile( + GetParam(), {app_image_arg, "--dex-location=/nonx/app.jar", "--copy-dex-files=false"})); + ASSERT_TRUE(Exec(GetParam(), + kArgAppImage | kArgOatApp | kArgDexApp | kArgBootImage | kArgBcp | kArgIsa, + {}, + kExpectImage | kExpectOat | kExpectCode | kExpectBssMappingsForBcp)); +} + } // namespace art |