source: rtems/testsuites/sptests/sp27/init.c @ 70bb55f

4.104.114.84.95
Last change on this file since 70bb55f was e8064503, checked in by Ralf Corsepius <ralf.corsepius@…>, on 04/01/04 at 15:16:30
  • sp01/system.h: Include <rtems/confdefs.h> instead of <confdefs.h>.
  • sp02/system.h: Include <rtems/confdefs.h> instead of <confdefs.h>.
  • sp03/system.h: Include <rtems/confdefs.h> instead of <confdefs.h>.
  • sp04/system.h: Include <rtems/confdefs.h> instead of <confdefs.h>.
  • sp05/system.h: Include <rtems/confdefs.h> instead of <confdefs.h>.
  • sp06/system.h: Include <rtems/confdefs.h> instead of <confdefs.h>.
  • sp07/system.h: Include <rtems/confdefs.h> instead of <confdefs.h>.
  • sp08/system.h: Include <rtems/confdefs.h> instead of <confdefs.h>.
  • sp09/system.h: Include <rtems/confdefs.h> instead of <confdefs.h>.
  • sp11/system.h: Include <rtems/confdefs.h> instead of <confdefs.h>.
  • sp12/system.h: Include <rtems/confdefs.h> instead of <confdefs.h>.
  • sp13/system.h: Include <rtems/confdefs.h> instead of <confdefs.h>.
  • sp14/system.h: Include <rtems/confdefs.h> instead of <confdefs.h>.
  • sp15/system.h: Include <rtems/confdefs.h> instead of <confdefs.h>.
  • sp16/system.h: Include <rtems/confdefs.h> instead of <confdefs.h>.
  • sp17/system.h: Include <rtems/confdefs.h> instead of <confdefs.h>.
  • sp19/system.h: Include <rtems/confdefs.h> instead of <confdefs.h>.
  • sp20/system.h: Include <rtems/confdefs.h> instead of <confdefs.h>.
  • sp21/system.h: Include <rtems/confdefs.h> instead of <confdefs.h>.
  • sp22/system.h: Include <rtems/confdefs.h> instead of <confdefs.h>.
  • sp23/system.h: Include <rtems/confdefs.h> instead of <confdefs.h>.
  • sp24/system.h: Include <rtems/confdefs.h> instead of <confdefs.h>.
  • sp25/system.h: Include <rtems/confdefs.h> instead of <confdefs.h>.
  • sp26/system.h: Include <rtems/confdefs.h> instead of <confdefs.h>.
  • sp27/init.c: Include <rtems/confdefs.h> instead of <confdefs.h>.
  • sp28/init.c: Include <rtems/confdefs.h> instead of <confdefs.h>.
  • sp29/init.c: Include <rtems/confdefs.h> instead of <confdefs.h>.
  • sp30/system.h: Include <rtems/confdefs.h> instead of <confdefs.h>.
  • sp31/system.h: Include <rtems/confdefs.h> instead of <confdefs.h>.
  • sp32/init.c: Include <rtems/confdefs.h> instead of <confdefs.h>.
  • spfatal/system.h: Include <rtems/confdefs.h> instead of <confdefs.h>.
  • spsize/system.h: Include <rtems/confdefs.h> instead of <confdefs.h>.
  • Property mode set to 100644
File size: 2.6 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
18#define CONFIGURE_MICROSECONDS_PER_TICK       52429
19
20#define CONFIGURE_INIT
21
22#include <rtems/confdefs.h>
23
24#include <rtems/error.h>
25#include <stdio.h>
26#include <stdlib.h>
27
28#define NTASK 4
29
30rtems_id semaphore;
31volatile int flags[NTASK];
32
33rtems_task
34subtask (rtems_task_argument arg)
35{
36  rtems_status_code sc;
37
38  for (;;) {
39    flags[arg]++;
40    sc = rtems_semaphore_obtain (semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
41    if (sc == RTEMS_SUCCESSFUL)
42      puts ("Obtained semaphore -- and should not have done so!");
43    else if (sc != RTEMS_UNSATISFIED)
44      printf ("Can't get semaphore: %s\n", rtems_status_text (sc));
45  }
46}
47
48void
49starttask (int arg)
50{
51  rtems_id tid;
52  rtems_status_code sc;
53  rtems_task_priority priority;
54
55  rtems_task_set_priority (RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &priority);
56  sc = rtems_task_create (rtems_build_name ('S', 'R', 'V', arg + 'A'),
57    priority,
58    RTEMS_MINIMUM_STACK_SIZE,
59    RTEMS_PREEMPT|RTEMS_NO_TIMESLICE|RTEMS_NO_ASR|RTEMS_INTERRUPT_LEVEL(0),
60    RTEMS_NO_FLOATING_POINT|RTEMS_LOCAL,
61    &tid);
62  if (sc != RTEMS_SUCCESSFUL) {
63    printf ("Can't create task: %s\n", rtems_status_text (sc));
64    rtems_task_suspend (RTEMS_SELF);
65  }
66  sc = rtems_task_start (tid, subtask, arg);
67  if (sc != RTEMS_SUCCESSFUL) {
68        printf ("Can't start task: %s\n", rtems_status_text (sc));
69    rtems_task_suspend (RTEMS_SELF);
70  }
71}
72
73rtems_task
74Init (rtems_task_argument ignored)
75{
76  int pass, i;
77  rtems_status_code sc;
78
79  puts("**** Semaphore flush test ****");
80  sc = rtems_semaphore_create (
81    rtems_build_name ('S', 'E', 'M', 'F'),
82    0,
83    RTEMS_LOCAL|RTEMS_BINARY_SEMAPHORE|RTEMS_NO_INHERIT_PRIORITY|RTEMS_NO_PRIORITY_CEILING|RTEMS_FIFO,
84    0,
85    &semaphore);
86  if (sc != RTEMS_SUCCESSFUL) {
87    printf ("Can't flush semaphore: %s\n", rtems_status_text (sc));
88    exit (1);
89  }
90  for (i = 0 ; i < NTASK ; i++)
91    starttask (i);
92  for (pass = 1 ; pass < 10 ; pass++) {
93    rtems_task_wake_after (1);
94    for (i = 0 ; i < NTASK ; i++) {
95      if (flags[i] != pass)
96        printf ("flags[%d] = %d -- expected %d\n", i, flags[i], pass);
97    }
98    sc = rtems_semaphore_flush (semaphore);
99    if (sc != RTEMS_SUCCESSFUL) {
100      printf ("Can't flush semaphore: %s\n", rtems_status_text (sc));
101      exit (1);
102    }
103  }
104  puts ("**** Semaphore flush test succeeded ****");
105  exit (1);
106}
Note: See TracBrowser for help on using the repository browser.