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
17package com.android.perftest;
18
19import android.app.Instrumentation;
20import android.content.Context;
21import android.content.Intent;
22import android.net.Uri;
23import android.test.ActivityInstrumentationTestCase2;
24import android.test.TouchUtils;
25import android.test.suitebuilder.annotation.LargeTest;
26import 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 */
34public 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