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.pts.opengl.reference; 15 16 import com.android.pts.opengl.GLActivityIntentKeys; 17 import com.android.pts.util.PtsActivityInstrumentationTestCase2; 18 import com.android.pts.util.ResultType; 19 import com.android.pts.util.ResultUnit; 20 21 import android.content.Context; 22 import android.content.Intent; 23 import android.cts.util.TimeoutReq; 24 import android.view.Display; 25 import android.view.WindowManager; 26 27 import java.util.Arrays; 28 29 /** 30 * Runs the Reference OpenGL ES 2.0 Benchmark. 31 */ 32 public class GLReferenceBenchmark extends PtsActivityInstrumentationTestCase2<GLReferenceActivity> { 33 34 private static final int NUM_FRAMES_PER_SCENE = 500; 35 private static final int NUM_SCENES = 2; 36 private static final int NUM_FRAMES = NUM_FRAMES_PER_SCENE * NUM_SCENES; 37 private static final int TIMEOUT = 1000000; 38 39 public GLReferenceBenchmark() { 40 super(GLReferenceActivity.class); 41 } 42 43 /** 44 * Runs the reference benchmark. 45 */ 46 @TimeoutReq(minutes = 30) 47 public void testReferenceBenchmark() throws Exception { 48 Intent intent = new Intent(); 49 intent.putExtra(GLActivityIntentKeys.INTENT_EXTRA_NUM_FRAMES, NUM_FRAMES); 50 intent.putExtra(GLActivityIntentKeys.INTENT_EXTRA_TIMEOUT, TIMEOUT); 51 52 GLReferenceActivity activity = null; 53 setActivityIntent(intent); 54 activity = getActivity(); 55 if (activity != null) { 56 activity.waitForCompletion(); 57 double totalTime = 0; 58 if (activity.mSuccess) { 59 double[] setUpTimes = activity.mSetUpTimes; 60 double[] updateTimes = activity.mUpdateTimes; 61 double[] renderTimes = activity.mRenderTimes; 62 63 // Calculate update and render average. 64 double updateSum = updateTimes[0]; 65 double renderSum = renderTimes[0]; 66 for (int i = 0; i < NUM_FRAMES - 1; i++) { 67 updateSum += updateTimes[i + 1]; 68 renderSum += renderTimes[i + 1]; 69 } 70 double updateAverage = updateSum / NUM_FRAMES; 71 double renderAverage = renderSum / NUM_FRAMES; 72 73 /* Held back for now 74 getReportLog().printArray( 75 "Set Up Times", setUpTimes, ResultType.LOWER_BETTER, ResultUnit.MS); 76 getReportLog().printArray( 77 "Update Times", updateTimes, ResultType.LOWER_BETTER, ResultUnit.MS); 78 getReportLog().printValue( 79 "Update Time Average", updateAverage, ResultType.LOWER_BETTER, 80 ResultUnit.MS); 81 getReportLog().printArray( 82 "Render Times", renderTimes, ResultType.LOWER_BETTER, ResultUnit.MS); 83 getReportLog().printValue( 84 "Render Time Average", renderAverage, ResultType.LOWER_BETTER, 85 ResultUnit.MS); 86 totalTime = setUpTimes[0] + setUpTimes[1] + setUpTimes[2] + 87 setUpTimes[3] + updateAverage + renderAverage; 88 */ 89 } else { 90 // TODO benchmark failed to run 91 } 92 /* 93 getReportLog().printSummary( 94 "Total Time", totalTime, ResultType.LOWER_BETTER, ResultUnit.MS); 95 */ 96 } 97 } 98 } 99