hotspot/test/testlibrary_tests/RandomGeneratorTest.java
author roland
Wed, 29 Jul 2015 17:25:04 +0200
changeset 32372 b82e88dcb26c
parent 31232 741963a4e59e
child 36851 03e2f4d0a421
permissions -rw-r--r--
8080289: Intermediate writes in a loop not eliminated by optimizer Summary: Move Stores out of loop (after or before) when possible Reviewed-by: kvn, vlivanov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27453
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
     1
/*
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 29350
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
27453
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
     4
 *
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
     7
 * published by the Free Software Foundation.
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
     8
 *
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    13
 * accompanied this code).
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    14
 *
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    18
 *
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    21
 * questions.
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    22
 */
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    23
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    24
/*
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    25
 * @test
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    26
 * @summary Verify correctnes of the random generator from Utility.java
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    27
 * @library /testlibrary
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 29350
diff changeset
    28
 * @modules java.base/sun.misc
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 29350
diff changeset
    29
 *          java.management
27453
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    30
 * @run driver RandomGeneratorTest SAME_SEED
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    31
 * @run driver RandomGeneratorTest NO_SEED
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    32
 * @run driver RandomGeneratorTest DIFFERENT_SEED
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    33
 */
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    34
31232
741963a4e59e 8078145: testlibrary_tests/RandomGeneratorTest.java failed with AssertionError : Unexpected random number sequence for mode: NO_SEED
skovalev
parents: 30604
diff changeset
    35
import java.io.FileWriter;
741963a4e59e 8078145: testlibrary_tests/RandomGeneratorTest.java failed with AssertionError : Unexpected random number sequence for mode: NO_SEED
skovalev
parents: 30604
diff changeset
    36
import java.io.IOException;
741963a4e59e 8078145: testlibrary_tests/RandomGeneratorTest.java failed with AssertionError : Unexpected random number sequence for mode: NO_SEED
skovalev
parents: 30604
diff changeset
    37
import java.io.PrintWriter;
27453
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    38
import java.util.ArrayList;
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    39
import java.util.List;
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    40
import java.util.Random;
31232
741963a4e59e 8078145: testlibrary_tests/RandomGeneratorTest.java failed with AssertionError : Unexpected random number sequence for mode: NO_SEED
skovalev
parents: 30604
diff changeset
    41
import jdk.test.lib.OutputAnalyzer;
741963a4e59e 8078145: testlibrary_tests/RandomGeneratorTest.java failed with AssertionError : Unexpected random number sequence for mode: NO_SEED
skovalev
parents: 30604
diff changeset
    42
import jdk.test.lib.ProcessTools;
741963a4e59e 8078145: testlibrary_tests/RandomGeneratorTest.java failed with AssertionError : Unexpected random number sequence for mode: NO_SEED
skovalev
parents: 30604
diff changeset
    43
import jdk.test.lib.Utils;
27453
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    44
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    45
/**
30604
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 29678
diff changeset
    46
 * The test verifies correctness of work {@link jdk.test.lib.Utils#getRandomInstance()}.
27453
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    47
 * Test works in three modes: same seed provided, no seed provided and
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    48
 * different seed provided. In the first case the test expects that all random numbers
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    49
 * will be repeated in all next iterations. For other two modes test expects that
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    50
 * randomly generated numbers differ from original.
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    51
 */
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    52
public class RandomGeneratorTest {
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    53
    private static final String SEED_VM_OPTION = "-D" + Utils.SEED_PROPERTY_NAME + "=";
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    54
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    55
    public static void main( String[] args) throws Throwable {
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    56
        if (args.length == 0) {
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    57
            throw new Error("TESTBUG: No test mode provided.");
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    58
        }
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    59
        SeedOption seedOpt = SeedOption.valueOf(args[0]);
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    60
        List<String> jvmArgs = new ArrayList<String>();
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    61
        String optStr = seedOpt.getSeedOption();
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    62
        if (optStr != null) {
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    63
            jvmArgs.add(optStr);
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    64
        }
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    65
        jvmArgs.add(RandomRunner.class.getName());
31232
741963a4e59e 8078145: testlibrary_tests/RandomGeneratorTest.java failed with AssertionError : Unexpected random number sequence for mode: NO_SEED
skovalev
parents: 30604
diff changeset
    66
        String origFileName = seedOpt.name() + "_orig";
741963a4e59e 8078145: testlibrary_tests/RandomGeneratorTest.java failed with AssertionError : Unexpected random number sequence for mode: NO_SEED
skovalev
parents: 30604
diff changeset
    67
        jvmArgs.add(origFileName);
741963a4e59e 8078145: testlibrary_tests/RandomGeneratorTest.java failed with AssertionError : Unexpected random number sequence for mode: NO_SEED
skovalev
parents: 30604
diff changeset
    68
        int fileNameIndex = jvmArgs.size() - 1;
27453
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    69
        String[] cmdLineArgs = jvmArgs.toArray(new String[jvmArgs.size()]);
31232
741963a4e59e 8078145: testlibrary_tests/RandomGeneratorTest.java failed with AssertionError : Unexpected random number sequence for mode: NO_SEED
skovalev
parents: 30604
diff changeset
    70
        ProcessTools.executeTestJvm(cmdLineArgs).shouldHaveExitValue(0);
741963a4e59e 8078145: testlibrary_tests/RandomGeneratorTest.java failed with AssertionError : Unexpected random number sequence for mode: NO_SEED
skovalev
parents: 30604
diff changeset
    71
        String etalon = Utils.fileAsString(origFileName).trim();
741963a4e59e 8078145: testlibrary_tests/RandomGeneratorTest.java failed with AssertionError : Unexpected random number sequence for mode: NO_SEED
skovalev
parents: 30604
diff changeset
    72
        cmdLineArgs[fileNameIndex] = seedOpt.name();
27453
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    73
        seedOpt.verify(etalon, cmdLineArgs);
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    74
    }
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    75
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    76
    /**
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    77
     * The utility enum helps to generate an appropriate string that should be passed
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    78
     * to the command line depends on the testing mode. It is also responsible for the result
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    79
     * validation.
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    80
     */
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    81
    private enum SeedOption {
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    82
        SAME_SEED {
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    83
            @Override
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    84
            public String getSeedOption() {
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    85
                return SEED_VM_OPTION + Utils.SEED;
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    86
            }
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    87
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    88
            @Override
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    89
            protected boolean isOutputExpected(String orig, String output) {
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    90
                return output.equals(orig);
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    91
            }
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    92
        },
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    93
        DIFFERENT_SEED {
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    94
            @Override
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    95
            public String getSeedOption() {
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    96
                return SEED_VM_OPTION + Utils.getRandomInstance().nextLong();
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    97
            }
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    98
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
    99
            @Override
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   100
            public void verify(String orig, String[] cmdLine) {
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   101
                cmdLine[0] = getSeedOption();
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   102
                super.verify(orig, cmdLine);
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   103
            }
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   104
        },
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   105
        NO_SEED {
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   106
            @Override
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   107
            public String getSeedOption() {
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   108
                return null;
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   109
            }
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   110
        };
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   111
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   112
        /**
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   113
         * Generates a string to be added as a command line argument.
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   114
         * It contains "-D" prefix, system property name, '=' sign
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   115
         * and seed value.
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   116
         * @return command line argument
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   117
         */
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   118
        public abstract String getSeedOption();
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   119
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   120
        protected boolean isOutputExpected(String orig, String output) {
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   121
            return !output.equals(orig);
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   122
        }
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   123
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   124
        /**
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   125
         * Verifies that the original output meets expectations
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   126
         * depending on the test mode. It compares the output of second execution
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   127
         * to original one.
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   128
         * @param orig original output
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   129
         * @param cmdLine command line arguments
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   130
         * @throws Throwable - Throws an exception in case test failure.
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   131
         */
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   132
        public void verify(String orig, String[] cmdLine) {
31232
741963a4e59e 8078145: testlibrary_tests/RandomGeneratorTest.java failed with AssertionError : Unexpected random number sequence for mode: NO_SEED
skovalev
parents: 30604
diff changeset
   133
            String output;
741963a4e59e 8078145: testlibrary_tests/RandomGeneratorTest.java failed with AssertionError : Unexpected random number sequence for mode: NO_SEED
skovalev
parents: 30604
diff changeset
   134
            OutputAnalyzer oa;
27453
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   135
            try {
31232
741963a4e59e 8078145: testlibrary_tests/RandomGeneratorTest.java failed with AssertionError : Unexpected random number sequence for mode: NO_SEED
skovalev
parents: 30604
diff changeset
   136
                oa = ProcessTools.executeTestJvm(cmdLine);
27453
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   137
            } catch (Throwable t) {
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   138
                throw new Error("TESTBUG: Unexpedted exception during jvm execution.", t);
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   139
            }
31232
741963a4e59e 8078145: testlibrary_tests/RandomGeneratorTest.java failed with AssertionError : Unexpected random number sequence for mode: NO_SEED
skovalev
parents: 30604
diff changeset
   140
            oa.shouldHaveExitValue(0);
741963a4e59e 8078145: testlibrary_tests/RandomGeneratorTest.java failed with AssertionError : Unexpected random number sequence for mode: NO_SEED
skovalev
parents: 30604
diff changeset
   141
            try {
741963a4e59e 8078145: testlibrary_tests/RandomGeneratorTest.java failed with AssertionError : Unexpected random number sequence for mode: NO_SEED
skovalev
parents: 30604
diff changeset
   142
                output = Utils.fileAsString(name()).trim();
741963a4e59e 8078145: testlibrary_tests/RandomGeneratorTest.java failed with AssertionError : Unexpected random number sequence for mode: NO_SEED
skovalev
parents: 30604
diff changeset
   143
            } catch (IOException ioe) {
741963a4e59e 8078145: testlibrary_tests/RandomGeneratorTest.java failed with AssertionError : Unexpected random number sequence for mode: NO_SEED
skovalev
parents: 30604
diff changeset
   144
                throw new Error("TESTBUG: Problem during IO operation with file: " + name(), ioe);
27453
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   145
            }
31232
741963a4e59e 8078145: testlibrary_tests/RandomGeneratorTest.java failed with AssertionError : Unexpected random number sequence for mode: NO_SEED
skovalev
parents: 30604
diff changeset
   146
            if (!isOutputExpected(orig, output)) {
741963a4e59e 8078145: testlibrary_tests/RandomGeneratorTest.java failed with AssertionError : Unexpected random number sequence for mode: NO_SEED
skovalev
parents: 30604
diff changeset
   147
                System.err.println("Initial output: " + orig);
741963a4e59e 8078145: testlibrary_tests/RandomGeneratorTest.java failed with AssertionError : Unexpected random number sequence for mode: NO_SEED
skovalev
parents: 30604
diff changeset
   148
                System.err.println("Second run output: " + output);
741963a4e59e 8078145: testlibrary_tests/RandomGeneratorTest.java failed with AssertionError : Unexpected random number sequence for mode: NO_SEED
skovalev
parents: 30604
diff changeset
   149
                throw new AssertionError("Unexpected random number sequence for mode: " + this.name());
741963a4e59e 8078145: testlibrary_tests/RandomGeneratorTest.java failed with AssertionError : Unexpected random number sequence for mode: NO_SEED
skovalev
parents: 30604
diff changeset
   150
            }
27453
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   151
        }
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   152
    }
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   153
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   154
    /**
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   155
     * The helper class generates several random numbers
31232
741963a4e59e 8078145: testlibrary_tests/RandomGeneratorTest.java failed with AssertionError : Unexpected random number sequence for mode: NO_SEED
skovalev
parents: 30604
diff changeset
   156
     * and put results to a file. The file name came as first
741963a4e59e 8078145: testlibrary_tests/RandomGeneratorTest.java failed with AssertionError : Unexpected random number sequence for mode: NO_SEED
skovalev
parents: 30604
diff changeset
   157
     * command line argument.
27453
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   158
     */
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   159
    public static class RandomRunner {
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   160
        private static final int COUNT = 10;
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   161
        public static void main(String[] args) {
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   162
            StringBuilder sb = new StringBuilder();
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   163
            Random rng = Utils.getRandomInstance();
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   164
            for (int i = 0; i < COUNT; i++) {
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   165
                sb.append(rng.nextLong()).append(' ');
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   166
            }
31232
741963a4e59e 8078145: testlibrary_tests/RandomGeneratorTest.java failed with AssertionError : Unexpected random number sequence for mode: NO_SEED
skovalev
parents: 30604
diff changeset
   167
            try (PrintWriter pw = new PrintWriter(new FileWriter(args[0]))) {
741963a4e59e 8078145: testlibrary_tests/RandomGeneratorTest.java failed with AssertionError : Unexpected random number sequence for mode: NO_SEED
skovalev
parents: 30604
diff changeset
   168
                pw.write(sb.toString());
741963a4e59e 8078145: testlibrary_tests/RandomGeneratorTest.java failed with AssertionError : Unexpected random number sequence for mode: NO_SEED
skovalev
parents: 30604
diff changeset
   169
            } catch (IOException ioe) {
741963a4e59e 8078145: testlibrary_tests/RandomGeneratorTest.java failed with AssertionError : Unexpected random number sequence for mode: NO_SEED
skovalev
parents: 30604
diff changeset
   170
                throw new Error("TESTBUG: Problem during IO operation with file: " + args[0], ioe);
741963a4e59e 8078145: testlibrary_tests/RandomGeneratorTest.java failed with AssertionError : Unexpected random number sequence for mode: NO_SEED
skovalev
parents: 30604
diff changeset
   171
            }
27453
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   172
        }
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   173
    }
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents:
diff changeset
   174
}