Home | History | Annotate | Download | only in reference
      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 android.opengl2.cts.reference;
     15 
     16 import android.content.Intent;
     17 import android.opengl2.cts.GLActivityIntentKeys;
     18 import android.test.ActivityInstrumentationTestCase2;
     19 
     20 import com.android.compatibility.common.util.DeviceReportLog;
     21 import com.android.compatibility.common.util.ResultType;
     22 import com.android.compatibility.common.util.ResultUnit;
     23 
     24 /**
     25  * Runs the Reference OpenGL ES 2.0 Benchmark.
     26  */
     27 public class GLReferenceBenchmark extends ActivityInstrumentationTestCase2<GLReferenceActivity> {
     28 
     29     private static final int NUM_FRAMES_PER_SCENE = 500;
     30     private static final int NUM_SCENES = 2;
     31     private static final int NUM_FRAMES = NUM_FRAMES_PER_SCENE * NUM_SCENES;
     32     private static final int TIMEOUT = 1000000;
     33     private static final String REPORT_LOG_NAME = "CtsOpenGlPerf2TestCases";
     34 
     35     public GLReferenceBenchmark() {
     36         super(GLReferenceActivity.class);
     37     }
     38 
     39     /**
     40      * Runs the reference benchmark.
     41      */
     42     public void testReferenceBenchmark() throws Exception {
     43         Intent intent = new Intent();
     44         intent.putExtra(GLActivityIntentKeys.INTENT_EXTRA_NUM_FRAMES, NUM_FRAMES);
     45         intent.putExtra(GLActivityIntentKeys.INTENT_EXTRA_TIMEOUT, TIMEOUT);
     46 
     47         GLReferenceActivity activity = null;
     48         setActivityIntent(intent);
     49         activity = getActivity();
     50         if (activity != null) {
     51             activity.waitForCompletion();
     52             double totalTime = 0;
     53             double[] setUpTimes = activity.mSetUpTimes;
     54             double[] updateTimes = activity.mUpdateTimes;
     55             double[] renderTimes = activity.mRenderTimes;
     56 
     57             // Calculate update and render average.
     58             double updateSum = updateTimes[0];
     59             double renderSum = renderTimes[0];
     60             for (int i = 0; i < NUM_FRAMES - 1; i++) {
     61                 updateSum += updateTimes[i + 1];
     62                 renderSum += renderTimes[i + 1];
     63             }
     64             double updateAverage = updateSum / NUM_FRAMES;
     65             double renderAverage = renderSum / NUM_FRAMES;
     66 
     67             String streamName = "test_reference_benchmark";
     68             DeviceReportLog report = new DeviceReportLog(REPORT_LOG_NAME, streamName);
     69             report.addValues("set_up_times", setUpTimes, ResultType.LOWER_BETTER, ResultUnit.MS);
     70             report.addValue("update_time_average", updateAverage, ResultType.LOWER_BETTER,
     71                     ResultUnit.MS);
     72             report.addValue("render_time_average", renderAverage, ResultType.LOWER_BETTER,
     73                     ResultUnit.MS);
     74             totalTime = setUpTimes[0] + setUpTimes[1] + setUpTimes[2] + setUpTimes[3] +
     75                     updateAverage + renderAverage;
     76             report.setSummary("total_time_average", totalTime, ResultType.LOWER_BETTER,
     77                     ResultUnit.MS);
     78             report.submit(getInstrumentation());
     79         }
     80     }
     81 }
     82