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.RenderScript; 21 22public class UT_single_source_alloc extends UnitTest { 23 private int dimX = 3; 24 private int dimY = 4; 25 private int dimZ = 5; 26 private int start = 23; 27 28 // Mimicking enum rs_data_type in frameworks/rs/script_api/include/rs_object_types.rsh 29 private enum rsDataType { 30 RS_TYPE_FLOAT_16 (1), 31 RS_TYPE_FLOAT_32 (2), 32 RS_TYPE_FLOAT_64 (3), 33 RS_TYPE_SIGNED_8 (4), 34 RS_TYPE_SIGNED_16 (5), 35 RS_TYPE_SIGNED_32 (6), 36 RS_TYPE_SIGNED_64 (7), 37 RS_TYPE_UNSIGNED_8 (8), 38 RS_TYPE_UNSIGNED_16 (9), 39 RS_TYPE_UNSIGNED_32 (10), 40 RS_TYPE_UNSIGNED_64 (11); 41 42 private int value; 43 44 rsDataType(int value) { this.value = value; } 45 public int Value() { return value; } 46 } 47 48 public UT_single_source_alloc(Context ctx) { 49 super("SingleSourceAllocation", ctx); 50 } 51 52 private void initializeGlobals(RenderScript RS, ScriptC_single_source_alloc s, int nDims) { 53 s.set_gDimX(dimX); 54 s.set_gDimY(nDims > 1 ? dimY : 0); 55 s.set_gDimZ(nDims > 2 ? dimZ : 0); 56 s.set_gStart(start); 57 58 return; 59 } 60 61 public void run() { 62 RenderScript pRS = createRenderScript(true); 63 ScriptC_single_source_alloc s = new ScriptC_single_source_alloc(pRS); 64 65 // Test 1-D, 2-D and 3-D Allocations of basic RenderScript types by creating Allocations and 66 // invoking a kernel on them. 67 for (rsDataType dataType : rsDataType.values()) { 68 for (int vecSize = 1; vecSize <= 4; vecSize++) { 69 for (int nDims = 1; nDims <= 3; nDims++) { 70 initializeGlobals(pRS, s, nDims); 71 s.invoke_CreateAndTestAlloc(dataType.Value(), vecSize); 72 } 73 } 74 } 75 76 // Exhaustively test valid and invalid calls to rs_* creation functions. (These tests don't 77 // walk the created allocations, though.) 78 s.invoke_TestAllCases(); 79 80 s.invoke_single_source_alloc_test(); 81 pRS.finish(); 82 s.destroy(); 83 pRS.destroy(); 84 } 85} 86