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

Commit f6244d1c authored by Xia Wang's avatar Xia Wang
Browse files

Integrate ImageProcessing test into test framework

http://b/issue?id=5274365
Change-Id: I7949b4114dcab17d895d04755df5df2bd5a576a3
parent 8ec83219
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -17,7 +17,9 @@
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)
+7 −1
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@
    <uses-sdk android:minSdkVersion="11" />
    <application android:label="Image Processing"
                 android:hardwareAccelerated="true">
        <uses-library android:name="android.test.runner" />
        <activity android:name="ImageProcessingActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
@@ -13,4 +14,9 @@
            </intent-filter>
        </activity>
    </application>

    <instrumentation android:name=".ImageProcessingTestRunner"
      android:targetPackage="com.android.rs.image"
      android:label="Test runner for Image Processing Benchmark Test"
    />
</manifest>
+13 −7
Original line number Diff line number Diff line
@@ -33,11 +33,13 @@ import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;
import android.view.View;
import android.util.Log;
import java.lang.Math;

public class ImageProcessingActivity extends Activity
                                       implements SurfaceHolder.Callback,
                                       SeekBar.OnSeekBarChangeListener {
    private final String TAG = "Img";
    private Bitmap mBitmapIn;
    private Bitmap mBitmapOut;
    private ScriptC_threshold mScript;
@@ -268,7 +270,15 @@ public class ImageProcessingActivity extends Activity

    // button hook
    public void benchmark(View v) {
        android.util.Log.v("Img", "Benchmarking");
        long t = getBenchmark();
        //long javaTime = javaFilter();
        //mBenchmarkResult.setText("RS: " + t + " ms  Java: " + javaTime + " ms");
        mBenchmarkResult.setText("Result: " + t + " ms");
    }

    // For benchmark test
    public long getBenchmark() {
        Log.v(TAG, "Benchmarking");
        int oldRadius = mRadius;
        mRadius = MAX_RADIUS;
        mScript.set_radius(mRadius);
@@ -279,16 +289,12 @@ public class ImageProcessingActivity extends Activity
        mOutPixelsAllocation.copyTo(mBitmapOut);

        t = java.lang.System.currentTimeMillis() - t;
        android.util.Log.v("Img", "Renderscript frame time core ms " + t);

        //long javaTime = javaFilter();
        //mBenchmarkResult.setText("RS: " + t + " ms  Java: " + javaTime + " ms");
        mBenchmarkResult.setText("Result: " + t + " ms");

        Log.v(TAG, "getBenchmark: Renderscript frame time core ms " + t);
        mRadius = oldRadius;
        mScript.set_radius(mRadius);

        mScript.invoke_filter();
        mOutPixelsAllocation.copyTo(mBitmapOut);
        return t;
    }
}
+86 −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.rs.image;

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

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

/**
 * ImageProcessing benchmark test.
 * To run the test, please use command
 *
 * adb shell am instrument -w com.android.rs.image/.ImageProcessingTestRunner
 *
 */
public class ImageProcessingTest extends ActivityInstrumentationTestCase2<ImageProcessingActivity> {
    private final String TAG = "ImageProcessingTest";
    private final String RESULT_FILE = "image_processing_result.txt";
    private ImageProcessingActivity mAct;

    public ImageProcessingTest() {
        super(ImageProcessingActivity.class);
    }

    @Override
    public void setUp() throws Exception {
        super.setUp();
        mAct = getActivity();
   }

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

    /**
     * ImageProcessing benchmark test
     */
    @LargeTest
    public void testImageProcessingBench() {
        long t = mAct.getBenchmark();
        Log.v(TAG, "t = " + t);

        // write result into a file
        File externalStorage = Environment.getExternalStorageDirectory();
        if (!externalStorage.canWrite()) {
            Log.v(TAG, "sdcard is not writable");
            return;
        }
        File resultFile = new File(externalStorage, RESULT_FILE);
        resultFile.setWritable(true, false);
        try {
            BufferedWriter results = new BufferedWriter(new FileWriter(resultFile));
            results.write("Renderscript frame time core: " + t + " ms");
            results.close();
            Log.v(TAG, "Saved results in: " + resultFile.getAbsolutePath());
        } catch (IOException e) {
            Log.v(TAG, "Unable to write result file " + e.getMessage());
        }
    }
}
+37 −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.rs.image;

import com.android.rs.image.ImageProcessingTest;
import android.os.Bundle;
import android.test.InstrumentationTestRunner;
import android.test.InstrumentationTestSuite;
import junit.framework.TestSuite;

/**
 * Run the ImageProcessing benchmark test
 * adb shell am instrument -w com.android.rs.image/.ImageProcessingTestRunner
 *
 */
public class ImageProcessingTestRunner extends InstrumentationTestRunner {
    @Override
    public TestSuite getAllTests() {
        TestSuite suite = new InstrumentationTestSuite(this);
        suite.addTestSuite(ImageProcessingTest.class);
        return suite;
    }
}