Skip to content

Commit

Permalink
8319567: Update java/lang/invoke tests to support vm flags
Browse files Browse the repository at this point in the history
8319568: Update java/lang/reflect/exeCallerAccessTest/CallerAccessTest.java to accept vm flags
8319672: Several classloader tests ignore VM flags
8319676: A couple of jdk/modules/incubator/ tests ignore VM flags
8319677: Test jdk/internal/misc/VM/RuntimeArguments.java should be marked as flagless

Reviewed-by: jvernee, lmesnik
  • Loading branch information
Mandy Chung committed Nov 16, 2023
1 parent 9727f4b commit 1588dd9
Show file tree
Hide file tree
Showing 17 changed files with 219 additions and 434 deletions.
40 changes: 18 additions & 22 deletions test/jdk/java/lang/ClassLoader/Assert.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 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 All @@ -24,19 +24,26 @@
/*
* @test
* @bug 4290640 4785473
* @requires vm.flagless
* @library /test/lib
* @build package1.Class1 package2.Class2 package1.package3.Class3 Assert
* @run main/othervm Assert
* @summary Test the assertion facility
* @author Mike McCloskey
* @key randomness
*/

import jdk.test.lib.process.OutputAnalyzer;
import package1.*;
import package2.*;
import package1.package3.*;
import java.io.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import static jdk.test.lib.process.ProcessTools.*;

public class Assert {

private static Class1 testClass1;
Expand All @@ -56,7 +63,7 @@ public class Assert {
* off at class load time. Once the class is loaded its assertion status
* does not change.
*/
public static void main(String[] args) throws Exception {
public static void main(String[] args) throws Throwable {

// Switch values: 0=don't touch, 1=off, 2 = on
int[] switches = new int[7];
Expand All @@ -77,28 +84,17 @@ public static void main(String[] args) throws Exception {
}

// Spawn new VM and load classes
String command = System.getProperty("java.home") +
File.separator + "bin" + File.separator + "java Assert";

StringBuffer commandString = new StringBuffer(command);
List<String> commands = new ArrayList<>();
commands.add("Assert");
for(int j=0; j<7; j++)
commandString.append(" "+switches[j]);

Process p = null;
p = Runtime.getRuntime().exec(commandString.toString());

commands.add(Integer.toString(switches[j]));
OutputAnalyzer outputAnalyzer = executeCommand(createLimitedTestJavaProcessBuilder(commands));
if (debug) { // See output of test VMs
BufferedReader blah = new BufferedReader(
new InputStreamReader(p.getInputStream()));
String outString = blah.readLine();
while (outString != null) {
System.out.println("from BufferedReader:"+outString);
outString = blah.readLine();
}
outputAnalyzer.asLines()
.stream()
.forEach(s -> System.out.println(s));
}

p.waitFor();
int result = p.exitValue();
int result = outputAnalyzer.getExitValue();
if (debug) { // See which switch configs failed
if (result == 0) {
for(int k=6; k>=0; k--)
Expand Down
8 changes: 6 additions & 2 deletions test/jdk/java/lang/ClassLoader/GetSystemPackage.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
/*
* @test
* @bug 8060130
* @requires vm.flagless
* @library /test/lib
* @build package2.Class2 GetSystemPackage
* @summary Test if getSystemPackage() return consistent values for cases
Expand All @@ -41,6 +42,8 @@
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;

import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;

public class GetSystemPackage {
Expand Down Expand Up @@ -118,8 +121,9 @@ private static void buildJar(String name, Manifest man) throws Exception {
private static void runSubProcess(String messageOnError, String ... args)
throws Exception
{
ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(args);
int res = pb.directory(tmpFolder).inheritIO().start().waitFor();
ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(args)
.directory(tmpFolder);
int res = ProcessTools.executeProcess(pb).getExitValue();
if (res != 0) {
throw new RuntimeException(messageOnError);
}
Expand Down
22 changes: 4 additions & 18 deletions test/jdk/java/lang/ClassLoader/getResource/GetResource.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 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 @@ -40,11 +40,9 @@
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import jdk.test.lib.JDKToolFinder;
import static jdk.test.lib.process.ProcessTools.*;

import org.testng.annotations.BeforeTest;
Expand Down Expand Up @@ -144,26 +142,14 @@ public void testCurrentDirA(List<String> options, String expected) throws Throwa
private void runTest(Path dir, List<String> options, String expected)
throws Throwable
{
String javapath = JDKToolFinder.getJDKTool("java");

List<String> cmdLine = new ArrayList<>();
cmdLine.add(javapath);
options.forEach(cmdLine::add);

cmdLine.add("GetResource");
cmdLine.add(expected);

System.out.println("Command line: " + cmdLine);
ProcessBuilder pb =
new ProcessBuilder(cmdLine.stream().toArray(String[]::new));

// change working directory
pb.directory(dir.toFile());

// remove CLASSPATH environment variable
Map<String,String> env = pb.environment();
String value = env.remove("CLASSPATH");

ProcessBuilder pb = createTestJavaProcessBuilder(cmdLine);
pb.directory(dir.toFile()); // change working directory
pb.environment().remove("CLASSPATH"); // remove CLASSPATH environment variable
executeCommand(pb).shouldHaveExitValue(0);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, BELLSOFT. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -38,31 +38,15 @@
*/

import jdk.test.lib.Asserts;
import jdk.test.lib.JDKToolFinder;
import jdk.test.lib.process.OutputAnalyzer;

import java.lang.ProcessBuilder;
import java.lang.Process;
import java.io.File;
import java.util.*;
import static jdk.test.lib.process.ProcessTools.*;

public class LoadLibraryUnloadTest {

private static String testClassPath = System.getProperty("test.classes");
private static String testLibraryPath = System.getProperty("test.nativepath");

private static Process runJavaCommand(String... command) throws Throwable {
String java = JDKToolFinder.getJDKTool("java");
List<String> commands = new ArrayList<>();
Collections.addAll(commands, java);
Collections.addAll(commands, command);
System.out.println("COMMAND: " + String.join(" ", commands));
return new ProcessBuilder(commands.toArray(new String[0]))
.redirectErrorStream(true)
.directory(new File(testClassPath))
.start();
}

private final static long countLines(OutputAnalyzer output, String string) {
return output.asLines()
.stream()
Expand All @@ -78,12 +62,10 @@ private final static void dump(OutputAnalyzer output) {

public static void main(String[] args) throws Throwable {

Process process = runJavaCommand(
OutputAnalyzer outputAnalyzer = executeCommand(createTestJavaProcessBuilder(
"-Dtest.classes=" + testClassPath,
"-Djava.library.path=" + testLibraryPath,
"LoadLibraryUnload");

OutputAnalyzer outputAnalyzer = new OutputAnalyzer(process);
"LoadLibraryUnload"));
dump(outputAnalyzer);

Asserts.assertTrue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
*/
public class CondyNestedResolutionTest {
public static void main(String args[]) throws Throwable {
ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder("CondyNestedResolution");
ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder("CondyNestedResolution");
OutputAnalyzer oa = new OutputAnalyzer(pb.start());
oa.shouldContain("StackOverflowError");
oa.shouldContain("bsm1arg");
Expand Down
20 changes: 9 additions & 11 deletions test/jdk/java/lang/invoke/findSpecial/FindSpecialTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 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 @@ -37,13 +37,11 @@
import java.nio.file.Path;
import java.nio.file.Paths;

import jdk.test.lib.JDKToolFinder;
import jdk.test.lib.process.ProcessTools;
import static jdk.test.lib.process.ProcessTools.*;

import org.testng.annotations.Test;

public class FindSpecialTest {
static final String JAVA_LAUNCHER = JDKToolFinder.getJDKTool("java");
static final String TEST_CLASSES = System.getProperty("test.classes", ".");
static final String TEST_CLASS_PATH = System.getProperty("test.class.path");
static final String TEST_MAIN_CLASS = "test.FindSpecial";
Expand All @@ -59,8 +57,9 @@ public static void callerInUnnamedModule() throws Throwable {
throw new Error(m1 + " not exist");
}
String classpath = m1.toString() + File.pathSeparator + TEST_CLASS_PATH;
ProcessTools.executeCommand(JAVA_LAUNCHER, "-cp", classpath, TEST_MAIN_CLASS)
.shouldHaveExitValue(0);
executeCommand(createTestJavaProcessBuilder("-cp", classpath,
TEST_MAIN_CLASS))
.shouldHaveExitValue(0);
}

/*
Expand All @@ -72,10 +71,9 @@ public static void callerInNamedModule() throws Throwable {
if (Files.notExists(modules)) {
throw new Error(modules + " not exist");
}
ProcessTools.executeCommand(JAVA_LAUNCHER,
"-cp", TEST_CLASS_PATH,
"-p", modules.toString(),
"-m", TEST_MODULE + "/" + TEST_MAIN_CLASS)
.shouldHaveExitValue(0);
executeCommand(createTestJavaProcessBuilder("-cp", TEST_CLASS_PATH,
"-p", modules.toString(),
"-m", TEST_MODULE + "/" + TEST_MAIN_CLASS))
.shouldHaveExitValue(0);
}
}

3 comments on commit 1588dd9

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

@GoeLin
Copy link
Member

@GoeLin GoeLin commented on 1588dd9 Mar 23, 2024

Choose a reason for hiding this comment

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

/backport jdk21u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 1588dd9 Mar 23, 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-1588dd93 in my personal fork of openjdk/jdk21u-dev. To create a pull request with this backport targeting openjdk/jdk21u-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 1588dd93 from the openjdk/jdk repository.

The commit being backported was authored by Mandy Chung on 16 Nov 2023 and was reviewed by Jorn Vernee and Leonid Mesnik.

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/jdk21u-dev:

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

Please sign in to comment.