hotspot/test/testlibrary_tests/ctw/CtwTest.java
author ykantser
Mon, 04 May 2015 16:30:07 +0200
changeset 30604 b8d532cb6420
parent 26915 ba674d5d0f77
child 40631 ed82623d7831
permissions -rw-r--r--
8067013: Rename the com.oracle.java.testlibary package Reviewed-by: dholmes, gtriantafill, sla Contributed-by: alexander.kulyakhtin@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26915
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
     1
/*
30604
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 26915
diff changeset
     2
 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
26915
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
     4
 *
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
     8
 *
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    13
 * accompanied this code).
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    14
 *
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    18
 *
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    21
 * questions.
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    22
 */
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    23
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    24
import java.util.List;
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    25
import java.util.Collections;
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    26
import java.util.ArrayList;
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    27
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    28
import java.io.File;
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    29
import java.io.Writer;
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    30
import java.io.FileWriter;
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    31
import java.io.IOException;
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    32
import java.io.BufferedReader;
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    33
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    34
import java.nio.file.Files;
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    35
import java.nio.file.Paths;
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    36
import java.nio.file.StandardCopyOption;
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    37
import java.nio.charset.Charset;
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    38
30604
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 26915
diff changeset
    39
import jdk.test.lib.JDKToolFinder;
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 26915
diff changeset
    40
import jdk.test.lib.OutputAnalyzer;
26915
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    41
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    42
public abstract class CtwTest {
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    43
    protected final String[] shouldContain;
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    44
    protected CtwTest(String[] shouldContain) {
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    45
        this.shouldContain = shouldContain;
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    46
    }
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    47
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    48
    public void run(String[] args) throws Exception {
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    49
        if (args.length == 0) {
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    50
            throw new Error("args is empty");
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    51
        }
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    52
        switch (args[0]) {
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    53
            case "prepare":
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    54
                prepare();
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    55
                break;
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    56
            case "check":
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    57
                check(args);
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    58
                break;
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    59
            default:
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    60
                throw new Error("unregonized action -- " + args[0]);
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    61
        }
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    62
    }
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    63
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    64
    protected void prepare() throws Exception { }
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    65
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    66
    protected void check(String[] args) throws Exception  {
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    67
        if (args.length < 2) {
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    68
            throw new Error("logfile isn't specified");
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    69
        }
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    70
        String logfile = args[1];
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    71
        try (BufferedReader r = Files.newBufferedReader(Paths.get(logfile),
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    72
                Charset.defaultCharset())) {
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    73
            OutputAnalyzer output = readOutput(r);
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    74
           for (String test : shouldContain) {
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    75
                output.shouldContain(test);
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    76
            }
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    77
        }
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    78
    }
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    79
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    80
    private static OutputAnalyzer readOutput(BufferedReader reader)
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    81
            throws IOException {
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    82
        StringBuilder builder = new StringBuilder();
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    83
        String eol = String.format("%n");
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    84
        String line;
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    85
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    86
        while ((line = reader.readLine()) != null) {
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    87
            builder.append(line);
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    88
            builder.append(eol);
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    89
        }
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    90
        return new OutputAnalyzer(builder.toString(), "");
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    91
    }
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    92
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    93
    protected void dump(OutputAnalyzer output, String name) {
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    94
        try (Writer w = new FileWriter(name + ".out")) {
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    95
            String s = output.getStdout();
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    96
            w.write(s, s.length(), 0);
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    97
        } catch (IOException io) {
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    98
            io.printStackTrace();
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
    99
        }
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
   100
        try (Writer w = new FileWriter(name + ".err")) {
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
   101
            String s = output.getStderr();
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
   102
            w.write(s, s.length(), 0);
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
   103
        } catch (IOException io) {
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
   104
            io.printStackTrace();
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
   105
        }
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
   106
    }
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
   107
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
   108
    protected ProcessBuilder createJarProcessBuilder(String... command)
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
   109
            throws Exception {
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
   110
        String javapath = JDKToolFinder.getJDKTool("jar");
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
   111
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
   112
        ArrayList<String> args = new ArrayList<>();
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
   113
        args.add(javapath);
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
   114
        Collections.addAll(args, command);
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
   115
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
   116
        return new ProcessBuilder(args.toArray(new String[args.size()]));
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
   117
    }
ba674d5d0f77 8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff changeset
   118
}