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