Changeset a5e620e8 in rtems for testsuites/sptests/sp27/init.c


Ignore:
Timestamp:
Jul 8, 2009, 8:26:45 PM (12 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 5, master
Children:
299fc7a
Parents:
2962c99
Message:

2009-07-08 Joel Sherrill <joel.sherrill@…>

  • Makefile.am, configure.ac, sp27/Makefile.am, sp27/init.c, sp27/sp27.doc, sp27/sp27.scn: Rework sp27 so it can be reinstantiated as sp27a and test flushing both counting and binary semaphores. Reformatted.
  • sp27a/.cvsignore, sp27a/Makefile.am, sp27a/sp27a.doc, sp27a/sp27a.scn: New files.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • testsuites/sptests/sp27/init.c

    r2962c99 ra5e620e8  
    1313
    1414#include <bsp.h>
     15#include <tmacros.h>
    1516
    16 rtems_task Init (rtems_task_argument argument);
    1717void starttask(int arg);
    1818rtems_task subtask(rtems_task_argument arg);
     19
     20#include <stdio.h>
     21#include <stdlib.h>
     22
     23#define NTASK 4
     24
     25#if defined(USE_COUNTING_SEMAPHORE)
     26  #define TEST_NAME                 "27a"
     27  #define TEST_SEMAPHORE_TYPE       "counting"
     28  #define TEST_SEMAPHORE_ATTRIBUTES RTEMS_DEFAULT_ATTRIBUTES
     29#else
     30  #define TEST_NAME                 "27"
     31  #define TEST_SEMAPHORE_TYPE       "binary"
     32  #define TEST_SEMAPHORE_ATTRIBUTES (RTEMS_LOCAL| \
     33            RTEMS_BINARY_SEMAPHORE|RTEMS_NO_INHERIT_PRIORITY| \
     34            RTEMS_NO_PRIORITY_CEILING|RTEMS_FIFO)
     35#endif
     36
     37rtems_id semaphore;
     38volatile int flags[NTASK];
     39
     40rtems_task subtask(
     41  rtems_task_argument arg
     42)
     43{
     44  rtems_status_code sc;
     45
     46  for (;;) {
     47    flags[arg]++;
     48    sc = rtems_semaphore_obtain(semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
     49    if (sc == RTEMS_SUCCESSFUL)
     50      puts("Obtained semaphore -- and should not have done so!");
     51    else if (sc != RTEMS_UNSATISFIED)
     52      printf("Can't get semaphore: %s\n", rtems_status_text(sc));
     53  }
     54}
     55
     56void starttask(
     57  int arg
     58)
     59{
     60  rtems_id tid;
     61  rtems_status_code sc;
     62  rtems_task_priority priority;
     63
     64  rtems_task_set_priority(RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &priority);
     65  sc = rtems_task_create(rtems_build_name('S', 'R', 'V', arg + 'A'),
     66    priority,
     67    RTEMS_MINIMUM_STACK_SIZE,
     68    RTEMS_PREEMPT|RTEMS_NO_TIMESLICE|RTEMS_NO_ASR|RTEMS_INTERRUPT_LEVEL(0),
     69    RTEMS_NO_FLOATING_POINT|RTEMS_LOCAL,
     70    &tid);
     71  directive_failed( sc, "task create" );
     72
     73  sc = rtems_task_start(tid, subtask, (rtems_task_argument) arg);
     74  directive_failed( sc, "task start" );
     75}
     76
     77void doTest()
     78{
     79  rtems_status_code sc;
     80  rtems_attribute   attr;
     81  int               pass, i;
     82
     83  sc = rtems_semaphore_create(
     84    rtems_build_name('S', 'E', 'M', 'F'),
     85    0,
     86    TEST_SEMAPHORE_ATTRIBUTES,
     87    0,
     88    &semaphore);
     89  directive_failed( sc, "semaphore create" );
     90
     91  for (i = 0 ; i < NTASK ; i++)
     92    flags[i] = 0;
     93
     94  for (i = 0 ; i < NTASK ; i++)
     95    starttask(i);
     96
     97  for (pass = 1 ; pass < 10 ; pass++) {
     98    rtems_task_wake_after(1);
     99    for (i = 0 ; i < NTASK ; i++) {
     100      if (flags[i] != pass)
     101        printf("flags[%d] = %d -- expected %d\n", i, flags[i], pass);
     102    }
     103    sc = rtems_semaphore_flush(semaphore);
     104    directive_failed( sc, "semaphore flush" );
     105  }
     106
     107  printf("Flushed all waiting tasks\n", NTASK );
     108}
     109
     110rtems_task Init(
     111  rtems_task_argument ignored
     112)
     113{
     114  puts( "\n\n*** TEST " TEST_NAME " ***" );
     115  puts( "Testing " TEST_SEMAPHORE_TYPE " semaphore flush" );
     116  doTest();
     117  puts( "*** END OF TEST " TEST_NAME " ***" );
     118
     119  rtems_test_exit(0);
     120}
     121
     122/**************** START OF CONFIGURATION INFORMATION ****************/
    19123
    20124#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
     
    26130#define CONFIGURE_MAXIMUM_SEMAPHORES          1
    27131
    28 #define CONFIGURE_MICROSECONDS_PER_TICK       52429
    29 
    30132#define CONFIGURE_INIT
    31133
    32134#include <rtems/confdefs.h>
    33135
    34 #include <rtems/error.h>
    35 #include <stdio.h>
    36 #include <stdlib.h>
     136/****************  END OF CONFIGURATION INFORMATION  ****************/
    37137
    38 #define NTASK 4
    39 
    40 rtems_id semaphore;
    41 volatile int flags[NTASK];
    42 
    43 rtems_task
    44 subtask (rtems_task_argument arg)
    45 {
    46   rtems_status_code sc;
    47 
    48   for (;;) {
    49     flags[arg]++;
    50     sc = rtems_semaphore_obtain (semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
    51     if (sc == RTEMS_SUCCESSFUL)
    52       puts ("Obtained semaphore -- and should not have done so!");
    53     else if (sc != RTEMS_UNSATISFIED)
    54       printf ("Can't get semaphore: %s\n", rtems_status_text (sc));
    55   }
    56 }
    57 
    58 void
    59 starttask (int arg)
    60 {
    61   rtems_id tid;
    62   rtems_status_code sc;
    63   rtems_task_priority priority;
    64 
    65   rtems_task_set_priority (RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &priority);
    66   sc = rtems_task_create (rtems_build_name ('S', 'R', 'V', arg + 'A'),
    67     priority,
    68     RTEMS_MINIMUM_STACK_SIZE,
    69     RTEMS_PREEMPT|RTEMS_NO_TIMESLICE|RTEMS_NO_ASR|RTEMS_INTERRUPT_LEVEL(0),
    70     RTEMS_NO_FLOATING_POINT|RTEMS_LOCAL,
    71     &tid);
    72   if (sc != RTEMS_SUCCESSFUL) {
    73     printf ("Can't create task: %s\n", rtems_status_text (sc));
    74     rtems_task_suspend (RTEMS_SELF);
    75   }
    76   sc = rtems_task_start (tid, subtask, (rtems_task_argument) arg);
    77   if (sc != RTEMS_SUCCESSFUL) {
    78         printf ("Can't start task: %s\n", rtems_status_text (sc));
    79     rtems_task_suspend (RTEMS_SELF);
    80   }
    81 }
    82 
    83 rtems_task
    84 Init (rtems_task_argument ignored)
    85 {
    86   int pass, i;
    87   rtems_status_code sc;
    88 
    89   puts( "\n\n*** TEST 27 ***" );
    90   puts("Testing semaphore flush");
    91   sc = rtems_semaphore_create (
    92     rtems_build_name ('S', 'E', 'M', 'F'),
    93     0,
    94     RTEMS_LOCAL|
    95       RTEMS_BINARY_SEMAPHORE|RTEMS_NO_INHERIT_PRIORITY|
    96       RTEMS_NO_PRIORITY_CEILING|RTEMS_FIFO,
    97     0,
    98     &semaphore);
    99   if (sc != RTEMS_SUCCESSFUL) {
    100     printf ("Can't flush semaphore: %s\n", rtems_status_text (sc));
    101     exit (1);
    102   }
    103   for (i = 0 ; i < NTASK ; i++)
    104     starttask (i);
    105   for (pass = 1 ; pass < 10 ; pass++) {
    106     rtems_task_wake_after (1);
    107     for (i = 0 ; i < NTASK ; i++) {
    108       if (flags[i] != pass)
    109         printf ("flags[%d] = %d -- expected %d\n", i, flags[i], pass);
    110     }
    111     sc = rtems_semaphore_flush (semaphore);
    112     if (sc != RTEMS_SUCCESSFUL) {
    113       printf ("Can't flush semaphore: %s\n", rtems_status_text (sc));
    114       exit (1);
    115     }
    116   }
    117   printf ("Flushed all waiting tasks\n", NTASK );
    118   puts( "*** END OF TEST 27 ***" );
    119 
    120   exit (1);
    121 }
Note: See TracChangeset for help on using the changeset viewer.