| /* |
| * Copyright (C) 2013 The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
| * in compliance with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software distributed under the License |
| * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| * or implied. See the License for the specific language governing permissions and limitations under |
| * the License. |
| */ |
| package com.android.pts.opengl.reference; |
| |
| import com.android.pts.opengl.GLActivityIntentKeys; |
| import com.android.pts.util.PtsActivityInstrumentationTestCase2; |
| import com.android.pts.util.ResultType; |
| import com.android.pts.util.ResultUnit; |
| |
| import android.content.Context; |
| import android.content.Intent; |
| import android.cts.util.TimeoutReq; |
| import android.view.Display; |
| import android.view.WindowManager; |
| |
| import java.util.Arrays; |
| |
| /** |
| * Runs the Reference OpenGL ES 2.0 Benchmark. |
| */ |
| public class GLReferenceBenchmark extends PtsActivityInstrumentationTestCase2<GLReferenceActivity> { |
| |
| private static final int NUM_FRAMES_PER_SCENE = 500; |
| private static final int NUM_SCENES = 2; |
| private static final int NUM_FRAMES = NUM_FRAMES_PER_SCENE * NUM_SCENES; |
| private static final int TIMEOUT = 1000000; |
| |
| public GLReferenceBenchmark() { |
| super(GLReferenceActivity.class); |
| } |
| |
| /** |
| * Runs the reference benchmark. |
| */ |
| @TimeoutReq(minutes = 30) |
| public void testReferenceBenchmark() throws Exception { |
| Intent intent = new Intent(); |
| intent.putExtra(GLActivityIntentKeys.INTENT_EXTRA_NUM_FRAMES, NUM_FRAMES); |
| intent.putExtra(GLActivityIntentKeys.INTENT_EXTRA_TIMEOUT, TIMEOUT); |
| |
| setActivityIntent(intent); |
| GLReferenceActivity activity = getActivity(); |
| if (activity != null) { |
| activity.waitForCompletion(); |
| double totalTime = 0; |
| if (activity.mSuccess) { |
| double[] setUpTimes = activity.mSetUpTimes; |
| double[] updateTimes = activity.mUpdateTimes; |
| double[] renderTimes = activity.mRenderTimes; |
| |
| // Calculate update and render average. |
| double updateSum = updateTimes[0]; |
| double renderSum = renderTimes[0]; |
| for (int i = 0; i < NUM_FRAMES - 1; i++) { |
| updateSum += updateTimes[i + 1]; |
| renderSum += renderTimes[i + 1]; |
| } |
| double updateAverage = updateSum / NUM_FRAMES; |
| double renderAverage = renderSum / NUM_FRAMES; |
| |
| /* Held back for now |
| getReportLog().printArray( |
| "Set Up Times", setUpTimes, ResultType.LOWER_BETTER, ResultUnit.MS); |
| getReportLog().printArray( |
| "Update Times", updateTimes, ResultType.LOWER_BETTER, ResultUnit.MS); |
| getReportLog().printValue( |
| "Update Time Average", updateAverage, ResultType.LOWER_BETTER, |
| ResultUnit.MS); |
| getReportLog().printArray( |
| "Render Times", renderTimes, ResultType.LOWER_BETTER, ResultUnit.MS); |
| getReportLog().printValue( |
| "Render Time Average", renderAverage, ResultType.LOWER_BETTER, |
| ResultUnit.MS); |
| totalTime = setUpTimes[0] + setUpTimes[1] + setUpTimes[2] + |
| setUpTimes[3] + updateAverage + renderAverage; |
| */ |
| } else { |
| // TODO benchmark failed to run |
| } |
| /* |
| getReportLog().printSummary( |
| "Total Time", totalTime, ResultType.LOWER_BETTER, ResultUnit.MS); |
| */ |
| } |
| } |
| } |