1 /*
2  * Copyright (c) 2017, 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  * @test
26  * @bug 8175000
27  * @summary test jexec
28  * @build TestHelper
29  * @run main Jexec
30  */
31 
32 import java.io.File;
33 import java.io.IOException;
34 
35 public class Jexec extends TestHelper {
36     private final File testJar;
37     private final File jexecCmd;
38     private final String message = "Hello, do you read me ?";
39 
Jexec()40     Jexec() throws IOException {
41         jexecCmd = new File(JAVA_LIB, "jexec");
42         if (!jexecCmd.exists() || !jexecCmd.canExecute()) {
43             throw new Error("jexec: does not exist or not executable");
44         }
45 
46         testJar = new File("test.jar");
47         StringBuilder tsrc = new StringBuilder();
48         tsrc.append("public static void main(String... args) {\n");
49         tsrc.append("   for (String x : args) {\n");
50         tsrc.append("        System.out.println(x);\n");
51         tsrc.append("   }\n");
52         tsrc.append("}\n");
53         createJar(testJar, tsrc.toString());
54     }
55 
main(String... args)56     public static void main(String... args) throws Exception {
57         // linux is the only supported platform, give the others a pass
58         if (!isLinux) {
59             System.err.println("Warning: unsupported platform test passes vacuously");
60             return;
61         }
62         // ok to run the test now
63         Jexec t = new Jexec();
64         t.run(null);
65     }
66 
67     @Test
jexec()68     void jexec() throws Exception {
69         TestResult tr = doExec(jexecCmd.getAbsolutePath(),
70                 testJar.getAbsolutePath(), message);
71         if (!tr.isOK()) {
72             System.err.println(tr);
73             throw new Exception("incorrect exit value");
74         }
75         if (!tr.contains(message)) {
76             System.err.println(tr);
77             throw new Exception("expected message \'" + message + "\' not found");
78         }
79     }
80 }
81