1 /* 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 17 package art; 18 19 import java.util.Arrays; 20 21 public class Test927 { run()22 public static void run() throws Exception { 23 doTest(); 24 } 25 doTest()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 getAvailableProcessors()59 private static native int getAvailableProcessors(); getTimerInfo()60 private static native Object[] getTimerInfo(); getTime()61 private static native long getTime(); 62 } 63