2 * Written by Doug Lea with assistance from members of JCP JSR-166
3 * Expert Group and released to the public domain, as explained at
4 * http://creativecommons.org/licenses/publicdomain
5 * Other contributors include Andrew Wright, Jeffrey Hayes,
6 * Pat Fisher, Mike Judd.
9 package tests.api.java.util.concurrent; // android-added
11 import junit.framework.*;
13 public class SystemTest extends JSR166TestCase {
14 public static Test suite() {
15 return new TestSuite(SystemTest.class);
19 * Worst case rounding for millisecs; set for 60 cycle millis clock.
20 * This value might need to be changed on JVMs with coarser
21 * System.currentTimeMillis clocks.
23 static final long MILLIS_ROUND = 17;
26 * Nanos between readings of millis is no longer than millis (plus
28 * This shows only that nano timing not (much) worse than milli.
30 public void testNanoTime1() throws InterruptedException {
31 long m1 = System.currentTimeMillis();
33 long n1 = System.nanoTime();
34 Thread.sleep(SHORT_DELAY_MS);
35 long n2 = System.nanoTime();
37 long m2 = System.currentTimeMillis();
38 long millis = m2 - m1;
40 assertTrue(nanos >= 0);
41 long nanosAsMillis = nanos / 1000000;
42 assertTrue(nanosAsMillis <= millis + MILLIS_ROUND);
46 * Millis between readings of nanos is less than nanos, adjusting
48 * This shows only that nano timing not (much) worse than milli.
50 public void testNanoTime2() throws InterruptedException {
51 long n1 = System.nanoTime();
53 long m1 = System.currentTimeMillis();
54 Thread.sleep(SHORT_DELAY_MS);
55 long m2 = System.currentTimeMillis();
57 long n2 = System.nanoTime();
58 long millis = m2 - m1;
61 assertTrue(nanos >= 0);
62 long nanosAsMillis = nanos / 1000000;
63 assertTrue(millis <= nanosAsMillis + MILLIS_ROUND);