1#include "shared.rsh"
2
3int dimX;
4int dimY;
5int xStart = 0;
6int xEnd = 0;
7int yStart = 0;
8int yEnd = 0;
9
10rs_script s;
11rs_allocation aRaw;
12rs_allocation ain;
13rs_allocation aout;
14
15void root(int *out, uint32_t x, uint32_t y) {
16    *out = x + y * dimX;
17}
18
19int RS_KERNEL zero() {
20    return 0;
21}
22
23static bool test_root_output() {
24    bool failed = false;
25    int i, j;
26
27    for (j = 0; j < dimY; j++) {
28        for (i = 0; i < dimX; i++) {
29            int v = rsGetElementAt_int(aRaw, i, j);
30            rsDebug("i: ", i);
31            rsDebug("j: ", j);
32            rsDebug("a[j][i]: ", v);
33            if (i < xStart || i >= xEnd || j < yStart || j >= yEnd) {
34                _RS_ASSERT(v == 0);
35            } else {
36                _RS_ASSERT(v == (i + j * dimX));
37            }
38        }
39    }
40
41    if (failed) {
42        rsDebug("test_root_output FAILED", 0);
43    }
44    else {
45        rsDebug("test_root_output PASSED", 0);
46    }
47
48    return failed;
49}
50
51void foreach_bounds_test() {
52    static bool failed = false;
53
54    rs_script_call_t rssc = {0};
55    rssc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE;
56    rssc.xStart = xStart;
57    rssc.xEnd = xEnd;
58    rssc.yStart = yStart;
59    rssc.yEnd = yEnd;
60
61    rsForEach(s, ain, aout, NULL, 0, &rssc);
62
63    failed |= test_root_output();
64
65    if (failed) {
66        rsSendToClientBlocking(RS_MSG_TEST_FAILED);
67    }
68    else {
69        rsSendToClientBlocking(RS_MSG_TEST_PASSED);
70    }
71}
72
73