clock_t clock () { struct tms tim_s; clock_t res; if ((res = (clock_t) _times_r (_REENT, &tim_s)) != -1) res = (clock_t) (tim_s.tms_utime + tim_s.tms_stime + tim_s.tms_cutime + tim_s.tms_cstime); return res; }
rtems_task Init( rtems_task_argument argument ) { clock_t start; clock_t end; clock_t now; clock_t sc; clock_t difference; struct tms start_tm; struct tms end_tm; int interval = 5; puts( "\n\n*** TEST TIMES 01 ***" ); puts( "times( NULL ) -- EFAULT" ); sc = times( NULL ); rtems_test_assert( sc == -1 ); rtems_test_assert( errno == EFAULT ); puts( "_times_r( NULL, NULL ) -- EFAULT" ); start = _times_r( NULL, NULL ); rtems_test_assert( sc == -1 ); rtems_test_assert( errno == EFAULT ); while ( rtems_clock_get_ticks_since_boot() == 0 ) ; puts( "_times( &start_tm ) -- OK" ); now = _times( &start_tm ); rtems_test_assert( start != 0 ); rtems_test_assert( now != 0 ); rtems_test_spin_for_ticks( interval ); puts( "_times( &end_tm ) -- OK" ); end = _times( &end_tm ); rtems_test_assert( end != 0 ); puts( "Check various values" ); difference = end - start; rtems_test_assert( difference >= interval ); rtems_test_assert( end_tm.tms_utime - start_tm.tms_utime >= interval ); rtems_test_assert( end_tm.tms_stime - start_tm.tms_stime >= interval ); rtems_test_assert( end_tm.tms_cutime == 0 ); rtems_test_assert( end_tm.tms_cstime == 0 ); puts( "*** END OF TEST TIMES 01 ***" ); rtems_test_exit(0); }