Debian Codegraph @

libartservice/service/javatests/com/android/server/art/ReasonMappingTest.java

raw
1 /*
2 * Copyright (C) 2022 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 package com.android.server.art;
18
19 import static com.google.common.truth.Truth.assertThat;
20
21 import static org.mockito.Mockito.anyInt;
22 import static org.mockito.Mockito.eq;
23 import static org.mockito.Mockito.when;
24
25 import android.os.SystemProperties;
26
27 import androidx.test.filters.SmallTest;
28 import androidx.test.runner.AndroidJUnit4;
29
30 import com.android.server.art.model.ArtFlags;
31 import com.android.server.art.testing.StaticMockitoRule;
32
33 import org.junit.Rule;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36
37 @SmallTest
38 @RunWith(AndroidJUnit4.class)
39 public class ReasonMappingTest {
40 @Rule public StaticMockitoRule mockitoRule = new StaticMockitoRule(SystemProperties.class);
41
42 @Test
43 public void testGetCompilerFilterForReason() {
44 when(SystemProperties.get("pm.dexopt.foo")).thenReturn("speed");
45 assertThat(ReasonMapping.getCompilerFilterForReason("foo")).isEqualTo("speed");
46 }
47
48 @Test(expected = IllegalStateException.class)
49 public void testGetCompilerFilterForReasonInvalidFilter() throws Exception {
50 when(SystemProperties.get("pm.dexopt.foo")).thenReturn("invalid-filter");
51 ReasonMapping.getCompilerFilterForReason("foo");
52 }
53
54 @Test(expected = IllegalArgumentException.class)
55 public void testGetCompilerFilterForReasonInvalidReason() throws Exception {
56 ReasonMapping.getCompilerFilterForReason("foo");
57 }
58
59 @Test
60 public void testGetCompilerFilterForShared() {
61 when(SystemProperties.get("pm.dexopt.shared")).thenReturn("speed");
62 assertThat(ReasonMapping.getCompilerFilterForShared()).isEqualTo("speed");
63 }
64
65 @Test(expected = IllegalStateException.class)
66 public void testGetCompilerFilterForSharedProfileGuidedFilter() throws Exception {
67 when(SystemProperties.get("pm.dexopt.shared")).thenReturn("speed-profile");
68 ReasonMapping.getCompilerFilterForShared();
69 }
70
71 @Test
72 public void testGetPriorityClassForReason() throws Exception {
73 assertThat(ReasonMapping.getPriorityClassForReason("install"))
74 .isEqualTo(ArtFlags.PRIORITY_INTERACTIVE);
75 }
76
77 @Test(expected = IllegalArgumentException.class)
78 public void testGetPriorityClassForReasonInvalidReason() throws Exception {
79 ReasonMapping.getPriorityClassForReason("foo");
80 }
81
82 @Test
83 public void testGetConcurrencyForReason() {
84 when(SystemProperties.getInt(eq("pm.dexopt.bg-dexopt.concurrency"), anyInt()))
85 .thenReturn(3);
86 assertThat(ReasonMapping.getConcurrencyForReason("bg-dexopt")).isEqualTo(3);
87 }
88 }