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