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 TestFrexp extends RSBaseCompute { 29 30 private ScriptC_TestFrexp script; 31 private ScriptC_TestFrexpRelaxed scriptRelaxed; 32 33 @Override setUp()34 protected void setUp() throws Exception { 35 super.setUp(); 36 script = new ScriptC_TestFrexp(mRS); 37 scriptRelaxed = new ScriptC_TestFrexpRelaxed(mRS); 38 } 39 40 public class ArgumentsFloatIntFloat { 41 public float inV; 42 public int outExponent; 43 public Target.Floaty out; 44 } 45 checkFrexpFloatIntFloat()46 private void checkFrexpFloatIntFloat() { 47 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x7384e56dl, false); 48 try { 49 Allocation outExponent = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 1), INPUTSIZE); 50 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 51 script.set_gAllocOutExponent(outExponent); 52 script.forEach_testFrexpFloatIntFloat(inV, out); 53 verifyResultsFrexpFloatIntFloat(inV, outExponent, out, false); 54 } catch (Exception e) { 55 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFrexpFloatIntFloat: " + e.toString()); 56 } 57 try { 58 Allocation outExponent = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 1), INPUTSIZE); 59 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 60 scriptRelaxed.set_gAllocOutExponent(outExponent); 61 scriptRelaxed.forEach_testFrexpFloatIntFloat(inV, out); 62 verifyResultsFrexpFloatIntFloat(inV, outExponent, out, true); 63 } catch (Exception e) { 64 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFrexpFloatIntFloat: " + e.toString()); 65 } 66 } 67 verifyResultsFrexpFloatIntFloat(Allocation inV, Allocation outExponent, Allocation out, boolean relaxed)68 private void verifyResultsFrexpFloatIntFloat(Allocation inV, Allocation outExponent, Allocation out, boolean relaxed) { 69 float[] arrayInV = new float[INPUTSIZE * 1]; 70 Arrays.fill(arrayInV, (float) 42); 71 inV.copyTo(arrayInV); 72 int[] arrayOutExponent = new int[INPUTSIZE * 1]; 73 Arrays.fill(arrayOutExponent, (int) 42); 74 outExponent.copyTo(arrayOutExponent); 75 float[] arrayOut = new float[INPUTSIZE * 1]; 76 Arrays.fill(arrayOut, (float) 42); 77 out.copyTo(arrayOut); 78 StringBuilder message = new StringBuilder(); 79 boolean errorFound = false; 80 for (int i = 0; i < INPUTSIZE; i++) { 81 for (int j = 0; j < 1 ; j++) { 82 // Extract the inputs. 83 ArgumentsFloatIntFloat args = new ArgumentsFloatIntFloat(); 84 args.inV = arrayInV[i]; 85 // Figure out what the outputs should have been. 86 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 87 CoreMathVerifier.computeFrexp(args, target); 88 // Validate the outputs. 89 boolean valid = true; 90 if (args.outExponent != arrayOutExponent[i * 1 + j]) { 91 valid = false; 92 } 93 if (!args.out.couldBe(arrayOut[i * 1 + j])) { 94 valid = false; 95 } 96 if (!valid) { 97 if (!errorFound) { 98 errorFound = true; 99 message.append("Input inV: "); 100 appendVariableToMessage(message, args.inV); 101 message.append("\n"); 102 message.append("Expected output outExponent: "); 103 appendVariableToMessage(message, args.outExponent); 104 message.append("\n"); 105 message.append("Actual output outExponent: "); 106 appendVariableToMessage(message, arrayOutExponent[i * 1 + j]); 107 if (args.outExponent != arrayOutExponent[i * 1 + j]) { 108 message.append(" FAIL"); 109 } 110 message.append("\n"); 111 message.append("Expected output out: "); 112 appendVariableToMessage(message, args.out); 113 message.append("\n"); 114 message.append("Actual output out: "); 115 appendVariableToMessage(message, arrayOut[i * 1 + j]); 116 if (!args.out.couldBe(arrayOut[i * 1 + j])) { 117 message.append(" FAIL"); 118 } 119 message.append("\n"); 120 message.append("Errors at"); 121 } 122 message.append(" ["); 123 message.append(Integer.toString(i)); 124 message.append(", "); 125 message.append(Integer.toString(j)); 126 message.append("]"); 127 } 128 } 129 } 130 assertFalse("Incorrect output for checkFrexpFloatIntFloat" + 131 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 132 } 133 checkFrexpFloat2Int2Float2()134 private void checkFrexpFloat2Int2Float2() { 135 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x88fe7701l, false); 136 try { 137 Allocation outExponent = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 2), INPUTSIZE); 138 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 139 script.set_gAllocOutExponent(outExponent); 140 script.forEach_testFrexpFloat2Int2Float2(inV, out); 141 verifyResultsFrexpFloat2Int2Float2(inV, outExponent, out, false); 142 } catch (Exception e) { 143 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFrexpFloat2Int2Float2: " + e.toString()); 144 } 145 try { 146 Allocation outExponent = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 2), INPUTSIZE); 147 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 148 scriptRelaxed.set_gAllocOutExponent(outExponent); 149 scriptRelaxed.forEach_testFrexpFloat2Int2Float2(inV, out); 150 verifyResultsFrexpFloat2Int2Float2(inV, outExponent, out, true); 151 } catch (Exception e) { 152 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFrexpFloat2Int2Float2: " + e.toString()); 153 } 154 } 155 verifyResultsFrexpFloat2Int2Float2(Allocation inV, Allocation outExponent, Allocation out, boolean relaxed)156 private void verifyResultsFrexpFloat2Int2Float2(Allocation inV, Allocation outExponent, Allocation out, boolean relaxed) { 157 float[] arrayInV = new float[INPUTSIZE * 2]; 158 Arrays.fill(arrayInV, (float) 42); 159 inV.copyTo(arrayInV); 160 int[] arrayOutExponent = new int[INPUTSIZE * 2]; 161 Arrays.fill(arrayOutExponent, (int) 42); 162 outExponent.copyTo(arrayOutExponent); 163 float[] arrayOut = new float[INPUTSIZE * 2]; 164 Arrays.fill(arrayOut, (float) 42); 165 out.copyTo(arrayOut); 166 StringBuilder message = new StringBuilder(); 167 boolean errorFound = false; 168 for (int i = 0; i < INPUTSIZE; i++) { 169 for (int j = 0; j < 2 ; j++) { 170 // Extract the inputs. 171 ArgumentsFloatIntFloat args = new ArgumentsFloatIntFloat(); 172 args.inV = arrayInV[i * 2 + j]; 173 // Figure out what the outputs should have been. 174 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 175 CoreMathVerifier.computeFrexp(args, target); 176 // Validate the outputs. 177 boolean valid = true; 178 if (args.outExponent != arrayOutExponent[i * 2 + j]) { 179 valid = false; 180 } 181 if (!args.out.couldBe(arrayOut[i * 2 + j])) { 182 valid = false; 183 } 184 if (!valid) { 185 if (!errorFound) { 186 errorFound = true; 187 message.append("Input inV: "); 188 appendVariableToMessage(message, args.inV); 189 message.append("\n"); 190 message.append("Expected output outExponent: "); 191 appendVariableToMessage(message, args.outExponent); 192 message.append("\n"); 193 message.append("Actual output outExponent: "); 194 appendVariableToMessage(message, arrayOutExponent[i * 2 + j]); 195 if (args.outExponent != arrayOutExponent[i * 2 + j]) { 196 message.append(" FAIL"); 197 } 198 message.append("\n"); 199 message.append("Expected output out: "); 200 appendVariableToMessage(message, args.out); 201 message.append("\n"); 202 message.append("Actual output out: "); 203 appendVariableToMessage(message, arrayOut[i * 2 + j]); 204 if (!args.out.couldBe(arrayOut[i * 2 + j])) { 205 message.append(" FAIL"); 206 } 207 message.append("\n"); 208 message.append("Errors at"); 209 } 210 message.append(" ["); 211 message.append(Integer.toString(i)); 212 message.append(", "); 213 message.append(Integer.toString(j)); 214 message.append("]"); 215 } 216 } 217 } 218 assertFalse("Incorrect output for checkFrexpFloat2Int2Float2" + 219 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 220 } 221 checkFrexpFloat3Int3Float3()222 private void checkFrexpFloat3Int3Float3() { 223 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x7eb0e3bal, false); 224 try { 225 Allocation outExponent = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 3), INPUTSIZE); 226 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 227 script.set_gAllocOutExponent(outExponent); 228 script.forEach_testFrexpFloat3Int3Float3(inV, out); 229 verifyResultsFrexpFloat3Int3Float3(inV, outExponent, out, false); 230 } catch (Exception e) { 231 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFrexpFloat3Int3Float3: " + e.toString()); 232 } 233 try { 234 Allocation outExponent = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 3), INPUTSIZE); 235 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 236 scriptRelaxed.set_gAllocOutExponent(outExponent); 237 scriptRelaxed.forEach_testFrexpFloat3Int3Float3(inV, out); 238 verifyResultsFrexpFloat3Int3Float3(inV, outExponent, out, true); 239 } catch (Exception e) { 240 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFrexpFloat3Int3Float3: " + e.toString()); 241 } 242 } 243 verifyResultsFrexpFloat3Int3Float3(Allocation inV, Allocation outExponent, Allocation out, boolean relaxed)244 private void verifyResultsFrexpFloat3Int3Float3(Allocation inV, Allocation outExponent, Allocation out, boolean relaxed) { 245 float[] arrayInV = new float[INPUTSIZE * 4]; 246 Arrays.fill(arrayInV, (float) 42); 247 inV.copyTo(arrayInV); 248 int[] arrayOutExponent = new int[INPUTSIZE * 4]; 249 Arrays.fill(arrayOutExponent, (int) 42); 250 outExponent.copyTo(arrayOutExponent); 251 float[] arrayOut = new float[INPUTSIZE * 4]; 252 Arrays.fill(arrayOut, (float) 42); 253 out.copyTo(arrayOut); 254 StringBuilder message = new StringBuilder(); 255 boolean errorFound = false; 256 for (int i = 0; i < INPUTSIZE; i++) { 257 for (int j = 0; j < 3 ; j++) { 258 // Extract the inputs. 259 ArgumentsFloatIntFloat args = new ArgumentsFloatIntFloat(); 260 args.inV = arrayInV[i * 4 + j]; 261 // Figure out what the outputs should have been. 262 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 263 CoreMathVerifier.computeFrexp(args, target); 264 // Validate the outputs. 265 boolean valid = true; 266 if (args.outExponent != arrayOutExponent[i * 4 + j]) { 267 valid = false; 268 } 269 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 270 valid = false; 271 } 272 if (!valid) { 273 if (!errorFound) { 274 errorFound = true; 275 message.append("Input inV: "); 276 appendVariableToMessage(message, args.inV); 277 message.append("\n"); 278 message.append("Expected output outExponent: "); 279 appendVariableToMessage(message, args.outExponent); 280 message.append("\n"); 281 message.append("Actual output outExponent: "); 282 appendVariableToMessage(message, arrayOutExponent[i * 4 + j]); 283 if (args.outExponent != arrayOutExponent[i * 4 + j]) { 284 message.append(" FAIL"); 285 } 286 message.append("\n"); 287 message.append("Expected output out: "); 288 appendVariableToMessage(message, args.out); 289 message.append("\n"); 290 message.append("Actual output out: "); 291 appendVariableToMessage(message, arrayOut[i * 4 + j]); 292 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 293 message.append(" FAIL"); 294 } 295 message.append("\n"); 296 message.append("Errors at"); 297 } 298 message.append(" ["); 299 message.append(Integer.toString(i)); 300 message.append(", "); 301 message.append(Integer.toString(j)); 302 message.append("]"); 303 } 304 } 305 } 306 assertFalse("Incorrect output for checkFrexpFloat3Int3Float3" + 307 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 308 } 309 checkFrexpFloat4Int4Float4()310 private void checkFrexpFloat4Int4Float4() { 311 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x74635073l, false); 312 try { 313 Allocation outExponent = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 4), INPUTSIZE); 314 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 315 script.set_gAllocOutExponent(outExponent); 316 script.forEach_testFrexpFloat4Int4Float4(inV, out); 317 verifyResultsFrexpFloat4Int4Float4(inV, outExponent, out, false); 318 } catch (Exception e) { 319 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFrexpFloat4Int4Float4: " + e.toString()); 320 } 321 try { 322 Allocation outExponent = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 4), INPUTSIZE); 323 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 324 scriptRelaxed.set_gAllocOutExponent(outExponent); 325 scriptRelaxed.forEach_testFrexpFloat4Int4Float4(inV, out); 326 verifyResultsFrexpFloat4Int4Float4(inV, outExponent, out, true); 327 } catch (Exception e) { 328 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFrexpFloat4Int4Float4: " + e.toString()); 329 } 330 } 331 verifyResultsFrexpFloat4Int4Float4(Allocation inV, Allocation outExponent, Allocation out, boolean relaxed)332 private void verifyResultsFrexpFloat4Int4Float4(Allocation inV, Allocation outExponent, Allocation out, boolean relaxed) { 333 float[] arrayInV = new float[INPUTSIZE * 4]; 334 Arrays.fill(arrayInV, (float) 42); 335 inV.copyTo(arrayInV); 336 int[] arrayOutExponent = new int[INPUTSIZE * 4]; 337 Arrays.fill(arrayOutExponent, (int) 42); 338 outExponent.copyTo(arrayOutExponent); 339 float[] arrayOut = new float[INPUTSIZE * 4]; 340 Arrays.fill(arrayOut, (float) 42); 341 out.copyTo(arrayOut); 342 StringBuilder message = new StringBuilder(); 343 boolean errorFound = false; 344 for (int i = 0; i < INPUTSIZE; i++) { 345 for (int j = 0; j < 4 ; j++) { 346 // Extract the inputs. 347 ArgumentsFloatIntFloat args = new ArgumentsFloatIntFloat(); 348 args.inV = arrayInV[i * 4 + j]; 349 // Figure out what the outputs should have been. 350 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 351 CoreMathVerifier.computeFrexp(args, target); 352 // Validate the outputs. 353 boolean valid = true; 354 if (args.outExponent != arrayOutExponent[i * 4 + j]) { 355 valid = false; 356 } 357 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 358 valid = false; 359 } 360 if (!valid) { 361 if (!errorFound) { 362 errorFound = true; 363 message.append("Input inV: "); 364 appendVariableToMessage(message, args.inV); 365 message.append("\n"); 366 message.append("Expected output outExponent: "); 367 appendVariableToMessage(message, args.outExponent); 368 message.append("\n"); 369 message.append("Actual output outExponent: "); 370 appendVariableToMessage(message, arrayOutExponent[i * 4 + j]); 371 if (args.outExponent != arrayOutExponent[i * 4 + j]) { 372 message.append(" FAIL"); 373 } 374 message.append("\n"); 375 message.append("Expected output out: "); 376 appendVariableToMessage(message, args.out); 377 message.append("\n"); 378 message.append("Actual output out: "); 379 appendVariableToMessage(message, arrayOut[i * 4 + j]); 380 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 381 message.append(" FAIL"); 382 } 383 message.append("\n"); 384 message.append("Errors at"); 385 } 386 message.append(" ["); 387 message.append(Integer.toString(i)); 388 message.append(", "); 389 message.append(Integer.toString(j)); 390 message.append("]"); 391 } 392 } 393 } 394 assertFalse("Incorrect output for checkFrexpFloat4Int4Float4" + 395 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 396 } 397 testFrexp()398 public void testFrexp() { 399 checkFrexpFloatIntFloat(); 400 checkFrexpFloat2Int2Float2(); 401 checkFrexpFloat3Int3Float3(); 402 checkFrexpFloat4Int4Float4(); 403 } 404 } 405