diff options
Diffstat (limited to 'dexlayout/dexlayout_test.cc')
| -rw-r--r-- | dexlayout/dexlayout_test.cc | 82 |
1 files changed, 55 insertions, 27 deletions
diff --git a/dexlayout/dexlayout_test.cc b/dexlayout/dexlayout_test.cc index be272fcf2c..bebdc202e7 100644 --- a/dexlayout/dexlayout_test.cc +++ b/dexlayout/dexlayout_test.cc @@ -221,6 +221,12 @@ static const char kDuplicateCodeItemInputDex[] = "AHAAAAACAAAAAwAAAIwAAAADAAAAAQAAAJgAAAAFAAAABAAAAKQAAAAGAAAAAQAAAMQAAAABIAAA" "AwAAAOQAAAACIAAABwAAACQBAAADIAAAAwAAAFYBAAAAIAAAAQAAAGUBAAAAEAAAAQAAAHgBAAA="; +// Returns the default compact dex option for dexlayout based on kDefaultCompactDexLevel. +static std::vector<std::string> DefaultCompactDexOption() { + return (kDefaultCompactDexLevel == CompactDexLevel::kCompactDexLevelFast) ? + std::vector<std::string>{"-x", "fast"} : std::vector<std::string>{"-x", "none"}; +} + static void WriteBase64ToFile(const char* base64, File* file) { // Decode base64. CHECK(base64 != nullptr); @@ -289,7 +295,7 @@ class DexLayoutTest : public CommonRuntimeTest { for (const std::string &dex_file : GetLibCoreDexFileNames()) { std::vector<std::string> dexlayout_args = { "-w", tmp_dir, "-o", tmp_name, dex_file }; - if (!DexLayoutExec(dexlayout_args, error_msg)) { + if (!DexLayoutExec(dexlayout_args, error_msg, /*pass_default_cdex_option*/ false)) { return false; } size_t dex_file_last_slash = dex_file.rfind('/'); @@ -304,12 +310,10 @@ class DexLayoutTest : public CommonRuntimeTest { if (!::art::Exec(diff_exec_argv, error_msg)) { return false; } - std::vector<std::string> rm_zip_exec_argv = { "/bin/rm", tmp_dir + "classes.dex" }; - if (!::art::Exec(rm_zip_exec_argv, error_msg)) { + if (!UnlinkFile(tmp_dir + "classes.dex")) { return false; } - std::vector<std::string> rm_out_exec_argv = { "/bin/rm", tmp_dir + dex_file_name }; - if (!::art::Exec(rm_out_exec_argv, error_msg)) { + if (!UnlinkFile(tmp_dir + dex_file_name)) { return false; } } @@ -426,10 +430,7 @@ class DexLayoutTest : public CommonRuntimeTest { } // -v makes sure that the layout did not corrupt the dex file. - - std::vector<std::string> rm_exec_argv = - { "/bin/rm", dex_file, profile_file, output_dex }; - if (!::art::Exec(rm_exec_argv, error_msg)) { + if (!UnlinkFile(dex_file) || !UnlinkFile(profile_file) || !UnlinkFile(output_dex)) { return false; } return true; @@ -467,7 +468,7 @@ class DexLayoutTest : public CommonRuntimeTest { // -v makes sure that the layout did not corrupt the dex file. std::vector<std::string> dexlayout_args = { "-i", "-v", "-w", tmp_dir, "-o", tmp_name, "-p", profile_file, dex_file }; - if (!DexLayoutExec(dexlayout_args, error_msg)) { + if (!DexLayoutExec(dexlayout_args, error_msg, /*pass_default_cdex_option*/ false)) { return false; } @@ -479,7 +480,7 @@ class DexLayoutTest : public CommonRuntimeTest { // -i since the checksum won't match from the first layout. std::vector<std::string> second_dexlayout_args = { "-i", "-v", "-w", tmp_dir, "-o", tmp_name, "-p", profile_file, output_dex }; - if (!DexLayoutExec(second_dexlayout_args, error_msg)) { + if (!DexLayoutExec(second_dexlayout_args, error_msg, /*pass_default_cdex_option*/ false)) { return false; } @@ -490,10 +491,11 @@ class DexLayoutTest : public CommonRuntimeTest { diff_result = false; } - std::vector<std::string> rm_exec_argv = - { "/bin/rm", dex_file, profile_file, output_dex, second_output_dex }; - if (!::art::Exec(rm_exec_argv, error_msg)) { - return false; + std::vector<std::string> test_files = { dex_file, profile_file, output_dex, second_output_dex }; + for (auto test_file : test_files) { + if (!UnlinkFile(test_file)) { + return false; + } } return diff_result; @@ -512,7 +514,7 @@ class DexLayoutTest : public CommonRuntimeTest { std::string output_dex = tmp_dir + "classes.dex.new"; std::vector<std::string> dexlayout_args = { "-w", tmp_dir, "-o", "/dev/null", input_dex }; - if (!DexLayoutExec(dexlayout_args, error_msg)) { + if (!DexLayoutExec(dexlayout_args, error_msg, /*pass_default_cdex_option*/ false)) { return false; } @@ -522,9 +524,11 @@ class DexLayoutTest : public CommonRuntimeTest { return false; } - std::vector<std::string> rm_exec_argv = { "/bin/rm", input_dex, output_dex }; - if (!::art::Exec(rm_exec_argv, error_msg)) { - return false; + std::vector<std::string> dex_files = { input_dex, output_dex }; + for (auto dex_file : dex_files) { + if (!UnlinkFile(dex_file)) { + return false; + } } return true; } @@ -550,17 +554,27 @@ class DexLayoutTest : public CommonRuntimeTest { return true; } - bool DexLayoutExec(const std::vector<std::string>& dexlayout_args, std::string* error_msg) { + bool DexLayoutExec(const std::vector<std::string>& dexlayout_args, + std::string* error_msg, + bool pass_default_cdex_option = true) { std::vector<std::string> argv; std::string dexlayout = GetDexLayoutPath(); CHECK(OS::FileExists(dexlayout.c_str())) << dexlayout << " should be a valid file path"; argv.push_back(dexlayout); + if (pass_default_cdex_option) { + std::vector<std::string> cdex_level = DefaultCompactDexOption(); + argv.insert(argv.end(), cdex_level.begin(), cdex_level.end()); + } argv.insert(argv.end(), dexlayout_args.begin(), dexlayout_args.end()); return ::art::Exec(argv, error_msg); } + + bool UnlinkFile(const std::string& file_path) { + return unix_file::FdFile(file_path, 0, false).Unlink(); + } }; @@ -730,11 +744,29 @@ TEST_F(DexLayoutTest, CodeItemOverrun) { CHECK(mutated_successfully) << "Failed to find candidate code item with only one code unit in last instruction."; }); - std::vector<std::string> dexlayout_args = { "-i", "-o", "/dev/null", temp_dex.GetFilename() }; + + std::string error_msg; + + ScratchFile tmp_file; + const std::string& tmp_name = tmp_file.GetFilename(); + size_t tmp_last_slash = tmp_name.rfind('/'); + std::string tmp_dir = tmp_name.substr(0, tmp_last_slash + 1); + ScratchFile profile_file; + + std::vector<std::string> dexlayout_args = + { "-i", + "-v", + "-w", tmp_dir, + "-o", tmp_name, + "-p", profile_file.GetFilename(), + temp_dex.GetFilename() + }; + // -v makes sure that the layout did not corrupt the dex file. ASSERT_TRUE(DexLayoutExec(&temp_dex, /*dex_filename*/ nullptr, - nullptr /* profile_file */, + &profile_file, dexlayout_args)); + ASSERT_TRUE(UnlinkFile(temp_dex.GetFilename() + ".new")); } // Test that link data is written out (or at least the header is updated). @@ -772,11 +804,7 @@ TEST_F(DexLayoutTest, LinkData) { /*dex_filename*/ nullptr, &profile_file, dexlayout_args)); - - std::string output_dex = temp_dex.GetFilename() + ".new"; - std::vector<std::string> rm_exec_argv = - { "/bin/rm", output_dex }; - ASSERT_TRUE(::art::Exec(rm_exec_argv, &error_msg)); + ASSERT_TRUE(UnlinkFile(temp_dex.GetFilename() + ".new")); } TEST_F(DexLayoutTest, ClassFilter) { |