test/jdk/tools/launcher/Jexec.java
author mr
Wed, 16 Jan 2019 16:27:21 -0800
changeset 53372 4003935e6e5f
parent 47216 71c04702a3d5
permissions -rw-r--r--
8216532: tools/launcher/Test7029048.java fails (Solaris) Reviewed-by: rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
44037
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
     1
/*
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
     4
 *
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
     7
 * published by the Free Software Foundation.
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
     8
 *
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    13
 * accompanied this code).
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    14
 *
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    18
 *
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    21
 * questions.
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    22
 */
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    23
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    24
/*
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    25
 * @test
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    26
 * @bug 8175000
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    27
 * @summary test jexec
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    28
 * @build TestHelper
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    29
 * @run main Jexec
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    30
 */
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    31
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    32
import java.io.File;
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    33
import java.io.IOException;
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    34
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    35
public class Jexec extends TestHelper {
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    36
    private final File testJar;
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    37
    private final File jexecCmd;
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    38
    private final String message = "Hello, do you read me ?";
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    39
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    40
    Jexec() throws IOException {
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    41
        jexecCmd = new File(JAVA_LIB, "jexec");
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    42
        if (!jexecCmd.exists() || !jexecCmd.canExecute()) {
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    43
            throw new Error("jexec: does not exist or not executable");
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    44
        }
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    45
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    46
        testJar = new File("test.jar");
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    47
        StringBuilder tsrc = new StringBuilder();
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    48
        tsrc.append("public static void main(String... args) {\n");
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    49
        tsrc.append("   for (String x : args) {\n");
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    50
        tsrc.append("        System.out.println(x);\n");
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    51
        tsrc.append("   }\n");
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    52
        tsrc.append("}\n");
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    53
        createJar(testJar, tsrc.toString());
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    54
    }
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    55
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    56
    public static void main(String... args) throws Exception {
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    57
        // linux is the only supported platform, give the others a pass
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    58
        if (!isLinux) {
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    59
            System.err.println("Warning: unsupported platform test passes vacuously");
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    60
            return;
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    61
        }
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    62
        // ok to run the test now
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    63
        Jexec t = new Jexec();
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    64
        t.run(null);
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    65
    }
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    66
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    67
    @Test
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    68
    void jexec() throws Exception {
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    69
        TestResult tr = doExec(jexecCmd.getAbsolutePath(),
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    70
                testJar.getAbsolutePath(), message);
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    71
        if (!tr.isOK()) {
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    72
            System.err.println(tr);
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    73
            throw new Exception("incorrect exit value");
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    74
        }
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    75
        if (!tr.contains(message)) {
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    76
            System.err.println(tr);
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    77
            throw new Exception("expected message \'" + message + "\' not found");
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    78
        }
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    79
    }
c590b1dc6334 8175000: jexec fails to execute simple helloworld.jar
mbaesken
parents:
diff changeset
    80
}