1/* 2 * Copyright (C) 2017 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.unittest; 18 19import android.content.Context; 20import android.renderscript.Allocation; 21import android.renderscript.Element; 22import android.renderscript.RenderScript; 23import android.renderscript.Type; 24 25public class UT_foreach_multi extends UnitTest { 26 private Allocation Ain0; 27 private Allocation Ain1; 28 private Allocation Ain2; 29 private Allocation Ain3; 30 31 private Allocation Out0; 32 private Allocation Out1; 33 private Allocation Out2; 34 private Allocation Out3; 35 36 public UT_foreach_multi(Context ctx) { 37 super("Foreach Multi-input", ctx); 38 } 39 40 private void initializeGlobals(RenderScript RS, ScriptC_foreach_multi s) { 41 Type.Builder type32Builder = new Type.Builder(RS, Element.U32(RS)); 42 Type.Builder type16Builder = new Type.Builder(RS, Element.U16(RS)); 43 44 int Xdim = 5; 45 s.set_dimX(Xdim); 46 type32Builder.setX(Xdim); 47 type16Builder.setX(Xdim); 48 49 // 32-bit input allocations 50 51 Ain0 = Allocation.createTyped(RS, type32Builder.create()); 52 s.set_ain0(Ain0); 53 s.forEach_init_uint32_alloc(Ain0); 54 55 Ain1 = Allocation.createTyped(RS, type32Builder.create()); 56 s.set_ain1(Ain1); 57 s.forEach_init_uint32_alloc(Ain1); 58 59 Ain2 = Allocation.createTyped(RS, type32Builder.create()); 60 s.set_ain2(Ain2); 61 s.forEach_init_uint32_alloc(Ain2); 62 63 // 16-bit input allocation 64 65 Ain3 = Allocation.createTyped(RS, type16Builder.create()); 66 s.set_ain3(Ain3); 67 s.forEach_init_uint16_alloc(Ain3); 68 69 // 32-bit output allocations 70 71 Out0 = Allocation.createTyped(RS, type32Builder.create()); 72 s.set_aout0(Out0); 73 74 Out1 = Allocation.createTyped(RS, type32Builder.create()); 75 s.set_aout1(Out1); 76 77 Out2 = Allocation.createTyped(RS, type32Builder.create()); 78 s.set_aout2(Out2); 79 80 // RetStruct output allocations 81 82 ScriptField_RetStruct StructType = new ScriptField_RetStruct(RS, Xdim); 83 Out3 = StructType.getAllocation(); 84 s.set_aout3(Out3); 85 86 return; 87 } 88 89 public void run() { 90 RenderScript pRS = createRenderScript(true); 91 ScriptC_foreach_multi s = new ScriptC_foreach_multi(pRS); 92 93 94 initializeGlobals(pRS, s); 95 96 s.forEach_sum2(Ain0, Ain1, Out0); 97 s.forEach_sum3(Ain0, Ain1, Ain2, Out1); 98 s.forEach_sum_mixed(Ain0, Ain3, Out2); 99 s.forEach_sum2_struct(Ain0, Ain1, Out3); 100 101 s.invoke_test_outputs(); 102 s.invoke_check_test_results(); 103 104 pRS.finish(); 105 s.destroy(); 106 pRS.destroy(); 107 } 108} 109