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