Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/tools/javah/T6893943.java
32285 views
1
/*
2
* Copyright (c) 2010, 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 6893943 6937318
27
* @summary exit code from javah with no args is 0
28
*/
29
30
import java.io.*;
31
import java.util.*;
32
33
public class T6893943 {
34
static final String[] NO_ARGS = { };
35
static final String[] HELP = { "-help" };
36
static final String NEWLINE = System.getProperty("line.separator");
37
38
public static void main(String... args) throws Exception {
39
new T6893943().run();
40
}
41
42
void run() throws Exception {
43
testSimpleAPI(NO_ARGS, 1);
44
testSimpleAPI(HELP, 0);
45
testCommand(NO_ARGS, 1);
46
testCommand(HELP, 0);
47
}
48
49
void testSimpleAPI(String[] args, int expect_rc) throws Exception {
50
System.err.println("Test simple api: " + Arrays.asList(args));
51
StringWriter sw = new StringWriter();
52
PrintWriter pw = new PrintWriter(sw);
53
int rc = com.sun.tools.javah.Main.run(args, pw);
54
pw.close();
55
expect("testSimpleAPI", sw.toString(), rc, expect_rc);
56
}
57
58
void testCommand(String[] args, int expect_rc) throws Exception {
59
System.err.println("Test command: " + Arrays.asList(args));
60
File javaHome = new File(System.getProperty("java.home"));
61
if (javaHome.getName().equals("jre"))
62
javaHome = javaHome.getParentFile();
63
64
List<String> command = new ArrayList<String>();
65
command.add(new File(new File(javaHome, "bin"), "javah").getPath());
66
command.add("-J-Xbootclasspath:" + System.getProperty("sun.boot.class.path"));
67
command.addAll(Arrays.asList(args));
68
//System.err.println("command: " + command);
69
70
ProcessBuilder pb = new ProcessBuilder(command);
71
pb.redirectErrorStream(true);
72
Process p = pb.start();
73
p.getOutputStream().close();
74
StringWriter sw = new StringWriter();
75
String line;
76
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
77
while ((line = in.readLine()) != null)
78
sw.write(line + NEWLINE);
79
int rc = p.waitFor();
80
expect("testCommand", sw.toString(), rc, expect_rc);
81
}
82
83
void expect(String name, String out, int actual_rc, int expect_rc) throws Exception {
84
if (out.isEmpty())
85
throw new Exception("No output from javah");
86
87
if (!out.startsWith("Usage:")) {
88
System.err.println(out);
89
throw new Exception("Unexpected output from javah");
90
}
91
92
if (actual_rc != expect_rc)
93
throw new Exception(name + ": unexpected exit: " + actual_rc + ", expected: " + expect_rc);
94
}
95
}
96
97