source: rtems/c/src/tests/sptests/sp27/init.c @ 8751d121

Last change on this file since 8751d121 was 8751d121, checked in by Joel Sherrill <joel.sherrill@…>, on May 29, 2003 at 7:08:38 PM

2003-05-29 Joel Sherrill <joel@…>

  • sp27/init.c, sp29/init.c, spsize/size.c: Removed warnings.
  • 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 <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.