1 /* 2 * Copyright (C) 2016 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 // Don't edit this file! It is auto-generated by frameworks/rs/api/generate.sh. 18 19 package android.renderscript.cts; 20 21 import android.renderscript.Allocation; 22 import android.renderscript.RSRuntimeException; 23 import android.renderscript.Element; 24 import android.renderscript.cts.Target; 25 26 import java.util.Arrays; 27 28 public class TestNanHalf extends RSBaseCompute { 29 30 private ScriptC_TestNanHalf script; 31 private ScriptC_TestNanHalfRelaxed scriptRelaxed; 32 33 @Override setUp()34 protected void setUp() throws Exception { 35 super.setUp(); 36 script = new ScriptC_TestNanHalf(mRS); 37 scriptRelaxed = new ScriptC_TestNanHalfRelaxed(mRS); 38 } 39 40 public class ArgumentsHalf { 41 public Target.Floaty out; 42 } 43 checkNanHalfHalf()44 private void checkNanHalfHalf() { 45 try { 46 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE); 47 script.forEach_testNanHalfHalf(out); 48 verifyResultsNanHalfHalf(out, false); 49 } catch (Exception e) { 50 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNanHalfHalf: " + e.toString()); 51 } 52 try { 53 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE); 54 scriptRelaxed.forEach_testNanHalfHalf(out); 55 verifyResultsNanHalfHalf(out, true); 56 } catch (Exception e) { 57 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNanHalfHalf: " + e.toString()); 58 } 59 } 60 verifyResultsNanHalfHalf(Allocation out, boolean relaxed)61 private void verifyResultsNanHalfHalf(Allocation out, boolean relaxed) { 62 short[] arrayOut = new short[INPUTSIZE * 1]; 63 Arrays.fill(arrayOut, (short) 42); 64 out.copyTo(arrayOut); 65 StringBuilder message = new StringBuilder(); 66 boolean errorFound = false; 67 for (int i = 0; i < INPUTSIZE; i++) { 68 for (int j = 0; j < 1 ; j++) { 69 // Extract the inputs. 70 ArgumentsHalf args = new ArgumentsHalf(); 71 // Figure out what the outputs should have been. 72 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 73 CoreMathVerifier.computeNanHalf(args, target); 74 // Validate the outputs. 75 boolean valid = true; 76 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j]))) { 77 valid = false; 78 } 79 if (!valid) { 80 if (!errorFound) { 81 errorFound = true; 82 message.append("Expected output out: "); 83 appendVariableToMessage(message, args.out); 84 message.append("\n"); 85 message.append("Actual output out: "); 86 appendVariableToMessage(message, arrayOut[i * 1 + j]); 87 message.append("\n"); 88 message.append("Actual output out (in double): "); 89 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j])); 90 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j]))) { 91 message.append(" FAIL"); 92 } 93 message.append("\n"); 94 message.append("Errors at"); 95 } 96 message.append(" ["); 97 message.append(Integer.toString(i)); 98 message.append(", "); 99 message.append(Integer.toString(j)); 100 message.append("]"); 101 } 102 } 103 } 104 assertFalse("Incorrect output for checkNanHalfHalf" + 105 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 106 } 107 testNanHalf()108 public void testNanHalf() { 109 checkNanHalfHalf(); 110 } 111 } 112