• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package com.android.game.qualification.metric;
17 
18 import static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.assertFalse;
20 import static org.junit.Assert.assertTrue;
21 import static org.junit.Assert.fail;
22 
23 import com.android.game.qualification.ApkInfo;
24 import com.android.tradefed.device.metric.DeviceMetricData;
25 
26 import org.junit.Before;
27 import org.junit.Test;
28 
29 import java.util.Collections;
30 import java.util.List;
31 
32 /** Test for {@link GameQualificationFpsCollector}. */
33 public class GameQualificationFpsCollectorTest {
34     private static final String VSYNC = "16666666";
35 
36     private static final ApkInfo APK = new ApkInfo(
37             "foo",
38             "foo.apk",
39             "com.foo",
40             null,
41             "Surface View - com.foo#0",
42             null,
43             Collections.emptyList(),
44             10000,
45             10000,
46             true);
47 
48     private GameQualificationFpsCollector mCollector;
49 
50     @Before
setUp()51     public void setUp() {
52         mCollector = new GameQualificationFpsCollector();
53         mCollector.setApkInfo(APK);
54         mCollector.enable();
55     }
56 
57     @Test
basic()58     public void basic() {
59         mCollector.doStart(new DeviceMetricData(null));
60         assertTrue(mCollector.hasError());
61 
62         mCollector.processRawData(new String[]{VSYNC, "1\t2\t3", "4\t5\t6"});
63         List<GameQualificationMetric> metrics = mCollector.getElapsedTimes();
64         assertFalse(mCollector.hasError());
65         assertEquals(2, metrics.get(0).getActualPresentTime());
66         assertEquals(3, metrics.get(0).getFrameReadyTime());
67 
68         assertEquals(5, metrics.get(1).getActualPresentTime());
69         assertEquals(6, metrics.get(1).getFrameReadyTime());
70 
71         mCollector.processRawData(new String[]{VSYNC, "7\t8\t9"});
72         assertEquals(8, metrics.get(2).getActualPresentTime());
73         assertEquals(9, metrics.get(2).getFrameReadyTime());
74     }
75 
76     @Test
appTerminated()77     public void appTerminated() {
78         mCollector.doStart(new DeviceMetricData(null));
79 
80         mCollector.processRawData(new String[]{VSYNC, "1\t2\t3"});
81         assertFalse(mCollector.hasError());
82         try {
83             // If layer does not exist, dumpsys contains a single
84             mCollector.processRawData(new String[]{VSYNC});
85             fail("expected exception");
86         } catch (RuntimeException e){
87             // Do nothing.
88         }
89     }
90 
91     @Test
regexPattern()92     public void regexPattern() {
93         ApkInfo apk = new ApkInfo(
94                 "foo",
95                 "foo.apk",
96                 "com.foo",
97                 null,
98                 "*Invalid pattern",
99                 null,
100                 Collections.emptyList(),
101                 10000,
102                 10000,
103                 true);
104         mCollector.setApkInfo(apk);
105         try {
106             mCollector.doStart(new DeviceMetricData(null));
107             fail("expected exception");
108         } catch (RuntimeException e){
109             // Do nothing.
110         }
111     }
112 }