Jeff Hao | c3acfc5 | 2016-08-29 14:18:26 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <string> |
| 18 | #include <vector> |
| 19 | #include <sstream> |
| 20 | |
| 21 | #include <sys/types.h> |
| 22 | #include <unistd.h> |
| 23 | |
| 24 | #include "base/stringprintf.h" |
| 25 | #include "common_runtime_test.h" |
| 26 | #include "utils.h" |
| 27 | |
| 28 | namespace art { |
| 29 | |
| 30 | class DexLayoutTest : public CommonRuntimeTest { |
| 31 | protected: |
| 32 | virtual void SetUp() { |
| 33 | CommonRuntimeTest::SetUp(); |
| 34 | // TODO: Test with other dex files for improved coverage. |
| 35 | // Dogfood our own lib core dex file. |
| 36 | dex_file_ = GetLibCoreDexFileNames()[0]; |
| 37 | } |
| 38 | |
| 39 | // Runs test with given arguments. |
| 40 | bool Exec(std::string* error_msg) { |
| 41 | // TODO: dexdump2 -> dexdump ? |
| 42 | ScratchFile dexdump_output; |
| 43 | std::string dexdump_filename = dexdump_output.GetFilename(); |
| 44 | std::string dexdump = GetTestAndroidRoot() + "/bin/dexdump2"; |
| 45 | EXPECT_TRUE(OS::FileExists(dexdump.c_str())) << dexdump << " should be a valid file path"; |
| 46 | std::vector<std::string> dexdump_exec_argv = |
| 47 | { dexdump, "-d", "-f", "-h", "-l", "plain", "-o", dexdump_filename, dex_file_ }; |
| 48 | |
| 49 | ScratchFile dexlayout_output; |
| 50 | std::string dexlayout_filename = dexlayout_output.GetFilename(); |
| 51 | std::string dexlayout = GetTestAndroidRoot() + "/bin/dexlayout"; |
| 52 | EXPECT_TRUE(OS::FileExists(dexlayout.c_str())) << dexlayout << " should be a valid file path"; |
| 53 | std::vector<std::string> dexlayout_exec_argv = |
| 54 | { dexlayout, "-d", "-f", "-h", "-l", "plain", "-o", dexlayout_filename, dex_file_ }; |
| 55 | |
| 56 | if (!::art::Exec(dexdump_exec_argv, error_msg)) { |
| 57 | return false; |
| 58 | } |
| 59 | if (!::art::Exec(dexlayout_exec_argv, error_msg)) { |
| 60 | return false; |
| 61 | } |
| 62 | std::vector<std::string> diff_exec_argv = |
| 63 | { "/usr/bin/diff", dexdump_filename, dexlayout_filename }; |
| 64 | if (!::art::Exec(diff_exec_argv, error_msg)) { |
| 65 | return false; |
| 66 | } |
| 67 | return true; |
| 68 | } |
| 69 | |
| 70 | std::string dex_file_; |
| 71 | }; |
| 72 | |
| 73 | |
| 74 | TEST_F(DexLayoutTest, FullPlainOutput) { |
Jeff Hao | 0f7eaeb | 2016-08-31 17:56:13 -0700 | [diff] [blame] | 75 | // Disable test on target. |
| 76 | TEST_DISABLED_FOR_TARGET(); |
Jeff Hao | c3acfc5 | 2016-08-29 14:18:26 -0700 | [diff] [blame] | 77 | std::string error_msg; |
| 78 | ASSERT_TRUE(Exec(&error_msg)) << error_msg; |
| 79 | } |
| 80 | |
| 81 | } // namespace art |