Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2738fb1c authored by Xia Wang's avatar Xia Wang
Browse files

- Add instrumentation utility to automate rs performance tests:

  The RsBench test activity can be launched within instrumentation

- Provide parameter to control test run:
  set the maximum number of loops from test runner,
  the script will send out a message after the test loops exceeds the maxium number

Change-Id: I5fba0543094ef7a8b5eaa6ff9a04367d272b4d65
parent a13802d8
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -19,7 +19,9 @@ ifneq ($(TARGET_SIMULATOR),true)
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_TAGS := tests

LOCAL_JAVA_LIBRARIES := android.test.runner

LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-renderscript-files-under, src)
#LOCAL_STATIC_JAVA_LIBRARIES := android.renderscript
+8 −2
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@
    <uses-sdk android:minSdkVersion="11" />
    <application android:label="PerfTest"
      android:icon="@drawable/test_pattern">
        <uses-library android:name="android.test.runner" />
        <activity android:name="RsBench"
                  android:label="RsBenchmark"
                  android:theme="@android:style/Theme.Black.NoTitleBar">
@@ -13,4 +14,9 @@
            </intent-filter>
        </activity>
      </application>

      <instrumentation android:name=".RsPerfTestRunner"
        android:targetPackage="com.android.perftest"
        android:label="Test runner for RsBench tests"
      />
</manifest>
+15 −5
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ import android.renderscript.RenderScript;

import android.app.Activity;
import android.content.res.Configuration;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
@@ -37,17 +39,27 @@ import android.widget.ListView;
import java.lang.Runtime;

public class RsBench extends Activity {

    private RsBenchView mView;
    private final String TAG = "RsBench";
    public RsBenchView mView;

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);

        int iterations = 0;
        Intent intent = getIntent();
        Uri uri = intent.getData();
        if (uri != null) {
            // when lauched from instrumentation
            String scheme = uri.getScheme();
            if ("iterations".equals(scheme)) {
                iterations = Integer.parseInt(uri.getSchemeSpecificPart());
            }
        }
        // Create our Preview view and set it as the content of our
        // Activity
        mView = new RsBenchView(this);
        setContentView(mView);
        mView.setLoops(iterations);
    }

    @Override
@@ -65,6 +77,4 @@ public class RsBench extends Activity {
        super.onPause();
        mView.pause();
    }

}
+45 −4
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.renderscript.Program.TextureType;
import android.renderscript.ProgramStore.DepthFunc;
import android.renderscript.ProgramStore.BlendSrcFunc;
import android.renderscript.ProgramStore.BlendDstFunc;
import android.renderscript.RenderScript.RSMessageHandler;
import android.renderscript.Sampler.Value;
import android.util.Log;

@@ -37,11 +38,12 @@ public class RsBenchRS {

    int mWidth;
    int mHeight;
    int mLoops;

    public RsBenchRS() {
    }

    public void init(RenderScriptGL rs, Resources res, int width, int height) {
    public void init(RenderScriptGL rs, Resources res, int width, int height, int loops) {
        mRS = rs;
        mRes = res;
        mWidth = width;
@@ -50,9 +52,12 @@ public class RsBenchRS {
        mOptionsARGB.inPreferredConfig = Bitmap.Config.ARGB_8888;
        mMode = 0;
        mMaxModes = 0;
        mLoops = loops;
        initRS();
    }

    private boolean stopTest = false;

    private Resources mRes;
    private RenderScriptGL mRS;

@@ -121,6 +126,43 @@ public class RsBenchRS {
        mScript.set_gDisplayMode(mMode);
    }

    /**
     * Create a message handler to handle message sent from the script
     */
    protected RSMessageHandler mRsMessage = new RSMessageHandler() {
        public void run() {
            if (mID == mScript.get_RS_MSG_TEST_DONE()) {
                synchronized(this) {
                    stopTest = true;
                    this.notifyAll();
                }
                return;
            } else {
                Log.v("RsBenchRS", "Perf test got unexpected message");
                return;
            }
        }
    };

    /**
     * Wait for message from the script
     */
    public boolean testIsFinished() {
        synchronized(this) {
            while (true) {
                if (stopTest) {
                    return true;
                } else {
                    try {
                        this.wait(60*1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }

    ProgramStore BLEND_ADD_DEPTH_NONE(RenderScript rs) {
        ProgramStore.Builder builder = new ProgramStore.Builder(rs);
        builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
@@ -388,8 +430,10 @@ public class RsBenchRS {
    private void initRS() {

        mScript = new ScriptC_rsbench(mRS, mRes, R.raw.rsbench);
        mRS.setMessageHandler(mRsMessage);

        mMaxModes = mScript.get_gMaxModes();
        mScript.set_gMaxLoops(mLoops);

        initSamplers();
        initProgramStore();
@@ -421,6 +465,3 @@ public class RsBenchRS {
        mRS.bindRootScript(mScript);
    }
}


+78 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2011 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.perftest;

import android.app.Instrumentation;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.test.ActivityInstrumentationTestCase2;
import android.test.TouchUtils;
import android.test.suitebuilder.annotation.LargeTest;
import android.util.Log;

/**
 * To run the test, please use command
 *
 * adb shell am instrument -w com.android.perftest/.RsPerfTestRunner
 *
 */
public class RsBenchTest extends ActivityInstrumentationTestCase2<RsBench> {
    private String TAG = "RsBenchTest";
    private int iterations = 0;
    private RsBench mAct;

    public RsBenchTest() {
        super(RsBench.class);
    }

    @Override
    public void setUp() throws Exception {
        super.setUp();
        Instrumentation mInst = getInstrumentation();
        RsPerfTestRunner mRunner = (RsPerfTestRunner) getInstrumentation();
        iterations = mRunner.iterations;
        Log.v(TAG, "Run benchmark for " + iterations + " iterations.");

        Uri data = Uri.fromParts("iterations", Integer.toString(iterations), null);
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setClassName("com.android.perftest", "com.android.perftest.RsBench");
        intent.setData(data);
        mAct = (RsBench) mInst.startActivitySync(intent);
        mInst.waitForIdleSync();

    }

    @Override
    public void tearDown() throws Exception {
        mAct.finish();
        super.tearDown();
    }

    /**
     * Run tests and wait until the test has been run for iterations.
     */
    @LargeTest
    public void testRsBench() {
        if (mAct.mView.testIsFinished()) {
            return;
        } else {
            fail("test didn't stop correctly");
        }
    }
}
Loading