Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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);
}
}
171 changes: 0 additions & 171 deletions test/jdk/java/lang/invoke/lambda/LUtils.java

This file was deleted.

Loading