summaryrefslogtreecommitdiffstats
path: root/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/ImageProcessingTest.java
blob: 5263c6158814f6ec709d48c540421d0865035665 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
/*
 * 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.ImageProcessingTestRunner;

import android.os.Bundle;
import com.android.rs.image.ImageProcessingActivity.TestName;

import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.LargeTest;
import android.util.Log;

/**
 * ImageProcessing benchmark test.
 * To run the test, please use command
 *
 * adb shell am instrument -e iteration <n> -w com.android.rs.image/.ImageProcessingTestRunner
 *
 */
public class ImageProcessingTest extends ActivityInstrumentationTestCase2<ImageProcessingActivity> {
    private final String TAG = "ImageProcessingTest";
    private final String TEST_NAME = "Testname";
    private final String ITERATIONS = "Iterations";
    private final String BENCHMARK = "Benchmark";
    private static int INSTRUMENTATION_IN_PROGRESS = 2;
    private int mIteration;
    private ImageProcessingActivity mActivity;

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

    @Override
    public void setUp() throws Exception {
        super.setUp();
        setActivityInitialTouchMode(false);
        mActivity = getActivity();
        ImageProcessingTestRunner mRunner = (ImageProcessingTestRunner) getInstrumentation();
        mIteration = mRunner.mIteration;
        assertTrue("please enter a valid iteration value", mIteration > 0);
   }

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

    class TestAction implements Runnable {
        TestName mTestName;
        float mResult;
        public TestAction(TestName testName) {
            mTestName = testName;
        }
        public void run() {
            mActivity.changeTest(mTestName);
            mResult = mActivity.getBenchmark();
            Log.v(TAG, "Benchmark for test \"" + mTestName.toString() + "\" is: " + mResult);
            synchronized(this) {
                this.notify();
            }
        }
        public float getBenchmark() {
            return mResult;
        }
    }

    // Set the benchmark thread to run on ui thread
    // Synchronized the thread such that the test will wait for the benchmark thread to finish
    public void runOnUiThread(Runnable action) {
        synchronized(action) {
            mActivity.runOnUiThread(action);
            try {
                action.wait();
            } catch (InterruptedException e) {
                Log.v(TAG, "waiting for action running on UI thread is interrupted: " +
                        e.toString());
            }
        }
    }

    public void runTest(TestAction ta, String testName) {
        float sum = 0;
        for (int i = 0; i < mIteration; i++) {
            runOnUiThread(ta);
            float bmValue = ta.getBenchmark();
            Log.v(TAG, "results for iteration " + i + " is " + bmValue);
            sum += bmValue;
        }
        float avgResult = sum/mIteration;

        // post result to INSTRUMENTATION_STATUS
        Bundle results = new Bundle();
        results.putString(TEST_NAME, testName);
        results.putInt(ITERATIONS, mIteration);
        results.putFloat(BENCHMARK, avgResult);
        getInstrumentation().sendStatus(INSTRUMENTATION_IN_PROGRESS, results);
    }

    // Test case 0: Levels Vec3 Relaxed
    @LargeTest
    public void testLevelsVec3Relaxed() {
        TestAction ta = new TestAction(TestName.LEVELS_VEC3_RELAXED);
        runTest(ta, TestName.LEVELS_VEC3_RELAXED.name());
    }

    // Test case 1: Levels Vec4 Relaxed
    @LargeTest
    public void testLevelsVec4Relaxed() {
        TestAction ta = new TestAction(TestName.LEVELS_VEC4_RELAXED);
        runTest(ta, TestName.LEVELS_VEC4_RELAXED.name());
    }

    // Test case 2: Levels Vec3 Full
    @LargeTest
    public void testLevelsVec3Full() {
        TestAction ta = new TestAction(TestName.LEVELS_VEC3_FULL);
        runTest(ta, TestName.LEVELS_VEC3_FULL.name());
    }

    // Test case 3: Levels Vec4 Full
    @LargeTest
    public void testLevelsVec4Full() {
        TestAction ta = new TestAction(TestName.LEVELS_VEC4_FULL);
        runTest(ta, TestName.LEVELS_VEC4_FULL.name());
    }

    // Test case 4: Blur Radius 25
    @LargeTest
    public void testBlurRadius25() {
        TestAction ta = new TestAction(TestName.BLUR_RADIUS_25);
        runTest(ta, TestName.BLUR_RADIUS_25.name());
    }

    // Test case 5: Intrinsic Blur Radius 25
    @LargeTest
    public void testIntrinsicBlurRadius25() {
        TestAction ta = new TestAction(TestName.INTRINSIC_BLUE_RADIUS_25);
        runTest(ta, TestName.INTRINSIC_BLUE_RADIUS_25.name());
    }

    // Test case 6: Greyscale
    @LargeTest
    public void testGreyscale() {
        TestAction ta = new TestAction(TestName.GREYSCALE);
        runTest(ta, TestName.GREYSCALE.name());
    }

    // Test case 7: Grain
    @LargeTest
    public void testGrain() {
        TestAction ta = new TestAction(TestName.GRAIN);
        runTest(ta, TestName.GRAIN.name());
    }

    // Test case 8: Fisheye Full
    @LargeTest
    public void testFisheyeFull() {
        TestAction ta = new TestAction(TestName.FISHEYE_FULL);
        runTest(ta, TestName.FISHEYE_FULL.name());
    }

    // Test case 9: Fisheye Relaxed
    @LargeTest
    public void testFishEyeRelaxed() {
        TestAction ta = new TestAction(TestName.FISHEYE_RELAXED);
        runTest(ta, TestName.FISHEYE_RELAXED.name());
    }

    // Test case 10: Fisheye Approximate Full
    @LargeTest
    public void testFisheyeApproximateFull() {
        TestAction ta = new TestAction(TestName.FISHEYE_APPROXIMATE_FULL);
        runTest(ta, TestName.FISHEYE_APPROXIMATE_FULL.name());
    }

    // Test case 11: Fisheye Approximate Relaxed
    @LargeTest
    public void testFisheyeApproximateRelaxed() {
        TestAction ta = new TestAction(TestName.FISHEYE_APPROXIMATE_RELAXED);
        runTest(ta, TestName.FISHEYE_APPROXIMATE_RELAXED.name());
    }

    // Test case 12: Vignette Full
    @LargeTest
    public void testVignetteFull() {
        TestAction ta = new TestAction(TestName.VIGNETTE_FULL);
        runTest(ta, TestName.VIGNETTE_FULL.name());
    }

    // Test case 13: Vignette Relaxed
    @LargeTest
    public void testVignetteRelaxed() {
        TestAction ta = new TestAction(TestName.VIGNETTE_RELAXED);
        runTest(ta, TestName.VIGNETTE_RELAXED.name());
    }

    // Test case 14: Vignette Approximate Full
    @LargeTest
    public void testVignetteApproximateFull() {
        TestAction ta = new TestAction(TestName.VIGNETTE_APPROXIMATE_FULL);
        runTest(ta, TestName.VIGNETTE_APPROXIMATE_FULL.name());
    }

    // Test case 15: Vignette Approximate Relaxed
    @LargeTest
    public void testVignetteApproximateRelaxed() {
        TestAction ta = new TestAction(TestName.VIGNETTE_APPROXIMATE_RELAXED);
        runTest(ta, TestName.VIGNETTE_APPROXIMATE_RELAXED.name());
    }

    // Test case 16: Group Test (emulated)
    @LargeTest
    public void testGroupTestEmulated() {
        TestAction ta = new TestAction(TestName.GROUP_TEST_EMULATED);
        runTest(ta, TestName.GROUP_TEST_EMULATED.name());
    }

    // Test case 17: Group Test (native)
    @LargeTest
    public void testGroupTestNative() {
        TestAction ta = new TestAction(TestName.GROUP_TEST_NATIVE);
        runTest(ta, TestName.GROUP_TEST_NATIVE.name());
    }

    // Test case 18: Convolve 3x3
    @LargeTest
    public void testConvolve3x3() {
        TestAction ta = new TestAction(TestName.CONVOLVE_3X3);
        runTest(ta, TestName.CONVOLVE_3X3.name());
    }

    // Test case 19: Intrinsics Convolve 3x3
    @LargeTest
    public void testIntrinsicsConvolve3x3() {
        TestAction ta = new TestAction(TestName.INTRINSICS_CONVOLVE_3X3);
        runTest(ta, TestName.INTRINSICS_CONVOLVE_3X3.name());
    }

    // Test case 20: ColorMatrix
    @LargeTest
    public void testColorMatrix() {
        TestAction ta = new TestAction(TestName.COLOR_MATRIX);
        runTest(ta, TestName.COLOR_MATRIX.name());
    }

    // Test case 21: Intrinsics ColorMatrix
    @LargeTest
    public void testIntrinsicsColorMatrix() {
        TestAction ta = new TestAction(TestName.INTRINSICS_COLOR_MATRIX);
        runTest(ta, TestName.INTRINSICS_COLOR_MATRIX.name());
    }

    // Test case 22: Intrinsics ColorMatrix Grey
    @LargeTest
    public void testIntrinsicsColorMatrixGrey() {
        TestAction ta = new TestAction(TestName.INTRINSICS_COLOR_MATRIX_GREY);
        runTest(ta, TestName.INTRINSICS_COLOR_MATRIX_GREY.name());
    }

    // Test case 23: Copy
    @LargeTest
    public void testCopy() {
        TestAction ta = new TestAction(TestName.COPY);
        runTest(ta, TestName.COPY.name());
    }

    // Test case 24: CrossProcess (using LUT)
    @LargeTest
    public void testCrossProcessUsingLUT() {
        TestAction ta = new TestAction(TestName.CROSS_PROCESS_USING_LUT);
        runTest(ta, TestName.CROSS_PROCESS_USING_LUT.name());
    }

    // Test case 25: Convolve 5x5
    @LargeTest
    public void testConvolve5x5() {
        TestAction ta = new TestAction(TestName.CONVOLVE_5X5);
        runTest(ta, TestName.CONVOLVE_5X5.name());
    }

    // Test case 26: Intrinsics Convolve 5x5
    @LargeTest
    public void testIntrinsicsConvolve5x5() {
        TestAction ta = new TestAction(TestName.INTRINSICS_CONVOLVE_5X5);
        runTest(ta, TestName.INTRINSICS_CONVOLVE_5X5.name());
    }

    // Test case 27: Mandelbrot
    @LargeTest
    public void testMandelbrot() {
        TestAction ta = new TestAction(TestName.MANDELBROT);
        runTest(ta, TestName.MANDELBROT.name());
    }

    // Test case 28: Intrinsics Blend
    @LargeTest
    public void testIntrinsicsBlend() {
        TestAction ta = new TestAction(TestName.INTRINSICS_BLEND);
        runTest(ta, TestName.INTRINSICS_BLEND.name());
    }

    // Test case 29: Intrinsics Blur 25 uchar
    @LargeTest
    public void testIntrinsicsBlur25G() {
        TestAction ta = new TestAction(TestName.INTRINSICS_BLUR_25G);
        runTest(ta, TestName.INTRINSICS_BLUR_25G.name());
    }

    // Test case 30: Vibrance
    @LargeTest
    public void testVibrance() {
        TestAction ta = new TestAction(TestName.VIBRANCE);
        runTest(ta, TestName.VIBRANCE.name());
    }

    // Test case 31: BWFilter
    @LargeTest
    public void testBWFilter() {
        TestAction ta = new TestAction(TestName.BW_FILTER);
        runTest(ta, TestName.BW_FILTER.name());
    }

    // Test case 32: Shadows
    @LargeTest
    public void testShadows() {
        TestAction ta = new TestAction(TestName.SHADOWS);
        runTest(ta, TestName.SHADOWS.name());
    }

    // Test case 33: Contrast
    @LargeTest
    public void testContrast() {
        TestAction ta = new TestAction(TestName.CONTRAST);
        runTest(ta, TestName.CONTRAST.name());
    }

    // Test case 34: Exposure
    @LargeTest
    public void testExposure(){
        TestAction ta = new TestAction(TestName.EXPOSURE);
        runTest(ta, TestName.EXPOSURE.name());
    }

    // Test case 35: White Balance
    @LargeTest
    public void testWhiteBalance() {
        TestAction ta = new TestAction(TestName.WHITE_BALANCE);
        runTest(ta, TestName.WHITE_BALANCE.name());
    }

    // Test case 36: Color Cube
    @LargeTest
    public void testColorCube() {
        TestAction ta = new TestAction(TestName.COLOR_CUBE);
        runTest(ta, TestName.COLOR_CUBE.name());
    }

    // Test case 37: Color Cube (3D Intrinsic)
    @LargeTest
    public void testColorCube3DIntrinsic() {
        TestAction ta = new TestAction(TestName.COLOR_CUBE_3D_INTRINSIC);
        runTest(ta, TestName.COLOR_CUBE_3D_INTRINSIC.name());
    }
}