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
|
/*
* Copyright (C) 2015 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.test;
import android.content.Context;
import android.content.res.Resources;
import android.renderscript.*;
import android.util.Log;
import java.lang.Thread;
import java.util.HashMap;
public class UT_script_group2_pointwise extends UnitTest {
private Resources mRes;
private static final int ARRAY_SIZE = 256;
private static final String TAG = "ScritGroup2 (Pointwise)";
protected UT_script_group2_pointwise(RSTestCore rstc, Resources res, Context ctx) {
super(rstc, TAG, ctx);
mRes = res;
}
public void run() {
RenderScript pRS = RenderScript.create(mCtx);
ScriptC_increment s_inc = new ScriptC_increment(pRS);
ScriptC_double s_double = new ScriptC_double(pRS);
pRS.setMessageHandler(mRsMessage);
int[] array = new int[ARRAY_SIZE * 4];
for (int i = 0; i < ARRAY_SIZE * 4; i++) {
array[i] = i;
}
Allocation input = Allocation.createSized(pRS, Element.I32_4(pRS), ARRAY_SIZE);
input.copyFrom(array);
ScriptGroup2.Builder builder = new ScriptGroup2.Builder(pRS);
ScriptGroup2.UnboundValue unbound = builder.addInput();
ScriptGroup2.Closure c0 =
builder.addKernel(s_inc.getKernelID_increment(),
Type.createX(pRS, Element.I32_4(pRS), ARRAY_SIZE),
unbound);
ScriptGroup2.Closure c1 =
builder.addKernel(s_double.getKernelID_doubleKernel(),
Type.createX(pRS, Element.I32_4(pRS), ARRAY_SIZE),
c0.getReturn());
ScriptGroup2 group = builder.create(c1.getReturn());
int[] a = new int[ARRAY_SIZE * 4];
((Allocation)group.execute(input)[0]).copyTo(a);
pRS.finish();
pRS.destroy();
boolean failed = false;
for (int i = 0; i < ARRAY_SIZE * 4; i++) {
if (a[i] != (i+1) * 2) {
Log.e(TAG, "a["+i+"]="+a[i]+", should be "+ ((i+1) * 2));
failed = true;
}
}
if (failed) {
failTest();
return;
}
passTest();
}
}
|