[cvs] / jsr166 / src / test / tck / SystemTest.java Repository:
ViewVC logotype

Annotation of /jsr166/src/test/tck/SystemTest.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.13 - (view) (download)

1 : dl 1.1 /*
2 : dl 1.5 * 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 : jsr166 1.11 * http://creativecommons.org/publicdomain/zero/1.0/
5 : jsr166 1.7 * Other contributors include Andrew Wright, Jeffrey Hayes,
6 :     * Pat Fisher, Mike Judd.
7 : dl 1.1 */
8 :    
9 : jsr166 1.12 import junit.framework.Test;
10 :     import junit.framework.TestSuite;
11 : dl 1.1
12 : dl 1.2 public class SystemTest extends JSR166TestCase {
13 : dl 1.1 public static void main(String[] args) {
14 : jsr166 1.13 main(suite(), args);
15 : dl 1.1 }
16 : jsr166 1.7
17 : dl 1.1 public static Test suite() {
18 : tim 1.4 return new TestSuite(SystemTest.class);
19 : dl 1.1 }
20 :    
21 : jsr166 1.7 /**
22 : dl 1.6 * Worst case rounding for millisecs; set for 60 cycle millis clock.
23 : jsr166 1.9 * This value might need to be changed on JVMs with coarser
24 : jsr166 1.10 * System.currentTimeMillis clocks.
25 : dl 1.6 */
26 :     static final long MILLIS_ROUND = 17;
27 :    
28 : dl 1.2 /**
29 : tim 1.4 * Nanos between readings of millis is no longer than millis (plus
30 : dl 1.6 * possible rounding).
31 : dl 1.2 * This shows only that nano timing not (much) worse than milli.
32 :     */
33 : jsr166 1.9 public void testNanoTime1() throws InterruptedException {
34 :     long m1 = System.currentTimeMillis();
35 :     Thread.sleep(1);
36 :     long n1 = System.nanoTime();
37 :     Thread.sleep(SHORT_DELAY_MS);
38 :     long n2 = System.nanoTime();
39 :     Thread.sleep(1);
40 :     long m2 = System.currentTimeMillis();
41 :     long millis = m2 - m1;
42 :     long nanos = n2 - n1;
43 :     assertTrue(nanos >= 0);
44 :     long nanosAsMillis = nanos / 1000000;
45 :     assertTrue(nanosAsMillis <= millis + MILLIS_ROUND);
46 : dl 1.1 }
47 :    
48 : dl 1.2 /**
49 : dl 1.6 * Millis between readings of nanos is less than nanos, adjusting
50 :     * for rounding.
51 : dl 1.2 * This shows only that nano timing not (much) worse than milli.
52 :     */
53 : jsr166 1.9 public void testNanoTime2() throws InterruptedException {
54 :     long n1 = System.nanoTime();
55 :     Thread.sleep(1);
56 :     long m1 = System.currentTimeMillis();
57 :     Thread.sleep(SHORT_DELAY_MS);
58 :     long m2 = System.currentTimeMillis();
59 :     Thread.sleep(1);
60 :     long n2 = System.nanoTime();
61 :     long millis = m2 - m1;
62 :     long nanos = n2 - n1;
63 : jsr166 1.7
64 : jsr166 1.9 assertTrue(nanos >= 0);
65 :     long nanosAsMillis = nanos / 1000000;
66 :     assertTrue(millis <= nanosAsMillis + MILLIS_ROUND);
67 : dl 1.1 }
68 :    
69 :     }

Doug Lea
ViewVC Help
Powered by ViewVC 1.0.8