Skip to content

Commit 0b32a25

Browse files
authored
Merge pull request #19943 from keithc-ca/runner
Add support for aarch64 to j9vm.runner.Runner
2 parents 07797d6 + 2cfd724 commit 0b32a25

File tree

2 files changed

+155
-133
lines changed

2 files changed

+155
-133
lines changed

test/functional/VM_Test/src/j9vm/runner/Runner.java

Lines changed: 126 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -20,137 +20,144 @@
2020
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0
2121
*/
2222
package j9vm.runner;
23-
import java.io.*;
24-
import java.util.Properties;
25-
import java.util.Iterator;
23+
24+
import java.io.BufferedInputStream;
2625
import java.util.Map;
27-
import java.lang.reflect.Method;
26+
import java.util.Properties;
2827

2928
public class Runner {
30-
31-
protected enum OSName {
29+
30+
protected static enum OSName {
3231
AIX,
3332
LINUX,
33+
MAC,
3434
WINDOWS,
3535
ZOS,
36-
MAC,
37-
UNKNOWN
36+
UNKNOWN;
37+
38+
public static OSName current() {
39+
String osSpec = System.getProperty("os.name", "?").toLowerCase();
40+
41+
/* Get OS from the spec string. */
42+
if (osSpec.contains("aix")) {
43+
return AIX;
44+
} else if (osSpec.contains("linux")) {
45+
return LINUX;
46+
} else if (osSpec.contains("mac")) {
47+
return MAC;
48+
} else if (osSpec.contains("windows")) {
49+
return WINDOWS;
50+
} else if (osSpec.contains("z/os")) {
51+
return ZOS;
52+
} else {
53+
System.out.println("Runner couldn't determine underlying OS. Got OS Name:" + osSpec);
54+
return UNKNOWN;
55+
}
56+
}
3857
}
39-
40-
protected enum OSArch {
58+
59+
protected static enum OSArch {
60+
AARCH64,
4161
PPC,
4262
S390X,
4363
X86,
44-
UNKNOWN
45-
}
46-
47-
protected enum AddrMode {
48-
BIT31,
49-
BIT32,
50-
BIT64,
51-
UNKNOWN
52-
}
53-
54-
public static final String systemPropertyPrefix = "j9vm.";
64+
UNKNOWN;
5565

56-
protected String className;
57-
protected String exeName;
58-
protected String bootClassPath;
59-
protected String userClassPath;
60-
protected String javaVersion;
61-
protected OutputCollector inCollector;
62-
protected OutputCollector errCollector;
63-
protected OSName osName = OSName.UNKNOWN;
64-
protected OSArch osArch = OSArch.UNKNOWN;
65-
protected AddrMode addrMode = AddrMode.UNKNOWN;
66-
67-
private final String heapOptions = "-Xms64m -Xmx64m";
68-
69-
private void setPlatform() {
70-
71-
String OSSpec = System.getProperty("os.name").toLowerCase();
72-
if (OSSpec != null) {
73-
/* Get OS from the spec string */
74-
if (OSSpec.contains("aix")) {
75-
osName = OSName.AIX;
76-
} else if (OSSpec.contains("linux")) {
77-
osName = OSName.LINUX;
78-
} else if (OSSpec.contains("windows")) {
79-
osName = OSName.WINDOWS;
80-
} else if (OSSpec.contains("z/os")) {
81-
osName = OSName.ZOS;
82-
} else if (OSSpec.contains("mac")) {
83-
osName = OSName.MAC;
84-
} else {
85-
System.out.println("Runner couldn't determine underlying OS. Got OS Name:" + OSSpec);
86-
osName = OSName.UNKNOWN;
87-
}
88-
}
89-
String archSpec = System.getProperty("os.arch").toLowerCase();
90-
if (archSpec != null) {
91-
/* Get arch from spec string */
92-
if (archSpec.contains("ppc")) {
93-
osArch = OSArch.PPC;
66+
public static OSArch current() {
67+
String archSpec = System.getProperty("os.arch", "?").toLowerCase();
68+
69+
/* Get arch from spec string. */
70+
if (archSpec.contains("aarch64")) {
71+
return AARCH64;
72+
} else if (archSpec.contains("ppc")) {
73+
return PPC;
9474
} else if (archSpec.contains("s390")) {
95-
osArch = OSArch.S390X;
75+
return S390X;
9676
} else if (archSpec.contains("amd64") || archSpec.contains("x86")) {
97-
osArch = OSArch.X86;
77+
return X86;
9878
} else {
9979
System.out.println("Runner couldn't determine underlying architecture. Got OS Arch:" + archSpec);
100-
osArch = OSArch.UNKNOWN;
80+
return UNKNOWN;
10181
}
10282
}
83+
}
84+
85+
protected static enum AddrMode {
86+
BIT31,
87+
BIT32,
88+
BIT64,
89+
UNKNOWN;
90+
91+
public static AddrMode current(OSArch osArch) {
92+
String dataModel = System.getProperty("sun.arch.data.model", "?");
10393

104-
String addressingMode = System.getProperty("sun.arch.data.model");
105-
if (addressingMode != null) {
10694
/* Get address mode. S390 31-Bit addressing mode should return 32. */
107-
if ((osArch == OSArch.S390X) && (addressingMode.contains("32"))) {
108-
addrMode = AddrMode.BIT31;
109-
} else if (addressingMode.contains("32")) {
110-
addrMode = AddrMode.BIT32;
111-
} else if (addressingMode.contains("64")) {
112-
addrMode = AddrMode.BIT64;
95+
if (dataModel.contains("32")) {
96+
return (osArch == OSArch.S390X) ? BIT31 : BIT32;
97+
} else if (dataModel.contains("64")) {
98+
return BIT64;
11399
} else {
114-
System.out.println("Runner couldn't determine underlying addressing mode. Got addressingMode:" + addressingMode);
115-
addrMode = AddrMode.UNKNOWN;
100+
System.out.println("Runner couldn't determine underlying addressing mode. Got addressing mode:" + dataModel);
101+
return UNKNOWN;
116102
}
117103
}
118104
}
119-
120-
public Runner(String className, String exeName, String bootClassPath, String userClassPath, String javaVersion) {
105+
106+
public static final String systemPropertyPrefix = "j9vm.";
107+
108+
private static final String heapOptions = "-Xms64m -Xmx64m";
109+
110+
protected final String className;
111+
protected final String exeName;
112+
protected final String bootClassPath;
113+
protected final String userClassPath;
114+
protected final String javaVersion;
115+
protected final OSName osName;
116+
protected final OSArch osArch;
117+
protected final AddrMode addrMode;
118+
protected OutputCollector inCollector;
119+
protected OutputCollector errCollector;
120+
121+
public Runner(String className, String exeName, String bootClassPath, String userClassPath, String javaVersion) {
121122
super();
122123
this.className = className;
123124
this.exeName = exeName;
124125
this.bootClassPath = bootClassPath;
125126
this.userClassPath = userClassPath;
126127
this.javaVersion = javaVersion;
127-
setPlatform();
128+
this.osName = OSName.current();
129+
this.osArch = OSArch.current();
130+
this.addrMode = AddrMode.current(osArch);
128131
}
129132

130-
public String getBootClassPathOption () {
131-
if (bootClassPath == null) return "";
133+
public String getBootClassPathOption() {
134+
if (bootClassPath == null) {
135+
return "";
136+
}
132137
return "-Xbootclasspath:" + bootClassPath;
133138
}
134139

135-
public String getUserClassPathOption () {
136-
if (userClassPath == null) return "";
140+
public String getUserClassPathOption() {
141+
if (userClassPath == null) {
142+
return "";
143+
}
137144
return "-classpath " + userClassPath;
138145
}
139146

140147
public String getJ9VMSystemPropertiesString() {
141-
String result = "";
148+
StringBuilder result = new StringBuilder();
142149
Properties systemProperties = System.getProperties();
143-
Iterator it = systemProperties.entrySet().iterator();
144-
while(it.hasNext()) {
145-
Map.Entry entry = (Map.Entry) it.next();
150+
for (Map.Entry<?, ?> entry : systemProperties.entrySet()) {
146151
String key = (String) entry.getKey();
147-
if(key.startsWith(systemPropertyPrefix)) {
148-
String value = (String) entry.getValue();
149-
result += "-D" + key + "=" + value + " ";
152+
if (key.startsWith(systemPropertyPrefix)) {
153+
if (result.length() > 0) {
154+
result.append(" ");
155+
}
156+
Object value = entry.getValue();
157+
result.append("-D").append(key).append("=").append(value);
150158
}
151-
152159
}
153-
return result;
160+
return result.toString();
154161
}
155162

156163
public String getCustomCommandLineOptions() {
@@ -159,23 +166,38 @@ public String getCustomCommandLineOptions() {
159166
}
160167

161168
public String getCommandLine() {
162-
return exeName + " " + heapOptions + " " + getCustomCommandLineOptions() + " "
163-
+ getJ9VMSystemPropertiesString() + " " + getBootClassPathOption() + " "
164-
+ getUserClassPathOption() + " ";
169+
StringBuilder command = new StringBuilder(exeName);
170+
171+
appendIfNonTrivial(command, heapOptions);
172+
appendIfNonTrivial(command, getCustomCommandLineOptions());
173+
appendIfNonTrivial(command, getJ9VMSystemPropertiesString());
174+
appendIfNonTrivial(command, getBootClassPathOption());
175+
appendIfNonTrivial(command, getUserClassPathOption());
176+
177+
return command.toString();
165178
}
166-
179+
180+
private static void appendIfNonTrivial(StringBuilder buffer, String options) {
181+
if (options != null) {
182+
options = options.trim();
183+
if (!options.isEmpty()) {
184+
buffer.append(" ").append(options);
185+
}
186+
}
187+
}
188+
167189
public String getTestClassArguments() {
168190
/* For sub-classes to override, if desired. */
169191
return "";
170192
}
171-
172-
public int runCommandLine(String commandLine) {
193+
194+
public int runCommandLine(String commandLine) {
173195
System.out.println("command: " + commandLine);
174196
System.out.println();
175197
Process process;
176-
try {
198+
try {
177199
process = Runtime.getRuntime().exec(commandLine);
178-
} catch (Throwable e) {
200+
} catch (Throwable e) {
179201
System.out.println("Exception starting process!");
180202
System.out.println("(" + e.getMessage() + ")");
181203
e.printStackTrace();
@@ -188,25 +210,25 @@ public int runCommandLine(String commandLine) {
188210
errCollector = new OutputCollector(errStream);
189211
inCollector.start();
190212
errCollector.start();
191-
try {
213+
try {
192214
process.waitFor();
193215
inCollector.join();
194216
errCollector.join();
195-
} catch (InterruptedException e) {
217+
} catch (InterruptedException e) {
196218
/* Nothing. */
197219
}
198-
/* Must release process resources here, or wimpy platforms
199-
like Neutrino will run out of handles! */
220+
/* Release process resources here, to avoid running out of handles. */
200221
int retval = process.exitValue();
201-
process.destroy(); process = null;
222+
process.destroy();
223+
process = null;
202224
System.gc();
203225
return retval;
204226
}
205227

206-
public boolean run() {
228+
public boolean run() {
207229
int retval = runCommandLine(getCommandLine() + " " + className + " " + getTestClassArguments());
208-
if ( 0 != retval ) {
209-
System.out.println("no-zero exit value: " + retval);
230+
if (0 != retval) {
231+
System.out.println("non-zero exit value: " + retval);
210232
return false;
211233
}
212234
return true;

test/functional/VM_Test/src/j9vm/test/javahome/JavaHomeTestRunner.java

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,39 +21,39 @@
2121
*/
2222
package j9vm.test.javahome;
2323

24-
2524
public class JavaHomeTestRunner extends j9vm.runner.Runner {
2625

27-
public JavaHomeTestRunner(String className, String exeName, String bootClassPath, String userClassPath, String javaVersion) {
28-
super(className, exeName, bootClassPath, userClassPath, javaVersion);
29-
}
30-
31-
public String getBootClassPathOption() { return ""; }
32-
33-
public boolean run() {
34-
boolean passed = true;
35-
int rc = runCommandLine(getCommandLine() + "-Djava.home=" +
36-
System.getProperty("java.home") + " " + className);
37-
System.out.println("rc = " + rc + "\n");
38-
if (0 != rc) {
39-
passed = false;
26+
public JavaHomeTestRunner(String className, String exeName, String bootClassPath, String userClassPath, String javaVersion) {
27+
super(className, exeName, bootClassPath, userClassPath, javaVersion);
4028
}
41-
42-
System.out.println("////// Failure starting VM expected here //////");
43-
rc = runCommandLine(getCommandLine() + "-Djava.home=FooFooFoo! " + className);
44-
System.out.println("rc = " + rc + "\n");
45-
if (1 != rc) {
46-
passed = false;
29+
30+
public String getBootClassPathOption() {
31+
return "";
4732
}
48-
49-
System.out.println("////// Failure starting VM expected here //////");
50-
rc = runCommandLine(getCommandLine() + "-Djava.home= " + className);
51-
System.out.println("rc = " + rc + "\n");
52-
if (1 != rc) {
53-
passed = false;
33+
34+
public boolean run() {
35+
boolean passed = true;
36+
int rc = runCommandLine(getCommandLine() + " -Djava.home=" + System.getProperty("java.home") + " " + className);
37+
System.out.println("rc = " + rc + "\n");
38+
if (0 != rc) {
39+
passed = false;
40+
}
41+
42+
System.out.println("////// Failure starting VM expected here //////");
43+
rc = runCommandLine(getCommandLine() + " -Djava.home=FooFooFoo! " + className);
44+
System.out.println("rc = " + rc + "\n");
45+
if (1 != rc) {
46+
passed = false;
47+
}
48+
49+
System.out.println("////// Failure starting VM expected here //////");
50+
rc = runCommandLine(getCommandLine() + " -Djava.home= " + className);
51+
System.out.println("rc = " + rc + "\n");
52+
if (1 != rc) {
53+
passed = false;
54+
}
55+
56+
return passed;
5457
}
55-
56-
return passed;
57-
}
5858

5959
}

0 commit comments

Comments
 (0)