26package com.jogamp.common.os;
28import java.time.Instant;
29import java.time.ZoneOffset;
30import java.time.temporal.ChronoUnit;
32import org.junit.Assert;
33import org.junit.FixMethodOrder;
35import org.junit.runners.MethodSorters;
37import com.jogamp.common.util.TSPrinter;
38import com.jogamp.junit.util.JunitTracer;
40import jogamp.common.os.PlatformPropsImpl;
42@FixMethodOrder(MethodSorters.NAME_ASCENDING)
58 }
catch (
final InterruptedException e) { }
65 final long m_t0_d = m_t0.until(m_t0_b, ChronoUnit.MILLIS);
66 final long m_t1_d = m_t1.until(m_t1_b, ChronoUnit.MILLIS);
67 final long w_t2_d = w_t2.until(w_t2_b, ChronoUnit.MILLIS);
68 final long w_t3_d = w_t3.until(w_t3_b, ChronoUnit.MILLIS);
70 TSPrinter.
printf(System.err,
"mono t0 %s, %d ms\n", m_t0.atZone(ZoneOffset.UTC), m_t0_d);
71 TSPrinter.
printf(System.err,
"mono t1 %s, %d ms\n", m_t1.atZone(ZoneOffset.UTC), m_t1_d);
72 TSPrinter.
printf(System.err,
"wall t2 %s, %d ms\n", w_t2.atZone(ZoneOffset.UTC), w_t2_d);
73 TSPrinter.
printf(System.err,
"wall t3 %s, %d ms\n", w_t3.atZone(ZoneOffset.UTC), w_t3_d);
75 final long td_min = 50;
76 final long td_max = 150;
77 Assert.assertTrue( td_min <= m_t0_d );
78 Assert.assertTrue( td_max >= m_t0_d );
80 Assert.assertTrue( td_min <= m_t1_d );
81 Assert.assertTrue( td_max >= m_t1_d );
83 Assert.assertTrue( 0 <= w_t2_d );
84 Assert.assertTrue( 1000 >= w_t2_d );
86 Assert.assertTrue( td_min <= w_t3_d );
87 Assert.assertTrue( td_max >= w_t3_d );
95 final long td_ar = ta0 - tr0;
98 }
catch (
final InterruptedException e) { }
102 TSPrinter.
printf(System.err,
"mono ts ms: tr0 rel %d, ta0 abs %d, diff %d\n", tr0, ta0, td_ar);
103 TSPrinter.
printf(System.err,
"mono td ms: tr* rel %d, ta* abs %d\n", td_r, td_a);
107 final long toleranceMS = PlatformPropsImpl.JAVA_21 ? 20 : 10;
108 Assert.assertTrue(td_ar >= 0);
109 Assert.assertTrue(Math.abs(td_r - 100) < toleranceMS);
110 Assert.assertTrue(Math.abs(td_a - 100) < toleranceMS);
113 public static void main(
final String args[]) {
114 final String tstname =
TestClock01.class.getName();
115 org.junit.runner.JUnitCore.
main(tstname);
static Instant getMonotonicTime()
Returns current monotonic time since Unix Epoch 00:00:00 UTC on 1970-01-01.
static Instant getWallClockTime()
Returns current wall-clock real-time since Unix Epoch 00:00:00 UTC on 1970-01-01.
static native long currentTimeMillis()
Returns the unix based current monotonic time in milliseconds.
static native long wallClockSeconds()
Returns current wall-clock system time of day in seconds since Unix Epoch 00:00:00 UTC on 1 January 1...
static native long currentMillis()
Returns current monotonic milliseconds since start of this application.
static void main(final String args[])
A simple millisecond timestamp prepending print*() wrapper for a PrintStream.
static void print(final PrintStream out, final long millis, final String msg)
static synchronized TSPrinter stderr()
static void printf(final PrintStream out, final long millis, final String format, final Object ... args)