Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 "compiler_filter.h" |
| 18 | |
| 19 | #include <gtest/gtest.h> |
| 20 | |
| 21 | namespace art { |
| 22 | |
Andreas Gampe | 641a473 | 2017-08-24 13:21:35 -0700 | [diff] [blame] | 23 | static void TestCompilerFilterName(CompilerFilter::Filter filter, const std::string& name) { |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 24 | CompilerFilter::Filter parsed; |
| 25 | EXPECT_TRUE(CompilerFilter::ParseCompilerFilter(name.c_str(), &parsed)); |
| 26 | EXPECT_EQ(filter, parsed); |
| 27 | |
| 28 | EXPECT_EQ(name, CompilerFilter::NameOfFilter(filter)); |
| 29 | } |
| 30 | |
Andreas Gampe | 641a473 | 2017-08-24 13:21:35 -0700 | [diff] [blame] | 31 | static void TestSafeModeFilter(CompilerFilter::Filter expected, const std::string& name) { |
Nicolas Geoffray | 741d426 | 2017-05-03 13:08:36 +0100 | [diff] [blame] | 32 | CompilerFilter::Filter parsed; |
| 33 | EXPECT_TRUE(CompilerFilter::ParseCompilerFilter(name.c_str(), &parsed)); |
| 34 | EXPECT_EQ(expected, CompilerFilter::GetSafeModeFilterFrom(parsed)); |
| 35 | } |
| 36 | |
| 37 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 38 | // Verify the dexopt status values from dalvik.system.DexFile |
| 39 | // match the OatFileAssistant::DexOptStatus values. |
| 40 | TEST(CompilerFilterTest, ParseCompilerFilter) { |
| 41 | CompilerFilter::Filter filter; |
| 42 | |
Nicolas Geoffray | 49cda06 | 2017-04-21 13:08:25 +0100 | [diff] [blame] | 43 | TestCompilerFilterName(CompilerFilter::kAssumeVerified, "assume-verified"); |
| 44 | TestCompilerFilterName(CompilerFilter::kExtract, "extract"); |
| 45 | TestCompilerFilterName(CompilerFilter::kVerify, "verify"); |
| 46 | TestCompilerFilterName(CompilerFilter::kQuicken, "quicken"); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 47 | TestCompilerFilterName(CompilerFilter::kSpaceProfile, "space-profile"); |
| 48 | TestCompilerFilterName(CompilerFilter::kSpace, "space"); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 49 | TestCompilerFilterName(CompilerFilter::kSpeedProfile, "speed-profile"); |
| 50 | TestCompilerFilterName(CompilerFilter::kSpeed, "speed"); |
| 51 | TestCompilerFilterName(CompilerFilter::kEverythingProfile, "everything-profile"); |
| 52 | TestCompilerFilterName(CompilerFilter::kEverything, "everything"); |
| 53 | |
| 54 | EXPECT_FALSE(CompilerFilter::ParseCompilerFilter("super-awesome-filter", &filter)); |
| 55 | } |
| 56 | |
Nicolas Geoffray | 741d426 | 2017-05-03 13:08:36 +0100 | [diff] [blame] | 57 | TEST(CompilerFilterTest, SafeModeFilter) { |
| 58 | TestSafeModeFilter(CompilerFilter::kAssumeVerified, "assume-verified"); |
| 59 | TestSafeModeFilter(CompilerFilter::kExtract, "extract"); |
| 60 | TestSafeModeFilter(CompilerFilter::kVerify, "verify"); |
| 61 | TestSafeModeFilter(CompilerFilter::kQuicken, "quicken"); |
| 62 | TestSafeModeFilter(CompilerFilter::kQuicken, "space-profile"); |
| 63 | TestSafeModeFilter(CompilerFilter::kQuicken, "space"); |
| 64 | TestSafeModeFilter(CompilerFilter::kQuicken, "speed-profile"); |
| 65 | TestSafeModeFilter(CompilerFilter::kQuicken, "speed"); |
| 66 | TestSafeModeFilter(CompilerFilter::kQuicken, "everything-profile"); |
| 67 | TestSafeModeFilter(CompilerFilter::kQuicken, "everything"); |
| 68 | } |
| 69 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 70 | } // namespace art |