Skip to content

Commit 9e3fa32

Browse files
Kazuhisa TakakuriDavid Holmes
authored andcommitted
8349288: runtime/os/windows/TestAvailableProcessors.java fails on localized Windows platform
Reviewed-by: dholmes, alanb
1 parent b7b01d6 commit 9e3fa32

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

test/hotspot/jtreg/runtime/os/windows/TestAvailableProcessors.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
* @run testng/othervm/native TestAvailableProcessors
3535
*/
3636

37+
import java.io.File;
3738
import java.io.IOException;
3839
import java.util.List;
3940
import java.util.HashSet;
@@ -58,7 +59,23 @@ public class TestAvailableProcessors {
5859
private static String getWindowsVersion() throws IOException {
5960
String systeminfoPath = "systeminfo.exe";
6061

61-
var processBuilder = new ProcessBuilder(systeminfoPath);
62+
List<String> command = new ArrayList<>();
63+
64+
String systemRoot = System.getenv("SystemRoot");
65+
if (systemRoot == null) {
66+
systemRoot = System.getenv("WINDIR");
67+
if (systemRoot == null) {
68+
throw new RuntimeException("SystemRoot or WINDIR environment variable is not set.");
69+
}
70+
}
71+
String system32 = Path.of(systemRoot, "System32").toString();
72+
73+
// It switches the active code page to cp437, the default code page for US english.
74+
command.addAll(List.of("cmd.exe", "/c", "set", "PATH=%PATH%;" + system32 + ";" + system32 + "\\wbem", "&&"));
75+
command.addAll(List.of("chcp", "437", ">nul", "2>&1", "&&"));
76+
command.add(systeminfoPath);
77+
78+
var processBuilder = new ProcessBuilder(command);
6279
OutputAnalyzer outputAnalyzer = new OutputAnalyzer(processBuilder.start());
6380
outputAnalyzer.shouldHaveExitValue(0);
6481
outputAnalyzer.shouldContain(osVersionMessage);

0 commit comments

Comments
 (0)