blob: 0b9adbddb8cf856be6dd06c631f0b7d0b3b14db5 [file] [log] [blame]
Aart Bik3e40f4a2015-07-07 17:09:41 -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 Bik3e40f4a2015-07-07 17:09:41 -070018#include <string>
19#include <vector>
Aart Bik3e40f4a2015-07-07 17:09:41 -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 Sehr8f4b0562018-03-02 12:01:51 -080025#include "base/os.h"
26#include "base/utils.h"
Aart Bik3e40f4a2015-07-07 17:09:41 -070027#include "common_runtime_test.h"
Andreas Gampe2c30e4a2017-08-23 11:31:32 -070028#include "exec_utils.h"
29#include "gc/heap.h"
30#include "gc/space/image_space.h"
Aart Bik3e40f4a2015-07-07 17:09:41 -070031
32namespace art {
33
34class DexListTest : public CommonRuntimeTest {
35 protected:
36 virtual void SetUp() {
37 CommonRuntimeTest::SetUp();
38 // Dogfood our own lib core dex file.
Przemyslaw Szczepaniak121b25e2015-11-20 11:24:33 +000039 dex_file_ = GetLibCoreDexFileNames()[0];
Aart Bik3e40f4a2015-07-07 17:09:41 -070040 }
41
42 // Runs test with given arguments.
43 bool Exec(const std::vector<std::string>& args, std::string* error_msg) {
Aart Bik3e40f4a2015-07-07 17:09:41 -070044 std::string file_path = GetTestAndroidRoot();
Colin Cross333e7c52016-09-14 13:07:27 -070045 file_path += "/bin/dexlist";
Aart Bik3e40f4a2015-07-07 17:09:41 -070046 EXPECT_TRUE(OS::FileExists(file_path.c_str())) << file_path << " should be a valid file path";
47 std::vector<std::string> exec_argv = { file_path };
48 exec_argv.insert(exec_argv.end(), args.begin(), args.end());
49 return ::art::Exec(exec_argv, error_msg);
50 }
51
52 std::string dex_file_;
53};
54
55
56TEST_F(DexListTest, NoInputFileGiven) {
57 std::string error_msg;
58 ASSERT_FALSE(Exec({}, &error_msg)) << error_msg;
59}
60
61TEST_F(DexListTest, CantOpenOutput) {
62 std::string error_msg;
63 ASSERT_FALSE(Exec({"-o", "/joho", dex_file_}, &error_msg)) << error_msg;
64}
65
66TEST_F(DexListTest, IllFormedMethod) {
67 std::string error_msg;
68 ASSERT_FALSE(Exec({"-m", "joho", dex_file_}, &error_msg)) << error_msg;
69}
70
71TEST_F(DexListTest, FullOutput) {
72 std::string error_msg;
73 ASSERT_TRUE(Exec({"-o", "/dev/null", dex_file_}, &error_msg)) << error_msg;
74}
75
76TEST_F(DexListTest, MethodOutput) {
77 std::string error_msg;
78 ASSERT_TRUE(Exec({"-o", "/dev/null", "-m", "java.lang.Object.toString",
79 dex_file_}, &error_msg)) << error_msg;
80}
81
82} // namespace art