Skip to content

Commit f6244d1

Browse files
author
Xia Wang
committed
Integrate ImageProcessing test into test framework
http://b/issue?id=5274365 Change-Id: I7949b4114dcab17d895d04755df5df2bd5a576a3
1 parent 8ec8321 commit f6244d1

File tree

5 files changed

+146
-9
lines changed

5 files changed

+146
-9
lines changed

tests/RenderScriptTests/ImageProcessing/Android.mk

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
LOCAL_PATH := $(call my-dir)
1818
include $(CLEAR_VARS)
1919

20-
LOCAL_MODULE_TAGS := optional
20+
LOCAL_MODULE_TAGS := tests
21+
22+
LOCAL_JAVA_LIBRARIES := android.test.runner
2123

2224
LOCAL_SRC_FILES := $(call all-java-files-under, src) \
2325
$(call all-renderscript-files-under, src)

tests/RenderScriptTests/ImageProcessing/AndroidManifest.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,21 @@
22

33
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
44
package="com.android.rs.image">
5-
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
5+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
66
<uses-sdk android:minSdkVersion="11" />
77
<application android:label="Image Processing"
88
android:hardwareAccelerated="true">
9+
<uses-library android:name="android.test.runner" />
910
<activity android:name="ImageProcessingActivity">
1011
<intent-filter>
1112
<action android:name="android.intent.action.MAIN" />
1213
<category android:name="android.intent.category.LAUNCHER" />
1314
</intent-filter>
1415
</activity>
1516
</application>
17+
18+
<instrumentation android:name=".ImageProcessingTestRunner"
19+
android:targetPackage="com.android.rs.image"
20+
android:label="Test runner for Image Processing Benchmark Test"
21+
/>
1622
</manifest>

tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@
3333
import android.widget.SeekBar;
3434
import android.widget.TextView;
3535
import android.view.View;
36+
import android.util.Log;
3637
import java.lang.Math;
3738

3839
public class ImageProcessingActivity extends Activity
3940
implements SurfaceHolder.Callback,
4041
SeekBar.OnSeekBarChangeListener {
42+
private final String TAG = "Img";
4143
private Bitmap mBitmapIn;
4244
private Bitmap mBitmapOut;
4345
private ScriptC_threshold mScript;
@@ -268,7 +270,15 @@ private static Bitmap copyBitmap(Bitmap source) {
268270

269271
// button hook
270272
public void benchmark(View v) {
271-
android.util.Log.v("Img", "Benchmarking");
273+
long t = getBenchmark();
274+
//long javaTime = javaFilter();
275+
//mBenchmarkResult.setText("RS: " + t + " ms Java: " + javaTime + " ms");
276+
mBenchmarkResult.setText("Result: " + t + " ms");
277+
}
278+
279+
// For benchmark test
280+
public long getBenchmark() {
281+
Log.v(TAG, "Benchmarking");
272282
int oldRadius = mRadius;
273283
mRadius = MAX_RADIUS;
274284
mScript.set_radius(mRadius);
@@ -279,16 +289,12 @@ public void benchmark(View v) {
279289
mOutPixelsAllocation.copyTo(mBitmapOut);
280290

281291
t = java.lang.System.currentTimeMillis() - t;
282-
android.util.Log.v("Img", "Renderscript frame time core ms " + t);
283-
284-
//long javaTime = javaFilter();
285-
//mBenchmarkResult.setText("RS: " + t + " ms Java: " + javaTime + " ms");
286-
mBenchmarkResult.setText("Result: " + t + " ms");
287-
292+
Log.v(TAG, "getBenchmark: Renderscript frame time core ms " + t);
288293
mRadius = oldRadius;
289294
mScript.set_radius(mRadius);
290295

291296
mScript.invoke_filter();
292297
mOutPixelsAllocation.copyTo(mBitmapOut);
298+
return t;
293299
}
294300
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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.rs.image;
18+
19+
import android.os.Bundle;
20+
import android.os.Environment;
21+
import android.app.Instrumentation;
22+
import android.content.Context;
23+
import android.content.Intent;
24+
import android.net.Uri;
25+
import android.test.ActivityInstrumentationTestCase2;
26+
import android.test.suitebuilder.annotation.LargeTest;
27+
import android.util.Log;
28+
29+
import java.io.BufferedWriter;
30+
import java.io.File;
31+
import java.io.FileWriter;
32+
import java.io.IOException;
33+
34+
/**
35+
* ImageProcessing benchmark test.
36+
* To run the test, please use command
37+
*
38+
* adb shell am instrument -w com.android.rs.image/.ImageProcessingTestRunner
39+
*
40+
*/
41+
public class ImageProcessingTest extends ActivityInstrumentationTestCase2<ImageProcessingActivity> {
42+
private final String TAG = "ImageProcessingTest";
43+
private final String RESULT_FILE = "image_processing_result.txt";
44+
private ImageProcessingActivity mAct;
45+
46+
public ImageProcessingTest() {
47+
super(ImageProcessingActivity.class);
48+
}
49+
50+
@Override
51+
public void setUp() throws Exception {
52+
super.setUp();
53+
mAct = getActivity();
54+
}
55+
56+
@Override
57+
public void tearDown() throws Exception {
58+
super.tearDown();
59+
}
60+
61+
/**
62+
* ImageProcessing benchmark test
63+
*/
64+
@LargeTest
65+
public void testImageProcessingBench() {
66+
long t = mAct.getBenchmark();
67+
Log.v(TAG, "t = " + t);
68+
69+
// write result into a file
70+
File externalStorage = Environment.getExternalStorageDirectory();
71+
if (!externalStorage.canWrite()) {
72+
Log.v(TAG, "sdcard is not writable");
73+
return;
74+
}
75+
File resultFile = new File(externalStorage, RESULT_FILE);
76+
resultFile.setWritable(true, false);
77+
try {
78+
BufferedWriter results = new BufferedWriter(new FileWriter(resultFile));
79+
results.write("Renderscript frame time core: " + t + " ms");
80+
results.close();
81+
Log.v(TAG, "Saved results in: " + resultFile.getAbsolutePath());
82+
} catch (IOException e) {
83+
Log.v(TAG, "Unable to write result file " + e.getMessage());
84+
}
85+
}
86+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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.rs.image;
18+
19+
import com.android.rs.image.ImageProcessingTest;
20+
import android.os.Bundle;
21+
import android.test.InstrumentationTestRunner;
22+
import android.test.InstrumentationTestSuite;
23+
import junit.framework.TestSuite;
24+
25+
/**
26+
* Run the ImageProcessing benchmark test
27+
* adb shell am instrument -w com.android.rs.image/.ImageProcessingTestRunner
28+
*
29+
*/
30+
public class ImageProcessingTestRunner extends InstrumentationTestRunner {
31+
@Override
32+
public TestSuite getAllTests() {
33+
TestSuite suite = new InstrumentationTestSuite(this);
34+
suite.addTestSuite(ImageProcessingTest.class);
35+
return suite;
36+
}
37+
}

0 commit comments

Comments
 (0)