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