source: rtems/testsuites/itrontests/itronmbf01/init.c @ 713b2ea

4.104.114.84.95
Last change on this file since 713b2ea was 713b2ea, checked in by Joel Sherrill <joel.sherrill@…>, on Nov 10, 1999 at 10:15:42 PM

General cleanup. Test documentation improved. The message buffer test
prints a message instead of actually testing since the message buffer
implementation is not in yet.

  • Property mode set to 100644
File size: 9.6 KB
Line 
1/*  Init
2 *
3 *  This routine is the initialization task for this test program.
4 *  It is called from init_exec and has the responsibility for creating
5 *  and starting the tasks that make up the test.  If the time of day
6 *  clock is required for the test, it should also be set to a known
7 *  value by this function.
8 *
9 *  Input parameters:  NONE
10 *
11 *  Output parameters:  NONE
12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.OARcorp.com/rtems/license.html.
16 *
17 *  $Id$
18 */
19
20#define TEST_INIT
21#include "system.h"
22#include <stdio.h>
23#include <assert.h>
24
25/*
26 *  The following is hopefully temporary.
27 */
28
29#include <time.h>
30
31#define put_time(_s) \
32do { \
33     time_t a_time_t; \
34     a_time_t = time( 0 ); \
35     printf( "%s%s", _s, ctime( &a_time_t ) ); \
36} while(0)
37
38
39
40void TestCre();
41void TestDel();
42void TestPsnd();
43void TestRef();
44void TestTrcv();
45void TestRcv();
46void TestPrcv();
47
48void ITRON_Init( void )
49{
50    puts( "\n\n*** ITRONMBF01 -- ITRON MESSAGE BUFFER TEST ***" );
51
52#if 0
53    TestCre();
54    TestDel();
55    TestPsnd();
56    TestRef();
57    TestRcv();
58    TestRef();
59    TestPrcv();
60    TestTrcv();
61#else
62    puts("Enable the code in this test when messages buffers are implemented"); 
63#endif
64
65    printf("*** ITRONMBF01 --- ITRON MESSAGE BUFFER TEST ***");
66    exit(0);
67}
68
69void TestCre()
70{
71    ER      status;
72    T_CMBF  pk_cmbf;
73   
74    /*
75     *  Exercise cre_mbf - this code seems to exercise every path.
76     */
77
78    puts( "Init - cre_mbf - NULL pk_cmbf returns E_PAR" );
79    status = cre_mbf( 1, NULL );
80    assert( status == E_PAR );
81
82    puts( "Init - cre_mbf - negative values for bufsz returns E_PAR" );
83    pk_cmbf.bufsz = -1;
84    pk_cmbf.maxmsz  = 100;
85    status = cre_mbf( 1, &pk_cmbf );
86    assert( status == E_PAR );
87
88    puts( "Init - cre_mbf - negative values for maxmsz returns E_PAR" );
89    pk_cmbf.bufsz = 100;
90    pk_cmbf.maxmsz  = -1;
91    status = cre_mbf( 1, &pk_cmbf );
92    assert( status == E_PAR );
93
94    puts( "Init - cre_mbf - bufsz < maxmsz returns E_PAR" );
95    pk_cmbf.bufsz = 100;
96    pk_cmbf.maxmsz  = 101;
97    status = cre_mbf( 1, &pk_cmbf );
98    assert( status == E_PAR );
99 
100    /*
101     *  Now run through all the bad ID errors
102     */
103
104    pk_cmbf.bufsz = 200;
105    pk_cmbf.maxmsz = 30;
106    puts( "Init - cre_mbf - bad id (less than -4) - E_OACV" );
107    status = cre_mbf( -5, &pk_cmbf );
108    assert( status == E_OACV );
109
110    puts( "Init - cre_mbf - bad id (between 0 and -4) - E_ID" );
111    status = cre_mbf( -4, &pk_cmbf );
112    assert( status == E_ID );
113
114    puts( "Init - cre_mbf - bad id (0) - E_ID" );
115    status = cre_mbf( 0, &pk_cmbf );
116    assert( status == E_ID );
117
118    puts( "Init - cre_mbf - bad id (too great) - E_ID" );
119    status = cre_mbf( CONFIGURE_MAXIMUM_ITRON_MESSAGE_BUFFERS + 1, &pk_cmbf );
120    assert( status == E_ID );
121
122    puts( "Init - cre_mbf - create mbf 1 TA_TFIFO - E_OK" );
123    pk_cmbf.bufsz = 600;
124    pk_cmbf.maxmsz  = 200;
125    pk_cmbf.mbfatr  = TA_TFIFO;
126    status = cre_mbf( 1, &pk_cmbf );
127    assert( status == E_OK );
128   
129    puts( "Init - cre_mbf - create mbf 1 again - E_OBJ" );
130    status = cre_mbf( 1, &pk_cmbf );
131    assert( status == E_OBJ );
132
133    puts( "Init - cre_mbf - create mbf 2 TA_TPRI - E_OK" );
134    pk_cmbf.bufsz = 600;
135    pk_cmbf.maxmsz  = 200;
136    pk_cmbf.mbfatr  = TA_TPRI;
137    status = cre_mbf( 2, &pk_cmbf );
138    assert( status == E_OK );
139}
140
141void TestDel()
142{
143    ER    status;
144   
145    /*
146     *  Generate all the bad id errors for del_mbf
147     */
148
149    puts( "Init - del_mbf - bad id (less than -4) - E_OACV" );
150    status = del_mbf( -5 );
151    assert( status == E_OACV );
152
153    puts( "Init - del_mbf - bad id (between 0 and -4) - E_ID" );
154    status = del_mbf( -4 );
155    assert( status == E_ID );
156
157    puts( "Init - del_mbf - bad id (0) - E_ID" );
158    status = del_mbf( 0 );
159    assert( status == E_ID );
160
161    puts( "Init - del_mbf - bad id (too great) - E_ID" );
162    status = del_mbf( CONFIGURE_MAXIMUM_ITRON_MESSAGE_BUFFERS + 1 );
163    assert( status == E_ID );
164
165   
166    puts("Init - del_mbf   - E_OK" );
167    status = del_mbf(2);
168    assert(status == E_OK);
169}
170
171void TestPsnd()
172{
173    ER   status;
174    char msg[100] = "This is test message 1";
175   
176    /*
177     *  Generate all the bad id errors for psnd_mbf
178     */
179
180    puts( "Init - psnd_mbf - bad id (less than -4) - E_OACV" );
181    status = psnd_mbf(-5, msg, sizeof(msg));
182    assert( status == E_OACV );
183
184    puts( "Init - psnd_mbf - bad id (between 0 and -4) - E_ID" );
185    status = psnd_mbf(-4, msg, sizeof(msg));
186    assert( status == E_ID );
187
188    puts( "Init - psnd_mbf - bad id (0) - E_ID" );
189    status = psnd_mbf(0, msg, sizeof(msg));
190    assert( status == E_ID );
191
192    puts( "Init - psnd_mbf - bad id (too great) - E_ID" );
193    status = psnd_mbf(CONFIGURE_MAXIMUM_ITRON_MESSAGE_BUFFERS + 1, msg,
194                      sizeof(msg)); 
195    assert( status == E_ID );
196
197    puts( "Init - psnd_mbf - msg == 0, E_PAR" );
198    status = psnd_mbf(1, 0, sizeof(msg)); 
199    assert( status == E_PAR );
200
201    puts( "Init - psnd_mbf - msgsz too big - E_PAR" );
202    status = psnd_mbf(1, msg, 300); 
203    assert( status == E_PAR );
204
205    puts( "Init - psnd_mbf - msgsz <0 - E_PAR" );
206    status = psnd_mbf(1, msg, -10); 
207    assert( status == E_PAR );
208
209    puts( "Init - psnd_mbf - E_OK" );
210    status = psnd_mbf(1, msg, sizeof(msg)); 
211    assert( status == E_OK );
212}
213
214void TestRef()
215{
216    ER       status;
217    T_RMBF   pk_rmbf;
218   
219    puts( "Init - ref_mbf - bad id (less than -4) - E_OACV" );
220    status = ref_mbf(&pk_rmbf, -5);
221    assert( status == E_OACV );
222
223    puts( "Init - ref_mbf - bad id (between 0 and -4) - E_ID" );
224    status = ref_mbf(&pk_rmbf, -4);
225    assert( status == E_ID );
226
227    puts( "Init - ref_mbf - bad id (0) - E_ID" );
228    status = ref_mbf(&pk_rmbf, 0);
229    assert( status == E_ID );
230
231    puts( "Init - ref_mbf - bad id (too great) - E_ID" );
232    status = ref_mbf(&pk_rmbf,
233                     CONFIGURE_MAXIMUM_ITRON_MESSAGE_BUFFERS + 1);
234    assert( status == E_ID );
235
236    puts( "Init - ref_mbf - NULL pk_mbf returns E_PAR" );
237    status = ref_mbf( NULL, 1 );
238    assert( status == E_PAR );
239
240    puts( "Init - ref_mbf - mbf 1 - E_OK" );
241    status = ref_mbf( &pk_rmbf, 1 );
242    assert( status == E_OK );
243   
244    printf( "Init - mbf 1 msgsz = %d\n", pk_rmbf.msgsz );
245    printf( "Init - mbf 1 frbufsz = %d\n", pk_rmbf.frbufsz );
246    printf( "Init - mbf 1 waiting tasks = %d\n", pk_rmbf.wtsk );
247    printf( "Init - mbf 1 sending tasks = %d\n", pk_rmbf.stsk);
248}
249
250void TestRcv()
251{
252    ER    status;
253    char  buffer[200];
254    int   s;
255
256    puts( "Init - rcv_mbf - bad id (less than -4) - E_OACV" );
257    status = rcv_mbf(buffer, &s, -5);
258    assert( status == E_OACV );
259
260    puts( "Init - rcv_mbf - bad id (between 0 and -4) - E_ID" );
261    status = rcv_mbf(buffer, &s, -4);
262    assert( status == E_ID );
263
264    puts( "Init - rcv_mbf - bad id (0) - E_ID" );
265    status = rcv_mbf(buffer, &s, 0);
266    assert( status == E_ID );
267
268    puts( "Init - rcv_mbf - bad id (too great) - E_ID" );
269    status = rcv_mbf(buffer, &s, CONFIGURE_MAXIMUM_ITRON_MESSAGE_BUFFERS + 1);
270    assert( status == E_ID );
271
272    puts( "Init - rcv_mbf - NULL msg returns E_PAR" );
273    status = rcv_mbf(NULL, &s, 1);
274    assert( status == E_PAR );
275
276    puts( "Init - rcv_mbf - NULL p_msgsz returns E_PAR" );
277    status = rcv_mbf(buffer, 0, 1);
278    assert( status == E_PAR );
279
280    puts("Init - rcv_mbf -- OK");
281    status = rcv_mbf(buffer, &s, 1);
282    assert(status == E_OK);
283    printf("Message:[%s], length:%d\n", buffer, s);
284}
285
286
287void TestPrcv()
288{
289    ER    status;
290    char  buffer[200];
291    int   s;
292
293    puts( "Init - prcv_mbf - bad id (less than -4) - E_OACV" );
294    status = prcv_mbf(buffer, &s, -5);
295    assert( status == E_OACV );
296
297    puts( "Init - prcv_mbf - bad id (between 0 and -4) - E_ID" );
298    status = prcv_mbf(buffer, &s, -4);
299    assert( status == E_ID );
300
301    puts( "Init - prcv_mbf - bad id (0) - E_ID" );
302    status = prcv_mbf(buffer, &s, 0);
303    assert( status == E_ID );
304
305    puts( "Init - prcv_mbf - bad id (too great) - E_ID" );
306    status = prcv_mbf(buffer, &s, CONFIGURE_MAXIMUM_ITRON_MESSAGE_BUFFERS + 1);
307    assert( status == E_ID );
308
309    puts( "Init - prcv_mbf - NULL msg returns E_PAR" );
310    status = prcv_mbf(NULL, &s, 1);
311    assert( status == E_PAR );
312
313    puts( "Init - prcv_mbf - NULL p_msgsz returns E_PAR" );
314    status = prcv_mbf(buffer, 0, 1);
315    assert( status == E_PAR );
316
317    puts("Init - prcv_mbf -- E_TMOUT");
318    status = prcv_mbf(buffer, &s, 1);
319    assert(status == E_TMOUT);
320}
321
322
323void TestTrcv()
324{
325    ER    status;
326    char  buffer[200];
327    int   s;
328
329    puts( "Init - trcv_mbf - bad id (less than -4) - E_OACV" );
330    status = trcv_mbf(buffer, &s, -5, 5000);
331    assert( status == E_OACV );
332
333    puts( "Init - trcv_mbf - bad id (between 0 and -4) - E_ID" );
334    status = trcv_mbf(buffer, &s, -4, 5000);
335    assert( status == E_ID );
336
337    puts( "Init - trcv_mbf - bad id (0) - E_ID" );
338    status = trcv_mbf(buffer, &s, 0, 5000);
339    assert( status == E_ID );
340
341    puts( "Init - trcv_mbf - bad id (too great) - E_ID" );
342    status = trcv_mbf(buffer, &s,
343                      CONFIGURE_MAXIMUM_ITRON_MESSAGE_BUFFERS + 1,
344                      5000); 
345    assert( status == E_ID );
346
347    puts( "Init - trcv_mbf - NULL msg returns E_PAR" );
348    status = trcv_mbf(NULL, &s, 1, 5000);
349    assert( status == E_PAR );
350
351    puts( "Init - trcv_mbf - NULL p_msgsz returns E_PAR" );
352    status = trcv_mbf(buffer, 0, 1, 5000);
353    assert( status == E_PAR );
354
355    puts( "Init - trcv_mbf - tmout <-2  returns E_PAR" );
356    status = trcv_mbf(buffer, &s, 1, -2);
357    assert( status == E_PAR );
358
359    puts("\nInit - trcv_mbf -- E_TMOUT");
360    put_time( "Init - starting to block at ");
361    status = trcv_mbf(buffer, &s, 1, 1000);
362    assert(status == E_TMOUT);
363    put_time( "Init - time out at ");
364}
365
366
Note: See TracBrowser for help on using the repository browser.