int status = OR_RETURN(Dex2Oat(args, &output_)); return status == 0;
}
Result<std::unique_ptr<VerifierDeps>> GetVerifierDeps(const std::string& vdex_location, const DexFile* dex_file) { // Verify the vdex file content: only the classes using public APIs should be verified.
std::string error_msg;
std::unique_ptr<VdexFile> vdex(VdexFile::Open(vdex_location, /*low_4gb=*/false,
&error_msg)); // Check the vdex doesn't have dex. if (vdex->HasDexSection()) { return Errorf("The vdex {} should not contain dex code", vdex_location);
}
// Verify the deps.
VdexFile::VdexFileHeader vdex_header = vdex->GetVdexFileHeader(); if (!vdex_header.IsValid()) { return Errorf("Invalid vdex header in {}", vdex_location);
}
// Validates verification against public API stubs: // - create a vdex file contraints by a predefined list of public API (passed as separate dex) // - compile with the above vdex file as input to validate the compilation flow
TEST_F(Dex2oatVdexTest, VerifyPublicSdkStubs) { // Dex2oatVdexTestDex is the subject app using normal APIs found in the boot classpath.
std::unique_ptr<const DexFile> dex_file(OpenTestDexFile("Dex2oatVdexTestDex")); // Dex2oatVdexPublicSdkDex serves as the public API-stubs, restricting what can be verified. const std::string api_dex_location = GetTestDexFileName("Dex2oatVdexPublicSdkDex");
// Compile the subject app using the predefined API-stubs
ASSERT_THAT(RunDex2oat(dex_file->GetLocation(), GetOdex(dex_file), &api_dex_location),
HasValue(true));
// Verify public API usage. The classes should be verified.
ASSERT_TRUE(HasVerifiedClass(deps, "LAccessPublicCtor;", *dex_file));
ASSERT_TRUE(HasVerifiedClass(deps, "LAccessPublicMethod;", *dex_file));
ASSERT_TRUE(HasVerifiedClass(deps, "LAccessPublicMethodFromParent;", *dex_file));
ASSERT_TRUE(HasVerifiedClass(deps, "LAccessPublicStaticMethod;", *dex_file));
ASSERT_TRUE(HasVerifiedClass(deps, "LAccessPublicStaticField;", *dex_file));
// Verify NON public API usage. The classes should be verified, but will run // with access checks.
ASSERT_TRUE(HasVerifiedClass(deps, "LAccessNonPublicCtor;", *dex_file));
ASSERT_TRUE(HasVerifiedClass(deps, "LAccessNonPublicMethod;", *dex_file));
ASSERT_TRUE(HasVerifiedClass(deps, "LAccessNonPublicMethodFromParent;", *dex_file));
ASSERT_TRUE(HasVerifiedClass(deps, "LAccessNonPublicStaticMethod;", *dex_file));
ASSERT_TRUE(HasVerifiedClass(deps, "LAccessNonPublicStaticField;", *dex_file));
// Compile again without public API stubs but with the previously generated vdex. // This simulates a normal install where the apk has its code pre-verified. // The results should be the same.
// Check that if the input dm does contain dex files then the compilation fails
TEST_F(Dex2oatVdexTest, VerifyPublicSdkStubsWithDexFiles) { // Dex2oatVdexTestDex is the subject app using normal APIs found in the boot classpath.
std::unique_ptr<const DexFile> dex_file(OpenTestDexFile("Dex2oatVdexTestDex"));
// Compile the subject app using the predefined API-stubs
ASSERT_THAT(RunDex2oat(dex_file->GetLocation(),
GetOdex(dex_file), /*public_sdk=*/nullptr, /*copy_dex_files=*/true),
HasValue(true));
// Create the .dm file with the output.
std::string dm_file = GetScratchDir() + "/base.dm";
CreateDexMetadata(GetVdex(dex_file), dm_file);
std::vector<std::string> extra_args;
extra_args.push_back("--dm-file=" + dm_file);
// Recompile again with the .dm file which contains a vdex with code. // The compilation will pass, but dex2oat will not use the vdex file.
ASSERT_THAT(RunDex2oat(dex_file->GetLocation(),
GetOdex(dex_file, "v2"), /*public_sdk=*/nullptr, /*copy_dex_files=*/true,
extra_args),
HasValue(true));
}
// Check that corrupt vdex files from .dm archives are ignored.
TEST_F(Dex2oatVdexTest, VerifyCorruptVdexFile) { // Dex2oatVdexTestDex is the subject app using normal APIs found in the boot classpath.
std::unique_ptr<const DexFile> dex_file(OpenTestDexFile("Dex2oatVdexTestDex"));
// Create the .dm file with the output. // Instead passing the vdex files, pass the actual dex file. This will simulate a vdex corruption. // The compiler should ignore it.
std::string dm_file = GetScratchDir() + "/base.dm";
CreateDexMetadata(dex_file->GetLocation(), dm_file);
std::vector<std::string> extra_args;
extra_args.push_back("--dm-file=" + dm_file);
// Compile the dex file. Despite having a corrupt input .vdex, we should not crash.
ASSERT_THAT(RunDex2oat(dex_file->GetLocation(),
GetOdex(dex_file), /*public_sdk=*/nullptr, /*copy_dex_files=*/true,
extra_args),
HasValue(true))
<< output_;
}
// Check that if the input dm a vdex with mismatching checksums the compilation fails
TEST_F(Dex2oatVdexTest, VerifyInputDmWithMismatchedChecksums) { // Generate a vdex file for Dex2oatVdexTestDex.
std::unique_ptr<const DexFile> dex_file(OpenTestDexFile("Dex2oatVdexTestDex"));
// Create the .dm file with the output.
std::string dm_file = GetScratchDir() + "/base.dm";
CreateDexMetadata(GetVdex(dex_file), dm_file);
std::vector<std::string> extra_args;
extra_args.push_back("--dm-file=" + dm_file);
// Try to compile Main using an input dm which contains the vdex for // Dex2oatVdexTestDex. It should fail.
std::unique_ptr<const DexFile> dex_file2(OpenTestDexFile("Main"));
ASSERT_THAT(RunDex2oat(dex_file2->GetLocation(),
GetOdex(dex_file2, "v2"), /*public_sdk=*/nullptr, /*copy_dex_files=*/false,
extra_args),
HasValue(false))
<< output_;
}
} // namespace art
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet am 2026-06-29)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.