summaryrefslogtreecommitdiff
path: root/tests/java_api/RSUnitTests/supportlibsrc_gen/com/android/rs/unittest/UT_single_source_alloc.java
blob: 2e4c8bd9aca07ebe28511e180fca063c934b7184 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// This file is automatically generated from
// frameworks/rs/tests/java_api/RSUnitTests/RSUnitTests.py
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.rs.unittest;

import android.content.Context;
import android.support.v8.renderscript.RenderScript;

public class UT_single_source_alloc extends UnitTest {
    private int dimX = 3;
    private int dimY = 4;
    private int dimZ = 5;
    private int start = 23;

    // Mimicking enum rs_data_type in frameworks/rs/script_api/include/rs_object_types.rsh
    private enum rsDataType {
        RS_TYPE_FLOAT_16    (1),
        RS_TYPE_FLOAT_32    (2),
        RS_TYPE_FLOAT_64    (3),
        RS_TYPE_SIGNED_8    (4),
        RS_TYPE_SIGNED_16   (5),
        RS_TYPE_SIGNED_32   (6),
        RS_TYPE_SIGNED_64   (7),
        RS_TYPE_UNSIGNED_8  (8),
        RS_TYPE_UNSIGNED_16 (9),
        RS_TYPE_UNSIGNED_32 (10),
        RS_TYPE_UNSIGNED_64 (11);

        private int value;

        rsDataType(int value) { this.value = value; }
        public int Value() { return value; }
    }

    public UT_single_source_alloc(Context ctx) {
        super("SingleSourceAllocation", ctx);
    }

    private void initializeGlobals(RenderScript RS, ScriptC_single_source_alloc s, int nDims) {
        s.set_gDimX(dimX);
        s.set_gDimY(nDims > 1 ? dimY : 0);
        s.set_gDimZ(nDims > 2 ? dimZ : 0);
        s.set_gStart(start);

        return;
    }

    public void run() {
        RenderScript pRS = createRenderScript(true);
        ScriptC_single_source_alloc s = new ScriptC_single_source_alloc(pRS);

        // Test 1-D, 2-D and 3-D Allocations of basic RenderScript types by creating Allocations and
        // invoking a kernel on them.
        for (rsDataType dataType : rsDataType.values()) {
            for (int vecSize = 1; vecSize <= 4; vecSize++) {
                for (int nDims = 1; nDims <= 3; nDims++) {
                    initializeGlobals(pRS, s, nDims);
                    s.invoke_CreateAndTestAlloc(dataType.Value(), vecSize);
                }
            }
        }

        // Exhaustively test valid and invalid calls to rs_* creation functions.  (These tests don't
        // walk the created allocations, though.)
        s.invoke_TestAllCases();

        s.invoke_single_source_alloc_test();
        pRS.finish();
        s.destroy();
        pRS.destroy();
    }
}