< prev index next >

test/compiler/intrinsics/sha/TestSHA.java

Print this page
rev 11557 : 8132919: use package in compiler tests
Reviewed-by: duke


  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 /**
  26  * @test
  27  * @bug 8035968
  28  * @summary C2 support for SHA on SPARC
  29  *
  30  * @run main/othervm/timeout=600 -Xbatch -Dalgorithm=SHA-1   TestSHA
  31  * @run main/othervm/timeout=600 -Xbatch -Dalgorithm=SHA-224 TestSHA
  32  * @run main/othervm/timeout=600 -Xbatch -Dalgorithm=SHA-256 TestSHA
  33  * @run main/othervm/timeout=600 -Xbatch -Dalgorithm=SHA-384 TestSHA
  34  * @run main/othervm/timeout=600 -Xbatch -Dalgorithm=SHA-512 TestSHA










  35  *
  36  * @run main/othervm/timeout=600 -Xbatch -Dalgorithm=SHA-1   -Doffset=1 TestSHA
  37  * @run main/othervm/timeout=600 -Xbatch -Dalgorithm=SHA-224 -Doffset=1 TestSHA
  38  * @run main/othervm/timeout=600 -Xbatch -Dalgorithm=SHA-256 -Doffset=1 TestSHA
  39  * @run main/othervm/timeout=600 -Xbatch -Dalgorithm=SHA-384 -Doffset=1 TestSHA
  40  * @run main/othervm/timeout=600 -Xbatch -Dalgorithm=SHA-512 -Doffset=1 TestSHA










  41  *
  42  * @run main/othervm/timeout=600 -Xbatch -Dalgorithm=SHA-1   -Dalgorithm2=SHA-256 TestSHA
  43  * @run main/othervm/timeout=600 -Xbatch -Dalgorithm=SHA-1   -Dalgorithm2=SHA-512 TestSHA
  44  * @run main/othervm/timeout=600 -Xbatch -Dalgorithm=SHA-256 -Dalgorithm2=SHA-512 TestSHA






  45  *
  46  * @run main/othervm/timeout=600 -Xbatch -Dalgorithm=SHA-1   -Dalgorithm2=MD5     TestSHA
  47  * @run main/othervm/timeout=600 -Xbatch -Dalgorithm=MD5     -Dalgorithm2=SHA-1   TestSHA




  48  */
  49 


  50 import java.security.MessageDigest;
  51 import java.util.Arrays;
  52 
  53 public class TestSHA {
  54     private static final int HASH_LEN = 64; /* up to 512-bit */
  55     private static final int ALIGN = 8;     /* for different data alignments */
  56 
  57     public static void main(String[] args) throws Exception {
  58         String provider = System.getProperty("provider", "SUN");
  59         String algorithm = System.getProperty("algorithm", "SHA-1");
  60         String algorithm2 = System.getProperty("algorithm2", "");
  61         int msgSize = Integer.getInteger("msgSize", 1024);
  62         int offset = Integer.getInteger("offset", 0)  % ALIGN;
  63         int iters = (args.length > 0 ? Integer.valueOf(args[0]) : 100000);
  64         int warmupIters = (args.length > 1 ? Integer.valueOf(args[1]) : 20000);
  65 
  66         testSHA(provider, algorithm, msgSize, offset, iters, warmupIters);
  67 
  68         if (algorithm2.equals("") == false) {
  69             testSHA(provider, algorithm2, msgSize, offset, iters, warmupIters);
  70         }
  71     }
  72 
  73     static void testSHA(String provider, String algorithm, int msgSize,
  74                         int offset, int iters, int warmupIters) throws Exception {
  75         System.out.println("provider = " + provider);
  76         System.out.println("algorithm = " + algorithm);
  77         System.out.println("msgSize = " + msgSize + " bytes");
  78         System.out.println("offset = " + offset);
  79         System.out.println("iters = " + iters);
  80 
  81         byte[] expectedHash = new byte[HASH_LEN];
  82         byte[] hash = new byte[HASH_LEN];
  83         byte[] data = new byte[msgSize + offset];
  84         for (int i = 0; i < (msgSize + offset); i++) {
  85             data[i] = (byte)(i & 0xff);
  86         }
  87 
  88         try {
  89             MessageDigest sha = MessageDigest.getInstance(algorithm, provider);
  90 
  91             /* do once, which doesn't use intrinsics */
  92             sha.reset();
  93             sha.update(data, offset, msgSize);




  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 /**
  26  * @test
  27  * @bug 8035968
  28  * @summary C2 support for SHA on SPARC
  29  *
  30  * @run main/othervm/timeout=600 -Xbatch
  31  *      -Dalgorithm=SHA-1
  32  *      compiler.intrinsics.sha.TestSHA
  33  * @run main/othervm/timeout=600 -Xbatch
  34  *      -Dalgorithm=SHA-224
  35  *      compiler.intrinsics.sha.TestSHA
  36  * @run main/othervm/timeout=600 -Xbatch
  37  *      -Dalgorithm=SHA-256
  38  *      compiler.intrinsics.sha.TestSHA
  39  * @run main/othervm/timeout=600 -Xbatch
  40  *      -Dalgorithm=SHA-384
  41  *      compiler.intrinsics.sha.TestSHA
  42  * @run main/othervm/timeout=600 -Xbatch
  43  *      -Dalgorithm=SHA-512
  44  *      compiler.intrinsics.sha.TestSHA
  45  *
  46  * @run main/othervm/timeout=600 -Xbatch
  47  *      -Dalgorithm=SHA-1   -Doffset=1
  48  *      compiler.intrinsics.sha.TestSHA
  49  * @run main/othervm/timeout=600 -Xbatch
  50  *      -Dalgorithm=SHA-224 -Doffset=1
  51  *      compiler.intrinsics.sha.TestSHA
  52  * @run main/othervm/timeout=600 -Xbatch
  53  *      -Dalgorithm=SHA-256 -Doffset=1
  54  *      compiler.intrinsics.sha.TestSHA
  55  * @run main/othervm/timeout=600 -Xbatch
  56  *      -Dalgorithm=SHA-384 -Doffset=1
  57  *      compiler.intrinsics.sha.TestSHA
  58  * @run main/othervm/timeout=600 -Xbatch
  59  *      -Dalgorithm=SHA-512 -Doffset=1
  60  *      compiler.intrinsics.sha.TestSHA
  61  *
  62  * @run main/othervm/timeout=600 -Xbatch
  63  *      -Dalgorithm=SHA-1   -Dalgorithm2=SHA-256
  64  *      compiler.intrinsics.sha.TestSHA
  65  * @run main/othervm/timeout=600 -Xbatch
  66  *      -Dalgorithm=SHA-1   -Dalgorithm2=SHA-512
  67  *      compiler.intrinsics.sha.TestSHA
  68  * @run main/othervm/timeout=600 -Xbatch
  69  *      -Dalgorithm=SHA-256 -Dalgorithm2=SHA-512
  70  *      compiler.intrinsics.sha.TestSHA
  71  *
  72  * @run main/othervm/timeout=600 -Xbatch
  73  *      -Dalgorithm=SHA-1   -Dalgorithm2=MD5
  74  *      compiler.intrinsics.sha.TestSHA
  75  * @run main/othervm/timeout=600 -Xbatch
  76  *      -Dalgorithm=MD5     -Dalgorithm2=SHA-1
  77  *      compiler.intrinsics.sha.TestSHA
  78  */
  79 
  80 package compiler.intrinsics.sha;
  81 
  82 import java.security.MessageDigest;
  83 import java.util.Arrays;
  84 
  85 public class TestSHA {
  86     private static final int HASH_LEN = 64; /* up to 512-bit */
  87     private static final int ALIGN = 8;     /* for different data alignments */
  88 
  89     public static void main(String[] args) throws Exception {
  90         String provider = System.getProperty("provider", "SUN");
  91         String algorithm = System.getProperty("algorithm", "SHA-1");
  92         String algorithm2 = System.getProperty("algorithm2", "");
  93         int msgSize = Integer.getInteger("msgSize", 1024);
  94         int offset = Integer.getInteger("offset", 0)  % ALIGN;
  95         int iters = (args.length > 0 ? Integer.valueOf(args[0]) : 100000);
  96         int warmupIters = (args.length > 1 ? Integer.valueOf(args[1]) : 20000);
  97 
  98         testSHA(provider, algorithm, msgSize, offset, iters, warmupIters);
  99 
 100         if (algorithm2.equals("") == false) {
 101             testSHA(provider, algorithm2, msgSize, offset, iters, warmupIters);
 102         }
 103     }
 104 
 105     public static void testSHA(String provider, String algorithm, int msgSize,
 106                         int offset, int iters, int warmupIters) throws Exception {
 107         System.out.println("provider = " + provider);
 108         System.out.println("algorithm = " + algorithm);
 109         System.out.println("msgSize = " + msgSize + " bytes");
 110         System.out.println("offset = " + offset);
 111         System.out.println("iters = " + iters);
 112 
 113         byte[] expectedHash = new byte[HASH_LEN];
 114         byte[] hash = new byte[HASH_LEN];
 115         byte[] data = new byte[msgSize + offset];
 116         for (int i = 0; i < (msgSize + offset); i++) {
 117             data[i] = (byte)(i & 0xff);
 118         }
 119 
 120         try {
 121             MessageDigest sha = MessageDigest.getInstance(algorithm, provider);
 122 
 123             /* do once, which doesn't use intrinsics */
 124             sha.reset();
 125             sha.update(data, offset, msgSize);


< prev index next >