ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/SystemTest.java
Revision: 1.14
Committed: Sun May 14 03:09:25 2017 UTC (6 years, 11 months ago) by jsr166
Branch: MAIN
CVS Tags: HEAD
Changes since 1.13: +11 -32 lines
Log Message:
coalesce low-value expensive tests

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 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 jsr166 1.14 * possible rounding), and vice versa.
31 dl 1.2 * This shows only that nano timing not (much) worse than milli.
32     */
33 jsr166 1.14 public void testNanoTime() throws InterruptedException {
34     long m0 = System.currentTimeMillis();
35     long n0 = System.nanoTime();
36     Thread.sleep(1);
37 jsr166 1.9 long m1 = System.currentTimeMillis();
38     long n1 = System.nanoTime();
39 jsr166 1.14 Thread.sleep(50); // avoid possibly scaled SHORT_DELAY_MS
40     long m2 = System.currentTimeMillis();
41 jsr166 1.9 long n2 = System.nanoTime();
42     Thread.sleep(1);
43 jsr166 1.14 long m3 = System.currentTimeMillis();
44     long n3 = System.nanoTime();
45     assertTrue((n2 - n1) / 1_000_000 <= m3 - m0 + MILLIS_ROUND);
46     assertTrue(m2 - m1 <= (n3 - n0) / 1_000_000 + MILLIS_ROUND);
47 dl 1.1 }
48     }