blob: 4ddb208a9243dea885e4544bcc9eb40d74a1de31 [file] [log] [blame]
Aart Bik69ae54a2015-07-01 14:52:26 -07001/*
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 Gampe8cf9cb32017-07-19 09:28:38 -070017#include <sstream>
Aart Bik69ae54a2015-07-01 14:52:26 -070018#include <string>
19#include <vector>
Aart Bik69ae54a2015-07-01 14:52:26 -070020
21#include <sys/types.h>
22#include <unistd.h>
23
Andreas Gampe2c30e4a2017-08-23 11:31:32 -070024#include "arch/instruction_set.h"
David Sehrc431b9d2018-03-02 12:01:51 -080025#include "base/os.h"
26#include "base/utils.h"
Aart Bik69ae54a2015-07-01 14:52:26 -070027#include "common_runtime_test.h"
Andreas Gampe2c30e4a2017-08-23 11:31:32 -070028#include "exec_utils.h"
Aart Bik69ae54a2015-07-01 14:52:26 -070029
30namespace art {
31
32class DexDumpTest : public CommonRuntimeTest {
33 protected:
Andreas Gampefa6a1b02018-09-07 08:11:55 -070034 void SetUp() override {
Aart Bik69ae54a2015-07-01 14:52:26 -070035 CommonRuntimeTest::SetUp();
36 // Dogfood our own lib core dex file.
Przemyslaw Szczepaniak121b25e2015-11-20 11:24:33 +000037 dex_file_ = GetLibCoreDexFileNames()[0];
Aart Bik69ae54a2015-07-01 14:52:26 -070038 }
39
40 // Runs test with given arguments.
41 bool Exec(const std::vector<std::string>& args, std::string* error_msg) {
Roland Levillainfb6a5c02019-03-29 20:20:16 +000042 std::string file_path = GetAndroidRuntimeBinDir() + "/dexdump";
Aart Bik69ae54a2015-07-01 14:52:26 -070043 EXPECT_TRUE(OS::FileExists(file_path.c_str())) << file_path << " should be a valid file path";
44 std::vector<std::string> exec_argv = { file_path };
45 exec_argv.insert(exec_argv.end(), args.begin(), args.end());
46 return ::art::Exec(exec_argv, error_msg);
47 }
48
49 std::string dex_file_;
50};
51
52
53TEST_F(DexDumpTest, NoInputFileGiven) {
54 std::string error_msg;
55 ASSERT_FALSE(Exec({}, &error_msg)) << error_msg;
56}
57
58TEST_F(DexDumpTest, CantOpenOutput) {
59 std::string error_msg;
Roland Levillaina28c9982017-10-30 13:14:28 +000060 ASSERT_FALSE(Exec({"-o", "/non/existent/path", dex_file_}, &error_msg)) << error_msg;
Aart Bik69ae54a2015-07-01 14:52:26 -070061}
62
63TEST_F(DexDumpTest, BadFlagCombination) {
64 std::string error_msg;
65 ASSERT_FALSE(Exec({"-c", "-i", dex_file_}, &error_msg)) << error_msg;
66}
67
68TEST_F(DexDumpTest, FullPlainOutput) {
69 std::string error_msg;
70 ASSERT_TRUE(Exec({"-d", "-f", "-h", "-l", "plain", "-o", "/dev/null",
71 dex_file_}, &error_msg)) << error_msg;
72}
73
74TEST_F(DexDumpTest, XMLOutput) {
75 std::string error_msg;
76 ASSERT_TRUE(Exec({"-l", "xml", "-o", "/dev/null",
77 dex_file_}, &error_msg)) << error_msg;
78}
79
80} // namespace art