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