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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1, Sun Aug 31 19:24:55 2003 UTC revision 1.2, Sun Sep 14 20:42:41 2003 UTC
# Line 7  Line 7 
7    
8  import junit.framework.*;  import junit.framework.*;
9    
10  public class SystemTest extends TestCase {  public class SystemTest extends JSR166TestCase {
11      public static void main(String[] args) {      public static void main(String[] args) {
12          junit.textui.TestRunner.run(suite());          junit.textui.TestRunner.run(suite());
13      }      }
# Line 16  Line 16 
16          return new TestSuite(SystemTest.class);          return new TestSuite(SystemTest.class);
17      }      }
18    
19        /**
20         * Nanos between readings of millis is no longer than millis.
21         * This shows only that nano timing not (much) worse than milli.
22         */
23      public void testNanoTime1() {      public void testNanoTime1() {
24          // Nanos between readings of millis must be no longer than millis          try {
25          long m1 = System.currentTimeMillis();          long m1 = System.currentTimeMillis();
26                Thread.sleep(1);
27          long n1 = System.nanoTime();          long n1 = System.nanoTime();
28                Thread.sleep(SHORT_DELAY_MS);
         // Ensure some computation that is not optimized away.  
         long sum = 0;  
         for (long i = 1; i < 10000; ++i)  
             sum += i;  
         assertTrue(sum != 0);  
   
29          long n2 = System.nanoTime();          long n2 = System.nanoTime();
30                Thread.sleep(1);
         for (long i = 1; i < 10000; ++i)  
             sum -= i;  
         assertTrue(sum == 0);  
   
31          long m2 = System.currentTimeMillis();          long m2 = System.currentTimeMillis();
32          long millis = m2 - m1;          long millis = m2 - m1;
33          long nanos = n2 - n1;          long nanos = n2 - n1;
# Line 40  Line 35 
35          assertTrue(nanos >= 0);          assertTrue(nanos >= 0);
36          assertTrue(nanos <= millis * 1000000);          assertTrue(nanos <= millis * 1000000);
37      }      }
38            catch(InterruptedException ie) {
39                fail("unexpected exception");
40            }
41        }
42    
43        /**
44         * Millis between readings of nanos is no longer than nanos
45         * This shows only that nano timing not (much) worse than milli.
46         */
47      public void testNanoTime2() {      public void testNanoTime2() {
48          // Millis between readings of nanos must be no longer than nanos          try {
49          long n1 = System.nanoTime();          long n1 = System.nanoTime();
50                Thread.sleep(1);
51          long m1 = System.currentTimeMillis();          long m1 = System.currentTimeMillis();
52                Thread.sleep(SHORT_DELAY_MS);
         // Ensure some computation that is not optimized away.  
         long sum = 0;  
         for (long i = 1; i < 10000; ++i)  
             sum += i;  
         assertTrue(sum != 0);  
   
53          long m2 = System.currentTimeMillis();          long m2 = System.currentTimeMillis();
54                Thread.sleep(1);
         for (long i = 1; i < 10000; ++i)  
             sum -= i;  
         assertTrue(sum == 0);  
   
55          long n2 = System.nanoTime();          long n2 = System.nanoTime();
   
56          long millis = m2 - m1;          long millis = m2 - m1;
57          long nanos = n2 - n1;          long nanos = n2 - n1;
58    
59          assertTrue(nanos >= 0);          assertTrue(nanos >= 0);
60          assertTrue(millis * 1000000 <= nanos);          assertTrue(millis * 1000000 <= nanos);
61      }      }
62            catch(InterruptedException ie) {
63                fail("unexpected exception");
64            }
65        }
66    
67  }  }
68    

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

Doug Lea
ViewVC Help
Powered by ViewVC 1.0.8