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
19rs_allocation A;
20rs_allocation B;
21uint32_t gDimX, gDimY, gDimZ;
22static bool failed = false;
23
24void init_vars(int *out) {
25    *out = 7;
26}
27
28int RS_KERNEL root(int ain, rs_kernel_context context, uint32_t x, uint32_t y, uint32_t z) {
29    if (!_RS_ASSERT_EQU(ain, 7))
30        rsDebug("root at x, y, z", x, y, z);
31    uint32_t dimX = rsGetDimX(context);
32    uint32_t dimY = rsGetDimY(context);
33    uint32_t dimZ = rsGetDimZ(context);
34    _RS_ASSERT_EQU(dimX, gDimX);
35    _RS_ASSERT_EQU(dimY, gDimY);
36    _RS_ASSERT_EQU(dimZ, gDimZ);
37    return ain + x + dimX * y + dimX * dimY * z;
38}
39
40static bool test_root_output() {
41    bool failed = false;
42    int i, j, k;
43
44    for (i = 0; i < gDimX; i++) {
45        for (j = 0; j < gDimY; j++) {
46            for (k = 0; k < gDimZ; k++) {
47                int bElt = rsGetElementAt_int(B, i, j, k);
48                int aElt = rsGetElementAt_int(A, i, j, k);
49                if (!_RS_ASSERT_EQU(bElt, (aElt + i + gDimX * j + gDimX * gDimY * k)))
50                    rsDebug("test_root_output at i, j, k", i, j, k);
51            }
52        }
53    }
54
55    if (failed) {
56        rsDebug("kernel3d test_root_output FAILED", 0);
57    }
58    else {
59        rsDebug("kernel3d test_root_output PASSED", 0);
60    }
61
62    return failed;
63}
64
65void verify_root() {
66    failed |= test_root_output();
67}
68
69void kernel_test() {
70    if (failed) {
71        rsSendToClientBlocking(RS_MSG_TEST_FAILED);
72    }
73    else {
74        rsSendToClientBlocking(RS_MSG_TEST_PASSED);
75    }
76}
77