blob: 9e6ed6df67e3ef1d088dd6eec7ff1a8b3258d40f [file] [log] [blame]
Mathieu Chartier2e0478a2018-04-06 14:33:25 -07001/*
2 * Copyright (C) 2018 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 "common_runtime_test.h"
18#include "exec_utils.h"
19
20namespace art {
21
22class DexAnalyzeTest : public CommonRuntimeTest {
23 public:
24 std::string GetDexAnalyzePath() {
Martin Stjernholme58624f2019-09-20 15:53:40 +010025 return GetArtBinDir() + "/dexanalyze";
Mathieu Chartier2e0478a2018-04-06 14:33:25 -070026 }
27
28 void DexAnalyzeExec(const std::vector<std::string>& args, bool expect_success) {
29 std::string binary = GetDexAnalyzePath();
30 CHECK(OS::FileExists(binary.c_str())) << binary << " should be a valid file path";
31 std::vector<std::string> argv;
32 argv.push_back(binary);
33 argv.insert(argv.end(), args.begin(), args.end());
34 std::string error_msg;
35 ASSERT_EQ(::art::Exec(argv, &error_msg), expect_success) << error_msg;
36 }
37};
38
Mathieu Chartier0226c1d2018-05-17 00:19:12 -070039TEST_F(DexAnalyzeTest, NoInputFileGiven) {
Andreas Gampe9b031f72018-10-04 11:03:34 -070040 DexAnalyzeExec({ "-a" }, /*expect_success=*/ false);
Mathieu Chartier0226c1d2018-05-17 00:19:12 -070041}
42
43TEST_F(DexAnalyzeTest, CantOpenInput) {
Andreas Gampe9b031f72018-10-04 11:03:34 -070044 DexAnalyzeExec({ "-a", "/non/existent/path" }, /*expect_success=*/ false);
Mathieu Chartier0226c1d2018-05-17 00:19:12 -070045}
46
Mathieu Chartier2e0478a2018-04-06 14:33:25 -070047TEST_F(DexAnalyzeTest, TestAnalyzeMultidex) {
Andreas Gampe9b031f72018-10-04 11:03:34 -070048 DexAnalyzeExec({ "-a", GetTestDexFileName("MultiDex") }, /*expect_success=*/ true);
Mathieu Chartier2e0478a2018-04-06 14:33:25 -070049}
50
Mathieu Chartier0226c1d2018-05-17 00:19:12 -070051TEST_F(DexAnalyzeTest, TestAnalizeCoreDex) {
Andreas Gampe9b031f72018-10-04 11:03:34 -070052 DexAnalyzeExec({ "-a", GetLibCoreDexFileNames()[0] }, /*expect_success=*/ true);
Mathieu Chartier0226c1d2018-05-17 00:19:12 -070053}
54
Mathieu Chartier2e0478a2018-04-06 14:33:25 -070055TEST_F(DexAnalyzeTest, TestInvalidArg) {
Andreas Gampe9b031f72018-10-04 11:03:34 -070056 DexAnalyzeExec({ "-invalid-option" }, /*expect_success=*/ false);
Mathieu Chartier2e0478a2018-04-06 14:33:25 -070057}
58
59} // namespace art