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 23 static void TestCompilerFilterName(CompilerFilter::Filter filter, const std::string& name) { 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 31 static void TestSafeModeFilter(CompilerFilter::Filter expected, const std::string& name) { 32 CompilerFilter::Filter parsed; 33 EXPECT_TRUE(CompilerFilter::ParseCompilerFilter(name.c_str(), &parsed)); 34 EXPECT_EQ(expected, CompilerFilter::GetSafeModeFilterFrom(parsed)); 35 } 36 37 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 43 TestCompilerFilterName(CompilerFilter::kAssumeVerified, "assume-verified"); 44 TestCompilerFilterName(CompilerFilter::kExtract, "extract"); 45 TestCompilerFilterName(CompilerFilter::kVerify, "verify"); 46 TestCompilerFilterName(CompilerFilter::kQuicken, "quicken"); 47 TestCompilerFilterName(CompilerFilter::kSpaceProfile, "space-profile"); 48 TestCompilerFilterName(CompilerFilter::kSpace, "space"); 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 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 70 } // namespace art 71