1/* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the License 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 * or implied. See the License for the specific language governing permissions and limitations under 12 * the License. 13 */ 14 15package com.android.rs.unittest; 16 17import android.content.Context; 18import android.renderscript.Allocation; 19import android.renderscript.Element; 20import android.renderscript.RenderScript; 21import android.renderscript.ScriptGroup; 22import android.renderscript.Type; 23import android.util.Log; 24 25public class UT_script_group2_pointwise extends UnitTest { 26 private static final int ARRAY_SIZE = 256; 27 28 private static final String TAG = "ScriptGroup2 (Pointwise)"; 29 30 public UT_script_group2_pointwise(Context ctx) { 31 super(TAG, ctx); 32 } 33 34 public void run() { 35 RenderScript pRS = createRenderScript(false); 36 ScriptC_increment s_inc = new ScriptC_increment(pRS); 37 ScriptC_double s_double = new ScriptC_double(pRS); 38 39 int[] array = new int[ARRAY_SIZE * 4]; 40 41 for (int i = 0; i < ARRAY_SIZE * 4; i++) { 42 array[i] = i; 43 } 44 45 Allocation input = Allocation.createSized(pRS, Element.I32_4(pRS), ARRAY_SIZE); 46 input.copyFrom(array); 47 48 ScriptGroup.Builder2 builder = new ScriptGroup.Builder2(pRS); 49 50 ScriptGroup.Input unbound = builder.addInput(); 51 52 Type T = Type.createX(pRS, Element.I32_4(pRS), ARRAY_SIZE); 53 54 ScriptGroup.Closure c0 = 55 builder.addKernel(s_inc.getKernelID_increment(), 56 T, 57 unbound); 58 59 ScriptGroup.Closure c1 = 60 builder.addKernel(s_double.getKernelID_doubleKernel(), 61 T, 62 c0.getReturn()); 63 64 ScriptGroup group = builder.create("AddDouble", c1.getReturn()); 65 66 int[] a = new int[ARRAY_SIZE * 4]; 67 ((Allocation) group.execute(input)[0]).copyTo(a); 68 69 pRS.finish(); 70 group.destroy(); 71 T.destroy(); 72 input.destroy(); 73 s_double.destroy(); 74 s_inc.destroy(); 75 pRS.destroy(); 76 77 boolean failed = false; 78 for (int i = 0; i < ARRAY_SIZE * 4; i++) { 79 if (a[i] != (i + 1) * 2) { 80 Log.e(TAG, "a[" + i + "]=" + a[i] + ", should be " + ((i + 1) * 2)); 81 failed = true; 82 } 83 } 84 if (failed) { 85 failTest(); 86 return; 87 } 88 passTest(); 89 } 90} 91