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// Same as small_struct_2.rs except for location of padding in struct small_struct[_2].
18
19#include "shared.rsh"
20
21int gDimX;
22int gDimY;
23
24rs_allocation A;
25rs_allocation B;
26
27static int gIntStart = 0x7;
28static long gLongStart = 0x12345678abcdef12;
29
30typedef struct small_struct {
31    int i;
32    // expect 4 bytes of padding here
33    long l;
34} small_struct;
35
36#define ARRAY_LEN 3
37
38typedef struct struct_of_struct {
39    small_struct arr[ARRAY_LEN];
40} struct_of_struct;
41
42void test() {
43    bool failed = false;
44    for (int x = 0; x < gDimX; x ++) {
45        for (int y = 0; y < gDimY; y ++) {
46            small_struct *v = (small_struct *) rsGetElementAt(A, x, y);
47            _RS_ASSERT_EQU(v->i, gIntStart + y * gDimX + x);
48            _RS_ASSERT_EQU(v->l, gLongStart + y * gDimX + x);
49        }
50    }
51
52    for (int x = 0; x < gDimX; x ++) {
53        for (int y = 0; y < gDimY; y ++) {
54            struct_of_struct *v = (struct_of_struct *) rsGetElementAt(B, x, y);
55            for (int idx = 0; idx < ARRAY_LEN; idx ++) {
56                _RS_ASSERT_EQU((*v).arr[idx].i, gIntStart + y * gDimX + x + idx);
57                _RS_ASSERT_EQU((*v).arr[idx].l, gLongStart + y * gDimX + x + idx);
58            }
59        }
60    }
61
62    if (failed) {
63        rsDebug("small_struct test FAILED", 0);
64        rsSendToClientBlocking(RS_MSG_TEST_FAILED);
65    }
66    else {
67        rsDebug("small_struct test PASSED", 0);
68        rsSendToClientBlocking(RS_MSG_TEST_PASSED);
69    }
70}
71
72small_struct RS_KERNEL setStruct(int x, int y) {
73    small_struct output;
74    output.i = gIntStart + y * gDimX + x;
75    output.l = gLongStart + y * gDimX + x;
76    return output;
77}
78
79struct_of_struct RS_KERNEL setArrayOfStruct(int x, int y) {
80    struct_of_struct output;
81    for (int idx = 0; idx < ARRAY_LEN; idx ++) {
82        output.arr[idx].i = gIntStart + y * gDimX + x + idx;
83        output.arr[idx].l = gLongStart + y * gDimX + x + idx;
84    }
85    return output;
86}
87