8158272: IncludeLocalesPluginTest.java fails with timeout
authorokutsu
Fri, 17 Jun 2016 17:06:16 +0900
changeset 39051 1b0204c55914
parent 39050 9de41b79ec7e
child 39052 6660a4142993
8158272: IncludeLocalesPluginTest.java fails with timeout 8158468: tools/jlink/plugins/IncludeLocalesPluginTest.java doesn't detect test failures Reviewed-by: alanb, mchung, naoto
jdk/test/ProblemList.txt
jdk/test/tools/jlink/plugins/GetAvailableLocales.java
jdk/test/tools/jlink/plugins/IncludeLocalesPluginTest.java
--- a/jdk/test/ProblemList.txt	Fri Jun 17 08:41:39 2016 +0100
+++ b/jdk/test/ProblemList.txt	Fri Jun 17 17:06:16 2016 +0900
@@ -387,7 +387,7 @@
 
 # core_tools
 
-tools/jlink/plugins/IncludeLocalesPluginTest.java               8158272 generic-all
+tools/jlink/plugins/IncludeLocalesPluginTest.java               8159781 generic-all
 
 tools/jlink/JLinkOptimTest.java                                 8159264 generic-all
 
--- a/jdk/test/tools/jlink/plugins/GetAvailableLocales.java	Fri Jun 17 08:41:39 2016 +0100
+++ b/jdk/test/tools/jlink/plugins/GetAvailableLocales.java	Fri Jun 17 17:06:16 2016 +0900
@@ -23,20 +23,36 @@
 
 import java.util.Arrays;
 import java.util.Locale;
+import java.util.Set;
+import java.util.TreeSet;
 import java.util.stream.Collectors;
 
 class GetAvailableLocales {
 
     public static void main(String[] args) {
-        String availableLocales = Arrays.stream(Locale.getAvailableLocales())
-            .map(l -> l.toString())
-            .sorted()
-            .collect(Collectors.joining(" "));
+        Set<String> expected = Set.of(args);
+        Set<String> actual =
+            Arrays.stream(Locale.getAvailableLocales())
+                  // "(root)" for Locale.ROOT rather than ""
+                  .map(loc -> loc.equals(Locale.ROOT) ? "(root)" : loc.toString())
+                  .collect(Collectors.toSet());
 
-        if (!availableLocales.equals(args[0])) {
-            throw new RuntimeException("Available locales are not equal to the expected ones.\n" +
-                "Expected: " + args[0] + "\n" +
-                "Actual:   " + availableLocales);
+        if (!expected.equals(actual)) {
+            diff(expected, actual);
+            System.exit(1);
+        }
+    }
+
+    private static void diff(Set<String> expected, Set<String> actual) {
+        Set<String> s1 = new TreeSet<>(expected);
+        s1.removeAll(actual);
+        if (!s1.isEmpty()) {
+            System.out.println("\tMissing locale(s): " + s1);
+        }
+        Set<String> s2 = new TreeSet<>(actual);
+        s2.removeAll(expected);
+        if (!s2.isEmpty()) {
+            System.out.println("\tExtra locale(s): " + s2);
         }
     }
 }
--- a/jdk/test/tools/jlink/plugins/IncludeLocalesPluginTest.java	Fri Jun 17 08:41:39 2016 +0100
+++ b/jdk/test/tools/jlink/plugins/IncludeLocalesPluginTest.java	Fri Jun 17 17:06:16 2016 +0900
@@ -22,7 +22,11 @@
  */
 
 import java.nio.file.Path;
+import java.util.Arrays;
+import java.util.ArrayList;
 import java.util.List;
+import java.util.Locale;
+import java.util.stream.Collectors;
 
 import jdk.tools.jlink.plugin.Plugin;
 import jdk.tools.jlink.plugin.PluginException;
@@ -49,7 +53,7 @@
  *          jdk.compiler
  * @build tests.*
  * @build tools.jlink.plugins.GetAvailableLocales
- * @run main/othervm -verbose:gc -Xmx1g IncludeLocalesPluginTest
+ * @run main/othervm -Xmx1g IncludeLocalesPluginTest
  */
 public class IncludeLocalesPluginTest {
 
@@ -62,6 +66,8 @@
     private final static int AVAILABLE_LOCALES      = 4;
     private final static int ERROR_MESSAGE          = 5;
 
+    private static int errors;
+
     private final static Object[][] testData = {
         // without --include-locales option: should include all locales
         {
@@ -77,74 +83,14 @@
                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_th.class",
                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_zh.class"),
             List.of(),
-            " af af_NA af_ZA agq agq_CM ak ak_GH am am_ET ar ar_001 ar_AE ar_BH " +
-            "ar_DJ ar_DZ ar_EG ar_EH ar_ER ar_IL ar_IQ ar_JO ar_KM ar_KW ar_LB " +
-            "ar_LY ar_MA ar_MR ar_OM ar_PS ar_QA ar_SA ar_SD ar_SO ar_SS ar_SY " +
-            "ar_TD ar_TN ar_YE as as_IN asa asa_TZ ast ast_ES az az_AZ_#Cyrl " +
-            "az_AZ_#Latn az__#Cyrl az__#Latn bas bas_CM be be_BY bem bem_ZM bez " +
-            "bez_TZ bg bg_BG bm bm_ML_#Latn bm__#Latn bn bn_BD bn_IN bo bo_CN " +
-            "bo_IN br br_FR brx brx_IN bs bs_BA_#Cyrl bs_BA_#Latn bs__#Cyrl " +
-            "bs__#Latn ca ca_AD ca_ES ca_ES_VALENCIA ca_FR ca_IT cgg cgg_UG chr " +
-            "chr_US cs cs_CZ cy cy_GB da da_DK da_GL dav dav_KE de de_AT de_BE " +
-            "de_CH de_DE de_GR de_LI de_LU dje dje_NE dsb dsb_DE dua dua_CM dyo " +
-            "dyo_SN dz dz_BT ebu ebu_KE ee ee_GH ee_TG el el_CY el_GR en en_001 " +
-            "en_150 en_AG en_AI en_AS en_AU en_BB en_BE en_BM en_BS en_BW en_BZ " +
-            "en_CA en_CC en_CK en_CM en_CX en_DG en_DM en_ER en_FJ en_FK en_FM " +
-            "en_GB en_GD en_GG en_GH en_GI en_GM en_GU en_GY en_HK en_IE en_IM " +
-            "en_IN en_IO en_JE en_JM en_KE en_KI en_KN en_KY en_LC en_LR en_LS " +
-            "en_MG en_MH en_MO en_MP en_MS en_MT en_MU en_MW en_MY en_NA en_NF " +
-            "en_NG en_NR en_NU en_NZ en_PG en_PH en_PK en_PN en_PR en_PW en_RW " +
-            "en_SB en_SC en_SD en_SG en_SH en_SL en_SS en_SX en_SZ en_TC en_TK " +
-            "en_TO en_TT en_TV en_TZ en_UG en_UM en_US en_US_POSIX en_VC en_VG " +
-            "en_VI en_VU en_WS en_ZA en_ZM en_ZW eo eo_001 es es_419 es_AR es_BO " +
-            "es_CL es_CO es_CR es_CU es_DO es_EA es_EC es_ES es_GQ es_GT es_HN " +
-            "es_IC es_MX es_NI es_PA es_PE es_PH es_PR es_PY es_SV es_US es_UY " +
-            "es_VE et et_EE eu eu_ES ewo ewo_CM fa fa_AF fa_IR ff ff_CM ff_GN " +
-            "ff_MR ff_SN fi fi_FI fil fil_PH fo fo_FO fr fr_BE fr_BF fr_BI fr_BJ " +
-            "fr_BL fr_CA fr_CD fr_CF fr_CG fr_CH fr_CI fr_CM fr_DJ fr_DZ fr_FR " +
-            "fr_GA fr_GF fr_GN fr_GP fr_GQ fr_HT fr_KM fr_LU fr_MA fr_MC fr_MF " +
-            "fr_MG fr_ML fr_MQ fr_MR fr_MU fr_NC fr_NE fr_PF fr_PM fr_RE fr_RW " +
-            "fr_SC fr_SN fr_SY fr_TD fr_TG fr_TN fr_VU fr_WF fr_YT fur fur_IT fy " +
-            "fy_NL ga ga_IE gd gd_GB gl gl_ES gsw gsw_CH gsw_FR gsw_LI gu gu_IN " +
-            "guz guz_KE gv gv_IM ha ha_GH_#Latn ha_NE_#Latn ha_NG_#Latn ha__#Latn " +
-            "haw haw_US hi hi_IN hr hr_BA hr_HR hsb hsb_DE hu hu_HU hy hy_AM ig " +
-            "ig_NG ii ii_CN in in_ID is is_IS it it_CH it_IT it_SM iw iw_IL ja " +
-            "ja_JP ja_JP_JP_#u-ca-japanese jgo jgo_CM ji ji_001 jmc jmc_TZ ka " +
-            "ka_GE kab kab_DZ kam kam_KE kde kde_TZ kea kea_CV khq khq_ML ki " +
-            "ki_KE kk kk_KZ_#Cyrl kk__#Cyrl kkj kkj_CM kl kl_GL kln kln_KE km " +
-            "km_KH kn kn_IN ko ko_KP ko_KR kok kok_IN ks ks_IN_#Arab ks__#Arab " +
-            "ksb ksb_TZ ksf ksf_CM ksh ksh_DE kw kw_GB ky ky_KG_#Cyrl ky__#Cyrl " +
-            "lag lag_TZ lb lb_LU lg lg_UG lkt lkt_US ln ln_AO ln_CD ln_CF ln_CG " +
-            "lo lo_LA lt lt_LT lu lu_CD luo luo_KE luy luy_KE lv lv_LV mas " +
-            "mas_KE mas_TZ mer mer_KE mfe mfe_MU mg mg_MG mgh mgh_MZ mgo mgo_CM " +
-            "mk mk_MK ml ml_IN mn mn_MN_#Cyrl mn__#Cyrl mr mr_IN ms ms_BN_#Latn " +
-            "ms_MY ms_MY_#Latn ms_SG_#Latn ms__#Latn mt mt_MT mua mua_CM my " +
-            "my_MM naq naq_NA nb nb_NO nb_SJ nd nd_ZW ne ne_IN ne_NP nl nl_AW " +
-            "nl_BE nl_BQ nl_CW nl_NL nl_SR nl_SX nmg nmg_CM nn nn_NO nnh nnh_CM " +
-            "no no_NO no_NO_NY nus nus_SD nyn nyn_UG om om_ET om_KE or or_IN os " +
-            "os_GE os_RU pa pa_IN_#Guru pa_PK_#Arab pa__#Arab pa__#Guru pl pl_PL " +
-            "ps ps_AF pt pt_AO pt_BR pt_CV pt_GW pt_MO pt_MZ pt_PT pt_ST pt_TL qu " +
-            "qu_BO qu_EC qu_PE rm rm_CH rn rn_BI ro ro_MD ro_RO rof rof_TZ ru " +
-            "ru_BY ru_KG ru_KZ ru_MD ru_RU ru_UA rw rw_RW rwk rwk_TZ sah sah_RU " +
-            "saq saq_KE sbp sbp_TZ se se_FI se_NO se_SE seh seh_MZ ses ses_ML sg " +
-            "sg_CF shi shi_MA_#Latn shi_MA_#Tfng shi__#Latn shi__#Tfng si si_LK " +
-            "sk sk_SK sl sl_SI smn smn_FI sn sn_ZW so so_DJ so_ET so_KE so_SO sq " +
-            "sq_AL sq_MK sq_XK sr sr_BA sr_BA_#Cyrl sr_BA_#Latn sr_CS sr_ME " +
-            "sr_ME_#Cyrl sr_ME_#Latn sr_RS sr_RS_#Cyrl sr_RS_#Latn sr_XK_#Cyrl " +
-            "sr_XK_#Latn sr__#Cyrl sr__#Latn sv sv_AX sv_FI sv_SE sw sw_CD sw_KE " +
-            "sw_TZ sw_UG ta ta_IN ta_LK ta_MY ta_SG te te_IN teo teo_KE teo_UG " +
-            "th th_TH th_TH_TH_#u-nu-thai ti ti_ER ti_ET to to_TO tr tr_CY tr_TR " +
-            "twq twq_NE tzm tzm_MA_#Latn tzm__#Latn ug ug_CN_#Arab ug__#Arab uk " +
-            "uk_UA ur ur_IN ur_PK uz uz_AF_#Arab uz_UZ_#Cyrl uz_UZ_#Latn " +
-            "uz__#Arab uz__#Cyrl uz__#Latn vai vai_LR_#Latn vai_LR_#Vaii " +
-            "vai__#Latn vai__#Vaii vi vi_VN vun vun_TZ wae wae_CH xog xog_UG yav " +
-            "yav_CM yo yo_BJ yo_NG zgh zgh_MA zh zh_CN zh_CN_#Hans zh_HK " +
-            "zh_HK_#Hans zh_HK_#Hant zh_MO_#Hans zh_MO_#Hant zh_SG zh_SG_#Hans " +
-            "zh_TW zh_TW_#Hant zh__#Hans zh__#Hant zu zu_ZA",
+            Arrays.stream(Locale.getAvailableLocales())
+                  // "(root)" for Locale.ROOT rather than ""
+                  .map(loc -> loc.equals(Locale.ROOT) ? "(root)" : loc.toString())
+                  .collect(Collectors.toList()),
             "",
         },
 
-        // All English/Japanese locales
+        // All English and Japanese locales
         {
             "--include-locales=en,ja",
             "jdk.localedata",
@@ -163,15 +109,22 @@
                 "/jdk.localedata/sun/text/resources/ext/FormatData_zh.class",
                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_th.class",
                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_zh.class"),
-            " en en_001 en_150 en_AG en_AI en_AS en_AU en_BB en_BE en_BM en_BS " +
-            "en_BW en_BZ en_CA en_CC en_CK en_CM en_CX en_DG en_DM en_ER en_FJ " +
-            "en_FK en_FM en_GB en_GD en_GG en_GH en_GI en_GM en_GU en_GY en_HK " +
-            "en_IE en_IM en_IN en_IO en_JE en_JM en_KE en_KI en_KN en_KY en_LC " +
-            "en_LR en_LS en_MG en_MH en_MO en_MP en_MS en_MT en_MU en_MW en_MY " +
-            "en_NA en_NF en_NG en_NR en_NU en_NZ en_PG en_PH en_PK en_PN en_PR " +
-            "en_PW en_RW en_SB en_SC en_SD en_SG en_SH en_SL en_SS en_SX en_SZ " +
-            "en_TC en_TK en_TO en_TT en_TV en_TZ en_UG en_UM en_US en_US_POSIX " +
-            "en_VC en_VG en_VI en_VU en_WS en_ZA en_ZM en_ZW ja ja_JP ja_JP_JP_#u-ca-japanese",
+            List.of(
+                "(root)", "en", "en_001", "en_150", "en_AG", "en_AI", "en_AS", "en_AT",
+                "en_AU", "en_BB", "en_BE", "en_BI", "en_BM", "en_BS", "en_BW", "en_BZ",
+                "en_CA", "en_CC", "en_CH", "en_CK", "en_CM", "en_CX", "en_CY", "en_DE",
+                "en_DG", "en_DK", "en_DM", "en_ER", "en_FI", "en_FJ", "en_FK", "en_FM",
+                "en_GB", "en_GD", "en_GG", "en_GH", "en_GI", "en_GM", "en_GU", "en_GY",
+                "en_HK", "en_IE", "en_IL", "en_IM", "en_IN", "en_IO", "en_JE", "en_JM",
+                "en_KE", "en_KI", "en_KN", "en_KY", "en_LC", "en_LR", "en_LS", "en_MG",
+                "en_MH", "en_MO", "en_MP", "en_MS", "en_MT", "en_MU", "en_MW", "en_MY",
+                "en_NA", "en_NF", "en_NG", "en_NL", "en_NR", "en_NU", "en_NZ", "en_PG",
+                "en_PH", "en_PK", "en_PN", "en_PR", "en_PW", "en_RW", "en_SB", "en_SC",
+                "en_SD", "en_SE", "en_SG", "en_SH", "en_SI", "en_SL", "en_SS", "en_SX",
+                "en_SZ", "en_TC", "en_TK", "en_TO", "en_TT", "en_TV", "en_TZ", "en_UG",
+                "en_UM", "en_US", "en_US_POSIX", "en_VC", "en_VG", "en_VI", "en_VU",
+                "en_WS", "en_ZA", "en_ZM", "en_ZW", "ja", "ja_JP",
+                "ja_JP_JP_#u-ca-japanese"),
             "",
         },
 
@@ -200,8 +153,11 @@
                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_ja.class",
                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_th.class",
                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_zh.class"),
-            " as_IN bn_IN bo_IN brx_IN en en_IN en_US en_US_POSIX gu_IN hi_IN kn_IN " +
-            "kok_IN ks_IN_#Arab ml_IN mr_IN ne_IN or_IN pa_IN_#Guru ta_IN te_IN ur_IN",
+            List.of(
+                "(root)", "as_IN", "bn_IN", "bo_IN", "brx_IN", "en", /* "en_001", */
+                "en_IN", "en_US", "en_US_POSIX", "gu_IN", "hi_IN", "kn_IN", "kok_IN",
+                "ks_IN", "ml_IN", "mr_IN", "ne_IN", "or_IN", "pa_IN", "pa_IN_#Guru",
+                "ta_IN", "te_IN", "ur_IN"),
             "",
         },
 
@@ -223,7 +179,9 @@
                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_en_001.class",
                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_ja.class",
                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_zh.class"),
-            " en en_US en_US_POSIX th th_TH th_TH_TH_#u-nu-thai",
+            List.of(
+                "(root)", "en", "en_US", "en_US_POSIX", "th", "th_TH",
+                "th_TH_TH_#u-nu-thai"),
             "",
         },
 
@@ -248,7 +206,9 @@
                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_en_001.class",
                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_ja.class",
                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_th.class"),
-            " en en_US en_US_POSIX zh_HK zh_HK_#Hans zh_HK_#Hant",
+            List.of(
+                "(root)", "en", "en_US", "en_US_POSIX", "zh_HK", "zh_HK_#Hans",
+                "zh_HK_#Hant"),
             "",
         },
 
@@ -274,7 +234,9 @@
                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_en_001.class",
                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_ja.class",
                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_th.class"),
-            " en en_US en_US_POSIX nb nb_NO nb_SJ nn nn_NO no no_NO no_NO_NY",
+            List.of(
+                "(root)", "en", "en_US", "en_US_POSIX", "nb", "nb_NO", "nb_SJ", "nn",
+                "nn_NO", "no", "no_NO", "no_NO_NY"),
             "",
         },
 
@@ -302,7 +264,9 @@
                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_en_001.class",
                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_ja.class",
                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_th.class"),
-            " en en_US en_US_POSIX in in_ID iw iw_IL ji ji_001",
+            List.of(
+                "(root)", "en", "en_US", "en_US_POSIX", "in", "in_ID", "iw", "iw_IL",
+                "ji", "ji_001"),
             "",
         },
 
@@ -349,50 +313,76 @@
             System.err.println("Test not run");
             return;
         }
-
         helper.generateDefaultModules();
 
         for (Object[] data : testData) {
             // create image for each test data
+            System.out.println("Invoking jlink with \"" + data[INCLUDE_LOCALES_OPTION] + "\"");
             Result result = JImageGenerator.getJLinkTask()
                     .modulePath(helper.defaultModulePath())
                     .output(helper.createNewImageDir(moduleName))
-                    .addMods((String)data[ADDMODS_OPTION])
-                    .option((String)data[INCLUDE_LOCALES_OPTION])
+                    .addMods((String) data[ADDMODS_OPTION])
+                    .option((String) data[INCLUDE_LOCALES_OPTION])
                     .call();
 
-            String errorMsg = (String)data[ERROR_MESSAGE];
+            String errorMsg = (String) data[ERROR_MESSAGE];
             if (errorMsg.isEmpty()) {
                 Path image = result.assertSuccess();
 
                 // test locale data entries
                 testLocaleDataEntries(image,
-                    (List<String>)data[EXPECTED_LOCATIONS],
-                    (List<String>)data[UNEXPECTED_PATHS]);
+                    (List<String>) data[EXPECTED_LOCATIONS],
+                    (List<String>) data[UNEXPECTED_PATHS]);
 
                 // test available locales
-                testAvailableLocales(image, (String)data[AVAILABLE_LOCALES]);
+                testAvailableLocales(image, (List<String>) data[AVAILABLE_LOCALES]);
             } else {
                 result.assertFailure(new TaskHelper(TaskHelper.JLINK_BUNDLE)
                     .getMessage("error.prefix") + " " +errorMsg);
+                System.out.println("\tExpected failure: " + result.getMessage());
             }
         }
+
+        if (errors > 0) {
+            throw new RuntimeException("Test failed");
+        }
     }
 
     private static void testLocaleDataEntries(Path image, List<String> expectedLocations,
                         List<String> unexpectedPaths) throws Exception {
-        JImageValidator.validate(
-            image.resolve("lib").resolve("modules"),
-            expectedLocations, unexpectedPaths);
+        System.out.println("testLocaleDataEntries:");
+        try {
+            JImageValidator.validate(
+                image.resolve("lib").resolve("modules"),
+                expectedLocations, unexpectedPaths);
+        } catch (Exception e) {
+            System.out.println("\tFailed with: " + e);
+            e.printStackTrace();
+            errors++;
+        }
     }
 
-    private static void testAvailableLocales(Path image, String availableLocales) throws Exception {
+    private static void testAvailableLocales(Path image, List<String> availableLocales) throws Exception {
+        System.out.println("testAvailableLocales:");
         Path launcher = image.resolve("bin/java" +
             (System.getProperty("os.name").startsWith("Windows") ? ".exe" : ""));
-        System.out.print(launcher);
-        ProcessBuilder pb = new ProcessBuilder(launcher.toString(),
-            "GetAvailableLocales", availableLocales);
-        int ret = pb.start().waitFor();
-        System.out.println(" Return code: " + ret);
+        List<String> args = new ArrayList<>(availableLocales.size() + 2);
+        args.add(launcher.toString());
+        args.add("GetAvailableLocales");
+        args.addAll(availableLocales);
+        Process proc = new ProcessBuilder(args).inheritIO().start();
+
+        int len = Math.min(10, args.size());
+        String command = args.subList(0, len).stream().collect(Collectors.joining(" "))
+                         + (len < availableLocales.size() ? " ..." : "");
+
+        int status = proc.waitFor();
+        if (status == 0) {
+            System.out.println("\tDone\t" + command);
+        } else {
+            System.out.println("\tExit " + status + "\t" + command);
+            errors++;
+        }
+        System.out.println();
     }
 }