blob: b67f66d3a77423e074c6bfb2169db1b446fa302a [file] [log] [blame]
Andreas Gampe35bcf812017-01-13 16:24:17 -08001/*
2 * Copyright (C) 2017 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
17import java.util.Arrays;
18
19public class Main {
20 public static void main(String[] args) throws Exception {
Andreas Gampe35bcf812017-01-13 16:24:17 -080021 doTest();
22 }
23
24 private static void doTest() {
25 int all1 = Runtime.getRuntime().availableProcessors();
26 int all2 = getAvailableProcessors();
27 if (all1 != all2) {
28 throw new RuntimeException("Available processors doesn't match: " + all1 + " vs " + all2);
29 }
30 System.out.println("availableProcessors OK");
31
32 Object info[] = getTimerInfo();
33 System.out.println(Arrays.toString(info));
34
35 // getTime checks.
36 // Note: there isn't really much to check independent from the implementation. So we check
37 // a few details of the ART implementation. This may fail on other runtimes.
38 long time1 = getTime();
39 long time2 = getTime();
40
41 // Under normal circumstances, time1 <= time2.
42 if (time2 < time1) {
43 throw new RuntimeException("Time unexpectedly decreased: " + time1 + " vs " + time2);
44 }
45
46 long time3 = System.nanoTime();
47 long time4 = getTime();
48
49 final long MINUTE = 60l * 1000 * 1000 * 1000;
50 if (time4 < time3 || (time4 - time3 > MINUTE)) {
51 throw new RuntimeException("Time unexpectedly divergent: " + time3 + " vs " + time4);
52 }
53
54 System.out.println("Time OK");
55 }
56
57 private static native int getAvailableProcessors();
58 private static native Object[] getTimerInfo();
59 private static native long getTime();
60}