OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / libcore / dalvik / src / test / java / dalvik / system / SamplingProfilerTest.java
1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package dalvik.system;
18
19 import dalvik.system.SamplingProfiler.ThreadSet;
20 import java.math.BigInteger;
21 import java.security.KeyPairGenerator;
22 import java.security.SecureRandom;
23 import javax.crypto.spec.DHParameterSpec;
24 import junit.framework.TestCase;
25
26 public class SamplingProfilerTest extends TestCase {
27
28     public void test_SamplingProfiler_basic() throws Exception {
29         ThreadSet threadSet = SamplingProfiler.newArrayThreadSet(Thread.currentThread());
30         SamplingProfiler profiler = new SamplingProfiler(12, threadSet);
31         profiler.start(10);
32         toBeMeasured();
33         profiler.stop();
34         profiler.shutdown();
35         profiler.writeHprofData(System.out);
36     }
37
38     private static final String P_STR =
39         "9494fec095f3b85ee286542b3836fc81a5dd0a0349b4c239dd38744d488cf8e3"
40             + "1db8bcb7d33b41abb9e5a33cca9144b1cef332c94bf0573bf047a3aca98cdf3b";
41     private static final String G_STR =
42             "98ab7c5c431479d8645e33aa09758e0907c78747798d0968576f9877421a9089"
43             + "756f7876e76590b76765645c987976d764dd4564698a87585e64554984bb4445"
44             + "76e5764786f875b4456c";
45
46     private static final byte[] P = new BigInteger(P_STR,16).toByteArray();
47     private static final byte[] G = new BigInteger(G_STR,16).toByteArray();
48
49     private static void toBeMeasured () throws Exception {
50         long start = System.currentTimeMillis();
51         for (int i = 0; i < 10000; i++) {
52             BigInteger p = new BigInteger(P);
53             BigInteger g = new BigInteger(G);
54             KeyPairGenerator gen = KeyPairGenerator.getInstance("DH");
55             gen.initialize(new DHParameterSpec(p, g), new SecureRandom());
56         }
57         long end = System.currentTimeMillis();
58     }
59
60 }