source: rtems/testsuites/sptests/sp29/init.c @ 280c4ca

4.104.114.84.95
Last change on this file since 280c4ca was 280c4ca, checked in by Joel Sherrill <joel.sherrill@…>, on 01/05/00 at 22:03:44

Corrected test and screen to reflect implementation working.

  • Property mode set to 100644
File size: 5.9 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_TEST_NEEDS_CONSOLE_DRIVER
14#define CONFIGURE_TEST_NEEDS_CLOCK_DRIVER
15
16#define CONFIGURE_INIT
17
18#include <confdefs.h>
19
20#include <rtems/error.h>
21#include <stdio.h>
22
23rtems_interval ticksPerSecond;
24
25rtems_task
26subtask (rtems_task_argument arg)
27{
28        rtems_status_code sc;
29        rtems_id sem = (rtems_id)arg;
30
31        for (;;) {
32                rtems_task_wake_after (ticksPerSecond * 2);
33
34                sc = rtems_semaphore_release (sem);
35                if (sc != RTEMS_SUCCESSFUL)
36                        printf ("%d: Can't release semaphore: %s\n", __LINE__, rtems_status_text (sc));
37        }
38}
39
40void
41startTask (rtems_id arg)
42{
43        rtems_id tid;
44        rtems_status_code sc;
45
46        sc = rtems_task_create (rtems_build_name ('S', 'R', 'V', 'A'),
47                100,
48                10000,
49                RTEMS_PREEMPT|RTEMS_NO_TIMESLICE|RTEMS_NO_ASR|RTEMS_INTERRUPT_LEVEL(0),
50                RTEMS_NO_FLOATING_POINT|RTEMS_LOCAL,
51                &tid);
52        if (sc != RTEMS_SUCCESSFUL) {
53                printf ("Can't create task: %s\n", rtems_status_text (sc));
54                rtems_task_suspend (RTEMS_SELF);
55        }
56        sc = rtems_task_start (tid, subtask, arg);
57        if (sc != RTEMS_SUCCESSFUL) {
58                printf ("Can't start task: %s\n", rtems_status_text (sc));
59                rtems_task_suspend (RTEMS_SELF);
60        }
61}
62
63rtems_task Init (rtems_task_argument ignored)
64{
65        int i;
66        rtems_id semrec, semnorec;
67        rtems_status_code sc;
68        rtems_interval then, now;
69
70        puts( "*** SP29 - SIMPLE SEMAPHORE TEST ***" );
71        puts( "This test only prints on errors." );
72 
73        sc = rtems_clock_get (RTEMS_CLOCK_GET_TICKS_PER_SECOND, &ticksPerSecond);
74        if (sc != RTEMS_SUCCESSFUL) {
75                printf ("Can't get ticks per second: %s\n", rtems_status_text (sc));
76                exit (1);
77        }
78        sc = rtems_semaphore_create (rtems_build_name ('S', 'M', 'r', 'c'),
79                1,
80                RTEMS_PRIORITY|RTEMS_BINARY_SEMAPHORE|RTEMS_INHERIT_PRIORITY |RTEMS_NO_PRIORITY_CEILING|RTEMS_LOCAL,
81                0,
82                &semrec);
83        if (sc != RTEMS_SUCCESSFUL) {
84                printf ("%d: Can't create recursive-lock semaphore: %s\n", __LINE__, rtems_status_text (sc));
85                exit (1);
86        }
87        sc = rtems_semaphore_create (rtems_build_name ('S', 'M', 'n', 'c'),
88                1,
89                RTEMS_PRIORITY|RTEMS_SIMPLE_BINARY_SEMAPHORE|RTEMS_INHERIT_PRIORITY |RTEMS_NO_PRIORITY_CEILING|RTEMS_LOCAL,
90                0,
91                &semnorec);
92        if (sc != RTEMS_SUCCESSFUL) {
93                printf ("%d: Can't create non-recursive-lock semaphore: %s\n", __LINE__, rtems_status_text (sc));
94                exit (1);
95        }
96
97        sc = rtems_semaphore_obtain (semrec, RTEMS_NO_WAIT, 0);
98        if (sc != RTEMS_SUCCESSFUL) {
99                printf ("%d: Can't obtain recursive-lock semaphore: %s\n", __LINE__, rtems_status_text (sc));
100        }
101        sc = rtems_semaphore_obtain (semrec, RTEMS_NO_WAIT, 0);
102        if (sc != RTEMS_SUCCESSFUL) {
103                printf ("%d: Can't reobtain recursive-lock semaphore: %s\n", __LINE__, rtems_status_text (sc));
104        }
105
106        sc = rtems_semaphore_obtain (semnorec, RTEMS_NO_WAIT, 0);
107        if (sc != RTEMS_SUCCESSFUL) {
108                printf ("%d: Can't obtain non-recursive-lock semaphore: %s\n", __LINE__, rtems_status_text (sc));
109        }
110        sc = rtems_semaphore_obtain (semnorec, RTEMS_NO_WAIT, 0);
111        if (sc == RTEMS_SUCCESSFUL) {
112                printf ("%d: Reobtain non-recursive-lock semaphore -- and should not have.\n", __LINE__);
113        }
114
115        sc = rtems_semaphore_release (semnorec);
116        if (sc != RTEMS_SUCCESSFUL) {
117                printf ("%d: Can't release non-recursive-lock semaphore: %s\n", __LINE__, rtems_status_text (sc));
118        }
119        sc = rtems_semaphore_release (semnorec);
120        if (sc != RTEMS_SUCCESSFUL) {
121                printf ("%d: Can't rerelease non-recursive-lock semaphore: %s\n", __LINE__, rtems_status_text (sc));
122        }
123        sc = rtems_semaphore_obtain (semnorec, RTEMS_NO_WAIT, 0);
124        if (sc != RTEMS_SUCCESSFUL) {
125                printf ("%d: Can't obtain non-recursive-lock semaphore: %s\n", __LINE__, rtems_status_text (sc));
126        }
127        sc = rtems_semaphore_obtain (semnorec, RTEMS_NO_WAIT, 0);
128        if (sc == RTEMS_SUCCESSFUL) {
129                printf ("%d: Reobtain non-recursive-lock semaphore -- and should not have.\n", __LINE__);
130        }
131        else if (sc != RTEMS_UNSATISFIED) {
132                printf ("%d: Reobtain non-recursive-lock semaphore failed, but error is %d (%s), not RTEMS_UNSATISFIED.\n", __LINE__, sc, rtems_status_text (sc));
133        }
134
135        sc = rtems_semaphore_release (semnorec);
136        if (sc != RTEMS_SUCCESSFUL) {
137                printf ("%d: Can't release non-recursive-lock semaphore: %s\n", __LINE__, rtems_status_text (sc));
138        }
139        sc = rtems_semaphore_release (semnorec);
140        if (sc != RTEMS_SUCCESSFUL) {
141                printf ("%d: Can't rerelease non-recursive-lock semaphore: %s\n", __LINE__, rtems_status_text (sc));
142        }
143        sc = rtems_semaphore_obtain (semnorec, RTEMS_NO_WAIT, 0);
144        if (sc != RTEMS_SUCCESSFUL) {
145                printf ("%d: Can't obtain non-recursive-lock semaphore: %s\n", __LINE__, rtems_status_text (sc));
146        }
147        /*
148         *  Since this task is holding this, there is no reason to block.
149         *  It is obviously an error to reobtain it.
150         */
151        rtems_clock_get (RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &then);
152        sc = rtems_semaphore_obtain (semnorec, RTEMS_WAIT, 5);
153        rtems_clock_get (RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &now);
154        if (sc == RTEMS_SUCCESSFUL) {
155                printf ("%d: Reobtain non-recursive-lock semaphore -- and should not have.\n", __LINE__);
156        }
157        else if (sc != RTEMS_TIMEOUT) {
158                printf ("%d: Reobtain non-recursive-lock semaphore failed, but error is %d (%s), not RTEMS_TIMEOUT.\n", __LINE__, sc, rtems_status_text (sc));
159        }
160        if ((then - now) < 4)
161                printf ("%d: Reobtain non-recursive-lock semaphore failed without timeout.\n", __LINE__);
162
163        startTask (semnorec);
164        rtems_clock_get (RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &then);
165        for (i = 0 ; i < 5 ; i++) {
166                int diff;
167
168                sc = rtems_semaphore_obtain (semnorec, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
169                rtems_clock_get (RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &now);
170                diff = now - then;
171                then = now;
172                if (sc != RTEMS_SUCCESSFUL)
173                        printf ("%d: Failed to obtain non-recursive-lock semaphore: %s\n", __LINE__, rtems_status_text (sc));
174                else if (diff < (2 * ticksPerSecond))
175                        printf ("%d: Obtained obtain non-recursive-lock semaphore too quickly -- %d ticks not %d ticks\n", __LINE__, diff, (2 * ticksPerSecond) );
176        }
177               
178        puts( "*** END OF SP29 ***" );
179        exit (0);
180}
Note: See TracBrowser for help on using the repository browser.