Home | History | Annotate | Download | only in perftest
      1 /*
      2  * Copyright (C) 2011 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 
     17 package com.android.perftest;
     18 
     19 import android.app.Instrumentation;
     20 import android.content.Context;
     21 import android.content.Intent;
     22 import android.net.Uri;
     23 import android.test.ActivityInstrumentationTestCase2;
     24 import android.test.TouchUtils;
     25 import android.test.suitebuilder.annotation.LargeTest;
     26 import android.util.Log;
     27 
     28 /**
     29  * To run the test, please use command
     30  *
     31  * adb shell am instrument -w com.android.perftest/.RsPerfTestRunner
     32  *
     33  */
     34 public class RsBenchTest extends ActivityInstrumentationTestCase2<RsBench> {
     35     private String TAG = "RsBenchTest";
     36     private int iterations = 0;
     37     private RsBench mAct;
     38 
     39     public RsBenchTest() {
     40         super(RsBench.class);
     41     }
     42 
     43     @Override
     44     public void setUp() throws Exception {
     45         super.setUp();
     46         Instrumentation mInst = getInstrumentation();
     47         RsPerfTestRunner mRunner = (RsPerfTestRunner) getInstrumentation();
     48         iterations = mRunner.iterations;
     49         Log.v(TAG, "Run benchmark for " + iterations + " iterations.");
     50 
     51         Uri data = Uri.fromParts("iterations", Integer.toString(iterations), null);
     52         Intent intent = new Intent(Intent.ACTION_MAIN);
     53         intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
     54         intent.setClassName("com.android.perftest", "com.android.perftest.RsBench");
     55         intent.setData(data);
     56         mAct = (RsBench) mInst.startActivitySync(intent);
     57         mInst.waitForIdleSync();
     58 
     59     }
     60 
     61     @Override
     62     public void tearDown() throws Exception {
     63         mAct.finish();
     64         super.tearDown();
     65     }
     66 
     67     /**
     68      * Run tests and wait until the test has been run for iterations.
     69      */
     70     @LargeTest
     71     public void testRsBench() {
     72         if (mAct.mView.testIsFinished()) {
     73             return;
     74         } else {
     75             fail("test didn't stop correctly");
     76         }
     77     }
     78 }
     79