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.rs.image; 18 19import com.android.rs.image.ImageProcessingTestRunner; 20 21import android.os.Bundle; 22import com.android.rs.image.ImageProcessingActivity.TestName; 23 24import android.test.ActivityInstrumentationTestCase2; 25import android.test.suitebuilder.annotation.LargeTest; 26import android.util.Log; 27 28/** 29 * ImageProcessing benchmark test. 30 * To run the test, please use command 31 * 32 * adb shell am instrument -e iteration <n> -w com.android.rs.image/.ImageProcessingTestRunner 33 * 34 */ 35public class ImageProcessingTest extends ActivityInstrumentationTestCase2<ImageProcessingActivity> { 36 private final String TAG = "ImageProcessingTest"; 37 private final String TEST_NAME = "Testname"; 38 private final String ITERATIONS = "Iterations"; 39 private final String BENCHMARK = "Benchmark"; 40 private static int INSTRUMENTATION_IN_PROGRESS = 2; 41 private int mIteration; 42 private ImageProcessingActivity mActivity; 43 44 public ImageProcessingTest() { 45 super(ImageProcessingActivity.class); 46 } 47 48 @Override 49 public void setUp() throws Exception { 50 super.setUp(); 51 setActivityInitialTouchMode(false); 52 mActivity = getActivity(); 53 ImageProcessingTestRunner mRunner = (ImageProcessingTestRunner) getInstrumentation(); 54 mIteration = mRunner.mIteration; 55 assertTrue("please enter a valid iteration value", mIteration > 0); 56 } 57 58 @Override 59 public void tearDown() throws Exception { 60 super.tearDown(); 61 } 62 63 class TestAction implements Runnable { 64 TestName mTestName; 65 float mResult; 66 public TestAction(TestName testName) { 67 mTestName = testName; 68 } 69 public void run() { 70 mActivity.changeTest(mTestName); 71 mResult = mActivity.getBenchmark(); 72 Log.v(TAG, "Benchmark for test \"" + mTestName.toString() + "\" is: " + mResult); 73 synchronized(this) { 74 this.notify(); 75 } 76 } 77 public float getBenchmark() { 78 return mResult; 79 } 80 } 81 82 // Set the benchmark thread to run on ui thread 83 // Synchronized the thread such that the test will wait for the benchmark thread to finish 84 public void runOnUiThread(Runnable action) { 85 synchronized(action) { 86 mActivity.runOnUiThread(action); 87 try { 88 action.wait(); 89 } catch (InterruptedException e) { 90 Log.v(TAG, "waiting for action running on UI thread is interrupted: " + 91 e.toString()); 92 } 93 } 94 } 95 96 public void runTest(TestAction ta, String testName) { 97 float sum = 0; 98 for (int i = 0; i < mIteration; i++) { 99 runOnUiThread(ta); 100 float bmValue = ta.getBenchmark(); 101 Log.v(TAG, "results for iteration " + i + " is " + bmValue); 102 sum += bmValue; 103 } 104 float avgResult = sum/mIteration; 105 106 // post result to INSTRUMENTATION_STATUS 107 Bundle results = new Bundle(); 108 results.putString(TEST_NAME, testName); 109 results.putInt(ITERATIONS, mIteration); 110 results.putFloat(BENCHMARK, avgResult); 111 getInstrumentation().sendStatus(INSTRUMENTATION_IN_PROGRESS, results); 112 } 113 114 // Test case 0: Levels Vec3 Relaxed 115 @LargeTest 116 public void testLevelsVec3Relaxed() { 117 TestAction ta = new TestAction(TestName.LEVELS_VEC3_RELAXED); 118 runTest(ta, TestName.LEVELS_VEC3_RELAXED.name()); 119 } 120 121 // Test case 1: Levels Vec4 Relaxed 122 @LargeTest 123 public void testLevelsVec4Relaxed() { 124 TestAction ta = new TestAction(TestName.LEVELS_VEC4_RELAXED); 125 runTest(ta, TestName.LEVELS_VEC4_RELAXED.name()); 126 } 127 128 // Test case 2: Levels Vec3 Full 129 @LargeTest 130 public void testLevelsVec3Full() { 131 TestAction ta = new TestAction(TestName.LEVELS_VEC3_FULL); 132 runTest(ta, TestName.LEVELS_VEC3_FULL.name()); 133 } 134 135 // Test case 3: Levels Vec4 Full 136 @LargeTest 137 public void testLevelsVec4Full() { 138 TestAction ta = new TestAction(TestName.LEVELS_VEC4_FULL); 139 runTest(ta, TestName.LEVELS_VEC4_FULL.name()); 140 } 141 142 // Test case 4: Blur Radius 25 143 @LargeTest 144 public void testBlurRadius25() { 145 TestAction ta = new TestAction(TestName.BLUR_RADIUS_25); 146 runTest(ta, TestName.BLUR_RADIUS_25.name()); 147 } 148 149 // Test case 5: Intrinsic Blur Radius 25 150 @LargeTest 151 public void testIntrinsicBlurRadius25() { 152 TestAction ta = new TestAction(TestName.INTRINSIC_BLUE_RADIUS_25); 153 runTest(ta, TestName.INTRINSIC_BLUE_RADIUS_25.name()); 154 } 155 156 // Test case 6: Greyscale 157 @LargeTest 158 public void testGreyscale() { 159 TestAction ta = new TestAction(TestName.GREYSCALE); 160 runTest(ta, TestName.GREYSCALE.name()); 161 } 162 163 // Test case 7: Grain 164 @LargeTest 165 public void testGrain() { 166 TestAction ta = new TestAction(TestName.GRAIN); 167 runTest(ta, TestName.GRAIN.name()); 168 } 169 170 // Test case 8: Fisheye Full 171 @LargeTest 172 public void testFisheyeFull() { 173 TestAction ta = new TestAction(TestName.FISHEYE_FULL); 174 runTest(ta, TestName.FISHEYE_FULL.name()); 175 } 176 177 // Test case 9: Fisheye Relaxed 178 @LargeTest 179 public void testFishEyeRelaxed() { 180 TestAction ta = new TestAction(TestName.FISHEYE_RELAXED); 181 runTest(ta, TestName.FISHEYE_RELAXED.name()); 182 } 183 184 // Test case 10: Fisheye Approximate Full 185 @LargeTest 186 public void testFisheyeApproximateFull() { 187 TestAction ta = new TestAction(TestName.FISHEYE_APPROXIMATE_FULL); 188 runTest(ta, TestName.FISHEYE_APPROXIMATE_FULL.name()); 189 } 190 191 // Test case 11: Fisheye Approximate Relaxed 192 @LargeTest 193 public void testFisheyeApproximateRelaxed() { 194 TestAction ta = new TestAction(TestName.FISHEYE_APPROXIMATE_RELAXED); 195 runTest(ta, TestName.FISHEYE_APPROXIMATE_RELAXED.name()); 196 } 197 198 // Test case 12: Vignette Full 199 @LargeTest 200 public void testVignetteFull() { 201 TestAction ta = new TestAction(TestName.VIGNETTE_FULL); 202 runTest(ta, TestName.VIGNETTE_FULL.name()); 203 } 204 205 // Test case 13: Vignette Relaxed 206 @LargeTest 207 public void testVignetteRelaxed() { 208 TestAction ta = new TestAction(TestName.VIGNETTE_RELAXED); 209 runTest(ta, TestName.VIGNETTE_RELAXED.name()); 210 } 211 212 // Test case 14: Vignette Approximate Full 213 @LargeTest 214 public void testVignetteApproximateFull() { 215 TestAction ta = new TestAction(TestName.VIGNETTE_APPROXIMATE_FULL); 216 runTest(ta, TestName.VIGNETTE_APPROXIMATE_FULL.name()); 217 } 218 219 // Test case 15: Vignette Approximate Relaxed 220 @LargeTest 221 public void testVignetteApproximateRelaxed() { 222 TestAction ta = new TestAction(TestName.VIGNETTE_APPROXIMATE_RELAXED); 223 runTest(ta, TestName.VIGNETTE_APPROXIMATE_RELAXED.name()); 224 } 225 226 // Test case 16: Group Test (emulated) 227 @LargeTest 228 public void testGroupTestEmulated() { 229 TestAction ta = new TestAction(TestName.GROUP_TEST_EMULATED); 230 runTest(ta, TestName.GROUP_TEST_EMULATED.name()); 231 } 232 233 // Test case 17: Group Test (native) 234 @LargeTest 235 public void testGroupTestNative() { 236 TestAction ta = new TestAction(TestName.GROUP_TEST_NATIVE); 237 runTest(ta, TestName.GROUP_TEST_NATIVE.name()); 238 } 239 240 // Test case 18: Convolve 3x3 241 @LargeTest 242 public void testConvolve3x3() { 243 TestAction ta = new TestAction(TestName.CONVOLVE_3X3); 244 runTest(ta, TestName.CONVOLVE_3X3.name()); 245 } 246 247 // Test case 19: Intrinsics Convolve 3x3 248 @LargeTest 249 public void testIntrinsicsConvolve3x3() { 250 TestAction ta = new TestAction(TestName.INTRINSICS_CONVOLVE_3X3); 251 runTest(ta, TestName.INTRINSICS_CONVOLVE_3X3.name()); 252 } 253 254 // Test case 20: ColorMatrix 255 @LargeTest 256 public void testColorMatrix() { 257 TestAction ta = new TestAction(TestName.COLOR_MATRIX); 258 runTest(ta, TestName.COLOR_MATRIX.name()); 259 } 260 261 // Test case 21: Intrinsics ColorMatrix 262 @LargeTest 263 public void testIntrinsicsColorMatrix() { 264 TestAction ta = new TestAction(TestName.INTRINSICS_COLOR_MATRIX); 265 runTest(ta, TestName.INTRINSICS_COLOR_MATRIX.name()); 266 } 267 268 // Test case 22: Intrinsics ColorMatrix Grey 269 @LargeTest 270 public void testIntrinsicsColorMatrixGrey() { 271 TestAction ta = new TestAction(TestName.INTRINSICS_COLOR_MATRIX_GREY); 272 runTest(ta, TestName.INTRINSICS_COLOR_MATRIX_GREY.name()); 273 } 274 275 // Test case 23: Copy 276 @LargeTest 277 public void testCopy() { 278 TestAction ta = new TestAction(TestName.COPY); 279 runTest(ta, TestName.COPY.name()); 280 } 281 282 // Test case 24: CrossProcess (using LUT) 283 @LargeTest 284 public void testCrossProcessUsingLUT() { 285 TestAction ta = new TestAction(TestName.CROSS_PROCESS_USING_LUT); 286 runTest(ta, TestName.CROSS_PROCESS_USING_LUT.name()); 287 } 288 289 // Test case 25: Convolve 5x5 290 @LargeTest 291 public void testConvolve5x5() { 292 TestAction ta = new TestAction(TestName.CONVOLVE_5X5); 293 runTest(ta, TestName.CONVOLVE_5X5.name()); 294 } 295 296 // Test case 26: Intrinsics Convolve 5x5 297 @LargeTest 298 public void testIntrinsicsConvolve5x5() { 299 TestAction ta = new TestAction(TestName.INTRINSICS_CONVOLVE_5X5); 300 runTest(ta, TestName.INTRINSICS_CONVOLVE_5X5.name()); 301 } 302 303 // Test case 27: Mandelbrot 304 @LargeTest 305 public void testMandelbrot() { 306 TestAction ta = new TestAction(TestName.MANDELBROT_FLOAT); 307 runTest(ta, TestName.MANDELBROT_FLOAT.name()); 308 } 309 310 // Test case 28: Intrinsics Blend 311 @LargeTest 312 public void testIntrinsicsBlend() { 313 TestAction ta = new TestAction(TestName.INTRINSICS_BLEND); 314 runTest(ta, TestName.INTRINSICS_BLEND.name()); 315 } 316 317 // Test case 29: Intrinsics Blur 25 uchar 318 @LargeTest 319 public void testIntrinsicsBlur25G() { 320 TestAction ta = new TestAction(TestName.INTRINSICS_BLUR_25G); 321 runTest(ta, TestName.INTRINSICS_BLUR_25G.name()); 322 } 323 324 // Test case 30: Vibrance 325 @LargeTest 326 public void testVibrance() { 327 TestAction ta = new TestAction(TestName.VIBRANCE); 328 runTest(ta, TestName.VIBRANCE.name()); 329 } 330 331 // Test case 31: BWFilter 332 @LargeTest 333 public void testBWFilter() { 334 TestAction ta = new TestAction(TestName.BW_FILTER); 335 runTest(ta, TestName.BW_FILTER.name()); 336 } 337 338 // Test case 32: Shadows 339 @LargeTest 340 public void testShadows() { 341 TestAction ta = new TestAction(TestName.SHADOWS); 342 runTest(ta, TestName.SHADOWS.name()); 343 } 344 345 // Test case 33: Contrast 346 @LargeTest 347 public void testContrast() { 348 TestAction ta = new TestAction(TestName.CONTRAST); 349 runTest(ta, TestName.CONTRAST.name()); 350 } 351 352 // Test case 34: Exposure 353 @LargeTest 354 public void testExposure(){ 355 TestAction ta = new TestAction(TestName.EXPOSURE); 356 runTest(ta, TestName.EXPOSURE.name()); 357 } 358 359 // Test case 35: White Balance 360 @LargeTest 361 public void testWhiteBalance() { 362 TestAction ta = new TestAction(TestName.WHITE_BALANCE); 363 runTest(ta, TestName.WHITE_BALANCE.name()); 364 } 365 366 // Test case 36: Color Cube 367 @LargeTest 368 public void testColorCube() { 369 TestAction ta = new TestAction(TestName.COLOR_CUBE); 370 runTest(ta, TestName.COLOR_CUBE.name()); 371 } 372 373 // Test case 37: Color Cube (3D Intrinsic) 374 @LargeTest 375 public void testColorCube3DIntrinsic() { 376 TestAction ta = new TestAction(TestName.COLOR_CUBE_3D_INTRINSIC); 377 runTest(ta, TestName.COLOR_CUBE_3D_INTRINSIC.name()); 378 } 379 380 // Test case 38: Usage io 381 @LargeTest 382 public void testUsageIO() { 383 TestAction ta = new TestAction(TestName.USAGE_IO); 384 runTest(ta, TestName.USAGE_IO.name()); 385 } 386 387 // Test case 39: Artistic 1 388 @LargeTest 389 public void testArtistic1() { 390 TestAction ta = new TestAction(TestName.ARTISTIC_1); 391 runTest(ta, TestName.ARTISTIC_1.name()); 392 } 393 394 // Test case 40 Histogram 395 @LargeTest 396 public void testHistogram() { 397 TestAction ta = new TestAction(TestName.HISTOGRAM); 398 runTest(ta, TestName.HISTOGRAM.name()); 399 } 400 401 // Test case 41: Mandelbrot fp64 402 @LargeTest 403 public void testMandelbrotfp64() { 404 TestAction ta = new TestAction(TestName.MANDELBROT_DOUBLE); 405 runTest(ta, TestName.MANDELBROT_DOUBLE.name()); 406 } 407} 408