summaryrefslogtreecommitdiffstats
path: root/testsuites/samples/nsecs
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2007-04-02 18:24:10 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2007-04-02 18:24:10 +0000
commit23a0105a78722111a2a2fd7e3c3b3bcd92ed8f44 (patch)
treee7e76afbb53c0c4b580f00af753d4ef20fe26d38 /testsuites/samples/nsecs
parent2007-04-02 Joel Sherrill <joel@OARcorp.com> (diff)
downloadrtems-23a0105a78722111a2a2fd7e3c3b3bcd92ed8f44.tar.bz2
2007-04-02 Joel Sherrill <joel@OARcorp.com>
* Makefile.am, configure.ac: Convert from Classic API style TOD_Control as fundamental time structure to POSIX struct timespec. Add clock_get_uptime(). * nsecs/.cvsignore, nsecs/Makefile.am, nsecs/init.c, nsecs/nsecs.doc, nsecs/nsecs.scn: New files.
Diffstat (limited to 'testsuites/samples/nsecs')
-rw-r--r--testsuites/samples/nsecs/.cvsignore2
-rw-r--r--testsuites/samples/nsecs/Makefile.am22
-rw-r--r--testsuites/samples/nsecs/init.c127
-rw-r--r--testsuites/samples/nsecs/nsecs.doc12
-rw-r--r--testsuites/samples/nsecs/nsecs.scn36
5 files changed, 199 insertions, 0 deletions
diff --git a/testsuites/samples/nsecs/.cvsignore b/testsuites/samples/nsecs/.cvsignore
new file mode 100644
index 0000000000..282522db03
--- /dev/null
+++ b/testsuites/samples/nsecs/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/testsuites/samples/nsecs/Makefile.am b/testsuites/samples/nsecs/Makefile.am
new file mode 100644
index 0000000000..8e1404141e
--- /dev/null
+++ b/testsuites/samples/nsecs/Makefile.am
@@ -0,0 +1,22 @@
+##
+## $Id$
+##
+
+rtems_tests_PROGRAMS = nsecs.exe
+nsecs_exe_SOURCES = init.c
+
+dist_rtems_tests_DATA = nsecs.scn
+dist_rtems_tests_DATA += nsecs.doc
+
+include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg
+include $(top_srcdir)/../automake/compile.am
+include $(top_srcdir)/../automake/leaf.am
+
+LINK_OBJS = $(nsecs_exe_OBJECTS) $(nsecs_exe_LDADD)
+LINK_LIBS = $(nsecs_exe_LDLIBS)
+
+nsecs.exe$(EXEEXT): $(nsecs_exe_OBJECTS) $(nsecs_exe_DEPENDENCIES)
+ @rm -f nsecs.exe$(EXEEXT)
+ $(make-exe)
+
+include $(top_srcdir)/../automake/local.am
diff --git a/testsuites/samples/nsecs/init.c b/testsuites/samples/nsecs/init.c
new file mode 100644
index 0000000000..fe98433967
--- /dev/null
+++ b/testsuites/samples/nsecs/init.c
@@ -0,0 +1,127 @@
+/*
+ * Nanoseconds accuracy timestamp test
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#define CONFIGURE_INIT
+
+#include <rtems.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/time.h>
+
+char *my_ctime( time_t t )
+{
+ static char b[32];
+ ctime_r(&t, b);
+ b[ strlen(b) - 1] = '\0';
+ return b;
+}
+
+void subtract_em(
+ struct timespec *start,
+ struct timespec *stop,
+ struct timespec *t
+)
+{
+ extern void _POSIX_Timespec_subtract(
+ const struct timespec *the_start,
+ const struct timespec *end,
+ struct timespec *result
+ );
+
+ t->tv_sec = 0;
+ t->tv_nsec = 0;
+ _POSIX_Timespec_subtract( start, stop, t );
+}
+
+volatile int i;
+rtems_task Init(
+ rtems_task_argument argument
+)
+{
+ rtems_status_code status;
+ rtems_time_of_day time;
+ int index;
+
+ puts( "\n\n*** NANOSECOND CLOCK TEST ***" );
+
+ time.year = 2007;
+ time.month = 03;
+ time.day = 24;
+ time.hour = 11;
+ time.minute = 15;
+ time.second = 0;
+ time.ticks = 0;
+
+ status = rtems_clock_set( &time );
+
+ /*
+ * Iterate 10 times showing difference in TOD
+ */
+ printf( "10 iterations of getting TOD\n" );
+ for (index=0 ; index <10 ; index++ ) {
+ struct timespec start, stop;
+ struct timespec diff;
+ clock_gettime( CLOCK_REALTIME, &start );
+ clock_gettime( CLOCK_REALTIME, &stop );
+
+ subtract_em( &start, &stop, &diff );
+#if 0
+ printf( "%d:%d %d:%d ",
+ start.tv_sec, start.tv_nsec,
+ stop.tv_sec, stop.tv_nsec,
+ );
+#else
+ printf( "Start: %s:%d\nStop : %s:%d",
+ my_ctime(start.tv_sec), start.tv_nsec,
+ my_ctime(stop.tv_sec), stop.tv_nsec
+ );
+#endif
+
+ printf( " --> %d:%d\n", diff.tv_sec, diff.tv_nsec );
+ }
+
+ /*
+ * Iterate 10 times showing difference in Uptime
+ */
+ printf( "\n10 iterations of getting Uptime\n" );
+ for (index=0 ; index <10 ; index++ ) {
+ struct timespec start, stop;
+ struct timespec diff;
+ rtems_clock_get_uptime( &start );
+ rtems_clock_get_uptime( &stop );
+
+ subtract_em( &start, &stop, &diff );
+ printf( "%d:%d %d:%d --> %d:%d\n",
+ start.tv_sec, start.tv_nsec,
+ stop.tv_sec, stop.tv_nsec,
+ diff.tv_sec, diff.tv_nsec
+ );
+ }
+
+ puts( "*** END OF NANOSECOND CLOCK TEST ***" );
+ exit(0);
+}
+
+
+#include <bsp.h> /* for device driver prototypes */
+
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+
+#define CONFIGURE_MICROSECONDS_PER_TICK 1000
+#define CONFIGURE_MAXIMUM_TASKS 1
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#include <rtems/confdefs.h>
diff --git a/testsuites/samples/nsecs/nsecs.doc b/testsuites/samples/nsecs/nsecs.doc
new file mode 100644
index 0000000000..5c0baceb8d
--- /dev/null
+++ b/testsuites/samples/nsecs/nsecs.doc
@@ -0,0 +1,12 @@
+#
+# $Id$
+#
+# COPYRIGHT (c) 1989-1999.
+# On-Line Applications Research Corporation (OAR).
+#
+# The license and distribution terms for this file may be
+# found in the file LICENSE in this distribution or at
+# http://www.rtems.com/license/LICENSE.
+#
+
+
diff --git a/testsuites/samples/nsecs/nsecs.scn b/testsuites/samples/nsecs/nsecs.scn
new file mode 100644
index 0000000000..323cea9300
--- /dev/null
+++ b/testsuites/samples/nsecs/nsecs.scn
@@ -0,0 +1,36 @@
+
+*** NANOSECOND CLOCK TEST ***
+10 iterations of getting TOD
+Start: Sat Mar 24 11:15:00 2007:540000
+Stop : Sat Mar 24 11:15:00 2007:549000 --> 0:9000
+Start: Sat Mar 24 11:15:00 2007:3974000
+Stop : Sat Mar 24 11:15:00 2007:3983000 --> 0:9000
+Start: Sat Mar 24 11:15:00 2007:7510000
+Stop : Sat Mar 24 11:15:00 2007:7519000 --> 0:9000
+Start: Sat Mar 24 11:15:00 2007:11054000
+Stop : Sat Mar 24 11:15:00 2007:11063000 --> 0:9000
+Start: Sat Mar 24 11:15:00 2007:14638000
+Stop : Sat Mar 24 11:15:00 2007:14647000 --> 0:9000
+Start: Sat Mar 24 11:15:00 2007:18301000
+Stop : Sat Mar 24 11:15:00 2007:18310000 --> 0:9000
+Start: Sat Mar 24 11:15:00 2007:21901000
+Stop : Sat Mar 24 11:15:00 2007:21910000 --> 0:9000
+Start: Sat Mar 24 11:15:00 2007:25526000
+Stop : Sat Mar 24 11:15:00 2007:25535000 --> 0:9000
+Start: Sat Mar 24 11:15:00 2007:29196000
+Stop : Sat Mar 24 11:15:00 2007:29206000 --> 0:10000
+Start: Sat Mar 24 11:15:00 2007:32826000
+Stop : Sat Mar 24 11:15:00 2007:32835000 --> 0:9000
+
+10 iterations of getting Uptime
+0:38977000 0:38986000 --> 0:9000
+0:40324000 0:40332000 --> 0:8000
+0:41636000 0:41645000 --> 0:9000
+0:42949000 0:42958000 --> 0:9000
+0:44295000 0:44304000 --> 0:9000
+0:45608000 0:45617000 --> 0:9000
+0:46921000 0:46930000 --> 0:9000
+0:48282000 0:48291000 --> 0:9000
+0:49595000 0:49603000 --> 0:8000
+0:50908000 0:50917000 --> 0:9000
+*** END OF NANOSECOND CLOCK TEST ***