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 17package com.android.rs.rsov.test; 18 19import android.content.Context; 20import android.renderscript.Allocation; 21import android.renderscript.Element; 22import android.renderscript.RenderScript; 23import android.renderscript.Type; 24import android.util.Log; 25 26public class UT_modulo extends UnitTest { 27 private Allocation A; 28 private Allocation B; 29 private final int X = 96; 30 private final int Y = 64; 31 32 protected UT_modulo(RSoVTestCore rstc, Context ctx) { 33 super(rstc, "modulo", ctx); 34 } 35 36 private void initializeGlobals(RenderScript RS, ScriptC_modulo s) { 37 Type.Builder typeBuilder = new Type.Builder(RS, Element.I32(RS)); 38 typeBuilder.setX(X); 39 typeBuilder.setY(Y); 40 41 A = Allocation.createTyped(RS, typeBuilder.create()); 42 B = Allocation.createTyped(RS, typeBuilder.create()); 43 return; 44 } 45 46 public void run() { 47 RenderScript pRS = RenderScript.create(mCtx); 48 ScriptC_modulo s = new ScriptC_modulo(pRS); 49 50 initializeGlobals(pRS, s); 51 52 int a[] = new int[X*Y]; 53 int b[] = new int[X*Y]; 54 55 java.util.Random rand = new java.util.Random(); 56 57 for (int i = 0; i < X * Y; i++) { 58 a[i] = rand.nextInt(65536); 59 } 60 61 A.copyFrom(a); 62 63 s.forEach_modulo(A, B); 64 65 B.copyTo(b); 66 67 pRS.finish(); 68 pRS.destroy(); 69 70 boolean failed = false; 71 for (int i = 0; i < X * Y; i++) { 72 int expected = a[i] % 256; 73 if (b[i] != expected) { 74 Log.e(name, "expects " + expected + " got " + b[i]); 75 failed = true; 76 break; 77 } 78 } 79 80 if (failed) { 81 failTest(); 82 } else { 83 passTest(); 84 } 85 } 86} 87