• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5  * in compliance with the License. You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the License
10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11  * or implied. See the License for the specific language governing permissions and limitations under
12  * the License.
13  */
14 package com.android.cts.opengl.primitive;
15 
16 import com.android.cts.opengl.GLActivityIntentKeys;
17 import android.cts.util.CtsActivityInstrumentationTestCase2;
18 import com.android.cts.util.ResultType;
19 import com.android.cts.util.ResultUnit;
20 
21 import android.content.Intent;
22 import com.android.cts.util.TimeoutReq;
23 
24 /**
25  * Runs the Primitive OpenGL ES 2.0 Benchmarks.
26  */
27 public class GLPrimitiveBenchmark extends CtsActivityInstrumentationTestCase2<GLPrimitiveActivity> {
28 
29     private static final int NUM_FRAMES = 100;
30     private static final int NUM_ITERATIONS = 8;
31     private static final int TIMEOUT = 1000000;
32 
GLPrimitiveBenchmark()33     public GLPrimitiveBenchmark() {
34         super(GLPrimitiveActivity.class);
35     }
36 
37     /**
38      * Runs the full OpenGL ES 2.0 pipeline test offscreen.
39      */
40     @TimeoutReq(minutes = 100)
testFullPipelineOffscreen()41     public void testFullPipelineOffscreen() throws Exception {
42         runBenchmark(BenchmarkName.FullPipeline, true, NUM_FRAMES, NUM_ITERATIONS, TIMEOUT);
43     }
44 
45     /**
46      * Runs the full OpenGL ES 2.0 pipeline test onscreen.
47      */
48     @TimeoutReq(minutes = 100)
testFullPipelineOnscreen()49     public void testFullPipelineOnscreen() throws Exception {
50         runBenchmark(BenchmarkName.FullPipeline, false, NUM_FRAMES, NUM_ITERATIONS, TIMEOUT);
51     }
52 
53     /**
54      * Runs the pixel output test offscreen.
55      */
56     @TimeoutReq(minutes = 100)
testPixelOutputOffscreen()57     public void testPixelOutputOffscreen() throws Exception {
58         runBenchmark(BenchmarkName.PixelOutput, true, NUM_FRAMES, NUM_ITERATIONS, TIMEOUT);
59     }
60 
61     /**
62      * Runs the pixel output test onscreen.
63      */
64     @TimeoutReq(minutes = 100)
testPixelOutputOnscreen()65     public void testPixelOutputOnscreen() throws Exception {
66         runBenchmark(BenchmarkName.PixelOutput, false, NUM_FRAMES, NUM_ITERATIONS, TIMEOUT);
67     }
68 
69     /**
70      * Runs the shader performance test offscreen.
71      */
72     @TimeoutReq(minutes = 100)
testShaderPerfOffscreen()73     public void testShaderPerfOffscreen() throws Exception {
74         runBenchmark(BenchmarkName.ShaderPerf, true, NUM_FRAMES, NUM_ITERATIONS, TIMEOUT);
75     }
76 
77     /**
78      * Runs the shader performance test onscreen.
79      */
80     @TimeoutReq(minutes = 100)
testShaderPerfOnscreen()81     public void testShaderPerfOnscreen() throws Exception {
82         runBenchmark(BenchmarkName.ShaderPerf, false, NUM_FRAMES, NUM_ITERATIONS, TIMEOUT);
83     }
84 
85     /**
86      * Runs the context switch overhead test offscreen.
87      */
88     @TimeoutReq(minutes = 100)
testContextSwitchOffscreen()89     public void testContextSwitchOffscreen() throws Exception {
90         runBenchmark(BenchmarkName.ContextSwitch, true, NUM_FRAMES, NUM_ITERATIONS, TIMEOUT);
91     }
92 
93     /**
94      * Runs the context switch overhead test onscreen.
95      */
96     @TimeoutReq(minutes = 100)
testContextSwitchOnscreen()97     public void testContextSwitchOnscreen() throws Exception {
98         runBenchmark(BenchmarkName.ContextSwitch, false, NUM_FRAMES, NUM_ITERATIONS, TIMEOUT);
99     }
100 
101     /**
102      * Runs the specified test.
103      *
104      * @param benchmark An enum representing the benchmark to run.
105      * @param offscreen Whether to render to an offscreen framebuffer rather than the screen.
106      * @param numFrames The number of frames to render.
107      * @param numIterations The number of iterations to run, each iteration has a bigger workload.
108      * @param timeout The milliseconds to wait for an iteration of the benchmark before timing out.
109      * @throws Exception If the benchmark could not be run.
110      */
runBenchmark(BenchmarkName benchmark, boolean offscreen, int numFrames, int numIterations, int timeout)111     private void runBenchmark(BenchmarkName benchmark, boolean offscreen, int numFrames,
112             int numIterations, int timeout) throws Exception {
113         String benchmarkName = benchmark.toString();
114         Intent intent = new Intent();
115         intent.putExtra(GLActivityIntentKeys.INTENT_EXTRA_BENCHMARK_NAME, benchmarkName);
116         intent.putExtra(GLActivityIntentKeys.INTENT_EXTRA_OFFSCREEN, offscreen);
117         intent.putExtra(GLActivityIntentKeys.INTENT_EXTRA_NUM_FRAMES, numFrames);
118         intent.putExtra(GLActivityIntentKeys.INTENT_EXTRA_NUM_ITERATIONS, numIterations);
119         intent.putExtra(GLActivityIntentKeys.INTENT_EXTRA_TIMEOUT, timeout);
120 
121         GLPrimitiveActivity activity = null;
122         setActivityIntent(intent);
123         activity = getActivity();
124         if (activity != null) {
125             activity.waitForCompletion();
126             double[] fpsValues = activity.mFpsValues;
127             double score = 0;
128             for (double d : fpsValues) {
129                 score += d;
130             }
131             score /= numIterations;// Average.
132 
133             // TODO: maybe standard deviation / RMSE will be useful?
134 
135             getReportLog().printArray(
136                     "Fps Values", fpsValues, ResultType.HIGHER_BETTER, ResultUnit.FPS);
137             getReportLog().printSummary(
138                     "Average Frames Per Second", score, ResultType.HIGHER_BETTER,
139                     ResultUnit.SCORE);
140         }
141     }
142 }
143