Skip to content

Commit

Permalink
8319569: Several java/util tests should be updated to accept VM flags
Browse files Browse the repository at this point in the history
Reviewed-by: naoto, lancea
  • Loading branch information
Justin Lu committed Nov 23, 2023
1 parent 6016536 commit 2bb4b93
Show file tree
Hide file tree
Showing 12 changed files with 143 additions and 165 deletions.
36 changes: 20 additions & 16 deletions test/jdk/java/util/Calendar/SupplementalJapaneseEraTestRun.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2019, 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 @@ -34,10 +34,15 @@
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;
import static java.util.Calendar.*;
import java.util.stream.Stream;

import static java.util.Calendar.DAY_OF_YEAR;
import static java.util.Calendar.ERA;
import static java.util.Calendar.FEBRUARY;
import static java.util.Calendar.LONG;
import static java.util.Calendar.YEAR;

import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.JDKToolLauncher;
import jdk.test.lib.Utils;

import org.testng.annotations.DataProvider;
Expand Down Expand Up @@ -91,19 +96,18 @@ public void InvalidPropertyValuesTest(String prop)
}

private static void testRun(String property, List<String> javaParam)
throws Throwable{
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("java");
launcher.addToolArg("-ea")
.addToolArg("-esa")
.addToolArg("-cp")
.addToolArg(Utils.TEST_CLASS_PATH)
.addToolArg("-Djdk.calendar.japanese.supplemental.era=" + property)
.addToolArg("SupplementalJapaneseEraTest");
for (String para: javaParam) {
launcher.addToolArg(para);
}
int exitCode = ProcessTools.executeCommand(launcher.getCommand())
.getExitValue();
throws Throwable {
List<String> params = List.of(
"-ea", "-esa",
"-cp", Utils.TEST_CLASS_PATH,
"-Djdk.calendar.japanese.supplemental.era=" + property,
"SupplementalJapaneseEraTest");
// Build process (with VM flags)
ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder(
Stream.concat(params.stream(), javaParam.stream()).toList());
// Evaluate process status
int exitCode = ProcessTools.executeCommand(pb).getExitValue();

System.out.println(property + ":pass");
if (exitCode != 0) {
System.out.println(property + ":fail");
Expand Down
12 changes: 6 additions & 6 deletions test/jdk/java/util/Currency/PropertiesTest.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

# Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2007, 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 @@ -76,7 +76,7 @@ failures=0

run() {
echo ''
${TESTJAVA}${FS}bin${FS}java ${TESTVMOPTS} -cp ${TESTCLASSES} $* 2>&1
${TESTJAVA}${FS}bin${FS}java ${TESTVMOPTS} ${TESTJAVAOPTS} -cp ${TESTCLASSES} $* 2>&1
if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
}

Expand Down Expand Up @@ -110,23 +110,23 @@ echo "Properties location: ${PROPLOCATION}"

# run
echo ''
${WRITABLEJDK}${FS}bin${FS}java ${TESTVMOPTS} -cp ${TESTCLASSES} PropertiesTest -d dump3
${WRITABLEJDK}${FS}bin${FS}java ${TESTVMOPTS} ${TESTJAVAOPTS} -cp ${TESTCLASSES} PropertiesTest -d dump3
if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
if [ ! -f dump3 ]; then echo "file dump3 not created. Test cannot execute. Failed."; exit 1; fi

# run bug7102969 test
echo ''
${WRITABLEJDK}${FS}bin${FS}java ${TESTVMOPTS} -cp ${TESTCLASSES} PropertiesTest bug7102969
${WRITABLEJDK}${FS}bin${FS}java ${TESTVMOPTS} ${TESTJAVAOPTS} -cp ${TESTCLASSES} PropertiesTest bug7102969
if [ $? != 0 ]; then failures=`expr $failures + 1`; fi

# run bug8157138 test
echo ''
${WRITABLEJDK}${FS}bin${FS}java ${TESTVMOPTS} -cp ${TESTCLASSES} PropertiesTest bug8157138
${WRITABLEJDK}${FS}bin${FS}java ${TESTVMOPTS} ${TESTJAVAOPTS} -cp ${TESTCLASSES} PropertiesTest bug8157138
if [ $? != 0 ]; then failures=`expr $failures + 1`; fi

# run bug8190904 test
echo ''
${WRITABLEJDK}${FS}bin${FS}java ${TESTVMOPTS} -cp ${TESTCLASSES} PropertiesTest bug8190904
${WRITABLEJDK}${FS}bin${FS}java ${TESTVMOPTS} ${TESTJAVAOPTS} -cp ${TESTCLASSES} PropertiesTest bug8190904
if [ $? != 0 ]; then failures=`expr $failures + 1`; fi

# Cleanup
Expand Down
31 changes: 13 additions & 18 deletions test/jdk/java/util/Locale/LocaleProvidersRun.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 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 @@ -39,7 +39,6 @@

import java.util.Locale;

import jdk.test.lib.JDKToolLauncher;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.Utils;

Expand Down Expand Up @@ -178,22 +177,18 @@ public static void main(String[] args) throws Throwable {
}

private static void testRun(String prefList, String methodName,
String param1, String param2, String param3) throws Throwable{
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("java");
launcher.addToolArg("-ea")
.addToolArg("-esa")
.addToolArg("-cp")
.addToolArg(Utils.TEST_CLASS_PATH)
.addToolArg("-Djava.util.logging.config.class=LocaleProviders$LogConfig")
.addToolArg("-Djava.locale.providers=" + prefList)
.addToolArg("--add-exports=java.base/sun.util.locale.provider=ALL-UNNAMED")
.addToolArg("LocaleProviders")
.addToolArg(methodName)
.addToolArg(param1)
.addToolArg(param2)
.addToolArg(param3);
int exitCode = ProcessTools.executeCommand(launcher.getCommand())
.getExitValue();
String param1, String param2, String param3) throws Throwable {

// Build process (with VM flags)
ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder(
"-ea", "-esa",
"-cp", Utils.TEST_CLASS_PATH,
"-Djava.util.logging.config.class=LocaleProviders$LogConfig",
"-Djava.locale.providers=" + prefList,
"--add-exports=java.base/sun.util.locale.provider=ALL-UNNAMED",
"LocaleProviders", methodName, param1, param2, param3);
// Evaluate process status
int exitCode = ProcessTools.executeCommand(pb).getExitValue();
if (exitCode != 0) {
throw new RuntimeException("Unexpected exit code: " + exitCode);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 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 @@ -84,15 +84,13 @@ private static void runCmd() throws Throwable {
// UnreadableRB.properties is in current directory
String cp = Utils.TEST_CLASSES + File.pathSeparator + Utils.TEST_SRC
+ File.pathSeparator + ".";
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("java");
launcher.addToolArg("-ea")
.addToolArg("-esa")
.addToolArg("-cp")
.addToolArg(cp)
.addToolArg("MissingResourceCauseTest");

int exitCode = ProcessTools.executeCommand(launcher.getCommand())
.getExitValue();
// Build process (with VM flags)
ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder(
"-ea", "-esa",
"-cp", cp,
"MissingResourceCauseTest");
// Evaluate process status
int exitCode = ProcessTools.executeCommand(pb).getExitValue();
if (exitCode != 0) {
throw new RuntimeException("Execution of the test failed. "
+ "Unexpected exit code: " + exitCode);
Expand Down
66 changes: 31 additions & 35 deletions test/jdk/java/util/ResourceBundle/modules/ModuleTestUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2021, 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 @@ -29,6 +29,7 @@
import java.util.stream.Stream;

import jdk.test.lib.JDKToolLauncher;
import jdk.test.lib.Utils;
import jdk.test.lib.compiler.CompilerUtils;
import jdk.test.lib.process.ProcessTools;

Expand Down Expand Up @@ -133,17 +134,15 @@ public static void copyResFiles(Path src, Path dest, String mn,
*/
public static void runModule(String mp, String mn, List<String> localeList)
throws Throwable {
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("java");
launcher.addToolArg("-ea")
.addToolArg("-esa")
.addToolArg("-p")
.addToolArg(mp)
.addToolArg("-m")
.addToolArg(mn);
localeList.forEach(launcher::addToolArg);

int exitCode = ProcessTools.executeCommand(launcher.getCommand())
.getExitValue();
List<String> args = List.of(
"-ea", "-esa",
"-p", mp,
"-m", mn);
// Build process (with VM flags)
ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder(
Stream.concat(args.stream(), localeList.stream()).toList());
// Evaluate process status
int exitCode = ProcessTools.executeCommand(pb).getExitValue();
if (exitCode != 0) {
throw new RuntimeException("Execution of the test failed. "
+ "Unexpected exit code: " + exitCode);
Expand All @@ -161,19 +160,17 @@ public static void runModule(String mp, String mn, List<String> localeList)
*/
public static void runModuleWithCp(String cp, String mp, String mn,
List<String> localeList, boolean expected) throws Throwable {
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("java");
launcher.addToolArg("-ea")
.addToolArg("-esa")
.addToolArg("-cp")
.addToolArg(cp)
.addToolArg("-p")
.addToolArg(mp)
.addToolArg("-m")
.addToolArg(mn);
localeList.forEach(launcher::addToolArg);
List<String> args = List.of(
"-ea", "-esa",
"-cp", cp,
"-p", mp,
"-m", mn);
// Build process (with VM flags)
ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder(
Stream.concat(args.stream(), localeList.stream()).toList());
// Evaluate process status
int exitCode = ProcessTools.executeCommand(pb).getExitValue();

int exitCode = ProcessTools.executeCommand(launcher.getCommand())
.getExitValue();
if (expected) {
if (exitCode != 0) {
throw new RuntimeException("Execution of the test loads bundles "
Expand All @@ -198,18 +195,17 @@ public static void runModuleWithCp(String cp, String mp, String mn,
*/
public static void runModuleWithLegacyCode(String mp, String mn, List<String> localeList)
throws Throwable {
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("java");
launcher.addToolArg("-ea")
.addToolArg("-esa")
.addToolArg("-Djava.locale.useOldISOCodes=true")
.addToolArg("-p")
.addToolArg(mp)
.addToolArg("-m")
.addToolArg(mn);
localeList.forEach(launcher::addToolArg);
List<String> args = List.of(
"-ea", "-esa",
"-Djava.locale.useOldISOCodes=true",
"-p", mp,
"-m", mn);
// Build process (with VM flags)
ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder(
Stream.concat(args.stream(), localeList.stream()).toList());
// Evaluate process status
int exitCode = ProcessTools.executeCommand(pb).getExitValue();

int exitCode = ProcessTools.executeCommand(launcher.getCommand())
.getExitValue();
if (exitCode != 0) {
throw new RuntimeException("Execution of the test failed. "
+ "Unexpected exit code: " + exitCode);
Expand Down
19 changes: 8 additions & 11 deletions test/jdk/java/util/ResourceBundle/modules/layer/LayerTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 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 @@ -71,16 +71,13 @@ private static void compileCmd() throws Throwable {
}

private static void runCmd() throws Throwable {
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("java");
launcher.addToolArg("-ea")
.addToolArg("-esa")
.addToolArg("-cp")
.addToolArg(Utils.TEST_CLASSES)
.addToolArg("Main")
.addToolArg(Utils.TEST_CLASSES);

int exitCode = ProcessTools.executeCommand(launcher.getCommand())
.getExitValue();
// Build process (with VM flags)
ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder(
"-ea", "-esa",
"-cp", Utils.TEST_CLASSES,
"Main", Utils.TEST_CLASSES);
// Evaluate process status
int exitCode = ProcessTools.executeCommand(pb).getExitValue();
if (exitCode != 0) {
throw new RuntimeException("Execution of the test failed. "
+ "Unexpected exit code: " + exitCode);
Expand Down
53 changes: 23 additions & 30 deletions test/jdk/java/util/ResourceBundle/modules/unnamed/UnNamedTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2019, 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 @@ -39,6 +39,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.stream.Stream;

import jdk.test.lib.JDKToolLauncher;
import jdk.test.lib.Utils;
Expand Down Expand Up @@ -73,42 +74,34 @@ private static void compileCmd() throws Throwable {

private static void runCmd() throws Throwable {
// access resource bundles that are exported private unconditionally.
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("java");
launcher.addToolArg("-ea")
.addToolArg("-esa")
.addToolArg("-cp")
.addToolArg(Utils.TEST_CLASSES)
.addToolArg("--module-path")
.addToolArg(MODS_DIR.toString())
.addToolArg("--add-modules")
.addToolArg("bundles")
.addToolArg("Main");
LOCALE_LIST.forEach(launcher::addToolArg);

int exitCode = ProcessTools.executeCommand(launcher.getCommand())
.getExitValue();
List<String> args = List.of(
"-ea", "-esa",
"-cp", Utils.TEST_CLASSES,
"--module-path", MODS_DIR.toString(),
"--add-modules", "bundles",
"Main");
ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder(
Stream.concat(args.stream(), LOCALE_LIST.stream()).toList());
// Evaluate process status
int exitCode = ProcessTools.executeCommand(pb).getExitValue();
if (exitCode != 0) {
throw new RuntimeException("Execution of the test1 failed. "
+ "Unexpected exit code: " + exitCode);
}

// --add-exports can't open resources
launcher = JDKToolLauncher.createUsingTestJDK("java");
launcher.addToolArg("-ea")
.addToolArg("-esa")
.addToolArg("-cp")
.addToolArg(Utils.TEST_CLASSES)
.addToolArg("--module-path")
.addToolArg(MODS_DIR.toString())
.addToolArg("--add-modules")
.addToolArg("bundles")
.addToolArg("--add-opens")
.addToolArg("bundles/jdk.test.internal.resources=ALL-UNNAMED")
.addToolArg("Main");
LOCALE_LIST.forEach(launcher::addToolArg);
List<String> argsWithOpens = List.of(
"-ea", "-esa",
"-cp", Utils.TEST_CLASSES,
"--module-path", MODS_DIR.toString(),
"--add-modules", "bundles",
"--add-opens", "bundles/jdk.test.internal.resources=ALL-UNNAMED",
"Main");
pb = ProcessTools.createTestJavaProcessBuilder(
Stream.concat(argsWithOpens.stream(), LOCALE_LIST.stream()).toList());

exitCode = ProcessTools.executeCommand(launcher.getCommand())
.getExitValue();
// Evaluate process status
exitCode = ProcessTools.executeCommand(pb).getExitValue();
if (exitCode != 0) {
throw new RuntimeException("Execution of the test2 failed. "
+ "Unexpected exit code: " + exitCode);
Expand Down

1 comment on commit 2bb4b93

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.