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
17#include "shared.rsh"
18
19int *a;
20int dimX;
21int dimY;
22int dimZ;
23
24rs_allocation aRaw;
25rs_allocation aFaces;
26rs_allocation aLOD;
27rs_allocation aFacesLOD;
28
29void root(int *o, uint32_t x, uint32_t y) {
30    *o = x + y * dimX;
31}
32
33static bool test_alloc_dims() {
34    bool failed = false;
35    int i, j;
36
37    _RS_ASSERT(rsAllocationGetDimX(aRaw) == dimX);
38    _RS_ASSERT(rsAllocationGetDimY(aRaw) == dimY);
39    _RS_ASSERT(rsAllocationGetDimZ(aRaw) == dimZ);
40
41    // Test 2D addressing
42    for (j = 0; j < dimY; j++) {
43        for (i = 0; i < dimX; i++) {
44            rsDebug("Verifying ", i + j * dimX);
45            const void *p = rsGetElementAt(aRaw, i, j);
46            int val = *(const int *)p;
47            _RS_ASSERT(val == (i + j * dimX));
48        }
49    }
50
51    // Test 1D addressing
52    for (i = 0; i < dimX; i++) {
53        rsDebug("Verifying ", i);
54        const void *p = rsGetElementAt(aRaw, i);
55        int val = *(const int *)p;
56        _RS_ASSERT(val == i);
57    }
58
59    // Test 3D addressing
60    for (j = 0; j < dimY; j++) {
61        for (i = 0; i < dimX; i++) {
62            rsDebug("Verifying ", i + j * dimX);
63            const void *p = rsGetElementAt(aRaw, i, j, 0);
64            int val = *(const int *)p;
65            _RS_ASSERT(val == (i + j * dimX));
66        }
67    }
68
69    _RS_ASSERT(rsAllocationGetDimX(aFaces) == dimX);
70    _RS_ASSERT(rsAllocationGetDimY(aFaces) == dimY);
71    _RS_ASSERT(rsAllocationGetDimZ(aFaces) == dimZ);
72    _RS_ASSERT(rsAllocationGetDimFaces(aFaces) != 0);
73    _RS_ASSERT(rsAllocationGetDimLOD(aFaces) == 0);
74
75    _RS_ASSERT(rsAllocationGetDimX(aLOD) == dimX);
76    _RS_ASSERT(rsAllocationGetDimY(aLOD) == dimY);
77    _RS_ASSERT(rsAllocationGetDimZ(aLOD) == dimZ);
78    _RS_ASSERT(rsAllocationGetDimFaces(aLOD) == 0);
79    _RS_ASSERT(rsAllocationGetDimLOD(aLOD) != 0);
80
81    _RS_ASSERT(rsAllocationGetDimX(aFacesLOD) == dimX);
82    _RS_ASSERT(rsAllocationGetDimY(aFacesLOD) == dimY);
83    _RS_ASSERT(rsAllocationGetDimZ(aFacesLOD) == dimZ);
84    _RS_ASSERT(rsAllocationGetDimFaces(aFacesLOD) != 0);
85    _RS_ASSERT(rsAllocationGetDimLOD(aFacesLOD) != 0);
86
87    if (failed) {
88        rsDebug("test_alloc_dims FAILED", 0);
89    }
90    else {
91        rsDebug("test_alloc_dims PASSED", 0);
92    }
93
94    return failed;
95}
96
97void alloc_supportlib_test() {
98    bool failed = false;
99    failed |= test_alloc_dims();
100
101    if (failed) {
102        rsSendToClientBlocking(RS_MSG_TEST_FAILED);
103    }
104    else {
105        rsSendToClientBlocking(RS_MSG_TEST_PASSED);
106    }
107}
108
109