• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.imagejb;
18 
19 
20 import android.app.Activity;
21 import android.os.Bundle;
22 import android.os.Environment;
23 import android.test.ActivityInstrumentationTestCase2;
24 import android.test.suitebuilder.annotation.MediumTest;
25 import android.util.Log;
26 
27 import com.android.rs.imagejb.IPTestListJB.TestName;
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.imagejb/androidx.test.runner.AndroidJUnitRunner
39  *
40  */
41 public class ImageProcessingTest extends ActivityInstrumentationTestCase2<ImageProcessingActivityJB> {
42     private final String TAG = "ImageProcessingTest";
43     // Only run 1 iteration now to fit the MediumTest time requirement.
44     // One iteration means running the tests continuous for 1s.
45     private ImageProcessingActivityJB mActivity;
46 
ImageProcessingTest()47     public ImageProcessingTest() {
48         super(ImageProcessingActivityJB.class);
49     }
50 
51 
52     // Initialize the parameter for ImageProcessingActivityJB.
prepareTest()53     protected void prepareTest() {
54         mActivity = getActivity();
55         mActivity.prepareInstrumentationTest();
56     }
57 
58     @Override
setUp()59     public void setUp() throws Exception {
60         super.setUp();
61         prepareTest();
62         setActivityInitialTouchMode(false);
63    }
64 
65     @Override
tearDown()66     public void tearDown() throws Exception {
67         if (mActivity.mProcessor != null) {
68             mActivity.mProcessor.exit();
69             mActivity.mProcessor = null;
70         }
71         super.tearDown();
72     }
73 
74     class TestAction implements Runnable {
75         private TestName mTestName;
76         private Result mResult;
TestAction(TestName testName)77         public TestAction(TestName testName) {
78             mTestName = testName;
79         }
run()80         public void run() {
81             mResult = mActivity.mProcessor.getInstrumentationResult(mTestName);
82             Log.v(TAG, "Benchmark for test \"" + mTestName.toString() + "\" is: " +
83                     mResult.getAvg() * 1000.f);
84             synchronized(this) {
85                 this.notify();
86             }
87         }
getBenchmark()88         public Result getBenchmark() {
89             return mResult;
90         }
91     }
92 
93     // Set the benchmark thread to run on ui thread
94     // Synchronized the thread such that the test will wait for the benchmark thread to finish
runOnUiThread(Runnable action)95     public void runOnUiThread(Runnable action) {
96         synchronized(action) {
97             mActivity.runOnUiThread(action);
98             try {
99                 action.wait();
100             } catch (InterruptedException e) {
101                 Log.v(TAG, "waiting for action running on UI thread is interrupted: " +
102                         e.toString());
103             }
104         }
105     }
106 
107     // TODO: Report more info: mean, median, std, etc.
runTest(TestAction ta, String testName)108     public void runTest(TestAction ta, String testName) {
109         runOnUiThread(ta);
110         Result times = ta.getBenchmark();
111 
112         // post result to INSTRUMENTATION_STATUS
113         Bundle results = new Bundle();
114         results.putFloat(testName + "_avg", times.getAvg() * 1000.0f); // ms
115         results.putFloat(testName + "_stdevp", times.getStdevp() * 1000.0f); // ms
116         results.putFloat(testName + "_stdcoef", times.getStdCoef() * 100.0f); // %
117         getInstrumentation().sendStatus(Activity.RESULT_OK, results);
118 
119         // save the runtime distribution to a file on the sdcard so a script can plot it
120         writeResults("rsTimes/", testName + "_DATA.txt", times);
121     }
122 
writeResults(String directory, String filename, Result times)123     private void writeResults(String directory, String filename, Result times) {
124         // write result into a file
125         File externalStorage = Environment.getExternalStorageDirectory();
126         if (!externalStorage.canWrite()) {
127             Log.v(TAG, "sdcard is not writable");
128             return;
129         }
130         File resultDirectory = new File(externalStorage, directory);
131         resultDirectory.mkdirs();
132         File resultFile = new File(externalStorage, directory + filename);
133         resultFile.setWritable(true, false);
134         try {
135             BufferedWriter rsWriter = new BufferedWriter(new FileWriter(resultFile));
136             Log.v(TAG, "Saved results in: " + resultFile.getAbsolutePath());
137 
138             float[] datapoints = times.getTimes();
139             for (int i = 0; i < times.getIterations(); i++) {
140                 rsWriter.write(String.format("%d %f\n", i, datapoints[i] * 1000.0));
141             }
142             rsWriter.close();
143         } catch (IOException e) {
144             Log.v(TAG, "Unable to write result file " + e.getMessage());
145         }
146     }
147 
148     // Test case 0: Levels Vec3 Relaxed
149     @MediumTest
testLevelsVec3Relaxed()150     public void testLevelsVec3Relaxed() {
151         TestAction ta = new TestAction(TestName.LEVELS_VEC3_RELAXED);
152         runTest(ta, TestName.LEVELS_VEC3_RELAXED.name());
153     }
154 
155     // Test case 1: Levels Vec4 Relaxed
156     @MediumTest
testLevelsVec4Relaxed()157     public void testLevelsVec4Relaxed() {
158         TestAction ta = new TestAction(TestName.LEVELS_VEC4_RELAXED);
159         runTest(ta, TestName.LEVELS_VEC4_RELAXED.name());
160     }
161 
162     // Test case 2: Levels Vec3 Full
163     @MediumTest
testLevelsVec3Full()164     public void testLevelsVec3Full() {
165         TestAction ta = new TestAction(TestName.LEVELS_VEC3_FULL);
166         runTest(ta, TestName.LEVELS_VEC3_FULL.name());
167     }
168 
169     // Test case 3: Levels Vec4 Full
170     @MediumTest
testLevelsVec4Full()171     public void testLevelsVec4Full() {
172         TestAction ta = new TestAction(TestName.LEVELS_VEC4_FULL);
173         runTest(ta, TestName.LEVELS_VEC4_FULL.name());
174     }
175 
176     // Test case 4: Blur Radius 25
177     @MediumTest
testBlurRadius25()178     public void testBlurRadius25() {
179         TestAction ta = new TestAction(TestName.BLUR_RADIUS_25);
180         runTest(ta, TestName.BLUR_RADIUS_25.name());
181     }
182 
183     // Test case 5: Intrinsic Blur Radius 25
184     @MediumTest
testIntrinsicBlurRadius25()185     public void testIntrinsicBlurRadius25() {
186         TestAction ta = new TestAction(TestName.INTRINSIC_BLUR_RADIUS_25);
187         runTest(ta, TestName.INTRINSIC_BLUR_RADIUS_25.name());
188     }
189 
190     // Test case 6: Greyscale
191     @MediumTest
testGreyscale()192     public void testGreyscale() {
193         TestAction ta = new TestAction(TestName.GREYSCALE);
194         runTest(ta, TestName.GREYSCALE.name());
195     }
196 
197     // Test case 7: Grain
198     @MediumTest
testGrain()199     public void testGrain() {
200         TestAction ta = new TestAction(TestName.GRAIN);
201         runTest(ta, TestName.GRAIN.name());
202     }
203 
204     // Test case 8: Fisheye Full
205     @MediumTest
testFisheyeFull()206     public void testFisheyeFull() {
207         TestAction ta = new TestAction(TestName.FISHEYE_FULL);
208         runTest(ta, TestName.FISHEYE_FULL.name());
209     }
210 
211     // Test case 9: Fisheye Relaxed
212     @MediumTest
testFishEyeRelaxed()213     public void testFishEyeRelaxed() {
214         TestAction ta = new TestAction(TestName.FISHEYE_RELAXED);
215         runTest(ta, TestName.FISHEYE_RELAXED.name());
216     }
217 
218     // Test case 10: Fisheye Approximate Full
219     @MediumTest
testFisheyeApproximateFull()220     public void testFisheyeApproximateFull() {
221         TestAction ta = new TestAction(TestName.FISHEYE_APPROXIMATE_FULL);
222         runTest(ta, TestName.FISHEYE_APPROXIMATE_FULL.name());
223     }
224 
225     // Test case 11: Fisheye Approximate Relaxed
226     @MediumTest
testFisheyeApproximateRelaxed()227     public void testFisheyeApproximateRelaxed() {
228         TestAction ta = new TestAction(TestName.FISHEYE_APPROXIMATE_RELAXED);
229         runTest(ta, TestName.FISHEYE_APPROXIMATE_RELAXED.name());
230     }
231 
232     // Test case 12: Vignette Full
233     @MediumTest
testVignetteFull()234     public void testVignetteFull() {
235         TestAction ta = new TestAction(TestName.VIGNETTE_FULL);
236         runTest(ta, TestName.VIGNETTE_FULL.name());
237     }
238 
239     // Test case 13: Vignette Relaxed
240     @MediumTest
testVignetteRelaxed()241     public void testVignetteRelaxed() {
242         TestAction ta = new TestAction(TestName.VIGNETTE_RELAXED);
243         runTest(ta, TestName.VIGNETTE_RELAXED.name());
244     }
245 
246     // Test case 14: Vignette Approximate Full
247     @MediumTest
testVignetteApproximateFull()248     public void testVignetteApproximateFull() {
249         TestAction ta = new TestAction(TestName.VIGNETTE_APPROXIMATE_FULL);
250         runTest(ta, TestName.VIGNETTE_APPROXIMATE_FULL.name());
251     }
252 
253     // Test case 15: Vignette Approximate Relaxed
254     @MediumTest
testVignetteApproximateRelaxed()255     public void testVignetteApproximateRelaxed() {
256         TestAction ta = new TestAction(TestName.VIGNETTE_APPROXIMATE_RELAXED);
257         runTest(ta, TestName.VIGNETTE_APPROXIMATE_RELAXED.name());
258     }
259 
260     // Test case 16: Group Test (emulated)
261     @MediumTest
testGroupTestEmulated()262     public void testGroupTestEmulated() {
263         TestAction ta = new TestAction(TestName.GROUP_TEST_EMULATED);
264         runTest(ta, TestName.GROUP_TEST_EMULATED.name());
265     }
266 
267     // Test case 17: Group Test (native)
268     @MediumTest
testGroupTestNative()269     public void testGroupTestNative() {
270         TestAction ta = new TestAction(TestName.GROUP_TEST_NATIVE);
271         runTest(ta, TestName.GROUP_TEST_NATIVE.name());
272     }
273 
274     // Test case 18: Convolve 3x3
275     @MediumTest
testConvolve3x3()276     public void testConvolve3x3() {
277         TestAction ta = new TestAction(TestName.CONVOLVE_3X3);
278         runTest(ta, TestName.CONVOLVE_3X3.name());
279     }
280 
281     // Test case 19: Intrinsics Convolve 3x3
282     @MediumTest
testIntrinsicsConvolve3x3()283     public void testIntrinsicsConvolve3x3() {
284         TestAction ta = new TestAction(TestName.INTRINSICS_CONVOLVE_3X3);
285         runTest(ta, TestName.INTRINSICS_CONVOLVE_3X3.name());
286     }
287 
288     // Test case 20: ColorMatrix
289     @MediumTest
testColorMatrix()290     public void testColorMatrix() {
291         TestAction ta = new TestAction(TestName.COLOR_MATRIX);
292         runTest(ta, TestName.COLOR_MATRIX.name());
293     }
294 
295     // Test case 21: Intrinsics ColorMatrix
296     @MediumTest
testIntrinsicsColorMatrix()297     public void testIntrinsicsColorMatrix() {
298         TestAction ta = new TestAction(TestName.INTRINSICS_COLOR_MATRIX);
299         runTest(ta, TestName.INTRINSICS_COLOR_MATRIX.name());
300     }
301 
302     // Test case 22: Intrinsics ColorMatrix Grey
303     @MediumTest
testIntrinsicsColorMatrixGrey()304     public void testIntrinsicsColorMatrixGrey() {
305         TestAction ta = new TestAction(TestName.INTRINSICS_COLOR_MATRIX_GREY);
306         runTest(ta, TestName.INTRINSICS_COLOR_MATRIX_GREY.name());
307     }
308 
309     // Test case 23: Copy
310     @MediumTest
testCopy()311     public void testCopy() {
312         TestAction ta = new TestAction(TestName.COPY);
313         runTest(ta, TestName.COPY.name());
314     }
315 
316     // Test case 24: CrossProcess (using LUT)
317     @MediumTest
testCrossProcessUsingLUT()318     public void testCrossProcessUsingLUT() {
319         TestAction ta = new TestAction(TestName.CROSS_PROCESS_USING_LUT);
320         runTest(ta, TestName.CROSS_PROCESS_USING_LUT.name());
321     }
322 
323     // Test case 25: Convolve 5x5
324     @MediumTest
testConvolve5x5()325     public void testConvolve5x5() {
326         TestAction ta = new TestAction(TestName.CONVOLVE_5X5);
327         runTest(ta, TestName.CONVOLVE_5X5.name());
328     }
329 
330     // Test case 26: Intrinsics Convolve 5x5
331     @MediumTest
testIntrinsicsConvolve5x5()332     public void testIntrinsicsConvolve5x5() {
333         TestAction ta = new TestAction(TestName.INTRINSICS_CONVOLVE_5X5);
334         runTest(ta, TestName.INTRINSICS_CONVOLVE_5X5.name());
335     }
336 
337     // Test case 27: Mandelbrot
338     @MediumTest
testMandelbrot()339     public void testMandelbrot() {
340         TestAction ta = new TestAction(TestName.MANDELBROT_FLOAT);
341         runTest(ta, TestName.MANDELBROT_FLOAT.name());
342     }
343 
344     // Test case 28: Intrinsics Blend
345     @MediumTest
testIntrinsicsBlend()346     public void testIntrinsicsBlend() {
347         TestAction ta = new TestAction(TestName.INTRINSICS_BLEND);
348         runTest(ta, TestName.INTRINSICS_BLEND.name());
349     }
350 
351     // Test case 29: Intrinsics Blur 25 uchar
352     @MediumTest
testIntrinsicsBlur25G()353     public void testIntrinsicsBlur25G() {
354         TestAction ta = new TestAction(TestName.INTRINSICS_BLUR_25G);
355         runTest(ta, TestName.INTRINSICS_BLUR_25G.name());
356     }
357 
358     // Test case 30: Vibrance
359     @MediumTest
testVibrance()360     public void testVibrance() {
361         TestAction ta = new TestAction(TestName.VIBRANCE);
362         runTest(ta, TestName.VIBRANCE.name());
363     }
364 
365     // Test case 31: BWFilter
366     @MediumTest
testBWFilter()367     public void testBWFilter() {
368         TestAction ta = new TestAction(TestName.BW_FILTER);
369         runTest(ta, TestName.BW_FILTER.name());
370     }
371 
372     // Test case 32: Shadows
373     @MediumTest
testShadows()374     public void testShadows() {
375         TestAction ta = new TestAction(TestName.SHADOWS);
376         runTest(ta, TestName.SHADOWS.name());
377     }
378 
379     // Test case 33: Contrast
380     @MediumTest
testContrast()381     public void testContrast() {
382         TestAction ta = new TestAction(TestName.CONTRAST);
383         runTest(ta, TestName.CONTRAST.name());
384     }
385 
386     // Test case 34: Exposure
387     @MediumTest
testExposure()388     public void testExposure(){
389         TestAction ta = new TestAction(TestName.EXPOSURE);
390         runTest(ta, TestName.EXPOSURE.name());
391     }
392 
393     // Test case 35: White Balance
394     @MediumTest
testWhiteBalance()395     public void testWhiteBalance() {
396         TestAction ta = new TestAction(TestName.WHITE_BALANCE);
397         runTest(ta, TestName.WHITE_BALANCE.name());
398     }
399 
400     // Test case 36: Color Cube
401     @MediumTest
testColorCube()402     public void testColorCube() {
403         TestAction ta = new TestAction(TestName.COLOR_CUBE);
404         runTest(ta, TestName.COLOR_CUBE.name());
405     }
406 
407     // Test case 37: Color Cube (3D Intrinsic)
408     @MediumTest
testColorCube3DIntrinsic()409     public void testColorCube3DIntrinsic() {
410         TestAction ta = new TestAction(TestName.COLOR_CUBE_3D_INTRINSIC);
411         runTest(ta, TestName.COLOR_CUBE_3D_INTRINSIC.name());
412     }
413 
414     // Test case 38: Artistic 1
415     @MediumTest
testArtistic1()416     public void testArtistic1() {
417         TestAction ta = new TestAction(TestName.ARTISTIC1);
418         runTest(ta, TestName.ARTISTIC1.name());
419     }
420 
421     // Test case 39: Resize BiCubic Script
422     @MediumTest
testResizeBiCubicScript()423     public void testResizeBiCubicScript() {
424         TestAction ta = new TestAction(TestName.RESIZE_BI_SCRIPT);
425         runTest(ta, TestName.RESIZE_BI_SCRIPT.name());
426     }
427 
428     // Test case 40: Resize BiCubic Intrinsic
429     @MediumTest
testResizeBiCubicIntrinsic()430     public void testResizeBiCubicIntrinsic() {
431         TestAction ta = new TestAction(TestName.RESIZE_BI_INTRINSIC);
432         runTest(ta, TestName.RESIZE_BI_INTRINSIC.name());
433     }
434 
435     // Test case 41: Posterize with invoke
436     @MediumTest
testPosterizeInvoke()437     public void testPosterizeInvoke() {
438         TestAction ta = new TestAction(TestName.POSTERIZE_INVOKE);
439         runTest(ta, TestName.POSTERIZE_INVOKE.name());
440     }
441 
442     // Test case 42: Posterize with set
443     @MediumTest
testPosterizeSet()444     public void testPosterizeSet() {
445         TestAction ta = new TestAction(TestName.POSTERIZE_SET);
446         runTest(ta, TestName.POSTERIZE_SET.name());
447     }
448 
449     // Test case 43 Histogram intrinsic
450     @MediumTest
testHistogramIntrinsic()451     public void testHistogramIntrinsic() {
452         TestAction ta = new TestAction(TestName.HISTOGRAM_INTRINSIC);
453         runTest(ta, TestName.HISTOGRAM_INTRINSIC.name());
454     }
455 
456     // Test case 44 Histogram script
457     @MediumTest
testHistogramScript()458     public void testHistogramScript() {
459         TestAction ta = new TestAction(TestName.HISTOGRAM_SCRIPT);
460         runTest(ta, TestName.HISTOGRAM_SCRIPT.name());
461     }
462 
463     // Test case 45: Mandelbrot fp64
464     @MediumTest
testMandelbrotfp64()465     public void testMandelbrotfp64() {
466         TestAction ta = new TestAction(TestName.MANDELBROT_DOUBLE);
467         runTest(ta, TestName.MANDELBROT_DOUBLE.name());
468     }
469 
470     // Test case 46: Blur Radius 25 Half Precision
471     @MediumTest
testBlurRadius25Half()472     public void testBlurRadius25Half() {
473         TestAction ta = new TestAction(TestName.BLUR_RADIUS_25_HALF);
474         runTest(ta, TestName.BLUR_RADIUS_25_HALF.name());
475     }
476 }
477