summaryrefslogtreecommitdiff
path: root/tests/java_api/RSUnitTests/supportlibsrc_gen/com/android/rs/unittest/shared.rsh
blob: 657280bf89f20837fbbe84a8a70809e6c028477f (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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// This file is automatically generated from
// frameworks/rs/tests/java_api/RSUnitTests/RSUnitTests.py
/*
 * Copyright (C) 2017 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.
 */

#pragma version(1)

#pragma rs java_package_name(com.android.rs.unittest)

typedef struct TestResult_s {
    rs_allocation name;
    bool pass;
    float score;
    int64_t time;
} TestResult;
//TestResult *g_results;

static int64_t g_time;

static inline void start(void) {
    g_time = rsUptimeMillis();
}

static inline float end(uint32_t idx) {
    int64_t t = rsUptimeMillis() - g_time;
    //g_results[idx].time = t;
    //rsDebug("test time", (int)t);
    return ((float)t) / 1000.f;
}

#define _RS_ASSERT(b) \
do { \
    if (!(b)) { \
        failed = true; \
        rsDebug(#b " FAILED", 0); \
    } \
\
} while (0)

#define _RS_ASSERT_EQU(e1, e2) \
  (((e1) != (e2)) ? (failed = true, rsDebug(#e1 " != " #e2, (e1), (e2)), false) : true)

static const int iposinf = 0x7f800000;
static const int ineginf = 0xff800000;

static inline const float posinf() {
    float f = *((float*)&iposinf);
    return f;
}

static inline const float neginf() {
    float f = *((float*)&ineginf);
    return f;
}

static inline bool isposinf(float f) {
    int i = *((int*)(void*)&f);
    return (i == iposinf);
}

static inline bool isneginf(float f) {
    int i = *((int*)(void*)&f);
    return (i == ineginf);
}

static inline bool isnan(float f) {
    int i = *((int*)(void*)&f);
    return (((i & 0x7f800000) == 0x7f800000) && (i & 0x007fffff));
}

static inline bool isposzero(float f) {
    int i = *((int*)(void*)&f);
    return (i == 0x00000000);
}

static inline bool isnegzero(float f) {
    int i = *((int*)(void*)&f);
    return (i == 0x80000000);
}

static inline bool iszero(float f) {
    return isposzero(f) || isnegzero(f);
}

/* Absolute epsilon used for floats.  Value is similar to float.h. */
#ifndef FLT_EPSILON
#define FLT_EPSILON 1.19e7f
#endif
/* Max ULPs while still being considered "equal".  Only used when this number
   of ULPs is of a greater size than FLT_EPSILON. */
#define FLT_MAX_ULP 1

/* Calculate the difference in ULPs between the two values.  (Return zero on
   perfect equality.) */
static inline int float_dist(float f1, float f2) {
    return *((int *)(&f1)) - *((int *)(&f2));
}

/* Check if two floats are essentially equal.  Will fail with some values
   due to design.  (Validate using FLT_EPSILON or similar if necessary.) */
static inline bool float_almost_equal(float f1, float f2) {
    int *i1 = (int*)(&f1);
    int *i2 = (int*)(&f2);

    // Check for sign equality
    if ( ((*i1 >> 31) == 0) != ((*i2 >> 31) == 0) ) {
        // Handle signed zeroes
        if (f1 == f2)
            return true;
        return false;
    }

    // Check with ULP distance
    if (float_dist(f1, f2) > FLT_MAX_ULP)
        return false;
    return true;
}

/* These constants must match those in UnitTest.java */
static const int RS_MSG_TEST_PASSED = 100;
static const int RS_MSG_TEST_FAILED = 101;

#define RSTEST_COMPAT