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