1/* 2 * Copyright (C) 2017 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 "shared.rsh" 18 19static bool test_clamp_vector() { 20 bool failed = false; 21 22 float2 src2 = { 2.0f, 2.0f}; 23 float2 min2 = { 0.5f, -3.0f}; 24 float2 max2 = { 1.0f, 9.0f}; 25 26 float2 res2 = clamp(src2, min2, max2); 27 _RS_ASSERT(res2.x == 1.0f); 28 _RS_ASSERT(res2.y == 2.0f); 29 30 31 float3 src3 = { 2.0f, 2.0f, 1.0f}; 32 float3 min3 = { 0.5f, -3.0f, 3.0f}; 33 float3 max3 = { 1.0f, 9.0f, 4.0f}; 34 35 float3 res3 = clamp(src3, min3, max3); 36 _RS_ASSERT(res3.x == 1.0f); 37 _RS_ASSERT(res3.y == 2.0f); 38 _RS_ASSERT(res3.z == 3.0f); 39 40 41 float4 src4 = { 2.0f, 2.0f, 1.0f, 4.0f }; 42 float4 min4 = { 0.5f, -3.0f, 3.0f, 4.0f }; 43 float4 max4 = { 1.0f, 9.0f, 4.0f, 4.0f }; 44 45 float4 res4 = clamp(src4, min4, max4); 46 _RS_ASSERT(res4.x == 1.0f); 47 _RS_ASSERT(res4.y == 2.0f); 48 _RS_ASSERT(res4.z == 3.0f); 49 _RS_ASSERT(res4.w == 4.0f); 50 51 if (failed) { 52 rsDebug("test_clamp_vector FAILED", 0); 53 } 54 else { 55 rsDebug("test_clamp_vector PASSED", 0); 56 } 57 58 return failed; 59} 60 61void clamp_test() { 62 bool failed = false; 63 failed |= test_clamp_vector(); 64 65 if (failed) { 66 rsSendToClientBlocking(RS_MSG_TEST_FAILED); 67 } 68 else { 69 rsSendToClientBlocking(RS_MSG_TEST_PASSED); 70 } 71} 72 73