source: rtems/testsuites/sptests/sp29/init.c @ a986c075

4.104.115
Last change on this file since a986c075 was a986c075, checked in by Joel Sherrill <joel.sherrill@…>, on 12/14/08 at 18:36:00

2008-12-14 Joel Sherrill <joel.sherrill@…>

  • sp07/init.c, sp12/init.c, sp12/pridrv.c, sp12/pritask.c, sp12/system.h, sp16/system.h, sp25/system.h, sp26/task1.c, sp28/init.c, sp29/init.c, sp35/priinv.c, sp42/init.c: Run all tests successfully with maxixum number of priorities as 16 instead of 256. This was done by temporarily modifying the score priority.h maximum. This allowed testing of all API code to ensure that it worked properly with a reduced number of priorities. Most modifications were to switch from hard-coded maximum to using the API provided methods to determine maximum number of priority levels.
  • Property mode set to 100644
File size: 6.1 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_EXTRA_TASK_STACKS RTEMS_MINIMUM_STACK_SIZE
12
13#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
14
15#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
16#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
17#define CONFIGURE_MAXIMUM_TASKS             2
18#define CONFIGURE_MAXIMUM_SEMAPHORES        2
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
28rtems_interval ticksPerSecond;
29
30rtems_task
31subtask (rtems_task_argument arg)
32{
33        rtems_status_code sc;
34        rtems_id sem = (rtems_id)arg;
35
36        for (;;) {
37                rtems_task_wake_after (ticksPerSecond * 2);
38
39                sc = rtems_semaphore_release (sem);
40                if (sc != RTEMS_SUCCESSFUL)
41                        printf ("%d: Can't release semaphore: %s\n", __LINE__, rtems_status_text (sc));
42        }
43}
44
45void
46startTask (rtems_id arg)
47{
48        rtems_id tid;
49        rtems_status_code sc;
50
51        sc = rtems_task_create (rtems_build_name ('S', 'R', 'V', 'A'),
52                RTEMS_MAXIMUM_PRIORITY - 1,
53                RTEMS_MINIMUM_STACK_SIZE * 2,
54                RTEMS_PREEMPT|RTEMS_NO_TIMESLICE|RTEMS_NO_ASR|RTEMS_INTERRUPT_LEVEL(0),
55                RTEMS_NO_FLOATING_POINT|RTEMS_LOCAL,
56                &tid);
57        if (sc != RTEMS_SUCCESSFUL) {
58                printf ("Can't create task: %s\n", rtems_status_text (sc));
59                rtems_task_suspend (RTEMS_SELF);
60        }
61        sc = rtems_task_start (tid, subtask, arg);
62        if (sc != RTEMS_SUCCESSFUL) {
63                printf ("Can't start task: %s\n", rtems_status_text (sc));
64                rtems_task_suspend (RTEMS_SELF);
65        }
66}
67
68rtems_task Init (rtems_task_argument ignored)
69{
70        int i;
71        rtems_id semrec, semnorec;
72        rtems_status_code sc;
73        rtems_interval then, now;
74
75        puts( "*** SP29 - SIMPLE SEMAPHORE TEST ***" );
76        puts( "This test only prints on errors." );
77
78        sc = rtems_clock_get (RTEMS_CLOCK_GET_TICKS_PER_SECOND, &ticksPerSecond);
79        if (sc != RTEMS_SUCCESSFUL) {
80                printf ("Can't get ticks per second: %s\n", rtems_status_text (sc));
81                exit (1);
82        }
83        sc = rtems_semaphore_create (rtems_build_name ('S', 'M', 'r', 'c'),
84                1,
85                RTEMS_PRIORITY|RTEMS_BINARY_SEMAPHORE|RTEMS_INHERIT_PRIORITY |RTEMS_NO_PRIORITY_CEILING|RTEMS_LOCAL,
86                0,
87                &semrec);
88        if (sc != RTEMS_SUCCESSFUL) {
89                printf ("%d: Can't create recursive-lock semaphore: %s\n", __LINE__, rtems_status_text (sc));
90                exit (1);
91        }
92        sc = rtems_semaphore_create (rtems_build_name ('S', 'M', 'n', 'c'),
93                1,
94                RTEMS_PRIORITY|RTEMS_SIMPLE_BINARY_SEMAPHORE|RTEMS_INHERIT_PRIORITY |RTEMS_NO_PRIORITY_CEILING|RTEMS_LOCAL,
95                0,
96                &semnorec);
97        if (sc != RTEMS_SUCCESSFUL) {
98                printf ("%d: Can't create non-recursive-lock semaphore: %s\n", __LINE__, rtems_status_text (sc));
99                exit (1);
100        }
101
102        sc = rtems_semaphore_obtain (semrec, RTEMS_NO_WAIT, 0);
103        if (sc != RTEMS_SUCCESSFUL) {
104                printf ("%d: Can't obtain recursive-lock semaphore: %s\n", __LINE__, rtems_status_text (sc));
105        }
106        sc = rtems_semaphore_obtain (semrec, RTEMS_NO_WAIT, 0);
107        if (sc != RTEMS_SUCCESSFUL) {
108                printf ("%d: Can't reobtain recursive-lock semaphore: %s\n", __LINE__, rtems_status_text (sc));
109        }
110
111        sc = rtems_semaphore_obtain (semnorec, RTEMS_NO_WAIT, 0);
112        if (sc != RTEMS_SUCCESSFUL) {
113                printf ("%d: Can't obtain non-recursive-lock semaphore: %s\n", __LINE__, rtems_status_text (sc));
114        }
115        sc = rtems_semaphore_obtain (semnorec, RTEMS_NO_WAIT, 0);
116        if (sc == RTEMS_SUCCESSFUL) {
117                printf ("%d: Reobtain non-recursive-lock semaphore -- and should not have.\n", __LINE__);
118        }
119
120        sc = rtems_semaphore_release (semnorec);
121        if (sc != RTEMS_SUCCESSFUL) {
122                printf ("%d: Can't release non-recursive-lock semaphore: %s\n", __LINE__, rtems_status_text (sc));
123        }
124        sc = rtems_semaphore_release (semnorec);
125        if (sc != RTEMS_SUCCESSFUL) {
126                printf ("%d: Can't rerelease non-recursive-lock semaphore: %s\n", __LINE__, rtems_status_text (sc));
127        }
128        sc = rtems_semaphore_obtain (semnorec, RTEMS_NO_WAIT, 0);
129        if (sc != RTEMS_SUCCESSFUL) {
130                printf ("%d: Can't obtain non-recursive-lock semaphore: %s\n", __LINE__, rtems_status_text (sc));
131        }
132        sc = rtems_semaphore_obtain (semnorec, RTEMS_NO_WAIT, 0);
133        if (sc == RTEMS_SUCCESSFUL) {
134                printf ("%d: Reobtain non-recursive-lock semaphore -- and should not have.\n", __LINE__);
135        }
136        else if (sc != RTEMS_UNSATISFIED) {
137                printf ("%d: Reobtain non-recursive-lock semaphore failed, but error is %d (%s), not RTEMS_UNSATISFIED.\n", __LINE__, sc, rtems_status_text (sc));
138        }
139
140        sc = rtems_semaphore_release (semnorec);
141        if (sc != RTEMS_SUCCESSFUL) {
142                printf ("%d: Can't release non-recursive-lock semaphore: %s\n", __LINE__, rtems_status_text (sc));
143        }
144        sc = rtems_semaphore_release (semnorec);
145        if (sc != RTEMS_SUCCESSFUL) {
146                printf ("%d: Can't rerelease non-recursive-lock semaphore: %s\n", __LINE__, rtems_status_text (sc));
147        }
148        sc = rtems_semaphore_obtain (semnorec, RTEMS_NO_WAIT, 0);
149        if (sc != RTEMS_SUCCESSFUL) {
150                printf ("%d: Can't obtain non-recursive-lock semaphore: %s\n", __LINE__, rtems_status_text (sc));
151        }
152        /*
153         *  Since this task is holding this, this task will block and timeout.
154         *  Then the timeout error will be returned.
155         */
156        rtems_clock_get (RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &then);
157        sc = rtems_semaphore_obtain (semnorec, RTEMS_WAIT, 5);
158        rtems_clock_get (RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &now);
159        if (sc == RTEMS_SUCCESSFUL) {
160                printf ("%d: Reobtain non-recursive-lock semaphore -- and should not have.\n", __LINE__);
161        }
162        else if (sc != RTEMS_TIMEOUT) {
163                printf ("%d: Reobtain non-recursive-lock semaphore failed, but error is %d (%s), not RTEMS_TIMEOUT.\n", __LINE__, sc, rtems_status_text (sc));
164        }
165        if ((then - now) < 4)
166                printf ("%d: Reobtain non-recursive-lock semaphore failed without timeout.\n", __LINE__);
167
168        startTask (semnorec);
169        rtems_clock_get (RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &then);
170        for (i = 0 ; i < 5 ; i++) {
171                int diff;
172
173                sc = rtems_semaphore_obtain (semnorec, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
174                rtems_clock_get (RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &now);
175                diff = now - then;
176                then = now;
177                if (sc != RTEMS_SUCCESSFUL)
178                        printf ("%d: Failed to obtain non-recursive-lock semaphore: %s\n", __LINE__, rtems_status_text (sc));
179                else if (diff < (2 * ticksPerSecond))
180                        printf ("%d: Obtained obtain non-recursive-lock semaphore too quickly -- %d ticks not %d ticks\n", __LINE__, diff, (2 * ticksPerSecond) );
181        }
182
183        puts( "*** END OF TEST 29 ***" );
184        exit (0);
185}
Note: See TracBrowser for help on using the repository browser.