1// This file is automatically generated from 2// frameworks/rs/tests/java_api/RSUnitTests/RSUnitTests.py 3/* 4 * Copyright (C) 2017 The Android Open Source Project 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19#pragma version(1) 20 21#pragma rs java_package_name(com.android.rs.unittest) 22 23typedef struct TestResult_s { 24 rs_allocation name; 25 bool pass; 26 float score; 27 int64_t time; 28} TestResult; 29//TestResult *g_results; 30 31static int64_t g_time; 32 33static inline void start(void) { 34 g_time = rsUptimeMillis(); 35} 36 37static inline float end(uint32_t idx) { 38 int64_t t = rsUptimeMillis() - g_time; 39 //g_results[idx].time = t; 40 //rsDebug("test time", (int)t); 41 return ((float)t) / 1000.f; 42} 43 44#define _RS_ASSERT(b) \ 45do { \ 46 if (!(b)) { \ 47 failed = true; \ 48 rsDebug(#b " FAILED", 0); \ 49 } \ 50\ 51} while (0) 52 53#define _RS_ASSERT_EQU(e1, e2) \ 54 (((e1) != (e2)) ? (failed = true, rsDebug(#e1 " != " #e2, (e1), (e2)), false) : true) 55 56static const int iposinf = 0x7f800000; 57static const int ineginf = 0xff800000; 58 59static inline const float posinf() { 60 float f = *((float*)&iposinf); 61 return f; 62} 63 64static inline const float neginf() { 65 float f = *((float*)&ineginf); 66 return f; 67} 68 69static inline bool isposinf(float f) { 70 int i = *((int*)(void*)&f); 71 return (i == iposinf); 72} 73 74static inline bool isneginf(float f) { 75 int i = *((int*)(void*)&f); 76 return (i == ineginf); 77} 78 79static inline bool isnan(float f) { 80 int i = *((int*)(void*)&f); 81 return (((i & 0x7f800000) == 0x7f800000) && (i & 0x007fffff)); 82} 83 84static inline bool isposzero(float f) { 85 int i = *((int*)(void*)&f); 86 return (i == 0x00000000); 87} 88 89static inline bool isnegzero(float f) { 90 int i = *((int*)(void*)&f); 91 return (i == 0x80000000); 92} 93 94static inline bool iszero(float f) { 95 return isposzero(f) || isnegzero(f); 96} 97 98/* Absolute epsilon used for floats. Value is similar to float.h. */ 99#ifndef FLT_EPSILON 100#define FLT_EPSILON 1.19e7f 101#endif 102/* Max ULPs while still being considered "equal". Only used when this number 103 of ULPs is of a greater size than FLT_EPSILON. */ 104#define FLT_MAX_ULP 1 105 106/* Calculate the difference in ULPs between the two values. (Return zero on 107 perfect equality.) */ 108static inline int float_dist(float f1, float f2) { 109 return *((int *)(&f1)) - *((int *)(&f2)); 110} 111 112/* Check if two floats are essentially equal. Will fail with some values 113 due to design. (Validate using FLT_EPSILON or similar if necessary.) */ 114static inline bool float_almost_equal(float f1, float f2) { 115 int *i1 = (int*)(&f1); 116 int *i2 = (int*)(&f2); 117 118 // Check for sign equality 119 if ( ((*i1 >> 31) == 0) != ((*i2 >> 31) == 0) ) { 120 // Handle signed zeroes 121 if (f1 == f2) 122 return true; 123 return false; 124 } 125 126 // Check with ULP distance 127 if (float_dist(f1, f2) > FLT_MAX_ULP) 128 return false; 129 return true; 130} 131 132/* These constants must match those in UnitTest.java */ 133static const int RS_MSG_TEST_PASSED = 100; 134static const int RS_MSG_TEST_FAILED = 101; 135 136#define RSTEST_COMPAT 137