1// This file is automatically generated from
2// frameworks/rs/tests/java_api/RSUnitTests/RSUnitTests.py
3/*
4 * Copyright (C) 2017 The Android Open Source Project
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 *      http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19#include "shared.rsh"
20
21struct RetStruct {
22    uint32_t i0;
23    uint32_t i1;
24    uint32_t i2;
25    uint32_t i3;
26    uint32_t i4;
27    uint32_t i5;
28    uint32_t i6;
29    uint32_t i7;
30};
31
32rs_allocation ain0, ain1, ain2;
33rs_allocation ain3;
34
35rs_allocation aout0, aout1, aout2, aout3;
36
37uint32_t dimX;
38
39static bool failed = false;
40
41uint32_t RS_KERNEL init_uint32_alloc(uint32_t x) {
42    return x;
43}
44
45uint16_t RS_KERNEL init_uint16_alloc(uint32_t x) {
46    return x;
47}
48
49uint32_t RS_KERNEL sum2(uint32_t in0, uint32_t in1, uint32_t x) {
50    _RS_ASSERT(in0 == x);
51    _RS_ASSERT(in1 == x);
52
53    return in0 + in1;
54}
55
56struct RetStruct RS_KERNEL
57sum2_struct(uint32_t in0, uint32_t in1, uint32_t x) {
58
59    _RS_ASSERT(in0 == x);
60    _RS_ASSERT(in1 == x);
61
62    struct RetStruct retval;
63
64    retval.i0 = in0 + in1;
65    retval.i1 = in0 + in1;
66    retval.i2 = in0 + in1;
67    retval.i3 = in0 + in1;
68    retval.i4 = in0 + in1;
69    retval.i5 = in0 + in1;
70    retval.i6 = in0 + in1;
71    retval.i7 = in0 + in1;
72
73    return retval;
74}
75
76uint32_t RS_KERNEL sum3(uint32_t in0, uint32_t in1, uint32_t in2, uint32_t x) {
77    _RS_ASSERT(in0 == x);
78    _RS_ASSERT(in1 == x);
79    _RS_ASSERT(in2 == x);
80
81    return in0 + in1 + in2;
82}
83
84
85uint32_t RS_KERNEL sum_mixed(uint32_t in0, uint16_t in1, uint32_t x) {
86    _RS_ASSERT(in0 == x);
87    _RS_ASSERT(in1 == x);
88
89    return in0 + in1;
90}
91
92static bool test_sum2_output() {
93    bool failed = false;
94    uint32_t i;
95
96    for (i = 0; i < dimX; i++) {
97        _RS_ASSERT(rsGetElementAt_uint(aout0, i) ==
98                   (rsGetElementAt_uint(ain0, i) +
99                    rsGetElementAt_uint(ain1, i)));
100    }
101
102    if (failed) {
103        rsDebug("test_sum2_output FAILED", 0);
104    }
105    else {
106        rsDebug("test_sum2_output PASSED", 0);
107    }
108
109    return failed;
110}
111
112static bool test_sum3_output() {
113    bool failed = false;
114    uint32_t i;
115
116    for (i = 0; i < dimX; i++) {
117        _RS_ASSERT(rsGetElementAt_uint(aout1, i) ==
118                   (rsGetElementAt_uint(ain0, i) +
119                    rsGetElementAt_uint(ain1, i) +
120                    rsGetElementAt_uint(ain2, i)));
121    }
122
123    if (failed) {
124        rsDebug("test_sum3_output FAILED", 0);
125    }
126    else {
127        rsDebug("test_sum3_output PASSED", 0);
128    }
129
130    return failed;
131}
132
133static bool test_sum_mixed_output() {
134    bool failed = false;
135    uint32_t i;
136
137    for (i = 0; i < dimX; i++) {
138        _RS_ASSERT(rsGetElementAt_uint(aout2, i) ==
139                   (rsGetElementAt_uint(ain0, i) +
140                    rsGetElementAt_ushort(ain3, i)));
141    }
142
143    if (failed) {
144        rsDebug("test_sum_mixed_output FAILED", 0);
145    }
146    else {
147        rsDebug("test_sum_mixed_output PASSED", 0);
148    }
149
150    return failed;
151}
152
153static bool test_sum2_struct_output() {
154    bool failed = false;
155    uint32_t i;
156
157    for (i = 0; i < dimX; i++) {
158        struct RetStruct *result = (struct RetStruct*)rsGetElementAt(aout3, i);
159
160        uint32_t sum = rsGetElementAt_uint(ain0, i) +
161                       rsGetElementAt_uint(ain1, i);
162
163        _RS_ASSERT(result->i0 == sum);
164        _RS_ASSERT(result->i1 == sum);
165        _RS_ASSERT(result->i2 == sum);
166        _RS_ASSERT(result->i3 == sum);
167        _RS_ASSERT(result->i4 == sum);
168        _RS_ASSERT(result->i5 == sum);
169        _RS_ASSERT(result->i6 == sum);
170        _RS_ASSERT(result->i7 == sum);
171    }
172
173    if (failed) {
174        rsDebug("test_sum2_struct_output FAILED", 0);
175    }
176    else {
177        rsDebug("test_sum2_struct_output PASSED", 0);
178    }
179
180    return failed;
181}
182
183void test_outputs() {
184    failed |= test_sum2_output();
185    failed |= test_sum3_output();
186    failed |= test_sum_mixed_output();
187    failed |= test_sum2_struct_output();
188}
189
190void check_test_results() {
191    if (failed) {
192        rsSendToClientBlocking(RS_MSG_TEST_FAILED);
193    } else {
194        rsSendToClientBlocking(RS_MSG_TEST_PASSED);
195    }
196}
197