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

4.104.11
Last change on this file since b84f1fdc was b84f1fdc, checked in by Joel Sherrill <joel.sherrill@…>, on May 10, 2009 at 2:39:46 PM

2009-05-10 Joel Sherrill <joel.sherrill@…>

  • sp04/system.h, sp04/task1.c, sp04/tswitch.c, sp07/init.c, sp12/init.c, sp13/putbuff.c, sp13/system.h, sp13/task1.c, sp15/init.c, sp16/system.h, sp19/fptask.c, sp25/system.h, sp26/task1.c, sp27/init.c, sp28/init.c, sp29/init.c, sp31/task1.c, sp33/init.c, sp34/changepri.c, sp35/priinv.c, sp37/init.c, sp38/init.c, sp39/init.c, sp41/init.c, sp42/init.c, sp43/init.c, sp44/init.c, sp45/init.c, sp46/init.c, sp47/init.c, sp48/init.c, spfatal03/testcase.h, spfatal05/testcase.h, spfatal06/testcase.h, spfatal_support/system.h, spobjgetnext/init.c, spsize/getint.c, spsize/size.c: Fix warnings.
  • Property mode set to 100644
File size: 3.0 KB
Line 
1/*
2 *  Test for rtems_semaphore_flush
3 *
4 *  COPYRIGHT (c) 1989-2009.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#include <bsp.h>
15
16rtems_task Init (rtems_task_argument argument);
17void starttask(int arg);
18rtems_task subtask(rtems_task_argument arg);
19
20#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
21
22#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
23#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
24
25#define CONFIGURE_MAXIMUM_TASKS               6
26#define CONFIGURE_MAXIMUM_SEMAPHORES          1
27
28#define CONFIGURE_MICROSECONDS_PER_TICK       52429
29
30#define CONFIGURE_INIT
31
32#include <rtems/confdefs.h>
33
34#include <rtems/error.h>
35#include <stdio.h>
36#include <stdlib.h>
37
38#define NTASK 4
39
40rtems_id semaphore;
41volatile int flags[NTASK];
42
43rtems_task
44subtask (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
58void
59starttask (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
83rtems_task
84Init (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 TracBrowser for help on using the repository browser.