source: rtems/testsuites/sptests/sp27/init.c @ c338ae2

4.104.114.84.9
Last change on this file since c338ae2 was c338ae2, checked in by Joel Sherrill <joel.sherrill@…>, on Nov 20, 2006 at 11:18:45 PM

2006-11-20 Joel Sherrill <joel@…>

  • sp27/init.c, sp27/sp27.scn: Correct configured number of semaphores and make output more compliant with other tests.
  • Property mode set to 100644
File size: 2.7 KB
Line 
1/*
2 *  Test for rtems_semaphore_flush
3 *
4 *  $Id$
5 */
6
7#include <bsp.h>
8
9rtems_task Init (rtems_task_argument argument);
10
11#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
12
13#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
14#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
15
16#define CONFIGURE_MAXIMUM_TASKS               6
17#define CONFIGURE_MAXIMUM_SEMAPHORES          1
18
19#define CONFIGURE_MICROSECONDS_PER_TICK       52429
20
21#define CONFIGURE_INIT
22
23#include <rtems/confdefs.h>
24
25#include <rtems/error.h>
26#include <stdio.h>
27#include <stdlib.h>
28
29#define NTASK 4
30
31rtems_id semaphore;
32volatile int flags[NTASK];
33
34rtems_task
35subtask (rtems_task_argument arg)
36{
37  rtems_status_code sc;
38
39  for (;;) {
40    flags[arg]++;
41    sc = rtems_semaphore_obtain (semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
42    if (sc == RTEMS_SUCCESSFUL)
43      puts ("Obtained semaphore -- and should not have done so!");
44    else if (sc != RTEMS_UNSATISFIED)
45      printf ("Can't get semaphore: %s\n", rtems_status_text (sc));
46  }
47}
48
49void
50starttask (int arg)
51{
52  rtems_id tid;
53  rtems_status_code sc;
54  rtems_task_priority priority;
55
56  rtems_task_set_priority (RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &priority);
57  sc = rtems_task_create (rtems_build_name ('S', 'R', 'V', arg + 'A'),
58    priority,
59    RTEMS_MINIMUM_STACK_SIZE,
60    RTEMS_PREEMPT|RTEMS_NO_TIMESLICE|RTEMS_NO_ASR|RTEMS_INTERRUPT_LEVEL(0),
61    RTEMS_NO_FLOATING_POINT|RTEMS_LOCAL,
62    &tid);
63  if (sc != RTEMS_SUCCESSFUL) {
64    printf ("Can't create task: %s\n", rtems_status_text (sc));
65    rtems_task_suspend (RTEMS_SELF);
66  }
67  sc = rtems_task_start (tid, subtask, arg);
68  if (sc != RTEMS_SUCCESSFUL) {
69        printf ("Can't start task: %s\n", rtems_status_text (sc));
70    rtems_task_suspend (RTEMS_SELF);
71  }
72}
73
74rtems_task
75Init (rtems_task_argument ignored)
76{
77  int pass, i;
78  rtems_status_code sc;
79
80  puts( "\n\n*** TEST 27 ***" );
81  puts("Testing semaphore flush"); 
82  sc = rtems_semaphore_create (
83    rtems_build_name ('S', 'E', 'M', 'F'),
84    0,
85    RTEMS_LOCAL|
86      RTEMS_BINARY_SEMAPHORE|RTEMS_NO_INHERIT_PRIORITY|
87      RTEMS_NO_PRIORITY_CEILING|RTEMS_FIFO,
88    0,
89    &semaphore);
90  if (sc != RTEMS_SUCCESSFUL) {
91    printf ("Can't flush semaphore: %s\n", rtems_status_text (sc));
92    exit (1);
93  }
94  for (i = 0 ; i < NTASK ; i++)
95    starttask (i);
96  for (pass = 1 ; pass < 10 ; pass++) {
97    rtems_task_wake_after (1);
98    for (i = 0 ; i < NTASK ; i++) {
99      if (flags[i] != pass)
100        printf ("flags[%d] = %d -- expected %d\n", i, flags[i], pass);
101    }
102    sc = rtems_semaphore_flush (semaphore);
103    if (sc != RTEMS_SUCCESSFUL) {
104      printf ("Can't flush semaphore: %s\n", rtems_status_text (sc));
105      exit (1);
106    }
107  }
108  printf ("Flushed all waiting tasks\n", NTASK );
109  puts( "*** END OF TEST 27 ***" );
110
111  exit (1);
112}
Note: See TracBrowser for help on using the repository browser.