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

4.104.115
Last change on this file since a5e620e8 was a5e620e8, checked in by Joel Sherrill <joel.sherrill@…>, on Jul 8, 2009 at 8:26:45 PM

2009-07-08 Joel Sherrill <joel.sherrill@…>

  • Makefile.am, configure.ac, sp27/Makefile.am, sp27/init.c, sp27/sp27.doc, sp27/sp27.scn: Rework sp27 so it can be reinstantiated as sp27a and test flushing both counting and binary semaphores. Reformatted.
  • sp27a/.cvsignore, sp27a/Makefile.am, sp27a/sp27a.doc, sp27a/sp27a.scn: New files.
  • Property mode set to 100644
File size: 3.3 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#include <tmacros.h>
16
17void starttask(int arg);
18rtems_task subtask(rtems_task_argument arg);
19
20#include <stdio.h>
21#include <stdlib.h>
22
23#define NTASK 4
24
25#if defined(USE_COUNTING_SEMAPHORE)
26  #define TEST_NAME                 "27a"
27  #define TEST_SEMAPHORE_TYPE       "counting"
28  #define TEST_SEMAPHORE_ATTRIBUTES RTEMS_DEFAULT_ATTRIBUTES
29#else
30  #define TEST_NAME                 "27"
31  #define TEST_SEMAPHORE_TYPE       "binary"
32  #define TEST_SEMAPHORE_ATTRIBUTES (RTEMS_LOCAL| \
33            RTEMS_BINARY_SEMAPHORE|RTEMS_NO_INHERIT_PRIORITY| \
34            RTEMS_NO_PRIORITY_CEILING|RTEMS_FIFO)
35#endif
36
37rtems_id semaphore;
38volatile int flags[NTASK];
39
40rtems_task subtask(
41  rtems_task_argument arg
42)
43{
44  rtems_status_code sc;
45
46  for (;;) {
47    flags[arg]++;
48    sc = rtems_semaphore_obtain(semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
49    if (sc == RTEMS_SUCCESSFUL)
50      puts("Obtained semaphore -- and should not have done so!");
51    else if (sc != RTEMS_UNSATISFIED)
52      printf("Can't get semaphore: %s\n", rtems_status_text(sc));
53  }
54}
55
56void starttask(
57  int arg
58)
59{
60  rtems_id tid;
61  rtems_status_code sc;
62  rtems_task_priority priority;
63
64  rtems_task_set_priority(RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &priority);
65  sc = rtems_task_create(rtems_build_name('S', 'R', 'V', arg + 'A'),
66    priority,
67    RTEMS_MINIMUM_STACK_SIZE,
68    RTEMS_PREEMPT|RTEMS_NO_TIMESLICE|RTEMS_NO_ASR|RTEMS_INTERRUPT_LEVEL(0),
69    RTEMS_NO_FLOATING_POINT|RTEMS_LOCAL,
70    &tid);
71  directive_failed( sc, "task create" );
72
73  sc = rtems_task_start(tid, subtask, (rtems_task_argument) arg);
74  directive_failed( sc, "task start" );
75}
76
77void doTest()
78{
79  rtems_status_code sc;
80  rtems_attribute   attr;
81  int               pass, i;
82
83  sc = rtems_semaphore_create(
84    rtems_build_name('S', 'E', 'M', 'F'),
85    0,
86    TEST_SEMAPHORE_ATTRIBUTES,
87    0,
88    &semaphore);
89  directive_failed( sc, "semaphore create" );
90
91  for (i = 0 ; i < NTASK ; i++)
92    flags[i] = 0;
93
94  for (i = 0 ; i < NTASK ; i++)
95    starttask(i);
96
97  for (pass = 1 ; pass < 10 ; pass++) {
98    rtems_task_wake_after(1);
99    for (i = 0 ; i < NTASK ; i++) {
100      if (flags[i] != pass)
101        printf("flags[%d] = %d -- expected %d\n", i, flags[i], pass);
102    }
103    sc = rtems_semaphore_flush(semaphore);
104    directive_failed( sc, "semaphore flush" );
105  }
106
107  printf("Flushed all waiting tasks\n", NTASK );
108}
109
110rtems_task Init(
111  rtems_task_argument ignored
112)
113{
114  puts( "\n\n*** TEST " TEST_NAME " ***" );
115  puts( "Testing " TEST_SEMAPHORE_TYPE " semaphore flush" ); 
116  doTest();
117  puts( "*** END OF TEST " TEST_NAME " ***" );
118
119  rtems_test_exit(0);
120}
121
122/**************** START OF CONFIGURATION INFORMATION ****************/
123
124#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
125
126#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
127#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
128
129#define CONFIGURE_MAXIMUM_TASKS               6
130#define CONFIGURE_MAXIMUM_SEMAPHORES          1
131
132#define CONFIGURE_INIT
133
134#include <rtems/confdefs.h>
135
136/****************  END OF CONFIGURATION INFORMATION  ****************/
137
Note: See TracBrowser for help on using the repository browser.