Changeset 0e4232b in rtems


Ignore:
Timestamp:
Jan 18, 2008, 4:33:35 PM (12 years ago)
Author:
Jennifer Averett <Jennifer.Averett@…>
Branches:
4.10, 4.11, 4.9, master
Children:
0c76166
Parents:
c3925db
Message:

2008-01-18 Jennifer Averett <jennifer.averett@…>

  • psx01/init.c, psxmsgq01/init.c, psxtimer01/psxtimer.c, psxtimer01/psxtimer01.scn, psxtimer02/psxtimer.c:
Location:
testsuites/psxtests
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • testsuites/psxtests/ChangeLog

    rc3925db r0e4232b  
     12008-01-18      Jennifer Averett <jennifer.averett@OARcorp.com>
     2
     3        * psx01/init.c, psxmsgq01/init.c, psxtimer01/psxtimer.c,
     4        psxtimer01/psxtimer01.scn, psxtimer02/psxtimer.c:
     5
    162007-12-20      Joel Sherrill <joel.sherrill@oarcorp.com>
    27
  • testsuites/psxtests/psx01/init.c

    rc3925db r0e4232b  
    11/*
    2  *  COPYRIGHT (c) 1989-1999.
     2 *  COPYRIGHT (c) 1989-2008.
    33 *  On-Line Applications Research Corporation (OAR).
    44 *
     
    5353  /* error cases in clock_gettime and clock_settime */
    5454
     55  puts( "Init: clock_gettime - EINVAL (NULL timespec)" );
     56  status = clock_gettime( CLOCK_REALTIME, NULL );
     57  assert( status == -1 );
     58  assert( errno == EINVAL );
     59
    5560  puts( "Init: clock_gettime - EINVAL (invalid clockid)" );
    56   status = clock_settime( -1, &tv );
     61  status = clock_gettime( -1, &tv );
    5762  assert( status == -1 );
    5863  assert( errno == EINVAL );
     
    103108  remaining = sleep( 3 );
    104109  assert( !remaining );
    105 
     110 
    106111  /* print new times to make sure it has changed and we can get the realtime */
     112  status = clock_gettime( CLOCK_PROCESS_CPUTIME, &tv );
     113  assert( !status );
     114  printf("Time since boot: (%d, %d)\n", tv.tv_sec,tv.tv_nsec );
    107115
    108116  status = clock_gettime( CLOCK_REALTIME, &tv );
  • testsuites/psxtests/psxmsgq01/init.c

    rc3925db r0e4232b  
    11/*
    2  *  COPYRIGHT (c) 1989-1999.
     2 *  COPYRIGHT (c) 1989-2008.
    33 *  On-Line Applications Research Corporation (OAR).
    44 *
     
    4444} Test_queue_type;
    4545
    46 Test_queue_type Test_q[ NUMBER_OF_TEST_QUEUES ] =
     46Test_queue_type Test_q[ NUMBER_OF_TEST_QUEUES + 1 ] =
    4747{
    4848  { 0, 0, "Qread",    ( O_CREAT | O_RDONLY | O_NONBLOCK ), MAXMSG, MSGSIZE, 0 },
     
    5252  { 0, 4, "Qdefault", ( O_CREAT | O_RDWR )               , 10,     16,      0 },
    5353  { 0, 5, "mq6",      ( O_CREAT | O_WRONLY | O_NONBLOCK ), MAXMSG, MSGSIZE, 0 },
     54  { 0, 6, "Qblock",   (           O_RDWR )               , MAXMSG, MSGSIZE, 0 },
    5455};
    5556
     
    131132  puts( "Init: Open Test Queues" );
    132133
    133   for( que = 0; que < NUMBER_OF_TEST_QUEUES; que++ ) {
     134  for( que = 0; que < NUMBER_OF_TEST_QUEUES+1; que++ ) {
    134135
    135136    tq = &Test_q[ que ];
     
    142143  }
    143144
     145  status = mq_close( Test_q[NUMBER_OF_TEST_QUEUES].mq );
     146  fatal_posix_service_status( status, 0, "mq_close duplicate message queue");
    144147  status = mq_close( Test_q[CLOSED].mq );
    145148  fatal_posix_service_status( status, 0, "mq_close message queue");
     
    950953   * XXX setup notification
    951954   */
    952 
    953955  printf( "_____mq_notify - notify when %s gets a message\n",RW_NAME);
    954956  status = mq_notify( Test_q[RW_QUEUE].mq, &event );
  • testsuites/psxtests/psxtimer01/psxtimer.c

    rc3925db r0e4232b  
    2828#include <time.h>     /* time facilities */
    2929#include <stdio.h>    /* console facilities */
    30 
     30#include <rtems/score/timespec.h>
    3131
    3232
     
    3535struct periodic_params {
    3636   struct timespec period;
     37   int count;       /* Number of iterations to run */
    3738   int signo;       /* signal number */
    3839   int id;          /* task identification */
     
    4748   pthread_cond_t  sync;
    4849   int updated;
    49    int x;
    5050 };
    5151
    5252struct shared_data data;
    5353
     54void StopTimer(
     55  timer_t  timer_id,
     56  struct   itimerspec *timerdata
     57)
     58{
     59   timerdata->it_value.tv_sec  = 0;
     60   timerdata->it_value.tv_nsec  = 0;
     61   if (timer_settime(timer_id,POSIX_TIMER_RELATIVE,timerdata,NULL) == -1) {
     62     perror ("Error in timer setting\n");
     63     pthread_exit ((void *) -1);
     64   }
     65}
     66 
    5467/* task A  */
    55 
    5668void * task_a (void *arg)
    5769{
     
    5971   int      my_sig, received_sig;
    6072   struct   itimerspec timerdata;
     73   struct   itimerspec timergetdata;
    6174   timer_t  timer_id;
    6275   time_t   clock;
    6376   struct   sigevent event;
    6477   sigset_t set;
    65 
    66    my_period = ((struct periodic_params*) arg)->period;
    67    my_sig    = ((struct periodic_params*) arg)->signo;
     78   struct periodic_params *params;
     79
     80   params = arg;
     81   my_period = params->period;
     82   my_sig    = params->signo;
    6883
    6984   /* timer create */
     
    8398   timerdata.it_interval = my_period;
    8499   timerdata.it_value    = my_period;
    85    if (timer_settime(timer_id, 0, &timerdata, NULL) == -1) {
     100   if (timer_settime(timer_id,POSIX_TIMER_RELATIVE,&timerdata,&timergetdata) == -1) {
    86101     perror ("Error in timer setting\n");
    87102     pthread_exit ((void *) -1);
    88103   }
     104   printf(
     105    "task A: timer_settime - value=%d:%d interval=%d:%d\n",
     106    timergetdata.it_value.tv_sec, timergetdata.it_value.tv_nsec,
     107    timergetdata.it_interval.tv_sec, timergetdata.it_interval.tv_nsec
     108  );
     109   
    89110
    90111   /* periodic activity */
     
    93114       perror ("Error in sigwait\n");
    94115     }
     116     if (timer_gettime(timer_id, &timerdata) == -1) {
     117       perror ("Error in timer_gettime\n");
     118       pthread_exit ((void *) -1);
     119     }
     120     if (! _Timespec_Equal_to( &timerdata.it_value, &my_period )){
     121       perror ("Error in Task A timer_gettime\n");
     122     }
    95123     clock = time(NULL);
    96      printf("Executing task A %s", ctime(&clock));
     124     printf("Executing task A with count = %2i %s", params->count, ctime(&clock));
     125     params->count--;
     126     if (params->count == 0)
     127       StopTimer(timer_id, &timerdata);
    97128   }
    98129   return NULL;
     
    110141   struct   sigevent event;
    111142   sigset_t set;
    112 
    113    int x;   /* value to be copied to the shared datum */
    114 
    115    my_period = ((struct periodic_params*) arg)->period;
    116    my_sig    = ((struct periodic_params*) arg)->signo;
    117 
    118    x = 1;
     143   struct periodic_params *params;
     144
     145   params = arg;
     146   my_period = params->period;
     147   my_sig    = params->signo;
     148
    119149
    120150   /* timer create */
     
    133163   /* set the timer in periodic mode */
    134164   timerdata.it_interval = my_period;
    135    timerdata.it_value    = my_period;
    136    if (timer_settime(timer_id, 0, &timerdata, NULL) == -1) {
     165   timerdata.it_value = _TOD_Now;
     166   _Timespec_Add_to( &timerdata.it_value, &my_period);
     167   if (timer_settime(timer_id,TIMER_ABSTIME,&timerdata,NULL) == -1) {
    137168     perror ("Error in timer setting\n");
    138169     pthread_exit ((void *) -1);
    139    }
     170   }     
    140171
    141172   /* periodic activity */
     
    145176       pthread_exit ((void *) -1);
    146177     }
     178 
     179     if (timer_gettime(timer_id, &timerdata) == -1) {
     180       perror ("Error in timer_gettime\n");
     181       pthread_exit ((void *) -1);
     182     }
     183     if (! _Timespec_Equal_to( &timerdata.it_value, &my_period) ){
     184       perror ("Error in Task B timer_gettime\n");
     185     }
     186
    147187     pthread_mutex_lock (&data.mutex);
    148188     clock = time(NULL);
    149      printf("Executing task B with x = %i %s", x, ctime(&clock));
    150      data.x = x;
     189     printf("Executing task B with count = %2i %s\n",
     190       params->count, ctime(&clock)
     191     );
    151192     data.updated = TRUE;
    152193     pthread_cond_signal  (&data.sync);
    153194     pthread_mutex_unlock (&data.mutex);
    154      x++;
     195     params->count--;
     196     if (params->count == 0)
     197       StopTimer(timer_id, &timerdata);
    155198   }
    156199   return NULL;
     
    161204void * task_c (void *arg)
    162205{
     206   int      count;
    163207   struct   timespec my_period;
    164208   int      my_sig, received_sig;
    165209   struct   itimerspec timerdata;
     210   struct   itimerspec timergetdata;
    166211   timer_t  timer_id;
    167212   time_t   clock;
    168213   struct   sigevent event;
    169214   sigset_t set;
    170 
    171    int x;   /* value to be copied to the shared datum */
    172 
    173    my_period = ((struct periodic_params*) arg)->period;
    174    my_sig    = ((struct periodic_params*) arg)->signo;
    175 
    176    x = 0;
     215   struct   periodic_params *params;
     216
     217   params = arg;
     218   my_period = params->period;
     219   my_sig    = params->signo;
    177220
    178221   /* timer create */
     
    192235   timerdata.it_interval = my_period;
    193236   timerdata.it_value    = my_period;
    194    if (timer_settime(timer_id, 0, &timerdata, NULL) == -1) {
     237   if (timer_settime(timer_id,POSIX_TIMER_RELATIVE,&timerdata,NULL) == -1) {
    195238     perror ("Error in timer setting\n");
    196239     pthread_exit ((void *) -1);
     
    198241
    199242   /* periodic activity */
    200    while(1) {
     243   for (count=0 ; ; count++) {
    201244      if (sigwait(&set,&received_sig) == -1) {
    202245       perror ("Error in sigwait\n");
    203246       pthread_exit ((void *) -1);
    204247     }
     248     if (timer_gettime(timer_id, &timerdata) == -1) {
     249       perror ("Error in timer_gettime\n");
     250       pthread_exit ((void *) -1);
     251     }
     252     if (! _Timespec_Equal_to( &timerdata.it_value, &my_period) ){
     253       perror ("Error in Task C timer_gettime\n");
     254     }
    205255     pthread_mutex_lock (&data.mutex);
    206256     while (data.updated == FALSE) {
    207257       pthread_cond_wait (&data.sync,&data.mutex);
    208258     }
    209      x = data.x;
    210259     clock = time(NULL);
    211      printf("Executing task C with x = %i %s", x, ctime(&clock));
     260     printf("Executing task C with count = %2i %s\n",
     261       params->count, ctime(&clock)
     262     );
     263
     264     if ( count && (count % 5) == 0 ) {
     265       int overruns = 0;
     266       sleep(1);
     267       overruns = timer_getoverrun( timer_id );
     268       printf( "task C: timer_getoverrun - overruns=%d\n", overruns );
     269     
     270       if (timer_gettime(timer_id, &timergetdata) == -1) {
     271         perror ("Error in timer setting\n");
     272         pthread_exit ((void *) -1);
     273       }
     274       printf(
     275         "task C: timer_gettime - %d:%d remaining from %d:%d\n",
     276         timergetdata.it_value.tv_sec, timergetdata.it_value.tv_nsec,
     277         timergetdata.it_interval.tv_sec, timergetdata.it_interval.tv_nsec
     278       );
     279     }
     280
    212281     pthread_mutex_unlock (&data.mutex);
     282     params->count--;
     283     if (params->count == 0)
     284       StopTimer(timer_id, &timerdata);
    213285   }
    214286   return NULL;
    215287}
    216 
    217288
    218289/* main */
     
    235306
    236307   data.updated = FALSE;
    237    data.x = 0;
    238308
    239309   /* mask signal */
     
    268338
    269339   /* set explicit schedule for every task */
    270    if (pthread_attr_setinheritsched (&attr,
    271      PTHREAD_EXPLICIT_SCHED) != 0) {
     340   if (pthread_attr_setinheritsched (&attr, PTHREAD_EXPLICIT_SCHED) != 0) {
    272341      perror("Error in attribute inheritsched\n");
    273342   }
    274343
    275344   /* set task independent (join will not use) */
    276    if (pthread_attr_setdetachstate (&attr,
    277      PTHREAD_CREATE_DETACHED) != 0) {
     345   if (pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED) != 0) {
    278346      perror ("Error in attribute detachstate\n");
    279347   }
     
    281349   /* schedule policy POSIX_FIFO (priority preemtive and FIFO within the same
    282350      priority) */
    283    if (pthread_attr_setschedpolicy (&attr,
    284      SCHED_FIFO) != 0) {
     351   if (pthread_attr_setschedpolicy (&attr, SCHED_FIFO) != 0) {
    285352      perror ("Error in attribute setschedpolicy\n");
    286353    }
     
    297364   params_a.period.tv_sec  = 1;         /* seconds */
    298365   params_a.period.tv_nsec = 000000000; /* nanoseconds */
     366   params_a.count          = 20;
    299367   params_a.signo = SIGALRM;
    300368   if (pthread_create (&ta, &attr, task_a, &params_a) != 0 ) {
     
    312380   params_b.period.tv_sec  = 2;         /* seconds */
    313381   params_b.period.tv_nsec = 000000000; /* nanoseconds */
     382   params_b.count          = 10;
    314383   params_b.signo = SIGALRM;
    315384   if (pthread_create (&tb, &attr, task_b, &params_b) != 0) {
     
    327396   params_c.period.tv_sec  = 3;         /* seconds */
    328397   params_c.period.tv_nsec = 000000000; /* nanoseconds */
     398   params_c.count          = 6;
    329399   params_c.signo = SIGALRM;
    330400   if (pthread_create (&tc, &attr, task_c, &params_c) != 0) {
     
    333403
    334404
    335    /* execute 20 seconds and finish */
    336    sleep (20);
     405   /* execute 25 seconds and finish */
     406   sleep (25);
    337407   puts( "*** END OF POSIX Timers Test 01 ***" );
    338408   rtems_test_exit (0);
  • testsuites/psxtests/psxtimer01/psxtimer01.scn

    rc3925db r0e4232b  
    11*** POSIX Timers Test 01 ***
     2task A: timer_settime - value=0:0 interval=0:0
    23Executing task A Fri Jan  1 00:00:01 1988
    34Executing task B with x = 1 Fri Jan  1 00:00:02 1988
     
    3334Executing task C with x = 9 Fri Jan  1 00:00:18 1988
    3435Executing task A Fri Jan  1 00:00:18 1988
     36task C: timer_getoverrun - overruns=0
     37task C: timer_gettime - 2:0 remaining from 3:0
    3538Executing task A Fri Jan  1 00:00:19 1988
    3639Executing task B with x = 10 Fri Jan  1 00:00:20 1988
  • testsuites/psxtests/psxtimer02/psxtimer.c

    rc3925db r0e4232b  
    9393  fatal_posix_service_status_errno( status, EINVAL, "bad itimer value #2" );
    9494
     95  itimer.it_value = _TOD_Now;
     96  itimer.it_value.tv_sec = itimer.it_value.tv_sec - 1;
     97  puts( "timer_settime - bad itimer value - previous time - EINVAL" );
     98  status = timer_settime( timer, TIMER_ABSTIME, &itimer, NULL );
     99  fatal_posix_service_status_errno( status, EINVAL, "bad itimer value #3" );
     100
    95101  itimer.it_value.tv_nsec = 0;
    96102  puts( "timer_settime - bad clock value - EINVAL" );
Note: See TracChangeset for help on using the changeset viewer.