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