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 TestAbs extends RSBaseCompute { 29 30 private ScriptC_TestAbs script; 31 private ScriptC_TestAbsRelaxed scriptRelaxed; 32 33 @Override setUp()34 protected void setUp() throws Exception { 35 super.setUp(); 36 script = new ScriptC_TestAbs(mRS); 37 scriptRelaxed = new ScriptC_TestAbsRelaxed(mRS); 38 } 39 40 public class ArgumentsCharUchar { 41 public byte inV; 42 public byte out; 43 } 44 checkAbsCharUchar()45 private void checkAbsCharUchar() { 46 Allocation inV = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 1, 0xf7393ea6l, false); 47 try { 48 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 1), INPUTSIZE); 49 script.forEach_testAbsCharUchar(inV, out); 50 verifyResultsAbsCharUchar(inV, out, false); 51 } catch (Exception e) { 52 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsCharUchar: " + e.toString()); 53 } 54 try { 55 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 1), INPUTSIZE); 56 scriptRelaxed.forEach_testAbsCharUchar(inV, out); 57 verifyResultsAbsCharUchar(inV, out, true); 58 } catch (Exception e) { 59 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsCharUchar: " + e.toString()); 60 } 61 } 62 verifyResultsAbsCharUchar(Allocation inV, Allocation out, boolean relaxed)63 private void verifyResultsAbsCharUchar(Allocation inV, Allocation out, boolean relaxed) { 64 byte[] arrayInV = new byte[INPUTSIZE * 1]; 65 Arrays.fill(arrayInV, (byte) 42); 66 inV.copyTo(arrayInV); 67 byte[] arrayOut = new byte[INPUTSIZE * 1]; 68 Arrays.fill(arrayOut, (byte) 42); 69 out.copyTo(arrayOut); 70 StringBuilder message = new StringBuilder(); 71 boolean errorFound = false; 72 for (int i = 0; i < INPUTSIZE; i++) { 73 for (int j = 0; j < 1 ; j++) { 74 // Extract the inputs. 75 ArgumentsCharUchar args = new ArgumentsCharUchar(); 76 args.inV = arrayInV[i]; 77 // Figure out what the outputs should have been. 78 CoreMathVerifier.computeAbs(args); 79 // Validate the outputs. 80 boolean valid = true; 81 if (args.out != arrayOut[i * 1 + j]) { 82 valid = false; 83 } 84 if (!valid) { 85 if (!errorFound) { 86 errorFound = true; 87 message.append("Input inV: "); 88 appendVariableToMessage(message, args.inV); 89 message.append("\n"); 90 message.append("Expected output out: "); 91 appendVariableToMessage(message, args.out); 92 message.append("\n"); 93 message.append("Actual output out: "); 94 appendVariableToMessage(message, arrayOut[i * 1 + j]); 95 if (args.out != arrayOut[i * 1 + j]) { 96 message.append(" FAIL"); 97 } 98 message.append("\n"); 99 message.append("Errors at"); 100 } 101 message.append(" ["); 102 message.append(Integer.toString(i)); 103 message.append(", "); 104 message.append(Integer.toString(j)); 105 message.append("]"); 106 } 107 } 108 } 109 assertFalse("Incorrect output for checkAbsCharUchar" + 110 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 111 } 112 checkAbsChar2Uchar2()113 private void checkAbsChar2Uchar2() { 114 Allocation inV = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 2, 0xe5e407cl, false); 115 try { 116 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 2), INPUTSIZE); 117 script.forEach_testAbsChar2Uchar2(inV, out); 118 verifyResultsAbsChar2Uchar2(inV, out, false); 119 } catch (Exception e) { 120 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsChar2Uchar2: " + e.toString()); 121 } 122 try { 123 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 2), INPUTSIZE); 124 scriptRelaxed.forEach_testAbsChar2Uchar2(inV, out); 125 verifyResultsAbsChar2Uchar2(inV, out, true); 126 } catch (Exception e) { 127 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsChar2Uchar2: " + e.toString()); 128 } 129 } 130 verifyResultsAbsChar2Uchar2(Allocation inV, Allocation out, boolean relaxed)131 private void verifyResultsAbsChar2Uchar2(Allocation inV, Allocation out, boolean relaxed) { 132 byte[] arrayInV = new byte[INPUTSIZE * 2]; 133 Arrays.fill(arrayInV, (byte) 42); 134 inV.copyTo(arrayInV); 135 byte[] arrayOut = new byte[INPUTSIZE * 2]; 136 Arrays.fill(arrayOut, (byte) 42); 137 out.copyTo(arrayOut); 138 StringBuilder message = new StringBuilder(); 139 boolean errorFound = false; 140 for (int i = 0; i < INPUTSIZE; i++) { 141 for (int j = 0; j < 2 ; j++) { 142 // Extract the inputs. 143 ArgumentsCharUchar args = new ArgumentsCharUchar(); 144 args.inV = arrayInV[i * 2 + j]; 145 // Figure out what the outputs should have been. 146 CoreMathVerifier.computeAbs(args); 147 // Validate the outputs. 148 boolean valid = true; 149 if (args.out != arrayOut[i * 2 + j]) { 150 valid = false; 151 } 152 if (!valid) { 153 if (!errorFound) { 154 errorFound = true; 155 message.append("Input inV: "); 156 appendVariableToMessage(message, args.inV); 157 message.append("\n"); 158 message.append("Expected output out: "); 159 appendVariableToMessage(message, args.out); 160 message.append("\n"); 161 message.append("Actual output out: "); 162 appendVariableToMessage(message, arrayOut[i * 2 + j]); 163 if (args.out != arrayOut[i * 2 + j]) { 164 message.append(" FAIL"); 165 } 166 message.append("\n"); 167 message.append("Errors at"); 168 } 169 message.append(" ["); 170 message.append(Integer.toString(i)); 171 message.append(", "); 172 message.append(Integer.toString(j)); 173 message.append("]"); 174 } 175 } 176 } 177 assertFalse("Incorrect output for checkAbsChar2Uchar2" + 178 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 179 } 180 checkAbsChar3Uchar3()181 private void checkAbsChar3Uchar3() { 182 Allocation inV = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 3, 0x479615al, false); 183 try { 184 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 3), INPUTSIZE); 185 script.forEach_testAbsChar3Uchar3(inV, out); 186 verifyResultsAbsChar3Uchar3(inV, out, false); 187 } catch (Exception e) { 188 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsChar3Uchar3: " + e.toString()); 189 } 190 try { 191 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 3), INPUTSIZE); 192 scriptRelaxed.forEach_testAbsChar3Uchar3(inV, out); 193 verifyResultsAbsChar3Uchar3(inV, out, true); 194 } catch (Exception e) { 195 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsChar3Uchar3: " + e.toString()); 196 } 197 } 198 verifyResultsAbsChar3Uchar3(Allocation inV, Allocation out, boolean relaxed)199 private void verifyResultsAbsChar3Uchar3(Allocation inV, Allocation out, boolean relaxed) { 200 byte[] arrayInV = new byte[INPUTSIZE * 4]; 201 Arrays.fill(arrayInV, (byte) 42); 202 inV.copyTo(arrayInV); 203 byte[] arrayOut = new byte[INPUTSIZE * 4]; 204 Arrays.fill(arrayOut, (byte) 42); 205 out.copyTo(arrayOut); 206 StringBuilder message = new StringBuilder(); 207 boolean errorFound = false; 208 for (int i = 0; i < INPUTSIZE; i++) { 209 for (int j = 0; j < 3 ; j++) { 210 // Extract the inputs. 211 ArgumentsCharUchar args = new ArgumentsCharUchar(); 212 args.inV = arrayInV[i * 4 + j]; 213 // Figure out what the outputs should have been. 214 CoreMathVerifier.computeAbs(args); 215 // Validate the outputs. 216 boolean valid = true; 217 if (args.out != arrayOut[i * 4 + j]) { 218 valid = false; 219 } 220 if (!valid) { 221 if (!errorFound) { 222 errorFound = true; 223 message.append("Input inV: "); 224 appendVariableToMessage(message, args.inV); 225 message.append("\n"); 226 message.append("Expected output out: "); 227 appendVariableToMessage(message, args.out); 228 message.append("\n"); 229 message.append("Actual output out: "); 230 appendVariableToMessage(message, arrayOut[i * 4 + j]); 231 if (args.out != arrayOut[i * 4 + j]) { 232 message.append(" FAIL"); 233 } 234 message.append("\n"); 235 message.append("Errors at"); 236 } 237 message.append(" ["); 238 message.append(Integer.toString(i)); 239 message.append(", "); 240 message.append(Integer.toString(j)); 241 message.append("]"); 242 } 243 } 244 } 245 assertFalse("Incorrect output for checkAbsChar3Uchar3" + 246 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 247 } 248 checkAbsChar4Uchar4()249 private void checkAbsChar4Uchar4() { 250 Allocation inV = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 4, 0xfa948238l, false); 251 try { 252 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 4), INPUTSIZE); 253 script.forEach_testAbsChar4Uchar4(inV, out); 254 verifyResultsAbsChar4Uchar4(inV, out, false); 255 } catch (Exception e) { 256 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsChar4Uchar4: " + e.toString()); 257 } 258 try { 259 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 4), INPUTSIZE); 260 scriptRelaxed.forEach_testAbsChar4Uchar4(inV, out); 261 verifyResultsAbsChar4Uchar4(inV, out, true); 262 } catch (Exception e) { 263 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsChar4Uchar4: " + e.toString()); 264 } 265 } 266 verifyResultsAbsChar4Uchar4(Allocation inV, Allocation out, boolean relaxed)267 private void verifyResultsAbsChar4Uchar4(Allocation inV, Allocation out, boolean relaxed) { 268 byte[] arrayInV = new byte[INPUTSIZE * 4]; 269 Arrays.fill(arrayInV, (byte) 42); 270 inV.copyTo(arrayInV); 271 byte[] arrayOut = new byte[INPUTSIZE * 4]; 272 Arrays.fill(arrayOut, (byte) 42); 273 out.copyTo(arrayOut); 274 StringBuilder message = new StringBuilder(); 275 boolean errorFound = false; 276 for (int i = 0; i < INPUTSIZE; i++) { 277 for (int j = 0; j < 4 ; j++) { 278 // Extract the inputs. 279 ArgumentsCharUchar args = new ArgumentsCharUchar(); 280 args.inV = arrayInV[i * 4 + j]; 281 // Figure out what the outputs should have been. 282 CoreMathVerifier.computeAbs(args); 283 // Validate the outputs. 284 boolean valid = true; 285 if (args.out != arrayOut[i * 4 + j]) { 286 valid = false; 287 } 288 if (!valid) { 289 if (!errorFound) { 290 errorFound = true; 291 message.append("Input inV: "); 292 appendVariableToMessage(message, args.inV); 293 message.append("\n"); 294 message.append("Expected output out: "); 295 appendVariableToMessage(message, args.out); 296 message.append("\n"); 297 message.append("Actual output out: "); 298 appendVariableToMessage(message, arrayOut[i * 4 + j]); 299 if (args.out != arrayOut[i * 4 + j]) { 300 message.append(" FAIL"); 301 } 302 message.append("\n"); 303 message.append("Errors at"); 304 } 305 message.append(" ["); 306 message.append(Integer.toString(i)); 307 message.append(", "); 308 message.append(Integer.toString(j)); 309 message.append("]"); 310 } 311 } 312 } 313 assertFalse("Incorrect output for checkAbsChar4Uchar4" + 314 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 315 } 316 317 public class ArgumentsShortUshort { 318 public short inV; 319 public short out; 320 } 321 checkAbsShortUshort()322 private void checkAbsShortUshort() { 323 Allocation inV = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 1, 0xa064819cl, false); 324 try { 325 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 1), INPUTSIZE); 326 script.forEach_testAbsShortUshort(inV, out); 327 verifyResultsAbsShortUshort(inV, out, false); 328 } catch (Exception e) { 329 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsShortUshort: " + e.toString()); 330 } 331 try { 332 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 1), INPUTSIZE); 333 scriptRelaxed.forEach_testAbsShortUshort(inV, out); 334 verifyResultsAbsShortUshort(inV, out, true); 335 } catch (Exception e) { 336 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsShortUshort: " + e.toString()); 337 } 338 } 339 verifyResultsAbsShortUshort(Allocation inV, Allocation out, boolean relaxed)340 private void verifyResultsAbsShortUshort(Allocation inV, Allocation out, boolean relaxed) { 341 short[] arrayInV = new short[INPUTSIZE * 1]; 342 Arrays.fill(arrayInV, (short) 42); 343 inV.copyTo(arrayInV); 344 short[] arrayOut = new short[INPUTSIZE * 1]; 345 Arrays.fill(arrayOut, (short) 42); 346 out.copyTo(arrayOut); 347 StringBuilder message = new StringBuilder(); 348 boolean errorFound = false; 349 for (int i = 0; i < INPUTSIZE; i++) { 350 for (int j = 0; j < 1 ; j++) { 351 // Extract the inputs. 352 ArgumentsShortUshort args = new ArgumentsShortUshort(); 353 args.inV = arrayInV[i]; 354 // Figure out what the outputs should have been. 355 CoreMathVerifier.computeAbs(args); 356 // Validate the outputs. 357 boolean valid = true; 358 if (args.out != arrayOut[i * 1 + j]) { 359 valid = false; 360 } 361 if (!valid) { 362 if (!errorFound) { 363 errorFound = true; 364 message.append("Input inV: "); 365 appendVariableToMessage(message, args.inV); 366 message.append("\n"); 367 message.append("Expected output out: "); 368 appendVariableToMessage(message, args.out); 369 message.append("\n"); 370 message.append("Actual output out: "); 371 appendVariableToMessage(message, arrayOut[i * 1 + j]); 372 if (args.out != arrayOut[i * 1 + j]) { 373 message.append(" FAIL"); 374 } 375 message.append("\n"); 376 message.append("Errors at"); 377 } 378 message.append(" ["); 379 message.append(Integer.toString(i)); 380 message.append(", "); 381 message.append(Integer.toString(j)); 382 message.append("]"); 383 } 384 } 385 } 386 assertFalse("Incorrect output for checkAbsShortUshort" + 387 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 388 } 389 checkAbsShort2Ushort2()390 private void checkAbsShort2Ushort2() { 391 Allocation inV = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 2, 0x6856b93el, false); 392 try { 393 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 2), INPUTSIZE); 394 script.forEach_testAbsShort2Ushort2(inV, out); 395 verifyResultsAbsShort2Ushort2(inV, out, false); 396 } catch (Exception e) { 397 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsShort2Ushort2: " + e.toString()); 398 } 399 try { 400 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 2), INPUTSIZE); 401 scriptRelaxed.forEach_testAbsShort2Ushort2(inV, out); 402 verifyResultsAbsShort2Ushort2(inV, out, true); 403 } catch (Exception e) { 404 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsShort2Ushort2: " + e.toString()); 405 } 406 } 407 verifyResultsAbsShort2Ushort2(Allocation inV, Allocation out, boolean relaxed)408 private void verifyResultsAbsShort2Ushort2(Allocation inV, Allocation out, boolean relaxed) { 409 short[] arrayInV = new short[INPUTSIZE * 2]; 410 Arrays.fill(arrayInV, (short) 42); 411 inV.copyTo(arrayInV); 412 short[] arrayOut = new short[INPUTSIZE * 2]; 413 Arrays.fill(arrayOut, (short) 42); 414 out.copyTo(arrayOut); 415 StringBuilder message = new StringBuilder(); 416 boolean errorFound = false; 417 for (int i = 0; i < INPUTSIZE; i++) { 418 for (int j = 0; j < 2 ; j++) { 419 // Extract the inputs. 420 ArgumentsShortUshort args = new ArgumentsShortUshort(); 421 args.inV = arrayInV[i * 2 + j]; 422 // Figure out what the outputs should have been. 423 CoreMathVerifier.computeAbs(args); 424 // Validate the outputs. 425 boolean valid = true; 426 if (args.out != arrayOut[i * 2 + j]) { 427 valid = false; 428 } 429 if (!valid) { 430 if (!errorFound) { 431 errorFound = true; 432 message.append("Input inV: "); 433 appendVariableToMessage(message, args.inV); 434 message.append("\n"); 435 message.append("Expected output out: "); 436 appendVariableToMessage(message, args.out); 437 message.append("\n"); 438 message.append("Actual output out: "); 439 appendVariableToMessage(message, arrayOut[i * 2 + j]); 440 if (args.out != arrayOut[i * 2 + j]) { 441 message.append(" FAIL"); 442 } 443 message.append("\n"); 444 message.append("Errors at"); 445 } 446 message.append(" ["); 447 message.append(Integer.toString(i)); 448 message.append(", "); 449 message.append(Integer.toString(j)); 450 message.append("]"); 451 } 452 } 453 } 454 assertFalse("Incorrect output for checkAbsShort2Ushort2" + 455 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 456 } 457 checkAbsShort3Ushort3()458 private void checkAbsShort3Ushort3() { 459 Allocation inV = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 3, 0xbeb24a6al, false); 460 try { 461 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 3), INPUTSIZE); 462 script.forEach_testAbsShort3Ushort3(inV, out); 463 verifyResultsAbsShort3Ushort3(inV, out, false); 464 } catch (Exception e) { 465 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsShort3Ushort3: " + e.toString()); 466 } 467 try { 468 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 3), INPUTSIZE); 469 scriptRelaxed.forEach_testAbsShort3Ushort3(inV, out); 470 verifyResultsAbsShort3Ushort3(inV, out, true); 471 } catch (Exception e) { 472 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsShort3Ushort3: " + e.toString()); 473 } 474 } 475 verifyResultsAbsShort3Ushort3(Allocation inV, Allocation out, boolean relaxed)476 private void verifyResultsAbsShort3Ushort3(Allocation inV, Allocation out, boolean relaxed) { 477 short[] arrayInV = new short[INPUTSIZE * 4]; 478 Arrays.fill(arrayInV, (short) 42); 479 inV.copyTo(arrayInV); 480 short[] arrayOut = new short[INPUTSIZE * 4]; 481 Arrays.fill(arrayOut, (short) 42); 482 out.copyTo(arrayOut); 483 StringBuilder message = new StringBuilder(); 484 boolean errorFound = false; 485 for (int i = 0; i < INPUTSIZE; i++) { 486 for (int j = 0; j < 3 ; j++) { 487 // Extract the inputs. 488 ArgumentsShortUshort args = new ArgumentsShortUshort(); 489 args.inV = arrayInV[i * 4 + j]; 490 // Figure out what the outputs should have been. 491 CoreMathVerifier.computeAbs(args); 492 // Validate the outputs. 493 boolean valid = true; 494 if (args.out != arrayOut[i * 4 + j]) { 495 valid = false; 496 } 497 if (!valid) { 498 if (!errorFound) { 499 errorFound = true; 500 message.append("Input inV: "); 501 appendVariableToMessage(message, args.inV); 502 message.append("\n"); 503 message.append("Expected output out: "); 504 appendVariableToMessage(message, args.out); 505 message.append("\n"); 506 message.append("Actual output out: "); 507 appendVariableToMessage(message, arrayOut[i * 4 + j]); 508 if (args.out != arrayOut[i * 4 + j]) { 509 message.append(" FAIL"); 510 } 511 message.append("\n"); 512 message.append("Errors at"); 513 } 514 message.append(" ["); 515 message.append(Integer.toString(i)); 516 message.append(", "); 517 message.append(Integer.toString(j)); 518 message.append("]"); 519 } 520 } 521 } 522 assertFalse("Incorrect output for checkAbsShort3Ushort3" + 523 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 524 } 525 checkAbsShort4Ushort4()526 private void checkAbsShort4Ushort4() { 527 Allocation inV = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 4, 0x150ddb96l, false); 528 try { 529 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 4), INPUTSIZE); 530 script.forEach_testAbsShort4Ushort4(inV, out); 531 verifyResultsAbsShort4Ushort4(inV, out, false); 532 } catch (Exception e) { 533 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsShort4Ushort4: " + e.toString()); 534 } 535 try { 536 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 4), INPUTSIZE); 537 scriptRelaxed.forEach_testAbsShort4Ushort4(inV, out); 538 verifyResultsAbsShort4Ushort4(inV, out, true); 539 } catch (Exception e) { 540 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsShort4Ushort4: " + e.toString()); 541 } 542 } 543 verifyResultsAbsShort4Ushort4(Allocation inV, Allocation out, boolean relaxed)544 private void verifyResultsAbsShort4Ushort4(Allocation inV, Allocation out, boolean relaxed) { 545 short[] arrayInV = new short[INPUTSIZE * 4]; 546 Arrays.fill(arrayInV, (short) 42); 547 inV.copyTo(arrayInV); 548 short[] arrayOut = new short[INPUTSIZE * 4]; 549 Arrays.fill(arrayOut, (short) 42); 550 out.copyTo(arrayOut); 551 StringBuilder message = new StringBuilder(); 552 boolean errorFound = false; 553 for (int i = 0; i < INPUTSIZE; i++) { 554 for (int j = 0; j < 4 ; j++) { 555 // Extract the inputs. 556 ArgumentsShortUshort args = new ArgumentsShortUshort(); 557 args.inV = arrayInV[i * 4 + j]; 558 // Figure out what the outputs should have been. 559 CoreMathVerifier.computeAbs(args); 560 // Validate the outputs. 561 boolean valid = true; 562 if (args.out != arrayOut[i * 4 + j]) { 563 valid = false; 564 } 565 if (!valid) { 566 if (!errorFound) { 567 errorFound = true; 568 message.append("Input inV: "); 569 appendVariableToMessage(message, args.inV); 570 message.append("\n"); 571 message.append("Expected output out: "); 572 appendVariableToMessage(message, args.out); 573 message.append("\n"); 574 message.append("Actual output out: "); 575 appendVariableToMessage(message, arrayOut[i * 4 + j]); 576 if (args.out != arrayOut[i * 4 + j]) { 577 message.append(" FAIL"); 578 } 579 message.append("\n"); 580 message.append("Errors at"); 581 } 582 message.append(" ["); 583 message.append(Integer.toString(i)); 584 message.append(", "); 585 message.append(Integer.toString(j)); 586 message.append("]"); 587 } 588 } 589 } 590 assertFalse("Incorrect output for checkAbsShort4Ushort4" + 591 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 592 } 593 594 public class ArgumentsIntUint { 595 public int inV; 596 public int out; 597 } 598 checkAbsIntUint()599 private void checkAbsIntUint() { 600 Allocation inV = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 1, 0xac5b83e6l, false); 601 try { 602 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 1), INPUTSIZE); 603 script.forEach_testAbsIntUint(inV, out); 604 verifyResultsAbsIntUint(inV, out, false); 605 } catch (Exception e) { 606 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsIntUint: " + e.toString()); 607 } 608 try { 609 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 1), INPUTSIZE); 610 scriptRelaxed.forEach_testAbsIntUint(inV, out); 611 verifyResultsAbsIntUint(inV, out, true); 612 } catch (Exception e) { 613 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsIntUint: " + e.toString()); 614 } 615 } 616 verifyResultsAbsIntUint(Allocation inV, Allocation out, boolean relaxed)617 private void verifyResultsAbsIntUint(Allocation inV, Allocation out, boolean relaxed) { 618 int[] arrayInV = new int[INPUTSIZE * 1]; 619 Arrays.fill(arrayInV, (int) 42); 620 inV.copyTo(arrayInV); 621 int[] arrayOut = new int[INPUTSIZE * 1]; 622 Arrays.fill(arrayOut, (int) 42); 623 out.copyTo(arrayOut); 624 StringBuilder message = new StringBuilder(); 625 boolean errorFound = false; 626 for (int i = 0; i < INPUTSIZE; i++) { 627 for (int j = 0; j < 1 ; j++) { 628 // Extract the inputs. 629 ArgumentsIntUint args = new ArgumentsIntUint(); 630 args.inV = arrayInV[i]; 631 // Figure out what the outputs should have been. 632 CoreMathVerifier.computeAbs(args); 633 // Validate the outputs. 634 boolean valid = true; 635 if (args.out != arrayOut[i * 1 + j]) { 636 valid = false; 637 } 638 if (!valid) { 639 if (!errorFound) { 640 errorFound = true; 641 message.append("Input inV: "); 642 appendVariableToMessage(message, args.inV); 643 message.append("\n"); 644 message.append("Expected output out: "); 645 appendVariableToMessage(message, args.out); 646 message.append("\n"); 647 message.append("Actual output out: "); 648 appendVariableToMessage(message, arrayOut[i * 1 + j]); 649 if (args.out != arrayOut[i * 1 + j]) { 650 message.append(" FAIL"); 651 } 652 message.append("\n"); 653 message.append("Errors at"); 654 } 655 message.append(" ["); 656 message.append(Integer.toString(i)); 657 message.append(", "); 658 message.append(Integer.toString(j)); 659 message.append("]"); 660 } 661 } 662 } 663 assertFalse("Incorrect output for checkAbsIntUint" + 664 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 665 } 666 checkAbsInt2Uint2()667 private void checkAbsInt2Uint2() { 668 Allocation inV = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 2, 0x938616fal, false); 669 try { 670 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 2), INPUTSIZE); 671 script.forEach_testAbsInt2Uint2(inV, out); 672 verifyResultsAbsInt2Uint2(inV, out, false); 673 } catch (Exception e) { 674 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsInt2Uint2: " + e.toString()); 675 } 676 try { 677 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 2), INPUTSIZE); 678 scriptRelaxed.forEach_testAbsInt2Uint2(inV, out); 679 verifyResultsAbsInt2Uint2(inV, out, true); 680 } catch (Exception e) { 681 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsInt2Uint2: " + e.toString()); 682 } 683 } 684 verifyResultsAbsInt2Uint2(Allocation inV, Allocation out, boolean relaxed)685 private void verifyResultsAbsInt2Uint2(Allocation inV, Allocation out, boolean relaxed) { 686 int[] arrayInV = new int[INPUTSIZE * 2]; 687 Arrays.fill(arrayInV, (int) 42); 688 inV.copyTo(arrayInV); 689 int[] arrayOut = new int[INPUTSIZE * 2]; 690 Arrays.fill(arrayOut, (int) 42); 691 out.copyTo(arrayOut); 692 StringBuilder message = new StringBuilder(); 693 boolean errorFound = false; 694 for (int i = 0; i < INPUTSIZE; i++) { 695 for (int j = 0; j < 2 ; j++) { 696 // Extract the inputs. 697 ArgumentsIntUint args = new ArgumentsIntUint(); 698 args.inV = arrayInV[i * 2 + j]; 699 // Figure out what the outputs should have been. 700 CoreMathVerifier.computeAbs(args); 701 // Validate the outputs. 702 boolean valid = true; 703 if (args.out != arrayOut[i * 2 + j]) { 704 valid = false; 705 } 706 if (!valid) { 707 if (!errorFound) { 708 errorFound = true; 709 message.append("Input inV: "); 710 appendVariableToMessage(message, args.inV); 711 message.append("\n"); 712 message.append("Expected output out: "); 713 appendVariableToMessage(message, args.out); 714 message.append("\n"); 715 message.append("Actual output out: "); 716 appendVariableToMessage(message, arrayOut[i * 2 + j]); 717 if (args.out != arrayOut[i * 2 + j]) { 718 message.append(" FAIL"); 719 } 720 message.append("\n"); 721 message.append("Errors at"); 722 } 723 message.append(" ["); 724 message.append(Integer.toString(i)); 725 message.append(", "); 726 message.append(Integer.toString(j)); 727 message.append("]"); 728 } 729 } 730 } 731 assertFalse("Incorrect output for checkAbsInt2Uint2" + 732 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 733 } 734 checkAbsInt3Uint3()735 private void checkAbsInt3Uint3() { 736 Allocation inV = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 3, 0xf28ddbeel, false); 737 try { 738 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 3), INPUTSIZE); 739 script.forEach_testAbsInt3Uint3(inV, out); 740 verifyResultsAbsInt3Uint3(inV, out, false); 741 } catch (Exception e) { 742 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsInt3Uint3: " + e.toString()); 743 } 744 try { 745 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 3), INPUTSIZE); 746 scriptRelaxed.forEach_testAbsInt3Uint3(inV, out); 747 verifyResultsAbsInt3Uint3(inV, out, true); 748 } catch (Exception e) { 749 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsInt3Uint3: " + e.toString()); 750 } 751 } 752 verifyResultsAbsInt3Uint3(Allocation inV, Allocation out, boolean relaxed)753 private void verifyResultsAbsInt3Uint3(Allocation inV, Allocation out, boolean relaxed) { 754 int[] arrayInV = new int[INPUTSIZE * 4]; 755 Arrays.fill(arrayInV, (int) 42); 756 inV.copyTo(arrayInV); 757 int[] arrayOut = new int[INPUTSIZE * 4]; 758 Arrays.fill(arrayOut, (int) 42); 759 out.copyTo(arrayOut); 760 StringBuilder message = new StringBuilder(); 761 boolean errorFound = false; 762 for (int i = 0; i < INPUTSIZE; i++) { 763 for (int j = 0; j < 3 ; j++) { 764 // Extract the inputs. 765 ArgumentsIntUint args = new ArgumentsIntUint(); 766 args.inV = arrayInV[i * 4 + j]; 767 // Figure out what the outputs should have been. 768 CoreMathVerifier.computeAbs(args); 769 // Validate the outputs. 770 boolean valid = true; 771 if (args.out != arrayOut[i * 4 + j]) { 772 valid = false; 773 } 774 if (!valid) { 775 if (!errorFound) { 776 errorFound = true; 777 message.append("Input inV: "); 778 appendVariableToMessage(message, args.inV); 779 message.append("\n"); 780 message.append("Expected output out: "); 781 appendVariableToMessage(message, args.out); 782 message.append("\n"); 783 message.append("Actual output out: "); 784 appendVariableToMessage(message, arrayOut[i * 4 + j]); 785 if (args.out != arrayOut[i * 4 + j]) { 786 message.append(" FAIL"); 787 } 788 message.append("\n"); 789 message.append("Errors at"); 790 } 791 message.append(" ["); 792 message.append(Integer.toString(i)); 793 message.append(", "); 794 message.append(Integer.toString(j)); 795 message.append("]"); 796 } 797 } 798 } 799 assertFalse("Incorrect output for checkAbsInt3Uint3" + 800 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 801 } 802 checkAbsInt4Uint4()803 private void checkAbsInt4Uint4() { 804 Allocation inV = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 4, 0x5195a0e2l, false); 805 try { 806 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 4), INPUTSIZE); 807 script.forEach_testAbsInt4Uint4(inV, out); 808 verifyResultsAbsInt4Uint4(inV, out, false); 809 } catch (Exception e) { 810 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsInt4Uint4: " + e.toString()); 811 } 812 try { 813 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 4), INPUTSIZE); 814 scriptRelaxed.forEach_testAbsInt4Uint4(inV, out); 815 verifyResultsAbsInt4Uint4(inV, out, true); 816 } catch (Exception e) { 817 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsInt4Uint4: " + e.toString()); 818 } 819 } 820 verifyResultsAbsInt4Uint4(Allocation inV, Allocation out, boolean relaxed)821 private void verifyResultsAbsInt4Uint4(Allocation inV, Allocation out, boolean relaxed) { 822 int[] arrayInV = new int[INPUTSIZE * 4]; 823 Arrays.fill(arrayInV, (int) 42); 824 inV.copyTo(arrayInV); 825 int[] arrayOut = new int[INPUTSIZE * 4]; 826 Arrays.fill(arrayOut, (int) 42); 827 out.copyTo(arrayOut); 828 StringBuilder message = new StringBuilder(); 829 boolean errorFound = false; 830 for (int i = 0; i < INPUTSIZE; i++) { 831 for (int j = 0; j < 4 ; j++) { 832 // Extract the inputs. 833 ArgumentsIntUint args = new ArgumentsIntUint(); 834 args.inV = arrayInV[i * 4 + j]; 835 // Figure out what the outputs should have been. 836 CoreMathVerifier.computeAbs(args); 837 // Validate the outputs. 838 boolean valid = true; 839 if (args.out != arrayOut[i * 4 + j]) { 840 valid = false; 841 } 842 if (!valid) { 843 if (!errorFound) { 844 errorFound = true; 845 message.append("Input inV: "); 846 appendVariableToMessage(message, args.inV); 847 message.append("\n"); 848 message.append("Expected output out: "); 849 appendVariableToMessage(message, args.out); 850 message.append("\n"); 851 message.append("Actual output out: "); 852 appendVariableToMessage(message, arrayOut[i * 4 + j]); 853 if (args.out != arrayOut[i * 4 + j]) { 854 message.append(" FAIL"); 855 } 856 message.append("\n"); 857 message.append("Errors at"); 858 } 859 message.append(" ["); 860 message.append(Integer.toString(i)); 861 message.append(", "); 862 message.append(Integer.toString(j)); 863 message.append("]"); 864 } 865 } 866 } 867 assertFalse("Incorrect output for checkAbsInt4Uint4" + 868 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 869 } 870 testAbs()871 public void testAbs() { 872 checkAbsCharUchar(); 873 checkAbsChar2Uchar2(); 874 checkAbsChar3Uchar3(); 875 checkAbsChar4Uchar4(); 876 checkAbsShortUshort(); 877 checkAbsShort2Ushort2(); 878 checkAbsShort3Ushort3(); 879 checkAbsShort4Ushort4(); 880 checkAbsIntUint(); 881 checkAbsInt2Uint2(); 882 checkAbsInt3Uint3(); 883 checkAbsInt4Uint4(); 884 } 885 } 886