1 /*
   2  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package com.oracle.graal.compiler.hsail.test.lambda;
  24 
  25 import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester;
  26 
  27 import org.junit.*;
  28 
  29 public class MoreThanEightArgsOOBTest extends GraalKernelTester {
  30 
  31     int[] makeIntArray(int size) {
  32         int[] out = new int[size];
  33 
  34         for (int i = 0; i < size; i++) {
  35             out[i] = 1;
  36         }
  37         return out;
  38     }
  39 
  40     final int rows = 4096;
  41     final int cols = 4096;
  42     final int loops = 1;
  43 
  44     @Result int[] result;
  45 
  46     void innerTest(int[] res, int[] a, int[] b, int[] c, int[] d, int base, int stride) {
  47         final int resCols = a.length;
  48         final int resRows = res.length;
  49         final int limit = resCols - stride;
  50 
  51         dispatchLambdaKernel(resRows, (row) -> {
  52             res[row] = 0;
  53             if (a != null) {
  54                 for (int col = base; col < limit; col += 4) {
  55                     int p0 = 0;
  56                     int p1 = 0;
  57                     int p2 = 0;
  58                     int p3 = 0;
  59                     p0 = a[col] + b[col] + c[col] + d[col] + stride;
  60                     p1 = a[col + 1] + b[col + 1] + c[col + 1] + d[col + 1];
  61                     p2 = a[col + 2] + b[col + 2] + c[col + 2] + d[col + 2];
  62                     p3 = a[col + 3] + b[col + 3] + c[col + 3] + d[col + 5000];
  63                     res[row] += p0 + p1 + p2 + p3;
  64                 }
  65             }
  66         });
  67     }
  68 
  69     @Override
  70     public void runTest() {
  71         int[] a;
  72         int[] b;
  73         int[] c;
  74         int[] d;
  75 
  76         result = makeIntArray(rows);
  77         a = makeIntArray(cols);
  78         b = makeIntArray(cols);
  79         c = makeIntArray(cols);
  80         d = makeIntArray(cols);
  81         for (int i = 0; i < loops; i++) {
  82             innerTest(result, a, b, c, d, 0, 4);
  83         }
  84     }
  85 
  86     @Test(expected = ArrayIndexOutOfBoundsException.class)
  87     public void test() {
  88         testGeneratedHsail();
  89     }
  90 
  91     @Test(expected = ArrayIndexOutOfBoundsException.class)
  92     public void testUsingLambdaMethod() {
  93         testGeneratedHsailUsingLambdaMethod();
  94     }
  95 }