Aart Bik | 69ae54a | 2015-07-01 14:52:26 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 17 | #include <sstream> |
Aart Bik | 69ae54a | 2015-07-01 14:52:26 -0700 | [diff] [blame] | 18 | #include <string> |
| 19 | #include <vector> |
Aart Bik | 69ae54a | 2015-07-01 14:52:26 -0700 | [diff] [blame] | 20 | |
| 21 | #include <sys/types.h> |
| 22 | #include <unistd.h> |
| 23 | |
Andreas Gampe | 2c30e4a | 2017-08-23 11:31:32 -0700 | [diff] [blame] | 24 | #include "arch/instruction_set.h" |
Aart Bik | 69ae54a | 2015-07-01 14:52:26 -0700 | [diff] [blame] | 25 | #include "common_runtime_test.h" |
Andreas Gampe | 2c30e4a | 2017-08-23 11:31:32 -0700 | [diff] [blame] | 26 | #include "exec_utils.h" |
| 27 | #include "os.h" |
Aart Bik | 69ae54a | 2015-07-01 14:52:26 -0700 | [diff] [blame] | 28 | #include "utils.h" |
| 29 | |
| 30 | namespace art { |
| 31 | |
| 32 | class DexDumpTest : public CommonRuntimeTest { |
| 33 | protected: |
| 34 | virtual void SetUp() { |
| 35 | CommonRuntimeTest::SetUp(); |
| 36 | // Dogfood our own lib core dex file. |
Przemyslaw Szczepaniak | 121b25e | 2015-11-20 11:24:33 +0000 | [diff] [blame] | 37 | dex_file_ = GetLibCoreDexFileNames()[0]; |
Aart Bik | 69ae54a | 2015-07-01 14:52:26 -0700 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | // Runs test with given arguments. |
| 41 | bool Exec(const std::vector<std::string>& args, std::string* error_msg) { |
Aart Bik | 22c26f5 | 2015-07-08 21:20:13 +0000 | [diff] [blame] | 42 | // TODO(ajcbik): dexdump2 -> dexdump |
Elliott Hughes | 5ed8b2d | 2015-09-23 23:01:31 -0700 | [diff] [blame] | 43 | std::string file_path = GetTestAndroidRoot() + "/bin/dexdump2"; |
Aart Bik | 69ae54a | 2015-07-01 14:52:26 -0700 | [diff] [blame] | 44 | EXPECT_TRUE(OS::FileExists(file_path.c_str())) << file_path << " should be a valid file path"; |
| 45 | std::vector<std::string> exec_argv = { file_path }; |
| 46 | exec_argv.insert(exec_argv.end(), args.begin(), args.end()); |
| 47 | return ::art::Exec(exec_argv, error_msg); |
| 48 | } |
| 49 | |
| 50 | std::string dex_file_; |
| 51 | }; |
| 52 | |
| 53 | |
| 54 | TEST_F(DexDumpTest, NoInputFileGiven) { |
| 55 | std::string error_msg; |
| 56 | ASSERT_FALSE(Exec({}, &error_msg)) << error_msg; |
| 57 | } |
| 58 | |
| 59 | TEST_F(DexDumpTest, CantOpenOutput) { |
| 60 | std::string error_msg; |
| 61 | ASSERT_FALSE(Exec({"-o", "/joho", dex_file_}, &error_msg)) << error_msg; |
| 62 | } |
| 63 | |
| 64 | TEST_F(DexDumpTest, BadFlagCombination) { |
| 65 | std::string error_msg; |
| 66 | ASSERT_FALSE(Exec({"-c", "-i", dex_file_}, &error_msg)) << error_msg; |
| 67 | } |
| 68 | |
| 69 | TEST_F(DexDumpTest, FullPlainOutput) { |
| 70 | std::string error_msg; |
| 71 | ASSERT_TRUE(Exec({"-d", "-f", "-h", "-l", "plain", "-o", "/dev/null", |
| 72 | dex_file_}, &error_msg)) << error_msg; |
| 73 | } |
| 74 | |
| 75 | TEST_F(DexDumpTest, XMLOutput) { |
| 76 | std::string error_msg; |
| 77 | ASSERT_TRUE(Exec({"-l", "xml", "-o", "/dev/null", |
| 78 | dex_file_}, &error_msg)) << error_msg; |
| 79 | } |
| 80 | |
| 81 | } // namespace art |