1 /*
   2  * Copyright (c) 2018, 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 
  24 
  25 package org.graalvm.compiler.hotspot.amd64.test;
  26 
  27 import static org.junit.Assume.assumeTrue;
  28 
  29 import java.util.ArrayList;
  30 import java.util.List;
  31 
  32 import org.graalvm.compiler.api.test.Graal;
  33 import org.graalvm.compiler.core.test.GraalCompilerTest;
  34 import org.graalvm.compiler.runtime.RuntimeProvider;
  35 import org.junit.Before;
  36 import org.junit.Test;
  37 import org.junit.runner.RunWith;
  38 import org.junit.runners.Parameterized;
  39 
  40 import jdk.vm.ci.amd64.AMD64;
  41 import jdk.vm.ci.code.Architecture;
  42 
  43 @RunWith(Parameterized.class)
  44 public class BinaryMathStubTest extends GraalCompilerTest {
  45 
  46     @Parameterized.Parameters(name = "{0}")
  47     public static List<Object[]> data() {
  48         ArrayList<Object[]> ret = new ArrayList<>();
  49         ret.add(new Object[]{"pow"});
  50         return ret;
  51     }
  52 
  53     private static final double[] inputs = {0.0D, Math.PI / 2, Math.PI, -1.0D, Double.MAX_VALUE, Double.MIN_VALUE, Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY};
  54     private final String stub;
  55 
  56     public BinaryMathStubTest(String stub) {
  57         this.stub = stub;
  58     }
  59 
  60     @Before
  61     public void checkAMD64() {
  62         Architecture arch = Graal.getRequiredCapability(RuntimeProvider.class).getHostBackend().getTarget().arch;
  63         assumeTrue("skipping AMD64 specific test", arch instanceof AMD64);
  64     }
  65 
  66     public static double pow(double x, double y) {
  67         return Math.pow(x, y);
  68     }
  69 
  70     @Test
  71     public void testStub() {
  72         for (double x : inputs) {
  73             for (double y : inputs) {
  74                 test(stub, x, y);
  75             }
  76         }
  77     }
  78 }