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