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;
18
19import android.content.Context;
20import android.content.res.Resources;
21import android.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    // rs_data_type for float, double, char, short, int, long, uchar, ushort, uint, ulong in that
33    // order
34    private int rsDataTypes[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
35
36    protected UT_single_source_alloc(RSTestCore rstc, Resources res, Context ctx) {
37        super(rstc, "SingleSourceAllocation", ctx);
38        mRes = res;
39    }
40
41    private void initializeGlobals(RenderScript RS, ScriptC_single_source_alloc s, int nDims) {
42        s.set_gDimX(dimX);
43        s.set_gDimY(nDims > 1? dimY: 0);
44        s.set_gDimZ(nDims > 2? dimZ: 0);
45        s.set_gStart(start);
46
47        return;
48    }
49
50    public void run() {
51        RenderScript pRS = RenderScript.create(mCtx);
52        ScriptC_single_source_alloc s = new ScriptC_single_source_alloc(pRS);
53        pRS.setMessageHandler(mRsMessage);
54
55        // Test 1-D, 2-D and 3-D Allocations of basic RenderScript types by creating Allocations and
56        // invoking a kernel on them.
57        for (int dataType: rsDataTypes) {
58            for (int vecSize = 1; vecSize <= 4; vecSize ++) {
59                for (int nDims = 1; nDims <= 3; nDims ++) {
60                    initializeGlobals(pRS, s, nDims);
61                    s.invoke_CreateAndTestAlloc(dataType, vecSize);
62                }
63            }
64        }
65
66        // Exhaustively test valid and invalid calls to rs_* creation functions.  (These tests don't
67        // walk the created allocations, though.)
68        s.invoke_TestAllCases();
69
70        s.invoke_single_source_alloc_test();
71        pRS.finish();
72        waitForMessage();
73        pRS.destroy();
74    }
75}
76