Skip to content

Commit

Permalink
Read output of GetAvailableProcessors from a temporary file
Browse files Browse the repository at this point in the history
  • Loading branch information
swesonga committed May 7, 2024
1 parent 96c76ca commit 04066dd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
15 changes: 13 additions & 2 deletions test/hotspot/jtreg/runtime/os/windows/GetAvailableProcessors.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 04066dd

Please sign in to comment.