summaryrefslogtreecommitdiff
path: root/tests/typecheck/typecheck.cpp
blob: 76ae16f386df738491b68f39d8cc0c2a48b8aa12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
 * Copyright (C) 2013 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "RenderScript.h"
#include "ScriptC_kernels.h"

using namespace android;
using namespace RSC;

const static uint32_t x = 7;

sp<Allocation> createAlloc(sp<RS> rs, sp<const Element> e) {
    Type::Builder tb(rs, e);
    tb.setX(x);
    sp<const Type> t = tb.create();
    return Allocation::createTyped(rs, t);
}

#define TEST_ELEM(KERNELNAME, ENAME) \
bool test_elem_##KERNELNAME##_##ENAME() { \
    printf("Verifying forEach_test_" #KERNELNAME "() with " #ENAME "\n"); \
    sp<RS> rs = new RS(); \
    bool r = rs->init("/system/bin"); \
    sp<Allocation> a = createAlloc(rs, Element::ENAME(rs)); \
    ScriptC_kernels sc(rs); \
    sc.forEach_test_##KERNELNAME(a); \
    rs->finish(); \
    bool shouldPass = !strcmp(#KERNELNAME, #ENAME); \
    if (shouldPass != (rs->getError() == RS_SUCCESS)) { \
        printf("Failed forEach_test_" #KERNELNAME "() with " #ENAME "\n"); \
        return true; \
    } \
    return false; \
}

#define TEST_ELEM_ALL(ENAME) \
TEST_ELEM(ENAME, BOOLEAN) \
TEST_ELEM(ENAME, I8) \
TEST_ELEM(ENAME, U8) \
TEST_ELEM(ENAME, I16) \
TEST_ELEM(ENAME, U16) \
TEST_ELEM(ENAME, I32) \
TEST_ELEM(ENAME, U32) \
TEST_ELEM(ENAME, I64) \
TEST_ELEM(ENAME, U64) \
TEST_ELEM(ENAME, F32) \
TEST_ELEM(ENAME, F64)

TEST_ELEM_ALL(BOOLEAN)
TEST_ELEM_ALL(I8)
TEST_ELEM_ALL(U8)
TEST_ELEM_ALL(I16)
TEST_ELEM_ALL(U16)
TEST_ELEM_ALL(I32)
TEST_ELEM_ALL(U32)
TEST_ELEM_ALL(I64)
TEST_ELEM_ALL(U64)
TEST_ELEM_ALL(F32)
TEST_ELEM_ALL(F64)

int main()
{
    bool failed = false;

#define EXECUTE_TEST_ELEM_ALL(ENAME) \
    failed |= test_elem_##ENAME##_BOOLEAN(); \
    failed |= test_elem_##ENAME##_I8(); \
    failed |= test_elem_##ENAME##_U8(); \
    failed |= test_elem_##ENAME##_I16(); \
    failed |= test_elem_##ENAME##_U16(); \
    failed |= test_elem_##ENAME##_I32(); \
    failed |= test_elem_##ENAME##_U32(); \
    failed |= test_elem_##ENAME##_I64(); \
    failed |= test_elem_##ENAME##_U64(); \
    failed |= test_elem_##ENAME##_F32(); \
    failed |= test_elem_##ENAME##_F64(); \

    EXECUTE_TEST_ELEM_ALL(BOOLEAN);
    EXECUTE_TEST_ELEM_ALL(I8);
    EXECUTE_TEST_ELEM_ALL(U8);
    EXECUTE_TEST_ELEM_ALL(I16);
    EXECUTE_TEST_ELEM_ALL(U16);
    EXECUTE_TEST_ELEM_ALL(I32);
    EXECUTE_TEST_ELEM_ALL(U32);
    EXECUTE_TEST_ELEM_ALL(I64);
    EXECUTE_TEST_ELEM_ALL(U64);
    EXECUTE_TEST_ELEM_ALL(F32);
    EXECUTE_TEST_ELEM_ALL(F64);

    if (failed) {
        printf("TEST FAILED!\n");
    } else {
        printf("TEST PASSED!\n");
    }

    return failed;
}