Mathieu Chartier | 2e0478a | 2018-04-06 14:33:25 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 20 | namespace art { |
| 21 | |
| 22 | class DexAnalyzeTest : public CommonRuntimeTest { |
| 23 | public: |
| 24 | std::string GetDexAnalyzePath() { |
Martin Stjernholm | e58624f | 2019-09-20 15:53:40 +0100 | [diff] [blame] | 25 | return GetArtBinDir() + "/dexanalyze"; |
Mathieu Chartier | 2e0478a | 2018-04-06 14:33:25 -0700 | [diff] [blame] | 26 | } |
| 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 Chartier | 0226c1d | 2018-05-17 00:19:12 -0700 | [diff] [blame] | 39 | TEST_F(DexAnalyzeTest, NoInputFileGiven) { |
Andreas Gampe | 9b031f7 | 2018-10-04 11:03:34 -0700 | [diff] [blame] | 40 | DexAnalyzeExec({ "-a" }, /*expect_success=*/ false); |
Mathieu Chartier | 0226c1d | 2018-05-17 00:19:12 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | TEST_F(DexAnalyzeTest, CantOpenInput) { |
Andreas Gampe | 9b031f7 | 2018-10-04 11:03:34 -0700 | [diff] [blame] | 44 | DexAnalyzeExec({ "-a", "/non/existent/path" }, /*expect_success=*/ false); |
Mathieu Chartier | 0226c1d | 2018-05-17 00:19:12 -0700 | [diff] [blame] | 45 | } |
| 46 | |
Mathieu Chartier | 2e0478a | 2018-04-06 14:33:25 -0700 | [diff] [blame] | 47 | TEST_F(DexAnalyzeTest, TestAnalyzeMultidex) { |
Andreas Gampe | 9b031f7 | 2018-10-04 11:03:34 -0700 | [diff] [blame] | 48 | DexAnalyzeExec({ "-a", GetTestDexFileName("MultiDex") }, /*expect_success=*/ true); |
Mathieu Chartier | 2e0478a | 2018-04-06 14:33:25 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Mathieu Chartier | 0226c1d | 2018-05-17 00:19:12 -0700 | [diff] [blame] | 51 | TEST_F(DexAnalyzeTest, TestAnalizeCoreDex) { |
Andreas Gampe | 9b031f7 | 2018-10-04 11:03:34 -0700 | [diff] [blame] | 52 | DexAnalyzeExec({ "-a", GetLibCoreDexFileNames()[0] }, /*expect_success=*/ true); |
Mathieu Chartier | 0226c1d | 2018-05-17 00:19:12 -0700 | [diff] [blame] | 53 | } |
| 54 | |
Mathieu Chartier | 2e0478a | 2018-04-06 14:33:25 -0700 | [diff] [blame] | 55 | TEST_F(DexAnalyzeTest, TestInvalidArg) { |
Andreas Gampe | 9b031f7 | 2018-10-04 11:03:34 -0700 | [diff] [blame] | 56 | DexAnalyzeExec({ "-invalid-option" }, /*expect_success=*/ false); |
Mathieu Chartier | 2e0478a | 2018-04-06 14:33:25 -0700 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | } // namespace art |