Skip to content

Commit

Permalink
8309303: jdk/internal/misc/VM/RuntimeArguments test ignores jdk/inter…
Browse files Browse the repository at this point in the history
…nal/vm/options

Reviewed-by: dnsimon, alanb
  • Loading branch information
Mandy Chung committed Jun 9, 2023
1 parent 6cd370e commit 679a6d8
Showing 1 changed file with 36 additions and 4 deletions.
40 changes: 36 additions & 4 deletions test/jdk/jdk/internal/misc/VM/RuntimeArguments.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -30,6 +30,12 @@
* @run testng RuntimeArguments
*/

import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.lang.module.ModuleFinder;
import java.lang.module.ModuleReader;
import java.lang.module.ModuleReference;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
Expand All @@ -41,6 +47,30 @@

public class RuntimeArguments {
static final String TEST_CLASSES = System.getProperty("test.classes");
static final List<String> VM_OPTIONS = getInitialOptions();

/*
* Read jdk/internal/vm/options resource from the runtime image.
* If present, the runtime image was created with jlink --add-options and
* the java launcher launches the application as if
* $ java @options <app>
* The VM options listed in the jdk/internal/vm/options resource file
* are passed to the VM.
*/
static List<String> getInitialOptions() {
ModuleReference mref = ModuleFinder.ofSystem().find("java.base").orElseThrow();
try (ModuleReader reader = mref.open()) {
InputStream in = reader.open("jdk/internal/vm/options").orElse(null);
if (in != null) {
// support the simplest form for now: whitespace-separated
return List.of(new String(in.readAllBytes()).split("\s"));
} else {
return List.of();
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

@DataProvider(name = "options")
public Object[][] options() {
Expand Down Expand Up @@ -83,13 +113,15 @@ public static void main(String... expected) {
@Test(dataProvider = "options")
public void test(List<String> args, List<String> expected) throws Exception {
// launch a test program
// $ java <runtime-arguments> -classpath <cpath> RuntimeArguments <expected>

// $ java <args> -classpath <cpath> RuntimeArguments <vm_options> <expected>
Stream<String> options = Stream.concat(args.stream(),
Stream.of("-classpath", TEST_CLASSES, "RuntimeArguments"));

ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
Stream.concat(options, expected.stream())
// The runtime image may be created with jlink --add-options
// The initial VM options will be included in the result
// returned by VM.getRuntimeArguments()
Stream.concat(options, Stream.concat(VM_OPTIONS.stream(), expected.stream()))
.toArray(String[]::new)
);
ProcessTools.executeProcess(pb).shouldHaveExitValue(0);
Expand Down

5 comments on commit 679a6d8

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mlchung
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk21

@openjdk
Copy link

@openjdk openjdk bot commented on 679a6d8 Jun 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mlchung the backport was successfully created on the branch mlchung-backport-679a6d89 in my personal fork of openjdk/jdk21. To create a pull request with this backport targeting openjdk/jdk21:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 679a6d89 from the openjdk/jdk repository.

The commit being backported was authored by Mandy Chung on 9 Jun 2023 and was reviewed by Doug Simon and Alan Bateman.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk21:

$ git fetch https://github.com/openjdk-bots/jdk21.git mlchung-backport-679a6d89:mlchung-backport-679a6d89
$ git checkout mlchung-backport-679a6d89
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk21.git mlchung-backport-679a6d89

@GoeLin
Copy link
Member

@GoeLin GoeLin commented on 679a6d8 Oct 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 679a6d8 Oct 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GoeLin the backport was successfully created on the branch backport-GoeLin-679a6d89-master in my personal fork of openjdk/jdk17u-dev. To create a pull request with this backport targeting openjdk/jdk17u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 679a6d89 from the openjdk/jdk repository.

The commit being backported was authored by Mandy Chung on 9 Jun 2023 and was reviewed by Doug Simon and Alan Bateman.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk17u-dev:

$ git fetch https://github.com/openjdk-bots/jdk17u-dev.git backport-GoeLin-679a6d89-master:backport-GoeLin-679a6d89-master
$ git checkout backport-GoeLin-679a6d89-master
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk17u-dev.git backport-GoeLin-679a6d89-master

Please sign in to comment.