From 04066dd70256e511f3715b67cdafc9e0bdbd1e52 Mon Sep 17 00:00:00 2001 From: Saint Wesonga Date: Mon, 6 May 2024 19:11:00 -0600 Subject: [PATCH] Read output of GetAvailableProcessors from a temporary file --- .../os/windows/GetAvailableProcessors.java | 15 +++++++++++++-- .../os/windows/TestAvailableProcessors.java | 15 ++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/test/hotspot/jtreg/runtime/os/windows/GetAvailableProcessors.java b/test/hotspot/jtreg/runtime/os/windows/GetAvailableProcessors.java index ee7d7c2f42fea..2631521b8d19f 100644 --- a/test/hotspot/jtreg/runtime/os/windows/GetAvailableProcessors.java +++ b/test/hotspot/jtreg/runtime/os/windows/GetAvailableProcessors.java @@ -22,8 +22,19 @@ * */ +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; + public class GetAvailableProcessors { - public static void main(String[] args) { - System.out.println("Runtime.availableProcessors: " + Runtime.getRuntime().availableProcessors()); + public static void main(String[] args) throws IOException { + String message = "Runtime.availableProcessors: " + Runtime.getRuntime().availableProcessors(); + System.out.println(message); + + if (args.length > 0) { + Path filePath = Path.of(args[0]); + Files.writeString(filePath, message, StandardCharsets.UTF_8); + } } } diff --git a/test/hotspot/jtreg/runtime/os/windows/TestAvailableProcessors.java b/test/hotspot/jtreg/runtime/os/windows/TestAvailableProcessors.java index 963f286455afa..9797e73704c18 100644 --- a/test/hotspot/jtreg/runtime/os/windows/TestAvailableProcessors.java +++ b/test/hotspot/jtreg/runtime/os/windows/TestAvailableProcessors.java @@ -38,6 +38,8 @@ */ import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; @@ -178,8 +180,12 @@ private static void verifyAvailableProcessorsFromStartAffinity(boolean productFl String productFlag = productFlagEnabled ? "-XX:+UseAllWindowsProcessorGroups" : "-XX:-UseAllWindowsProcessorGroups"; + // Write output of GetAvailableProcessors to a temporary file + Path outputFile = Files.createTempFile(Paths.get("."), TestAvailableProcessors.class.getSimpleName(), ".tmp"); + String outputFilePath = outputFile.toString(); + ProcessBuilder processBuilder = ProcessTools.createLimitedTestJavaProcessBuilder( - new String[] {productFlag, "GetAvailableProcessors"} + new String[] {productFlag, "GetAvailableProcessors", outputFilePath} ); String javaCommandLine = ProcessTools.getCommandLine(processBuilder); @@ -192,6 +198,13 @@ private static void verifyAvailableProcessorsFromStartAffinity(boolean productFl var outputAnalyzer = new OutputAnalyzer(processBuilder.start()); outputAnalyzer.shouldHaveExitValue(0); + + // Read the output of GetAvailableProcessors from the temporary file + byte[] bytesFromFile = Files.readAllBytes(outputFile); + String fileContent = new String(bytesFromFile, StandardCharsets.UTF_8); + System.out.println("GetAvailableProcessors output: " + fileContent); + + outputAnalyzer = new OutputAnalyzer(fileContent); outputAnalyzer.shouldContain(runtimeAvailableProcessorsMessage); int runtimeAvailableProcs = getAvailableProcessors(outputAnalyzer);