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 public class ArgumentsFloatFloatFloat { 41 public float inV; 42 public Target.Floaty outIntegralPart; 43 public Target.Floaty out; 44 } 45 checkModfFloatFloatFloat()46 private void checkModfFloatFloatFloat() { 47 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x5ccaef45l, false); 48 try { 49 Allocation outIntegralPart = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 50 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 51 script.set_gAllocOutIntegralPart(outIntegralPart); 52 script.forEach_testModfFloatFloatFloat(inV, out); 53 verifyResultsModfFloatFloatFloat(inV, outIntegralPart, out, false); 54 } catch (Exception e) { 55 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testModfFloatFloatFloat: " + e.toString()); 56 } 57 try { 58 Allocation outIntegralPart = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 59 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 60 scriptRelaxed.set_gAllocOutIntegralPart(outIntegralPart); 61 scriptRelaxed.forEach_testModfFloatFloatFloat(inV, out); 62 verifyResultsModfFloatFloatFloat(inV, outIntegralPart, out, true); 63 } catch (Exception e) { 64 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testModfFloatFloatFloat: " + e.toString()); 65 } 66 } 67 verifyResultsModfFloatFloatFloat(Allocation inV, Allocation outIntegralPart, Allocation out, boolean relaxed)68 private void verifyResultsModfFloatFloatFloat(Allocation inV, Allocation outIntegralPart, Allocation out, boolean relaxed) { 69 float[] arrayInV = new float[INPUTSIZE * 1]; 70 Arrays.fill(arrayInV, (float) 42); 71 inV.copyTo(arrayInV); 72 float[] arrayOutIntegralPart = new float[INPUTSIZE * 1]; 73 Arrays.fill(arrayOutIntegralPart, (float) 42); 74 outIntegralPart.copyTo(arrayOutIntegralPart); 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 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); 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.computeModf(args, target); 88 // Validate the outputs. 89 boolean valid = true; 90 if (!args.outIntegralPart.couldBe(arrayOutIntegralPart[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 outIntegralPart: "); 103 appendVariableToMessage(message, args.outIntegralPart); 104 message.append("\n"); 105 message.append("Actual output outIntegralPart: "); 106 appendVariableToMessage(message, arrayOutIntegralPart[i * 1 + j]); 107 if (!args.outIntegralPart.couldBe(arrayOutIntegralPart[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 checkModfFloatFloatFloat" + 131 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 132 } 133 checkModfFloat2Float2Float2()134 private void checkModfFloat2Float2Float2() { 135 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xfa16305fl, false); 136 try { 137 Allocation outIntegralPart = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 138 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 139 script.set_gAllocOutIntegralPart(outIntegralPart); 140 script.forEach_testModfFloat2Float2Float2(inV, out); 141 verifyResultsModfFloat2Float2Float2(inV, outIntegralPart, out, false); 142 } catch (Exception e) { 143 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testModfFloat2Float2Float2: " + e.toString()); 144 } 145 try { 146 Allocation outIntegralPart = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 147 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 148 scriptRelaxed.set_gAllocOutIntegralPart(outIntegralPart); 149 scriptRelaxed.forEach_testModfFloat2Float2Float2(inV, out); 150 verifyResultsModfFloat2Float2Float2(inV, outIntegralPart, out, true); 151 } catch (Exception e) { 152 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testModfFloat2Float2Float2: " + e.toString()); 153 } 154 } 155 verifyResultsModfFloat2Float2Float2(Allocation inV, Allocation outIntegralPart, Allocation out, boolean relaxed)156 private void verifyResultsModfFloat2Float2Float2(Allocation inV, Allocation outIntegralPart, Allocation out, boolean relaxed) { 157 float[] arrayInV = new float[INPUTSIZE * 2]; 158 Arrays.fill(arrayInV, (float) 42); 159 inV.copyTo(arrayInV); 160 float[] arrayOutIntegralPart = new float[INPUTSIZE * 2]; 161 Arrays.fill(arrayOutIntegralPart, (float) 42); 162 outIntegralPart.copyTo(arrayOutIntegralPart); 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 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); 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.computeModf(args, target); 176 // Validate the outputs. 177 boolean valid = true; 178 if (!args.outIntegralPart.couldBe(arrayOutIntegralPart[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 outIntegralPart: "); 191 appendVariableToMessage(message, args.outIntegralPart); 192 message.append("\n"); 193 message.append("Actual output outIntegralPart: "); 194 appendVariableToMessage(message, arrayOutIntegralPart[i * 2 + j]); 195 if (!args.outIntegralPart.couldBe(arrayOutIntegralPart[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 checkModfFloat2Float2Float2" + 219 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 220 } 221 checkModfFloat3Float3Float3()222 private void checkModfFloat3Float3Float3() { 223 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xfbf43200l, false); 224 try { 225 Allocation outIntegralPart = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 226 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 227 script.set_gAllocOutIntegralPart(outIntegralPart); 228 script.forEach_testModfFloat3Float3Float3(inV, out); 229 verifyResultsModfFloat3Float3Float3(inV, outIntegralPart, out, false); 230 } catch (Exception e) { 231 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testModfFloat3Float3Float3: " + e.toString()); 232 } 233 try { 234 Allocation outIntegralPart = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 235 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 236 scriptRelaxed.set_gAllocOutIntegralPart(outIntegralPart); 237 scriptRelaxed.forEach_testModfFloat3Float3Float3(inV, out); 238 verifyResultsModfFloat3Float3Float3(inV, outIntegralPart, out, true); 239 } catch (Exception e) { 240 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testModfFloat3Float3Float3: " + e.toString()); 241 } 242 } 243 verifyResultsModfFloat3Float3Float3(Allocation inV, Allocation outIntegralPart, Allocation out, boolean relaxed)244 private void verifyResultsModfFloat3Float3Float3(Allocation inV, Allocation outIntegralPart, Allocation out, boolean relaxed) { 245 float[] arrayInV = new float[INPUTSIZE * 4]; 246 Arrays.fill(arrayInV, (float) 42); 247 inV.copyTo(arrayInV); 248 float[] arrayOutIntegralPart = new float[INPUTSIZE * 4]; 249 Arrays.fill(arrayOutIntegralPart, (float) 42); 250 outIntegralPart.copyTo(arrayOutIntegralPart); 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 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); 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.computeModf(args, target); 264 // Validate the outputs. 265 boolean valid = true; 266 if (!args.outIntegralPart.couldBe(arrayOutIntegralPart[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 outIntegralPart: "); 279 appendVariableToMessage(message, args.outIntegralPart); 280 message.append("\n"); 281 message.append("Actual output outIntegralPart: "); 282 appendVariableToMessage(message, arrayOutIntegralPart[i * 4 + j]); 283 if (!args.outIntegralPart.couldBe(arrayOutIntegralPart[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 checkModfFloat3Float3Float3" + 307 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 308 } 309 checkModfFloat4Float4Float4()310 private void checkModfFloat4Float4Float4() { 311 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xfdd233a1l, false); 312 try { 313 Allocation outIntegralPart = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 314 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 315 script.set_gAllocOutIntegralPart(outIntegralPart); 316 script.forEach_testModfFloat4Float4Float4(inV, out); 317 verifyResultsModfFloat4Float4Float4(inV, outIntegralPart, out, false); 318 } catch (Exception e) { 319 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testModfFloat4Float4Float4: " + e.toString()); 320 } 321 try { 322 Allocation outIntegralPart = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 323 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 324 scriptRelaxed.set_gAllocOutIntegralPart(outIntegralPart); 325 scriptRelaxed.forEach_testModfFloat4Float4Float4(inV, out); 326 verifyResultsModfFloat4Float4Float4(inV, outIntegralPart, out, true); 327 } catch (Exception e) { 328 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testModfFloat4Float4Float4: " + e.toString()); 329 } 330 } 331 verifyResultsModfFloat4Float4Float4(Allocation inV, Allocation outIntegralPart, Allocation out, boolean relaxed)332 private void verifyResultsModfFloat4Float4Float4(Allocation inV, Allocation outIntegralPart, Allocation out, boolean relaxed) { 333 float[] arrayInV = new float[INPUTSIZE * 4]; 334 Arrays.fill(arrayInV, (float) 42); 335 inV.copyTo(arrayInV); 336 float[] arrayOutIntegralPart = new float[INPUTSIZE * 4]; 337 Arrays.fill(arrayOutIntegralPart, (float) 42); 338 outIntegralPart.copyTo(arrayOutIntegralPart); 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 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); 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.computeModf(args, target); 352 // Validate the outputs. 353 boolean valid = true; 354 if (!args.outIntegralPart.couldBe(arrayOutIntegralPart[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 outIntegralPart: "); 367 appendVariableToMessage(message, args.outIntegralPart); 368 message.append("\n"); 369 message.append("Actual output outIntegralPart: "); 370 appendVariableToMessage(message, arrayOutIntegralPart[i * 4 + j]); 371 if (!args.outIntegralPart.couldBe(arrayOutIntegralPart[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 checkModfFloat4Float4Float4" + 395 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 396 } 397 testModf()398 public void testModf() { 399 checkModfFloatFloatFloat(); 400 checkModfFloat2Float2Float2(); 401 checkModfFloat3Float3Float3(); 402 checkModfFloat4Float4Float4(); 403 } 404 } 405