changeset 5460:2658860ffd4a

7198146: Another new regression test does not compile on windows-amd64 Reviewed-by: valeriep
author wetmore
date Fri, 14 Sep 2012 14:12:22 -0700
parents 1ab07c3fe760
children e2d0770faae1
files make/javax/crypto/Defs-jce.gmk test/javax/crypto/sanity/CheckManifestForRelease.java
diffstat 2 files changed, 99 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/make/javax/crypto/Defs-jce.gmk	Fri Sep 14 09:38:27 2012 -0700
+++ b/make/javax/crypto/Defs-jce.gmk	Fri Sep 14 14:12:22 2012 -0700
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2007, 2012, 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
--- a/test/javax/crypto/sanity/CheckManifestForRelease.java	Fri Sep 14 09:38:27 2012 -0700
+++ b/test/javax/crypto/sanity/CheckManifestForRelease.java	Fri Sep 14 14:12:22 2012 -0700
@@ -23,13 +23,14 @@
 
 /*
  * @test
- * @bug 7195931 7197071
+ * @bug 7195931 7197071 7198146
  * @summary UnsatisfiedLinkError on PKCS11.C_GetOperationState while
  *          using NSS from jre7u6+
  */
 import java.net.*;
 import java.io.*;
 import java.security.*;
+import java.lang.reflect.*;
 
 /**
  * When the Java specification version is incremented, all of the providers
@@ -42,20 +43,25 @@
      */
     public static void main(String[] args) throws Exception {
         checkP11MessageDigestClone();
-        checkManifest();
+        checkFileManifests();
     }
 
     /*
-     * Check the root cause, no manifest values.
+     * Iterate over the files of interest: JCE framework and providers
      */
-    static private void checkManifest() throws Exception {
+    static private void checkFileManifests() throws Exception {
         System.out.println("=============");
-        String specVersion = System.getProperty("java.specification.version");
-        String extDirName = System.getProperty("java.home", ".") + "/"
-                + "lib/ext";
+        String libDirName = System.getProperty("java.home", ".") + "/lib";
+        String extDirName = libDirName + "/ext";
 
-        // Current list of JCE providers.  Add if more are created.
-        String[] files = new String[]{
+        System.out.println("Checking Manifest in directory: \n    " +
+            extDirName);
+
+        /*
+         * Current list of JCE providers, all of which currently live in
+         * the extensions directory.  Add if more are created.
+         */
+        String[] providers = new String[]{
             "sunjce_provider.jar",
             "sunec.jar",
             "sunmscapi.jar",
@@ -63,44 +69,75 @@
             "ucrypto.jar"
         };
 
-        System.out.println("Checking in " + extDirName);
+        checkManifest(libDirName, "jce.jar");
+        for (String provider : providers) {
+            checkManifest(extDirName, provider);
+        }
+        System.out.println("Passed.");
+    }
 
-        for (String file : files) {
-            System.out.println("Checking: " + file);
-            String urlString = "jar:file:" + extDirName + "/" + file + "!/";
-            JarURLConnection urlc =
-                    (JarURLConnection) (new URL(urlString).openConnection());
+    // Helper method to format the URL properly.
+    static private String formatURL(String dir, String file) {
+        return "jar:file:///" + dir + "/" + file + "!/";
+    }
 
-            String implVersion;
-            try {
-                /*
-                 * If the file doesn't exist (e.g. mscapi on solaris),
-                 * skip it. If there are other problems, fail out.
-                 */
-                implVersion = urlc.getManifest().getMainAttributes().getValue(
-                        "Implementation-Version");
-            } catch (FileNotFoundException e) {
-                System.out.println("    " + file + " not found, skipping...");
-                continue;
-            }
+    static private String specVersion =
+        System.getProperty("java.specification.version");
 
-            if (implVersion == null) {
-                throw new Exception(
-                        "Implementation-Version not found in Manifest");
-            }
+    /*
+     * Test the root cause, which is that there were no manifest values
+     * for many of the providers, and for those that had them, there was
+     * no test to make sure that the impl version was appropriate for
+     * the spec version.
+     */
+    static private void checkManifest(String dir, String file)
+            throws Exception {
 
-            if (!implVersion.startsWith(specVersion)) {
-                throw new Exception(
-                        "Implementation-Version does not match " +
-                        "Specification-Version");
-            }
+        System.out.println("Checking: " + file);
+
+        String url = formatURL(dir, file);
+        JarURLConnection urlc =
+            (JarURLConnection) (new URL(url).openConnection());
+
+        String implVersion;
+        try {
+            implVersion = urlc.getManifest().getMainAttributes().getValue(
+                "Implementation-Version");
+        } catch (FileNotFoundException e) {
+            /*
+             * If the file doesn't exist (e.g. mscapi on solaris),
+             * skip it. If there are other problems, fail out.
+             */
+            System.out.println("    " + file + " not found, skipping...");
+            return;
+        }
+
+        if (implVersion == null) {
+            throw new Exception(
+                "Implementation-Version not found in Manifest");
+        }
+
+        if (!implVersion.startsWith(specVersion)) {
+            throw new Exception(
+                "Implementation-Version does not match " +
+                "Specification-Version");
         }
     }
 
     /*
-     * Check the symptom, an UnsatisfiedLinkError
+     * Workaround for unfortunately generified forName() API
+     */
+    @SuppressWarnings("unchecked")
+    static private Class<Provider> getProviderClass(String name)
+            throws Exception {
+        return (Class<Provider>)Class.forName(name);
+    }
+
+    /*
+     * Check the symptom, an UnsatisfiedLinkError in MessageDigests.
      */
     static private void checkP11MessageDigestClone() throws Exception {
+
         System.out.println("=============");
         System.out.println("Checking for UnsatisfiedLinkError");
         String os = System.getProperty("os.name");
@@ -111,25 +148,40 @@
 
         /*
          * We have to do some gyrations here, since the code to exercise
-         * this is in the P11 MessageDigests, and most of mechanisms are
-         * disabled by default.
+         * this is in the P11 MessageDigests, and most of those mechanisms
+         * are disabled by default.
          */
         String customP11File =
-                System.getProperty("TESTSRC", ".") + "/p11-solaris.txt";
+            System.getProperty("TESTSRC", ".") + "/p11-solaris.txt";
+
+        /*
+         * In 7u, we don't have a 64 PKCS11 windows build yet, so we
+         * have to do some dynamic checking to determine if there is
+         * a PKCS11 library available to test against.  Otherwise, the
+         * windows 64 bit will throw a compilation error before the
+         * test is even run.
+         */
+        Constructor<Provider> cons;
+        Provider provider;
+        try {
+            Class<Provider> clazz =
+                getProviderClass("sun.security.pkcs11.SunPKCS11");
+            cons = clazz.getConstructor(new Class[]{String.class});
+            provider = cons.newInstance(new Object[]{customP11File});
+        } catch (Exception ex) {
+            System.out.println("Skipping test - no PKCS11 provider available");
+            return;
+        }
 
         try {
-            Provider provider =
-                new sun.security.pkcs11.SunPKCS11(customP11File);
-
             MessageDigest md = MessageDigest.getInstance("SHA1", provider);
             md.update((byte) 0x01);
             System.out.println(md.getProvider());
-
             md.clone();
         } catch (Exception e) {
-            // These kinds of failure is ok.  We're testing the
+            // These kinds of failure are ok.  We're testing the
             // UnsatisfiedLinkError here.
-            return;
         }
+        System.out.println("Passed.");
     }
 }