# HG changeset patch # User mli # Date 1541489032 -28800 # Node ID 00db205006c94be4191bfd320aec93d54343c155 # Parent 481e3b24a58c0fee8aad0e97492b0cd89da66739 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests Reviewed-by: naoto Contributed-by: ying.z.zhou@oracle.com diff -r 481e3b24a58c -r 00db205006c9 test/jdk/java/util/TimeZone/Bug8066652.sh --- a/test/jdk/java/util/TimeZone/Bug8066652.sh Mon Nov 05 22:22:49 2018 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -#!/bin/sh - -# Copyright (c) 2016, 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 -# under the terms of the GNU General Public License version 2 only, as -# published by the Free Software Foundation. -# -# This code is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -# version 2 for more details (a copy is included in the LICENSE file that -# accompanied this code). -# -# You should have received a copy of the GNU General Public License version -# 2 along with this work; if not, write to the Free Software Foundation, -# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. -# -# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA -# or visit www.oracle.com if you need additional information or have any -# questions. -# -# @test -# @bug 8066652 -# @requires os.family == "mac" -# @summary tests thread safe native function localtime_r is accessed by multiple threads at same time and -# zone id should not be “GMT+00:00” if default timezone is “GMT” and user specifies a fake timezone. -# @build Bug8066652 -# @run shell/timeout=600 Bug8066652.sh - - -if [ "${TESTSRC}" = "" ] -then - echo "TESTSRC not set. Test cannot execute. Failed." - exit 1 -fi -echo "TESTSRC=${TESTSRC}" -if [ "${TESTJAVA}" = "" ] -then - echo "TESTJAVA not set. Test cannot execute. Failed." - exit 1 -fi -echo "TESTJAVA=${TESTJAVA}" -if [ "${TESTCLASSES}" = "" ] -then - echo "TESTCLASSES not set. Test cannot execute. Failed." - exit 1 -fi -echo "TESTCLASSES=${TESTCLASSES}" -echo "CLASSPATH=${CLASSPATH}" - - -# set system TimeZone to GMT using environment variable TZ -export TZ="GMT" - -# Setting invalid TimeZone using VM option -${TESTJAVA}/bin/java -Duser.timezone=Foo/Bar ${TESTVMOPTS} -cp ${TESTCLASSES} Bug8066652 - -status=$? -if [ $status -eq 0 ] -then - echo "Success, Test Passed"; -else - echo "Test Failed"; -fi - -exit $status diff -r 481e3b24a58c -r 00db205006c9 test/jdk/java/util/TimeZone/Bug8066652Run.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/jdk/java/util/TimeZone/Bug8066652Run.java Tue Nov 06 15:23:52 2018 +0800 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2016, 2018, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8066652 + * @requires os.family == "mac" + * @summary tests thread safe native function localtime_r is accessed by multiple + * threads at same time and zone id should not be "GMT+00:00" + * if default timezone is "GMT" and user specifies a fake timezone. + * @library /test/lib + * @build Bug8066652 + * @run main Bug8066652Run + */ + +import java.util.Map; + +import jdk.test.lib.JDKToolLauncher; +import jdk.test.lib.Utils; +import jdk.test.lib.process.ProcessTools; + +public class Bug8066652Run { + private static String cp = Utils.TEST_CLASSES; + private static ProcessBuilder pb = new ProcessBuilder(); + + public static void main(String[] args) throws Throwable { + //set system TimeZone to GMT using environment variable TZ + Map env = pb.environment(); + env.put("TZ", "GMT"); + System.out.println("Current TimeZone:" + pb.environment().get("TZ")); + JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("java"); + //Setting invalid TimeZone using VM option + launcher.addToolArg("-Duser.timezone=Foo/Bar") + .addToolArg("-cp") + .addToolArg(cp) + .addToolArg("Bug8066652"); + + pb.command(launcher.getCommand()); + int exitCode = ProcessTools.executeCommand(pb) + .getExitValue(); + if (exitCode != 0) { + throw new RuntimeException("Unexpected exit code: " + exitCode); + } + } +} + diff -r 481e3b24a58c -r 00db205006c9 test/jdk/java/util/TimeZone/OldIDMappingTest.java --- a/test/jdk/java/util/TimeZone/OldIDMappingTest.java Mon Nov 05 22:22:49 2018 -0800 +++ b/test/jdk/java/util/TimeZone/OldIDMappingTest.java Tue Nov 06 15:23:52 2018 +0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2018, 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 @@ -22,11 +22,31 @@ */ /* - * See OldMappingTest.sh + * @test + * @bug 6466476 + * @summary Compatibility test for the old JDK ID mapping and Olson IDs + * @comment Expecting the new (Olson compatible) mapping (default) + * @run main/othervm -Dsun.timezone.ids.oldmapping=null OldIDMappingTest -new + * @run main/othervm -Dsun.timezone.ids.oldmapping="" OldIDMappingTest -new + * @run main/othervm -Dsun.timezone.ids.oldmapping=no OldIDMappingTest -new + * @run main/othervm -Dsun.timezone.ids.oldmapping=No OldIDMappingTest -new + * @run main/othervm -Dsun.timezone.ids.oldmapping=NO OldIDMappingTest -new + * @run main/othervm -Dsun.timezone.ids.oldmapping=false OldIDMappingTest -new + * @run main/othervm -Dsun.timezone.ids.oldmapping=False OldIDMappingTest -new + * @run main/othervm -Dsun.timezone.ids.oldmapping=FALSE OldIDMappingTest -new + * @run main/othervm -Dsun.timezone.ids.oldmapping=Hello OldIDMappingTest -new + * @comment Expecting the old mapping + * @run main/othervm -Dsun.timezone.ids.oldmapping=true OldIDMappingTest -old + * @run main/othervm -Dsun.timezone.ids.oldmapping=True OldIDMappingTest -old + * @run main/othervm -Dsun.timezone.ids.oldmapping=TRUE OldIDMappingTest -old + * @run main/othervm -Dsun.timezone.ids.oldmapping=yes OldIDMappingTest -old + * @run main/othervm -Dsun.timezone.ids.oldmapping=Yes OldIDMappingTest -old + * @run main/othervm -Dsun.timezone.ids.oldmapping=YES OldIDMappingTest -old */ -import java.lang.reflect.*; -import java.util.*; +import java.util.HashMap; +import java.util.Map; +import java.util.TimeZone; public class OldIDMappingTest { private static final String MAPPING_PROPERTY_NAME = "sun.timezone.ids.oldmapping"; @@ -62,8 +82,9 @@ TimeZone tz = TimeZone.getTimeZone(oldmap.get(id)); if (useOldMapping) { if (!tzAlias.hasSameRules(tz)) { - throw new RuntimeException("OLDMAP: " + MAPPING_PROPERTY_NAME + "=" + prop + ": " - + id + " isn't an alias of " + oldmap.get(id)); + throw new RuntimeException("OLDMAP: " + MAPPING_PROPERTY_NAME + + "=" + prop + ": " + id + + " isn't an alias of " + oldmap.get(id)); } if (count == 0) { System.out.println(" " + id + " => " + oldmap.get(id)); @@ -79,13 +100,15 @@ continue; } if (tzAlias.hasSameRules(tz)) { - throw new RuntimeException("NEWMAP: " + MAPPING_PROPERTY_NAME + "=" + prop + ": " - + id + " is an alias of " + oldmap.get(id)); + throw new RuntimeException("NEWMAP: " + MAPPING_PROPERTY_NAME + + "=" + prop + ": " + id + + " is an alias of " + oldmap.get(id)); } tz = TimeZone.getTimeZone(newmap.get(id)); if (!tzAlias.hasSameRules(tz)) { - throw new RuntimeException("NEWMAP: " + MAPPING_PROPERTY_NAME + "=" + prop + ": " - + id + " isn't an alias of " + newmap.get(id)); + throw new RuntimeException("NEWMAP: " + MAPPING_PROPERTY_NAME + + "=" + prop + ": " + id + + " isn't an alias of " + newmap.get(id)); } if (count == 0) { System.out.println(" " + id + " => " + newmap.get(id)); diff -r 481e3b24a58c -r 00db205006c9 test/jdk/java/util/TimeZone/OldIDMappingTest.sh --- a/test/jdk/java/util/TimeZone/OldIDMappingTest.sh Mon Nov 05 22:22:49 2018 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,57 +0,0 @@ -# Copyright (c) 2003, 2013, 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 -# under the terms of the GNU General Public License version 2 only, as -# published by the Free Software Foundation. -# -# This code is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -# version 2 for more details (a copy is included in the LICENSE file that -# accompanied this code). -# -# You should have received a copy of the GNU General Public License version -# 2 along with this work; if not, write to the Free Software Foundation, -# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. -# -# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA -# or visit www.oracle.com if you need additional information or have any -# questions. - -# @test -# @bug 6466476 -# @summary Compatibility test for the old JDK ID mapping and Olson IDs -# @build OldIDMappingTest -# @run shell OldIDMappingTest.sh - -: ${TESTJAVA:=${JAVA_HOME}} -: ${TESTCLASSES:="`pwd`"} - -JAVA="${TESTJAVA}/bin/java" - -STATUS=0 - -# Expecting the new (Olson compatible) mapping (default) -for I in "" " " no No NO false False FALSE Hello -do - if [ x"$I" != x ]; then - D="-Dsun.timezone.ids.oldmapping=${I}" - fi - if ! ${JAVA} ${D} ${TESTVMOPTS} -cp ${TESTCLASSES} OldIDMappingTest -new; then - STATUS=1 - fi -done - -# Expecting the old mapping -for I in true True TRUE yes Yes YES -do - if [ "x$I" != x ]; then - D="-Dsun.timezone.ids.oldmapping=${I}" - fi - if ! ${JAVA} ${D} ${TESTVMOPTS} -cp ${TESTCLASSES} OldIDMappingTest -old; then - STATUS=1 - fi -done - -exit ${STATUS} diff -r 481e3b24a58c -r 00db205006c9 test/jdk/java/util/TimeZone/TimeZoneDatePermissionCheck.sh --- a/test/jdk/java/util/TimeZone/TimeZoneDatePermissionCheck.sh Mon Nov 05 22:22:49 2018 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ -# Testcase for PR381 Stackoverflow error with security manager, signed jars -# and -Djava.security.debug set. -# -# Copyright (c) 2009, Red Hat Inc. -# -# This code is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. -# -# This code is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License version -# 2 along with this work; if not, write to the Free Software Foundation, -# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. -# -# @test -# @bug 6584033 -# @summary Stackoverflow error with security manager, signed jars and debug. -# @build TimeZoneDatePermissionCheck -# @run shell TimeZoneDatePermissionCheck.sh - -# Set default if not run under jtreg from test dir itself -if [ "${TESTCLASSES}" = "" ] ; then - TESTCLASSES="." -fi -if [ "${TESTJAVA}" = "" ] ; then - TESTJAVA=/usr -fi -if [ "${COMPILEJAVA}" = "" ]; then - COMPILEJAVA="${TESTJAVA}" -fi - -# create a test keystore and dummy cert. Note that we use the COMPILEJAVA -# as this test is a TimeZone test, it doesn't test keytool -rm -f ${TESTCLASSES}/timezonedatetest.store -${COMPILEJAVA}/bin/keytool ${TESTTOOLVMOPTS} -genkeypair -alias testcert \ - -keystore ${TESTCLASSES}/timezonedatetest.store \ - -storepass testpass -validity 360 \ - -keyalg rsa \ - -dname "cn=Mark Wildebeest, ou=FreeSoft, o=Red Hat, c=NL" \ - -keypass testpass - -# create a jar file to sign with the test class in it. -rm -f ${TESTCLASSES}/timezonedatetest.jar -${COMPILEJAVA}/bin/jar ${TESTTOOLVMOPTS} cf \ - ${TESTCLASSES}/timezonedatetest.jar \ - -C ${TESTCLASSES} TimeZoneDatePermissionCheck.class - -# sign it -${COMPILEJAVA}/bin/jarsigner ${TESTTOOLVMOPTS} \ - -keystore ${TESTCLASSES}/timezonedatetest.store \ - -storepass testpass ${TESTCLASSES}/timezonedatetest.jar testcert - -# run it with the security manager on, plus accesscontroller debugging -# will go into infinite recursion trying to get enough permissions for -# printing Date of failing certificate unless fix is applied. -${TESTJAVA}/bin/java ${TESTVMOPTS} -Djava.security.manager \ - -Djava.security.debug=access,failure,policy \ - -cp ${TESTCLASSES}/timezonedatetest.jar TimeZoneDatePermissionCheck diff -r 481e3b24a58c -r 00db205006c9 test/jdk/java/util/TimeZone/TimeZoneDatePermissionCheckRun.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/jdk/java/util/TimeZone/TimeZoneDatePermissionCheckRun.java Tue Nov 06 15:23:52 2018 +0800 @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2009, 2018, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 6584033 + * @summary Stackoverflow error with security manager, signed jars and debug. + * @library /test/lib + * @build TimeZoneDatePermissionCheck + * @run main TimeZoneDatePermissionCheckRun + */ + +import java.io.File; +import java.util.List; + +import jdk.test.lib.JDKToolLauncher; +import jdk.test.lib.Utils; +import jdk.test.lib.process.ProcessTools; + +public class TimeZoneDatePermissionCheckRun { + private static String storePath = Utils.TEST_CLASSES + File.separator + + "timezonedatetest.store"; + private static String jarPath = Utils.TEST_CLASSES + File.separator + + "timezonedatetest.jar"; + + public static void main(String[] args) throws Throwable { + try { + //create a test keystore and dummy cert. Note that we use the COMPILEJAVA + //as this test is a TimeZone test, it doesn't test keytool + runJavaCmd("keytool", + List.of("-genkeypair", "-alias", "testcert", "-keystore", + storePath, "-storepass", "testpass", "-validity", + "360", "-keyalg", "rsa", "-dname", + "cn=Mark Wildebeest, ou=FreeSoft, o=Red Hat, c=NL", + "-keypass", "testpass")); + + //create a jar file to sign with the test class in it. + runJavaCmd("jar", List.of("cf", jarPath, "-C", Utils.TEST_CLASSES, + "TimeZoneDatePermissionCheck.class")); + + //sign it + runJavaCmd("jarsigner", + List.of("-keystore", storePath, "-storepass", "testpass", + jarPath, "testcert")); + + //run it with the security manager on, plus accesscontroller debugging + //will go into infinite recursion trying to get enough permissions for + //printing Date of failing certificate unless fix is applied. + JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("java"); + launcher.addToolArg("-Djava.security.manager") + .addToolArg("-Djava.security.debug=access,failure,policy") + .addToolArg("-cp") + .addToolArg(jarPath) + .addToolArg("TimeZoneDatePermissionCheck"); + + int exitCode = ProcessTools.executeCommand(launcher.getCommand()) + .getExitValue(); + if (exitCode != 0) { + throw new RuntimeException("Unexpected exit code: " + exitCode); + } + } finally { + //clean up the test files + File storeFile = new File(storePath); + if (storeFile.exists()) { + storeFile.delete(); + } + File jarFile = new File(jarPath); + if (jarFile.exists()) { + jarFile.delete(); + } + } + } + + private static void runJavaCmd(String cmd, List javaParam) + throws Throwable{ + JDKToolLauncher launcher = JDKToolLauncher.create(cmd); + for (String para: javaParam) { + launcher.addToolArg(para); + } + + System.out.println(launcher.getCommand()); + int exitCode = ProcessTools.executeCommand(launcher.getCommand()) + .getExitValue(); + if (exitCode != 0) { + throw new RuntimeException("Unexpected exit code: " + exitCode); + } + } +}