1/* 2 * Copyright (C) 2015 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.test_compat; 18 19import android.content.Context; 20import android.content.res.Resources; 21import android.support.v8.renderscript.*; 22import android.util.Log; 23import java.lang.Thread; 24import java.util.HashMap; 25 26public class UT_script_group2_pointwise extends UnitTest { 27 private Resources mRes; 28 29 private static final int ARRAY_SIZE = 256; 30 31 private static final String TAG = "ScritGroup2 (Pointwise)"; 32 33 protected UT_script_group2_pointwise(RSTestCore rstc, Resources res, Context ctx) { 34 super(rstc, TAG, ctx); 35 mRes = res; 36 } 37 38 public void run() { 39 RenderScript pRS = RenderScript.create(mCtx); 40 ScriptC_increment s_inc = new ScriptC_increment(pRS); 41 ScriptC_double s_double = new ScriptC_double(pRS); 42 pRS.setMessageHandler(mRsMessage); 43 44 int[] array = new int[ARRAY_SIZE * 4]; 45 46 for (int i = 0; i < ARRAY_SIZE * 4; i++) { 47 array[i] = i; 48 } 49 50 Allocation input = Allocation.createSized(pRS, Element.I32_4(pRS), ARRAY_SIZE); 51 input.copyFrom(array); 52 53 ScriptGroup.Builder2 builder = new ScriptGroup.Builder2(pRS); 54 55 ScriptGroup.Input unbound = builder.addInput(); 56 57 ScriptGroup.Closure c0 = 58 builder.addKernel(s_inc.getKernelID_increment(), 59 Type.createX(pRS, Element.I32_4(pRS), ARRAY_SIZE), 60 unbound); 61 62 ScriptGroup.Closure c1 = 63 builder.addKernel(s_double.getKernelID_doubleKernel(), 64 Type.createX(pRS, Element.I32_4(pRS), ARRAY_SIZE), 65 c0.getReturn()); 66 67 ScriptGroup group = builder.create("AddDouble", c1.getReturn()); 68 69 int[] a = new int[ARRAY_SIZE * 4]; 70 ((Allocation)group.execute(input)[0]).copyTo(a); 71 72 pRS.finish(); 73 pRS.destroy(); 74 75 boolean failed = false; 76 for (int i = 0; i < ARRAY_SIZE * 4; i++) { 77 if (a[i] != (i+1) * 2) { 78 Log.e(TAG, "a["+i+"]="+a[i]+", should be "+ ((i+1) * 2)); 79 failed = true; 80 } 81 } 82 if (failed) { 83 failTest(); 84 return; 85 } 86 passTest(); 87 } 88} 89