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 TestFastLength extends RSBaseCompute { 29 30 private ScriptC_TestFastLength script; 31 private ScriptC_TestFastLengthRelaxed scriptRelaxed; 32 33 @Override setUp()34 protected void setUp() throws Exception { 35 super.setUp(); 36 script = new ScriptC_TestFastLength(mRS); 37 scriptRelaxed = new ScriptC_TestFastLengthRelaxed(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 ArgumentsFloatFloat { 48 public float inV; 49 public Target.Floaty out; 50 } 51 checkFastLengthFloatFloat()52 private void checkFastLengthFloatFloat() { 53 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xebac65aea2660e8fl, false); 54 try { 55 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 56 script.forEach_testFastLengthFloatFloat(inV, out); 57 verifyResultsFastLengthFloatFloat(inV, out, false); 58 out.destroy(); 59 } catch (Exception e) { 60 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFastLengthFloatFloat: " + e.toString()); 61 } 62 try { 63 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 64 scriptRelaxed.forEach_testFastLengthFloatFloat(inV, out); 65 verifyResultsFastLengthFloatFloat(inV, out, true); 66 out.destroy(); 67 } catch (Exception e) { 68 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFastLengthFloatFloat: " + e.toString()); 69 } 70 inV.destroy(); 71 } 72 verifyResultsFastLengthFloatFloat(Allocation inV, Allocation out, boolean relaxed)73 private void verifyResultsFastLengthFloatFloat(Allocation inV, Allocation out, boolean relaxed) { 74 float[] arrayInV = new float[INPUTSIZE * 1]; 75 Arrays.fill(arrayInV, (float) 42); 76 inV.copyTo(arrayInV); 77 float[] arrayOut = new float[INPUTSIZE * 1]; 78 Arrays.fill(arrayOut, (float) 42); 79 out.copyTo(arrayOut); 80 StringBuilder message = new StringBuilder(); 81 boolean errorFound = false; 82 for (int i = 0; i < INPUTSIZE; i++) { 83 ArgumentsFloatFloat args = new ArgumentsFloatFloat(); 84 // Create the appropriate sized arrays in args 85 // Fill args with the input values 86 args.inV = arrayInV[i]; 87 Target target = new Target(Target.FunctionType.FAST, Target.ReturnType.FLOAT, relaxed); 88 CoreMathVerifier.computeFastLength(args, target); 89 90 // Compare the expected outputs to the actual values returned by RS. 91 boolean valid = true; 92 if (!args.out.couldBe(arrayOut[i])) { 93 valid = false; 94 } 95 if (!valid) { 96 if (!errorFound) { 97 errorFound = true; 98 message.append("Input inV: "); 99 appendVariableToMessage(message, arrayInV[i]); 100 message.append("\n"); 101 message.append("Expected output out: "); 102 appendVariableToMessage(message, args.out); 103 message.append("\n"); 104 message.append("Actual output out: "); 105 appendVariableToMessage(message, arrayOut[i]); 106 if (!args.out.couldBe(arrayOut[i])) { 107 message.append(" FAIL"); 108 } 109 message.append("\n"); 110 message.append("Errors at"); 111 } 112 message.append(" ["); 113 message.append(Integer.toString(i)); 114 message.append("]"); 115 } 116 } 117 assertFalse("Incorrect output for checkFastLengthFloatFloat" + 118 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 119 } 120 121 public class ArgumentsFloatNFloat { 122 public float[] inV; 123 public Target.Floaty out; 124 } 125 checkFastLengthFloat2Float()126 private void checkFastLengthFloat2Float() { 127 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x95f43650f85e6cadl, false); 128 try { 129 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 130 script.forEach_testFastLengthFloat2Float(inV, out); 131 verifyResultsFastLengthFloat2Float(inV, out, false); 132 out.destroy(); 133 } catch (Exception e) { 134 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFastLengthFloat2Float: " + e.toString()); 135 } 136 try { 137 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 138 scriptRelaxed.forEach_testFastLengthFloat2Float(inV, out); 139 verifyResultsFastLengthFloat2Float(inV, out, true); 140 out.destroy(); 141 } catch (Exception e) { 142 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFastLengthFloat2Float: " + e.toString()); 143 } 144 inV.destroy(); 145 } 146 verifyResultsFastLengthFloat2Float(Allocation inV, Allocation out, boolean relaxed)147 private void verifyResultsFastLengthFloat2Float(Allocation inV, Allocation out, boolean relaxed) { 148 float[] arrayInV = new float[INPUTSIZE * 2]; 149 Arrays.fill(arrayInV, (float) 42); 150 inV.copyTo(arrayInV); 151 float[] arrayOut = new float[INPUTSIZE * 1]; 152 Arrays.fill(arrayOut, (float) 42); 153 out.copyTo(arrayOut); 154 StringBuilder message = new StringBuilder(); 155 boolean errorFound = false; 156 for (int i = 0; i < INPUTSIZE; i++) { 157 ArgumentsFloatNFloat args = new ArgumentsFloatNFloat(); 158 // Create the appropriate sized arrays in args 159 args.inV = new float[2]; 160 // Fill args with the input values 161 for (int j = 0; j < 2 ; j++) { 162 args.inV[j] = arrayInV[i * 2 + j]; 163 } 164 Target target = new Target(Target.FunctionType.FAST, Target.ReturnType.FLOAT, relaxed); 165 CoreMathVerifier.computeFastLength(args, target); 166 167 // Compare the expected outputs to the actual values returned by RS. 168 boolean valid = true; 169 if (!args.out.couldBe(arrayOut[i])) { 170 valid = false; 171 } 172 if (!valid) { 173 if (!errorFound) { 174 errorFound = true; 175 for (int j = 0; j < 2 ; j++) { 176 message.append("Input inV: "); 177 appendVariableToMessage(message, arrayInV[i * 2 + j]); 178 message.append("\n"); 179 } 180 message.append("Expected output out: "); 181 appendVariableToMessage(message, args.out); 182 message.append("\n"); 183 message.append("Actual output out: "); 184 appendVariableToMessage(message, arrayOut[i]); 185 if (!args.out.couldBe(arrayOut[i])) { 186 message.append(" FAIL"); 187 } 188 message.append("\n"); 189 message.append("Errors at"); 190 } 191 message.append(" ["); 192 message.append(Integer.toString(i)); 193 message.append("]"); 194 } 195 } 196 assertFalse("Incorrect output for checkFastLengthFloat2Float" + 197 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 198 } 199 checkFastLengthFloat3Float()200 private void checkFastLengthFloat3Float() { 201 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x95f440f25764fb0el, false); 202 try { 203 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 204 script.forEach_testFastLengthFloat3Float(inV, out); 205 verifyResultsFastLengthFloat3Float(inV, out, false); 206 out.destroy(); 207 } catch (Exception e) { 208 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFastLengthFloat3Float: " + e.toString()); 209 } 210 try { 211 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 212 scriptRelaxed.forEach_testFastLengthFloat3Float(inV, out); 213 verifyResultsFastLengthFloat3Float(inV, out, true); 214 out.destroy(); 215 } catch (Exception e) { 216 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFastLengthFloat3Float: " + e.toString()); 217 } 218 inV.destroy(); 219 } 220 verifyResultsFastLengthFloat3Float(Allocation inV, Allocation out, boolean relaxed)221 private void verifyResultsFastLengthFloat3Float(Allocation inV, Allocation out, boolean relaxed) { 222 float[] arrayInV = new float[INPUTSIZE * 4]; 223 Arrays.fill(arrayInV, (float) 42); 224 inV.copyTo(arrayInV); 225 float[] arrayOut = new float[INPUTSIZE * 1]; 226 Arrays.fill(arrayOut, (float) 42); 227 out.copyTo(arrayOut); 228 StringBuilder message = new StringBuilder(); 229 boolean errorFound = false; 230 for (int i = 0; i < INPUTSIZE; i++) { 231 ArgumentsFloatNFloat args = new ArgumentsFloatNFloat(); 232 // Create the appropriate sized arrays in args 233 args.inV = new float[3]; 234 // Fill args with the input values 235 for (int j = 0; j < 3 ; j++) { 236 args.inV[j] = arrayInV[i * 4 + j]; 237 } 238 Target target = new Target(Target.FunctionType.FAST, Target.ReturnType.FLOAT, relaxed); 239 CoreMathVerifier.computeFastLength(args, target); 240 241 // Compare the expected outputs to the actual values returned by RS. 242 boolean valid = true; 243 if (!args.out.couldBe(arrayOut[i])) { 244 valid = false; 245 } 246 if (!valid) { 247 if (!errorFound) { 248 errorFound = true; 249 for (int j = 0; j < 3 ; j++) { 250 message.append("Input inV: "); 251 appendVariableToMessage(message, arrayInV[i * 4 + j]); 252 message.append("\n"); 253 } 254 message.append("Expected output out: "); 255 appendVariableToMessage(message, args.out); 256 message.append("\n"); 257 message.append("Actual output out: "); 258 appendVariableToMessage(message, arrayOut[i]); 259 if (!args.out.couldBe(arrayOut[i])) { 260 message.append(" FAIL"); 261 } 262 message.append("\n"); 263 message.append("Errors at"); 264 } 265 message.append(" ["); 266 message.append(Integer.toString(i)); 267 message.append("]"); 268 } 269 } 270 assertFalse("Incorrect output for checkFastLengthFloat3Float" + 271 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 272 } 273 checkFastLengthFloat4Float()274 private void checkFastLengthFloat4Float() { 275 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x95f44b93b66b896fl, false); 276 try { 277 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 278 script.forEach_testFastLengthFloat4Float(inV, out); 279 verifyResultsFastLengthFloat4Float(inV, out, false); 280 out.destroy(); 281 } catch (Exception e) { 282 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFastLengthFloat4Float: " + e.toString()); 283 } 284 try { 285 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 286 scriptRelaxed.forEach_testFastLengthFloat4Float(inV, out); 287 verifyResultsFastLengthFloat4Float(inV, out, true); 288 out.destroy(); 289 } catch (Exception e) { 290 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFastLengthFloat4Float: " + e.toString()); 291 } 292 inV.destroy(); 293 } 294 verifyResultsFastLengthFloat4Float(Allocation inV, Allocation out, boolean relaxed)295 private void verifyResultsFastLengthFloat4Float(Allocation inV, Allocation out, boolean relaxed) { 296 float[] arrayInV = new float[INPUTSIZE * 4]; 297 Arrays.fill(arrayInV, (float) 42); 298 inV.copyTo(arrayInV); 299 float[] arrayOut = new float[INPUTSIZE * 1]; 300 Arrays.fill(arrayOut, (float) 42); 301 out.copyTo(arrayOut); 302 StringBuilder message = new StringBuilder(); 303 boolean errorFound = false; 304 for (int i = 0; i < INPUTSIZE; i++) { 305 ArgumentsFloatNFloat args = new ArgumentsFloatNFloat(); 306 // Create the appropriate sized arrays in args 307 args.inV = new float[4]; 308 // Fill args with the input values 309 for (int j = 0; j < 4 ; j++) { 310 args.inV[j] = arrayInV[i * 4 + j]; 311 } 312 Target target = new Target(Target.FunctionType.FAST, Target.ReturnType.FLOAT, relaxed); 313 CoreMathVerifier.computeFastLength(args, target); 314 315 // Compare the expected outputs to the actual values returned by RS. 316 boolean valid = true; 317 if (!args.out.couldBe(arrayOut[i])) { 318 valid = false; 319 } 320 if (!valid) { 321 if (!errorFound) { 322 errorFound = true; 323 for (int j = 0; j < 4 ; j++) { 324 message.append("Input inV: "); 325 appendVariableToMessage(message, arrayInV[i * 4 + j]); 326 message.append("\n"); 327 } 328 message.append("Expected output out: "); 329 appendVariableToMessage(message, args.out); 330 message.append("\n"); 331 message.append("Actual output out: "); 332 appendVariableToMessage(message, arrayOut[i]); 333 if (!args.out.couldBe(arrayOut[i])) { 334 message.append(" FAIL"); 335 } 336 message.append("\n"); 337 message.append("Errors at"); 338 } 339 message.append(" ["); 340 message.append(Integer.toString(i)); 341 message.append("]"); 342 } 343 } 344 assertFalse("Incorrect output for checkFastLengthFloat4Float" + 345 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 346 } 347 testFastLength()348 public void testFastLength() { 349 checkFastLengthFloatFloat(); 350 checkFastLengthFloat2Float(); 351 checkFastLengthFloat3Float(); 352 checkFastLengthFloat4Float(); 353 } 354 } 355