ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/SystemTest.java
Revision: 1.10
Committed: Sat Oct 9 19:30:35 2010 UTC (13 years, 6 months ago) by jsr166
Branch: MAIN
Changes since 1.9: +1 -1 lines
Log Message:
whitespace

File Contents

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