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

4.104.115
Last change on this file since b84f1fdc was b84f1fdc, checked in by Joel Sherrill <joel.sherrill@…>, on 05/10/09 at 14:39:46

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
RevLine 
[74db82a]1/*
2 *  Test for rtems_semaphore_flush
3 *
[b84f1fdc]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 *
[74db82a]11 *  $Id$
12 */
13
14#include <bsp.h>
15
16rtems_task Init (rtems_task_argument argument);
[b84f1fdc]17void starttask(int arg);
18rtems_task subtask(rtems_task_argument arg);
[74db82a]19
20#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
21
[df49c60]22#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
23#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
24
25#define CONFIGURE_MAXIMUM_TASKS               6
[c338ae2]26#define CONFIGURE_MAXIMUM_SEMAPHORES          1
[74db82a]27
28#define CONFIGURE_MICROSECONDS_PER_TICK       52429
29
30#define CONFIGURE_INIT
31
[e8064503]32#include <rtems/confdefs.h>
[74db82a]33
34#include <rtems/error.h>
35#include <stdio.h>
[18ee864]36#include <stdlib.h>
[74db82a]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,
[df49c60]68    RTEMS_MINIMUM_STACK_SIZE,
[74db82a]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  }
[b84f1fdc]76  sc = rtems_task_start (tid, subtask, (rtems_task_argument) arg);
[74db82a]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
[c338ae2]89  puts( "\n\n*** TEST 27 ***" );
90  puts("Testing semaphore flush");
[74db82a]91  sc = rtems_semaphore_create (
92    rtems_build_name ('S', 'E', 'M', 'F'),
93    0,
[c338ae2]94    RTEMS_LOCAL|
95      RTEMS_BINARY_SEMAPHORE|RTEMS_NO_INHERIT_PRIORITY|
96      RTEMS_NO_PRIORITY_CEILING|RTEMS_FIFO,
[74db82a]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  }
[c338ae2]117  printf ("Flushed all waiting tasks\n", NTASK );
118  puts( "*** END OF TEST 27 ***" );
119
[74db82a]120  exit (1);
121}
Note: See TracBrowser for help on using the repository browser.