Home | History | Annotate | Download | only in typecheck
      1 /*
      2  * Copyright (C) 2013 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 "RenderScript.h"
     18 #include "ScriptC_kernels.h"
     19 
     20 using namespace android;
     21 using namespace RSC;
     22 
     23 const static uint32_t x = 7;
     24 
     25 sp<Allocation> createAlloc(sp<RS> rs, sp<const Element> e) {
     26     Type::Builder tb(rs, e);
     27     tb.setX(x);
     28     sp<const Type> t = tb.create();
     29     return Allocation::createTyped(rs, t);
     30 }
     31 
     32 #define TEST_ELEM(KERNELNAME, ENAME) \
     33 bool test_elem_##KERNELNAME##_##ENAME() { \
     34     printf("Verifying forEach_test_" #KERNELNAME "() with " #ENAME "\n"); \
     35     sp<RS> rs = new RS(); \
     36     bool r = rs->init("/system/bin"); \
     37     sp<Allocation> a = createAlloc(rs, Element::ENAME(rs)); \
     38     ScriptC_kernels sc(rs); \
     39     sc.forEach_test_##KERNELNAME(a); \
     40     rs->finish(); \
     41     bool shouldPass = !strcmp(#KERNELNAME, #ENAME); \
     42     if (shouldPass != (rs->getError() == RS_SUCCESS)) { \
     43         printf("Failed forEach_test_" #KERNELNAME "() with " #ENAME "\n"); \
     44         return true; \
     45     } \
     46     return false; \
     47 }
     48 
     49 #define TEST_ELEM_ALL(ENAME) \
     50 TEST_ELEM(ENAME, BOOLEAN) \
     51 TEST_ELEM(ENAME, I8) \
     52 TEST_ELEM(ENAME, U8) \
     53 TEST_ELEM(ENAME, I16) \
     54 TEST_ELEM(ENAME, U16) \
     55 TEST_ELEM(ENAME, I32) \
     56 TEST_ELEM(ENAME, U32) \
     57 TEST_ELEM(ENAME, I64) \
     58 TEST_ELEM(ENAME, U64) \
     59 TEST_ELEM(ENAME, F32) \
     60 TEST_ELEM(ENAME, F64)
     61 
     62 TEST_ELEM_ALL(BOOLEAN)
     63 TEST_ELEM_ALL(I8)
     64 TEST_ELEM_ALL(U8)
     65 TEST_ELEM_ALL(I16)
     66 TEST_ELEM_ALL(U16)
     67 TEST_ELEM_ALL(I32)
     68 TEST_ELEM_ALL(U32)
     69 TEST_ELEM_ALL(I64)
     70 TEST_ELEM_ALL(U64)
     71 TEST_ELEM_ALL(F32)
     72 TEST_ELEM_ALL(F64)
     73 
     74 int main()
     75 {
     76     bool failed = false;
     77 
     78 #define EXECUTE_TEST_ELEM_ALL(ENAME) \
     79     failed |= test_elem_##ENAME##_BOOLEAN(); \
     80     failed |= test_elem_##ENAME##_I8(); \
     81     failed |= test_elem_##ENAME##_U8(); \
     82     failed |= test_elem_##ENAME##_I16(); \
     83     failed |= test_elem_##ENAME##_U16(); \
     84     failed |= test_elem_##ENAME##_I32(); \
     85     failed |= test_elem_##ENAME##_U32(); \
     86     failed |= test_elem_##ENAME##_I64(); \
     87     failed |= test_elem_##ENAME##_U64(); \
     88     failed |= test_elem_##ENAME##_F32(); \
     89     failed |= test_elem_##ENAME##_F64(); \
     90 
     91     EXECUTE_TEST_ELEM_ALL(BOOLEAN);
     92     EXECUTE_TEST_ELEM_ALL(I8);
     93     EXECUTE_TEST_ELEM_ALL(U8);
     94     EXECUTE_TEST_ELEM_ALL(I16);
     95     EXECUTE_TEST_ELEM_ALL(U16);
     96     EXECUTE_TEST_ELEM_ALL(I32);
     97     EXECUTE_TEST_ELEM_ALL(U32);
     98     EXECUTE_TEST_ELEM_ALL(I64);
     99     EXECUTE_TEST_ELEM_ALL(U64);
    100     EXECUTE_TEST_ELEM_ALL(F32);
    101     EXECUTE_TEST_ELEM_ALL(F64);
    102 
    103     if (failed) {
    104         printf("TEST FAILED!\n");
    105     } else {
    106         printf("TEST PASSED!\n");
    107     }
    108 
    109     return failed;
    110 }
    111