8027595: Enable BigInteger overflow tests in JTREG
Summary: Remove space in @test tags, remove OOME catches, add @run tag for StringConstructorOverflow.
Reviewed-by: mduigou
--- a/jdk/test/java/math/BigInteger/BitLengthOverflow.java Fri Apr 18 15:37:22 2014 -0400
+++ b/jdk/test/java/math/BigInteger/BitLengthOverflow.java Fri Apr 18 14:03:46 2014 -0700
@@ -22,7 +22,7 @@
*/
/*
- * @ test
+ * @test
* @bug 6910473
* @summary Test that bitLength() is not negative
* @author Dmitry Nadezhin
@@ -32,18 +32,15 @@
public class BitLengthOverflow {
public static void main(String[] args) {
-
try {
BigInteger x = BigInteger.ONE.shiftLeft(Integer.MAX_VALUE); // x = pow(2,Integer.MAX_VALUE)
- if (x.bitLength() != (1L << 31))
+ if (x.bitLength() != (1L << 31)) {
throw new RuntimeException("Incorrect bitLength() " + x.bitLength());
+ }
System.out.println("Surprisingly passed with correct bitLength() " + x.bitLength());
} catch (ArithmeticException e) {
// expected
System.out.println("Overflow is reported by ArithmeticException, as expected");
- } catch (OutOfMemoryError e) {
- // possible
- System.out.println("OutOfMemoryError");
}
}
}
--- a/jdk/test/java/math/BigInteger/DivisionOverflow.java Fri Apr 18 15:37:22 2014 -0400
+++ b/jdk/test/java/math/BigInteger/DivisionOverflow.java Fri Apr 18 14:03:46 2014 -0700
@@ -22,9 +22,10 @@
*/
/*
- * @ test
+ * @test
* @bug 8022780
* @summary Test division of large values
+ * @run main/othervm -Xshare:off DivisionOverflow
* @author Dmitry Nadezhin
*/
import java.math.BigInteger;
@@ -38,14 +39,17 @@
BigInteger[] qr = a.divideAndRemainder(b);
BigInteger q = qr[0];
BigInteger r = qr[1];
- if (!r.equals(BigInteger.ZERO))
- throw new RuntimeException("Incorrect singum() of remainder " + r.signum());
- if (q.bitLength() != 2147482079)
+ if (!r.equals(BigInteger.ZERO)) {
+ throw new RuntimeException("Incorrect signum() of remainder " + r.signum());
+ }
+ if (q.bitLength() != 2147482079) {
throw new RuntimeException("Incorrect bitLength() of quotient " + q.bitLength());
+ }
System.out.println("Division of large values passed without overflow.");
} catch (OutOfMemoryError e) {
// possible
- System.out.println("OutOfMemoryError");
+ System.err.println("DivisionOverflow skipped: OutOfMemoryError");
+ System.err.println("Run jtreg with -javaoption:-Xmx8g");
}
}
}
--- a/jdk/test/java/math/BigInteger/DoubleValueOverflow.java Fri Apr 18 15:37:22 2014 -0400
+++ b/jdk/test/java/math/BigInteger/DoubleValueOverflow.java Fri Apr 18 14:03:46 2014 -0700
@@ -22,7 +22,7 @@
*/
/*
- * @ test
+ * @test
* @bug 8021203
* @summary Test that doubleValue() doesn't overflow
* @author Dmitry Nadezhin
@@ -32,18 +32,15 @@
public class DoubleValueOverflow {
public static void main(String[] args) {
-
try {
BigInteger x = BigInteger.valueOf(2).shiftLeft(Integer.MAX_VALUE); // x = pow(2,pow(2,31))
- if (x.doubleValue() != Double.POSITIVE_INFINITY)
+ if (x.doubleValue() != Double.POSITIVE_INFINITY) {
throw new RuntimeException("Incorrect doubleValue() " + x.doubleValue());
+ }
System.out.println("Passed with correct result");
} catch (ArithmeticException e) {
// expected
System.out.println("Overflow is reported by ArithmeticException, as expected");
- } catch (OutOfMemoryError e) {
- // possible
- System.out.println("OutOfMemoryError");
}
}
}
--- a/jdk/test/java/math/BigInteger/StringConstructorOverflow.java Fri Apr 18 15:37:22 2014 -0400
+++ b/jdk/test/java/math/BigInteger/StringConstructorOverflow.java Fri Apr 18 14:03:46 2014 -0700
@@ -22,9 +22,11 @@
*/
/*
- * @ test
+ * @test
+ * @ignore This test has huge memory requirements
* @bug 8021204
* @summary Test constructor BigInteger(String val, int radix) on very long string
+ * @run main/othervm -Xshare:off -Xmx8g StringConstructorOverflow
* @author Dmitry Nadezhin
*/
import java.math.BigInteger;
@@ -45,15 +47,16 @@
public static void main(String[] args) {
try {
BigInteger bi = new BigInteger(makeLongHexString(), 16);
- if (bi.compareTo(BigInteger.ONE) <= 0)
+ if (bi.compareTo(BigInteger.ONE) <= 0) {
throw new RuntimeException("Incorrect result " + bi.toString());
+ }
} catch (ArithmeticException e) {
// expected
System.out.println("Overflow is reported by ArithmeticException, as expected");
} catch (OutOfMemoryError e) {
// possible
- System.out.println("OutOfMemoryError");
- System.out.println("Run jtreg with -javaoption:-Xmx8g");
+ System.err.println("StringConstructorOverflow skipped: OutOfMemoryError");
+ System.err.println("Run jtreg with -javaoption:-Xmx8g");
}
}
}
--- a/jdk/test/java/math/BigInteger/SymmetricRangeTests.java Fri Apr 18 15:37:22 2014 -0400
+++ b/jdk/test/java/math/BigInteger/SymmetricRangeTests.java Fri Apr 18 14:03:46 2014 -0700
@@ -22,8 +22,8 @@
*/
/*
- * This test is intentionally ignored because of huge memory requirements
- * @ test
+ * @test
+ * @ignore This test has huge memory requirements
* @run main/timeout=180/othervm -Xmx8g SymmetricRangeTests
* @bug 6910473 8021204 8021203 9005933
* @summary Test range of BigInteger values