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