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