1 /*
2  * Copyright (C) 2012 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.test;
18 
19 import android.content.Context;
20 import android.renderscript.Allocation;
21 import android.renderscript.Element;
22 import android.renderscript.RenderScript;
23 import android.renderscript.Type;
24 
25 public class UT_kernel extends UnitTest {
26     private Type TA;
27     private Type TB;
28     private Allocation A;
29     private Allocation B;
30 
UT_kernel(RSTestCore rstc, Context ctx)31     protected UT_kernel(RSTestCore rstc, Context ctx) {
32         super(rstc, "Kernels (pass-by-value)", ctx);
33     }
34 
initializeGlobals(RenderScript RS, ScriptC_kernel s)35     private void initializeGlobals(RenderScript RS, ScriptC_kernel s) {
36         Type.Builder typeBuilder = new Type.Builder(RS, Element.I32(RS));
37         int X = 5;
38         s.set_dimX(X);
39         typeBuilder.setX(X);
40         TA = typeBuilder.create();
41         A = Allocation.createTyped(RS, TA);
42         s.bind_ain(A);
43         TB = typeBuilder.create();
44         B = Allocation.createTyped(RS, TB);
45         s.bind_aout(B);
46 
47         return;
48     }
49 
run()50     public void run() {
51         RenderScript pRS = RenderScript.create(mCtx);
52         ScriptC_kernel s = new ScriptC_kernel(pRS);
53         pRS.setMessageHandler(mRsMessage);
54         initializeGlobals(pRS, s);
55         s.forEach_init_vars(A);
56         s.forEach_root(A, B);
57         s.invoke_verify_root();
58         s.invoke_kernel_test();
59         pRS.finish();
60         waitForMessage();
61         A.destroy();
62         B.destroy();
63         TA.destroy();
64         TB.destroy();
65         s.destroy();
66         pRS.destroy();
67     }
68 }
69