[aravis] tests: a small get_time test.



commit 12fdf66fcc70c1c15727f921ef53f439698be384
Author: Emmanuel Pacaud <emmanuel gnome org>
Date:   Thu Nov 7 15:18:48 2013 +0100

    tests: a small get_time test.

 tests/.gitignore  |    1 +
 tests/Makefile.am |    5 ++-
 tests/timetest.c  |   85 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 90 insertions(+), 1 deletions(-)
---
diff --git a/tests/.gitignore b/tests/.gitignore
index 71add26..cf27c42 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -11,3 +11,4 @@ arv-zip-test
 arv-camera-test
 arv-heartbeat-test
 arv-example
+time-test
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0536a84..6fdba2f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -6,7 +6,7 @@ test_progs_ldadd =                                      \
        $(top_builddir)/src/libaravis- ARAVIS_API_VERSION@.la           \
        $(ARAVIS_LIBS)
 
-noinst_PROGRAMS = arv-test arv-genicam-test arv-evaluator-test arv-zip-test arv-camera-test 
arv-heartbeat-test arv-example
+noinst_PROGRAMS = arv-test arv-genicam-test arv-evaluator-test arv-zip-test arv-camera-test 
arv-heartbeat-test arv-example time-test
 
 arv_test_SOURCES = arvtest.c
 arv_test_LDADD = $(test_progs_ldadd)
@@ -29,6 +29,9 @@ arv_heartbeat_test_LDADD = $(test_progs_ldadd)
 arv_example_SOURCES = arvexample.c
 arv_example_LDADD = $(test_progs_ldadd)
 
+time_test_SOURCES = timetest.c
+time_test_LDADD = $(test_progs_ldadd)
+
 TEST_PROGS += evaluator buffer misc fake genicam
 if ARAVIS_BUILD_CPP_TEST
 TEST_PROGS += cpp
diff --git a/tests/timetest.c b/tests/timetest.c
new file mode 100644
index 0000000..941af36
--- /dev/null
+++ b/tests/timetest.c
@@ -0,0 +1,85 @@
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <glib.h>
+
+static gint64
+get_time_us (void)
+{
+       GTimeVal time;
+
+       g_get_current_time (&time);
+
+       return time.tv_sec * 1000000LL + time.tv_usec;
+}
+
+static gint64
+time_wait (gint64 usec )
+{
+       gint64 wt, st, tt;
+       gint64 i, wait;
+
+       st = get_time_us ();
+       wt = st + usec;
+       wait = usec;
+       for( i = 0, tt = get_time_us(); tt < wt;  wait = (gint64) (wt - tt), i++ ) {
+               tt = get_time_us ();
+       }
+
+  return tt-st;
+}
+
+static gint64
+sleep_meas (gint64 usec) {
+       gint64 tt;
+
+       tt = get_time_us ();
+       g_usleep (usec);
+       tt = get_time_us () - tt;
+
+       return tt;
+}
+
+#define MAX_TIME_US    200000
+#define N_ITERS                100
+
+int
+main (int argc, char **argv)
+{
+       gint64 i, j, pTt;
+       double val, wt, min, max, swt;
+
+       for( i = 1; i < MAX_TIME_US; i = i*2 ) {
+               max = wt = swt = 0.; min = MAX_TIME_US;
+               for (j = 0; j < N_ITERS; j++ ) {
+                       val = sleep_meas (i);
+                       wt  += val;
+                       swt += val*val;
+                       if (val < min) min = val;
+                       if (val > max) max = val;
+               }
+               wt /= j;
+               printf ("SleepMeas: %6d - Mean %7g Max %5g Min %5g rms %g\n",
+                       i, wt, max, min, sqrt(swt/j - wt*wt));
+       } 
+
+       for( i = 1; i < MAX_TIME_US; i = i*2 ) {
+               max = wt = swt = 0.; min = MAX_TIME_US;
+               for (j = 0; j < N_ITERS; j++ ) {
+                       val = time_wait (i);
+                       wt  += val;
+                       swt += val*val;
+                       if( val < min ) min = val;
+                       if( val > max ) max = val;
+               }
+               wt /= j;
+               printf ("TimeWait:  %6d - Mean %7g Max %5g Min %5g rms %g\n",
+                       i, wt, max, min, sqrt(swt/j - wt*wt));
+       }
+
+       return EXIT_SUCCESS;
+}
+
+


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]