1*795d594fSAndroid Build Coastguard Worker /*
2*795d594fSAndroid Build Coastguard Worker * Copyright (C) 2015 The Android Open Source Project
3*795d594fSAndroid Build Coastguard Worker *
4*795d594fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*795d594fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*795d594fSAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*795d594fSAndroid Build Coastguard Worker *
8*795d594fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
9*795d594fSAndroid Build Coastguard Worker *
10*795d594fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*795d594fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*795d594fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*795d594fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*795d594fSAndroid Build Coastguard Worker * limitations under the License.
15*795d594fSAndroid Build Coastguard Worker */
16*795d594fSAndroid Build Coastguard Worker
17*795d594fSAndroid Build Coastguard Worker #include <sstream>
18*795d594fSAndroid Build Coastguard Worker #include <string>
19*795d594fSAndroid Build Coastguard Worker #include <vector>
20*795d594fSAndroid Build Coastguard Worker
21*795d594fSAndroid Build Coastguard Worker #include <sys/types.h>
22*795d594fSAndroid Build Coastguard Worker #include <unistd.h>
23*795d594fSAndroid Build Coastguard Worker
24*795d594fSAndroid Build Coastguard Worker #include "arch/instruction_set.h"
25*795d594fSAndroid Build Coastguard Worker #include "base/os.h"
26*795d594fSAndroid Build Coastguard Worker #include "base/utils.h"
27*795d594fSAndroid Build Coastguard Worker #include "common_runtime_test.h"
28*795d594fSAndroid Build Coastguard Worker #include "exec_utils.h"
29*795d594fSAndroid Build Coastguard Worker #include "gc/heap.h"
30*795d594fSAndroid Build Coastguard Worker #include "gc/space/image_space.h"
31*795d594fSAndroid Build Coastguard Worker
32*795d594fSAndroid Build Coastguard Worker namespace art {
33*795d594fSAndroid Build Coastguard Worker
34*795d594fSAndroid Build Coastguard Worker class DexListTest : public CommonRuntimeTest {
35*795d594fSAndroid Build Coastguard Worker protected:
SetUp()36*795d594fSAndroid Build Coastguard Worker void SetUp() override {
37*795d594fSAndroid Build Coastguard Worker CommonRuntimeTest::SetUp();
38*795d594fSAndroid Build Coastguard Worker // Dogfood our own lib core dex file.
39*795d594fSAndroid Build Coastguard Worker dex_file_ = GetLibCoreDexFileNames()[0];
40*795d594fSAndroid Build Coastguard Worker }
41*795d594fSAndroid Build Coastguard Worker
42*795d594fSAndroid Build Coastguard Worker // Runs test with given arguments.
Exec(const std::vector<std::string> & args,std::string * error_msg)43*795d594fSAndroid Build Coastguard Worker bool Exec(const std::vector<std::string>& args, std::string* error_msg) {
44*795d594fSAndroid Build Coastguard Worker std::string file_path = GetArtBinDir() + "/dexlist";
45*795d594fSAndroid Build Coastguard Worker EXPECT_TRUE(OS::FileExists(file_path.c_str())) << file_path << " should be a valid file path";
46*795d594fSAndroid Build Coastguard Worker std::vector<std::string> exec_argv = { file_path };
47*795d594fSAndroid Build Coastguard Worker exec_argv.insert(exec_argv.end(), args.begin(), args.end());
48*795d594fSAndroid Build Coastguard Worker return ::art::Exec(exec_argv, error_msg);
49*795d594fSAndroid Build Coastguard Worker }
50*795d594fSAndroid Build Coastguard Worker
51*795d594fSAndroid Build Coastguard Worker std::string dex_file_;
52*795d594fSAndroid Build Coastguard Worker };
53*795d594fSAndroid Build Coastguard Worker
54*795d594fSAndroid Build Coastguard Worker
TEST_F(DexListTest,NoInputFileGiven)55*795d594fSAndroid Build Coastguard Worker TEST_F(DexListTest, NoInputFileGiven) {
56*795d594fSAndroid Build Coastguard Worker std::string error_msg;
57*795d594fSAndroid Build Coastguard Worker ASSERT_FALSE(Exec({}, &error_msg)) << error_msg;
58*795d594fSAndroid Build Coastguard Worker }
59*795d594fSAndroid Build Coastguard Worker
TEST_F(DexListTest,CantOpenOutput)60*795d594fSAndroid Build Coastguard Worker TEST_F(DexListTest, CantOpenOutput) {
61*795d594fSAndroid Build Coastguard Worker std::string error_msg;
62*795d594fSAndroid Build Coastguard Worker ASSERT_FALSE(Exec({"-o", "/non/existent/path", dex_file_}, &error_msg)) << error_msg;
63*795d594fSAndroid Build Coastguard Worker }
64*795d594fSAndroid Build Coastguard Worker
TEST_F(DexListTest,IllFormedMethod)65*795d594fSAndroid Build Coastguard Worker TEST_F(DexListTest, IllFormedMethod) {
66*795d594fSAndroid Build Coastguard Worker std::string error_msg;
67*795d594fSAndroid Build Coastguard Worker ASSERT_FALSE(Exec({"-m", "joho", dex_file_}, &error_msg)) << error_msg;
68*795d594fSAndroid Build Coastguard Worker }
69*795d594fSAndroid Build Coastguard Worker
TEST_F(DexListTest,FullOutput)70*795d594fSAndroid Build Coastguard Worker TEST_F(DexListTest, FullOutput) {
71*795d594fSAndroid Build Coastguard Worker std::string error_msg;
72*795d594fSAndroid Build Coastguard Worker ASSERT_TRUE(Exec({"-o", "/dev/null", dex_file_}, &error_msg)) << error_msg;
73*795d594fSAndroid Build Coastguard Worker }
74*795d594fSAndroid Build Coastguard Worker
TEST_F(DexListTest,MethodOutput)75*795d594fSAndroid Build Coastguard Worker TEST_F(DexListTest, MethodOutput) {
76*795d594fSAndroid Build Coastguard Worker std::string error_msg;
77*795d594fSAndroid Build Coastguard Worker ASSERT_TRUE(Exec({"-o", "/dev/null", "-m", "java.lang.Object.toString",
78*795d594fSAndroid Build Coastguard Worker dex_file_}, &error_msg)) << error_msg;
79*795d594fSAndroid Build Coastguard Worker }
80*795d594fSAndroid Build Coastguard Worker
81*795d594fSAndroid Build Coastguard Worker } // namespace art
82