diff options
author | Gary E. Miller <gem@rellim.com> | 2015-04-28 20:35:32 -0700 |
---|---|---|
committer | Gary E. Miller <gem@rellim.com> | 2015-04-28 20:35:32 -0700 |
commit | 9b5ba6c7678eda129fe59512d3a8c16605da3d47 (patch) | |
tree | 4d6f297d294a838569196cea700dbbc712664df1 /test_timespec.c | |
parent | 932b2912d8e62c46d6f3e28cde277b0c2bd3c6dd (diff) | |
download | gpsd-9b5ba6c7678eda129fe59512d3a8c16605da3d47.tar.gz |
Add example to show why timespec_diff_ns() must die.
Diffstat (limited to 'test_timespec.c')
-rw-r--r-- | test_timespec.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/test_timespec.c b/test_timespec.c index 4df383bf..59e88787 100644 --- a/test_timespec.c +++ b/test_timespec.c @@ -12,6 +12,7 @@ #include "compiler.h" #include "revision.h" +#include "ppsthread.h" #include "timespec.h" #define TS_ZERO {0,0} @@ -180,12 +181,16 @@ struct timespec exs[] = { static void ex_precision(void) { + long l; float f; double d; char buf[TIMESPEC_LEN]; + char buf1[TIMESPEC_LEN]; struct timespec *v = exs; + struct timespec v1 = TS_2037; + struct timespec v2 = TS_2037_X; - puts( "\nPrecision examples:\n\n"); + puts( "\nPrecision examples:\n\n Simple conversions\n"); printf( "\n%10stimespec%14sdouble%16sfloat\n\n", "", "", ""); while ( 1 ) { @@ -201,6 +206,20 @@ static void ex_precision(void) v++; } + printf( "\n\nSubtraction:\n"); + printf( "\n\ntimespec_diff_ns( x, y) = z\n"); + + timespec_str( &v1, buf, sizeof(buf) ); + timespec_str( &v2, buf1, sizeof(buf1) ); + l = timespec_diff_ns( v1, v2); + printf( "%21s - %21s = %21ld\n", buf, buf1, l); + + v1.tv_sec += 4; + timespec_str( &v1, buf, sizeof(buf) ); + timespec_str( &v2, buf1, sizeof(buf1) ); + l = timespec_diff_ns( v1, v2); + printf( "%21s - %21s = %21ld\n", buf, buf1, l); + } int main(int argc, char *argv[]) |