summaryrefslogtreecommitdiffstats
path: root/testsuites/psxtests/psxclock/init.c
diff options
context:
space:
mode:
Diffstat (limited to 'testsuites/psxtests/psxclock/init.c')
-rw-r--r--testsuites/psxtests/psxclock/init.c206
1 files changed, 206 insertions, 0 deletions
diff --git a/testsuites/psxtests/psxclock/init.c b/testsuites/psxtests/psxclock/init.c
new file mode 100644
index 0000000000..9f8c5671d9
--- /dev/null
+++ b/testsuites/psxtests/psxclock/init.c
@@ -0,0 +1,206 @@
+/*
+ * COPYRIGHT (c) 1989-2009.
+ * 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$
+ */
+
+#include <pmacros.h>
+#include <time.h>
+#include <errno.h>
+
+rtems_task Init(
+ rtems_task_argument argument
+)
+{
+ struct timespec tv;
+ struct timespec tr;
+ int status;
+ int priority;
+ pthread_t thread_id;
+ time_t seconds;
+ time_t seconds1;
+ unsigned int remaining;
+ struct tm tm;
+ useconds_t useconds;
+
+ puts( "\n\n*** POSIX CLOCK TEST ***" );
+
+ tm_build_time( &tm, TM_FRIDAY, TM_MAY, 24, 96, 11, 5, 0 );
+
+ /* error cases in clock_gettime and clock_settime */
+
+ puts( "Init: clock_gettime - EINVAL (NULL timespec)" );
+ status = clock_gettime( CLOCK_REALTIME, NULL );
+ rtems_test_assert( status == -1 );
+ rtems_test_assert( errno == EINVAL );
+
+ puts( "Init: clock_gettime - EINVAL (invalid clockid)" );
+ status = clock_gettime( (clockid_t)-1, &tv );
+ rtems_test_assert( status == -1 );
+ rtems_test_assert( errno == EINVAL );
+
+ puts( "Init: clock_settime - EINVAL (invalid clockid)" );
+ status = clock_settime( (clockid_t)-1, &tv );
+ rtems_test_assert( status == -1 );
+ rtems_test_assert( errno == EINVAL );
+
+ /* way back near the dawn of time :D */
+ tv.tv_sec = 1;
+ tv.tv_nsec = 0;
+ printf( ctime( &tv.tv_sec ) );
+ puts( "Init: clock_settime - before 1988 EINVAL" );
+ status = clock_settime( CLOCK_REALTIME, &tv );
+ rtems_test_assert( status == -1 );
+ rtems_test_assert( errno == EINVAL );
+
+ /* exercise clock_getres */
+
+ puts( "Init: clock_getres - EINVAL (invalid clockid)" );
+ status = clock_getres( (clockid_t) -1, &tv );
+ rtems_test_assert( status == -1 );
+ rtems_test_assert( errno == EINVAL );
+
+ puts( "Init: clock_getres - EINVAL (NULL resolution)" );
+ status = clock_getres( CLOCK_REALTIME, NULL );
+ rtems_test_assert( status == -1 );
+ rtems_test_assert( errno == EINVAL );
+
+ puts( "Init: clock_getres - SUCCESSFUL" );
+ status = clock_getres( CLOCK_REALTIME, &tv );
+ printf( "Init: resolution = sec (%ld), nsec (%ld)\n", tv.tv_sec, tv.tv_nsec );
+ rtems_test_assert( !status );
+
+ /* set the time of day, and print our buffer in multiple ways */
+
+ tv.tv_sec = mktime( &tm );
+ rtems_test_assert( tv.tv_sec != -1 );
+
+ tv.tv_nsec = 0;
+
+ /* now set the time of day */
+
+ empty_line();
+
+ printf( asctime( &tm ) );
+ puts( "Init: clock_settime - SUCCESSFUL" );
+ status = clock_settime( CLOCK_REALTIME, &tv );
+ rtems_test_assert( !status );
+
+ printf( asctime( &tm ) );
+ printf( ctime( &tv.tv_sec ) );
+
+ /* use sleep to delay */
+
+ remaining = sleep( 3 );
+ rtems_test_assert( !remaining );
+
+ /* print new times to make sure it has changed and we can get the realtime */
+ status = clock_gettime( CLOCK_PROCESS_CPUTIME, &tv );
+ rtems_test_assert( !status );
+ printf("Time since boot: (%d, %d)\n", tv.tv_sec,tv.tv_nsec );
+
+ status = clock_gettime( CLOCK_REALTIME, &tv );
+ rtems_test_assert( !status );
+
+ printf( ctime( &tv.tv_sec ) );
+
+ seconds = time( NULL );
+ printf( ctime( &seconds ) );
+
+ /* just to have the value copied out through the parameter */
+
+ seconds = time( &seconds1 );
+ rtems_test_assert( seconds == seconds1 );
+
+ /* check the time remaining */
+
+ printf( "Init: seconds remaining (%d)\n", (int)remaining );
+ rtems_test_assert( !remaining );
+
+ /* error cases in nanosleep */
+
+ empty_line();
+ puts( "Init: nanosleep - EINVAL (NULL time)" );
+ status = nanosleep ( NULL, &tr );
+ rtems_test_assert( status == -1 );
+ rtems_test_assert( errno == EINVAL );
+
+ tv.tv_sec = 0;
+ tv.tv_nsec = TOD_NANOSECONDS_PER_SECOND * 2;
+ puts( "Init: nanosleep - EINVAL (too many nanoseconds)" );
+ status = nanosleep ( &tv, &tr );
+ rtems_test_assert( status == -1 );
+ rtems_test_assert( errno == EINVAL );
+
+ /* this is actually a small delay or yield */
+ tv.tv_sec = -1;
+ tv.tv_nsec = 0;
+ puts( "Init: nanosleep - negative seconds small delay " );
+ status = nanosleep ( &tv, &tr );
+ rtems_test_assert( status == -1 );
+ rtems_test_assert( errno == EINVAL );
+
+ /* use nanosleep to yield */
+
+ tv.tv_sec = 0;
+ tv.tv_nsec = 0;
+
+ puts( "Init: nanosleep - yield with remaining" );
+ status = nanosleep ( &tv, &tr );
+ rtems_test_assert( !status );
+ rtems_test_assert( !tr.tv_sec );
+ rtems_test_assert( !tr.tv_nsec );
+
+ puts( "Init: nanosleep - yield with NULL time remaining" );
+ status = nanosleep ( &tv, NULL );
+ rtems_test_assert( !status );
+ rtems_test_assert( !tr.tv_sec );
+ rtems_test_assert( !tr.tv_nsec );
+
+ /* use nanosleep to delay */
+
+ tv.tv_sec = 3;
+ tv.tv_nsec = 500000;
+
+ puts( "Init: nanosleep - 1.05 seconds" );
+ status = nanosleep ( &tv, &tr );
+ rtems_test_assert( !status );
+
+ /* print the current real time again */
+ status = clock_gettime( CLOCK_REALTIME, &tv );
+ rtems_test_assert( !status );
+ printf( ctime( &tv.tv_sec ) );
+
+ /* check the time remaining */
+
+ printf( "Init: sec (%ld), nsec (%ld) remaining\n", tr.tv_sec, tr.tv_nsec );
+ rtems_test_assert( !tr.tv_sec && !tr.tv_nsec );
+
+ puts( "Init: usleep - 1.35 seconds" );
+ useconds = usleep ( 1350000 );
+ rtems_test_assert( useconds < 1350000 );
+
+ /* print the current real time again */
+ status = clock_gettime( CLOCK_REALTIME, &tv );
+ rtems_test_assert( !status );
+ printf( ctime( &tv.tv_sec ) );
+
+ puts( "*** END OF POSIX CLOCK TEST ***" );
+ rtems_test_exit(0);
+}
+
+
+/* configuration information */
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+#define CONFIGURE_MAXIMUM_TASKS 1
+
+#define CONFIGURE_INIT
+#include <rtems/confdefs.h>