blob: 9b4f845b2c52b2d4ee70dd6e182bcb242a68ef19 [file] [log] [blame]
Andreas Gampe29d38e72016-03-23 15:31:51 +00001/*
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
21namespace art {
22
Andreas Gampe641a4732017-08-24 13:21:35 -070023static void TestCompilerFilterName(CompilerFilter::Filter filter, const std::string& name) {
Andreas Gampe29d38e72016-03-23 15:31:51 +000024 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 Gampe641a4732017-08-24 13:21:35 -070031static void TestSafeModeFilter(CompilerFilter::Filter expected, const std::string& name) {
Nicolas Geoffray741d4262017-05-03 13:08:36 +010032 CompilerFilter::Filter parsed;
33 EXPECT_TRUE(CompilerFilter::ParseCompilerFilter(name.c_str(), &parsed));
34 EXPECT_EQ(expected, CompilerFilter::GetSafeModeFilterFrom(parsed));
35}
36
37
Andreas Gampe29d38e72016-03-23 15:31:51 +000038// Verify the dexopt status values from dalvik.system.DexFile
39// match the OatFileAssistant::DexOptStatus values.
40TEST(CompilerFilterTest, ParseCompilerFilter) {
41 CompilerFilter::Filter filter;
42
Nicolas Geoffray49cda062017-04-21 13:08:25 +010043 TestCompilerFilterName(CompilerFilter::kAssumeVerified, "assume-verified");
44 TestCompilerFilterName(CompilerFilter::kExtract, "extract");
45 TestCompilerFilterName(CompilerFilter::kVerify, "verify");
46 TestCompilerFilterName(CompilerFilter::kQuicken, "quicken");
Andreas Gampe29d38e72016-03-23 15:31:51 +000047 TestCompilerFilterName(CompilerFilter::kSpaceProfile, "space-profile");
48 TestCompilerFilterName(CompilerFilter::kSpace, "space");
Andreas Gampe29d38e72016-03-23 15:31:51 +000049 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 Geoffray741d4262017-05-03 13:08:36 +010057TEST(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 Gampe29d38e72016-03-23 15:31:51 +000070} // namespace art