source: rtems/testsuites/itrontests/itronmbf01/init.c @ 6977b38

4.104.114.84.95
Last change on this file since 6977b38 was 6977b38, checked in by Joel Sherrill <joel.sherrill@…>, on Nov 12, 1999 at 1:45:39 PM

Enabled after merging message buffer code.

  • Property mode set to 100644
File size: 9.5 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    printf( "\n\n*** ITRONMBF01 -- ITRON MESSAGE BUFFER TEST ***\n" );
51
52    TestCre();
53    TestDel();
54    TestPsnd();
55    TestRef();
56    TestRcv();
57    TestRef();
58    TestPrcv();
59    TestTrcv();
60
61    printf("\n\n*** ITRONMBF01 --- ITRON MESSAGE BUFFER TEST ***\n");
62    exit(0);
63}
64
65void TestCre()
66{
67    ER      status;
68    T_CMBF  pk_cmbf;
69   
70    /*
71     *  Exercise cre_mbf - this code seems to exercise every path.
72     */
73
74    puts( "Init - cre_mbf - NULL pk_cmbf returns E_PAR" );
75    status = cre_mbf( 1, NULL );
76    assert( status == E_PAR );
77
78    puts( "Init - cre_mbf - negative values for bufsz returns E_PAR" );
79    pk_cmbf.bufsz = -1;
80    pk_cmbf.maxmsz  = 100;
81    status = cre_mbf( 1, &pk_cmbf );
82    assert( status == E_PAR );
83
84    puts( "Init - cre_mbf - negative values for maxmsz returns E_PAR" );
85    pk_cmbf.bufsz = 100;
86    pk_cmbf.maxmsz  = -1;
87    status = cre_mbf( 1, &pk_cmbf );
88    assert( status == E_PAR );
89
90    puts( "Init - cre_mbf - bufsz < maxmsz returns E_PAR" );
91    pk_cmbf.bufsz = 100;
92    pk_cmbf.maxmsz  = 101;
93    status = cre_mbf( 1, &pk_cmbf );
94    assert( status == E_PAR );
95 
96    /*
97     *  Now run through all the bad ID errors
98     */
99
100    pk_cmbf.bufsz = 200;
101    pk_cmbf.maxmsz = 30;
102    puts( "Init - cre_mbf - bad id (less than -4) - E_OACV" );
103    status = cre_mbf( -5, &pk_cmbf );
104    assert( status == E_OACV );
105
106    puts( "Init - cre_mbf - bad id (between 0 and -4) - E_ID" );
107    status = cre_mbf( -4, &pk_cmbf );
108    assert( status == E_ID );
109
110    puts( "Init - cre_mbf - bad id (0) - E_ID" );
111    status = cre_mbf( 0, &pk_cmbf );
112    assert( status == E_ID );
113
114    puts( "Init - cre_mbf - bad id (too great) - E_ID" );
115    status = cre_mbf( CONFIGURE_MAXIMUM_ITRON_MESSAGE_BUFFERS + 1, &pk_cmbf );
116    assert( status == E_ID );
117
118    puts( "Init - cre_mbf - create mbf 1 TA_TFIFO - E_OK" );
119    pk_cmbf.bufsz = 600;
120    pk_cmbf.maxmsz  = 200;
121    pk_cmbf.mbfatr  = TA_TFIFO;
122    status = cre_mbf( 1, &pk_cmbf );
123    assert( status == E_OK );
124   
125    puts( "Init - cre_mbf - create mbf 1 again - E_OBJ" );
126    status = cre_mbf( 1, &pk_cmbf );
127    assert( status == E_OBJ );
128
129    puts( "Init - cre_mbf - create mbf 2 TA_TPRI - E_OK" );
130    pk_cmbf.bufsz = 600;
131    pk_cmbf.maxmsz  = 200;
132    pk_cmbf.mbfatr  = TA_TPRI;
133    status = cre_mbf( 2, &pk_cmbf );
134    assert( status == E_OK );
135}
136
137void TestDel()
138{
139    ER    status;
140   
141    /*
142     *  Generate all the bad id errors for del_mbf
143     */
144
145    puts( "Init - del_mbf - bad id (less than -4) - E_OACV" );
146    status = del_mbf( -5 );
147    assert( status == E_OACV );
148
149    puts( "Init - del_mbf - bad id (between 0 and -4) - E_ID" );
150    status = del_mbf( -4 );
151    assert( status == E_ID );
152
153    puts( "Init - del_mbf - bad id (0) - E_ID" );
154    status = del_mbf( 0 );
155    assert( status == E_ID );
156
157    puts( "Init - del_mbf - bad id (too great) - E_ID" );
158    status = del_mbf( CONFIGURE_MAXIMUM_ITRON_MESSAGE_BUFFERS + 1 );
159    assert( status == E_ID );
160
161   
162    puts("Init - del_mbf   - E_OK" );
163    status = del_mbf(2);
164    assert(status == E_OK);
165}
166
167void TestPsnd()
168{
169    ER   status;
170    char msg[100] = "This is test message 1";
171   
172    /*
173     *  Generate all the bad id errors for psnd_mbf
174     */
175
176    puts( "Init - psnd_mbf - bad id (less than -4) - E_OACV" );
177    status = psnd_mbf(-5, msg, sizeof(msg));
178    assert( status == E_OACV );
179
180    puts( "Init - psnd_mbf - bad id (between 0 and -4) - E_ID" );
181    status = psnd_mbf(-4, msg, sizeof(msg));
182    assert( status == E_ID );
183
184    puts( "Init - psnd_mbf - bad id (0) - E_ID" );
185    status = psnd_mbf(0, msg, sizeof(msg));
186    assert( status == E_ID );
187
188    puts( "Init - psnd_mbf - bad id (too great) - E_ID" );
189    status = psnd_mbf(CONFIGURE_MAXIMUM_ITRON_MESSAGE_BUFFERS + 1, msg,
190                      sizeof(msg)); 
191    assert( status == E_ID );
192
193    puts( "Init - psnd_mbf - msg == 0, E_PAR" );
194    status = psnd_mbf(1, 0, sizeof(msg)); 
195    assert( status == E_PAR );
196
197    puts( "Init - psnd_mbf - msgsz too big - E_PAR" );
198    status = psnd_mbf(1, msg, 300); 
199    assert( status == E_PAR );
200
201    puts( "Init - psnd_mbf - msgsz <0 - E_PAR" );
202    status = psnd_mbf(1, msg, -10); 
203    assert( status == E_PAR );
204
205    puts( "Init - psnd_mbf - E_OK" );
206    status = psnd_mbf(1, msg, sizeof(msg)); 
207    assert( status == E_OK );
208}
209
210void TestRef()
211{
212    ER       status;
213    T_RMBF   pk_rmbf;
214   
215    puts( "Init - ref_mbf - bad id (less than -4) - E_OACV" );
216    status = ref_mbf(&pk_rmbf, -5);
217    assert( status == E_OACV );
218
219    puts( "Init - ref_mbf - bad id (between 0 and -4) - E_ID" );
220    status = ref_mbf(&pk_rmbf, -4);
221    assert( status == E_ID );
222
223    puts( "Init - ref_mbf - bad id (0) - E_ID" );
224    status = ref_mbf(&pk_rmbf, 0);
225    assert( status == E_ID );
226
227    puts( "Init - ref_mbf - bad id (too great) - E_ID" );
228    status = ref_mbf(&pk_rmbf,
229                     CONFIGURE_MAXIMUM_ITRON_MESSAGE_BUFFERS + 1);
230    assert( status == E_ID );
231
232    puts( "Init - ref_mbf - NULL pk_mbf returns E_PAR" );
233    status = ref_mbf( NULL, 1 );
234    assert( status == E_PAR );
235
236    puts( "Init - ref_mbf - mbf 1 - E_OK" );
237    status = ref_mbf( &pk_rmbf, 1 );
238    assert( status == E_OK );
239   
240    printf( "Init - mbf 1 msgsz = %d\n", pk_rmbf.msgsz );
241    printf( "Init - mbf 1 frbufsz = %d\n", pk_rmbf.frbufsz );
242    printf( "Init - mbf 1 waiting tasks = %d\n", pk_rmbf.wtsk );
243    printf( "Init - mbf 1 sending tasks = %d\n", pk_rmbf.stsk);
244}
245
246void TestRcv()
247{
248    ER    status;
249    char  buffer[200];
250    int   s;
251
252    puts( "Init - rcv_mbf - bad id (less than -4) - E_OACV" );
253    status = rcv_mbf(buffer, &s, -5);
254    assert( status == E_OACV );
255
256    puts( "Init - rcv_mbf - bad id (between 0 and -4) - E_ID" );
257    status = rcv_mbf(buffer, &s, -4);
258    assert( status == E_ID );
259
260    puts( "Init - rcv_mbf - bad id (0) - E_ID" );
261    status = rcv_mbf(buffer, &s, 0);
262    assert( status == E_ID );
263
264    puts( "Init - rcv_mbf - bad id (too great) - E_ID" );
265    status = rcv_mbf(buffer, &s, CONFIGURE_MAXIMUM_ITRON_MESSAGE_BUFFERS + 1);
266    assert( status == E_ID );
267
268    puts( "Init - rcv_mbf - NULL msg returns E_PAR" );
269    status = rcv_mbf(NULL, &s, 1);
270    assert( status == E_PAR );
271
272    puts( "Init - rcv_mbf - NULL p_msgsz returns E_PAR" );
273    status = rcv_mbf(buffer, 0, 1);
274    assert( status == E_PAR );
275
276    puts("Init - rcv_mbf -- OK");
277    status = rcv_mbf(buffer, &s, 1);
278    assert(status == E_OK);
279    printf("Message:[%s], length:%d\n", buffer, s);
280}
281
282
283void TestPrcv()
284{
285    ER    status;
286    char  buffer[200];
287    int   s;
288
289    puts( "Init - prcv_mbf - bad id (less than -4) - E_OACV" );
290    status = prcv_mbf(buffer, &s, -5);
291    assert( status == E_OACV );
292
293    puts( "Init - prcv_mbf - bad id (between 0 and -4) - E_ID" );
294    status = prcv_mbf(buffer, &s, -4);
295    assert( status == E_ID );
296
297    puts( "Init - prcv_mbf - bad id (0) - E_ID" );
298    status = prcv_mbf(buffer, &s, 0);
299    assert( status == E_ID );
300
301    puts( "Init - prcv_mbf - bad id (too great) - E_ID" );
302    status = prcv_mbf(buffer, &s, CONFIGURE_MAXIMUM_ITRON_MESSAGE_BUFFERS + 1);
303    assert( status == E_ID );
304
305    puts( "Init - prcv_mbf - NULL msg returns E_PAR" );
306    status = prcv_mbf(NULL, &s, 1);
307    assert( status == E_PAR );
308
309    puts( "Init - prcv_mbf - NULL p_msgsz returns E_PAR" );
310    status = prcv_mbf(buffer, 0, 1);
311    assert( status == E_PAR );
312
313    puts("Init - prcv_mbf -- E_TMOUT");
314    status = prcv_mbf(buffer, &s, 1);
315    assert(status == E_TMOUT);
316}
317
318
319void TestTrcv()
320{
321    ER    status;
322    char  buffer[200];
323    int   s;
324
325    puts( "Init - trcv_mbf - bad id (less than -4) - E_OACV" );
326    status = trcv_mbf(buffer, &s, -5, 5000);
327    assert( status == E_OACV );
328
329    puts( "Init - trcv_mbf - bad id (between 0 and -4) - E_ID" );
330    status = trcv_mbf(buffer, &s, -4, 5000);
331    assert( status == E_ID );
332
333    puts( "Init - trcv_mbf - bad id (0) - E_ID" );
334    status = trcv_mbf(buffer, &s, 0, 5000);
335    assert( status == E_ID );
336
337    puts( "Init - trcv_mbf - bad id (too great) - E_ID" );
338    status = trcv_mbf(buffer, &s,
339                      CONFIGURE_MAXIMUM_ITRON_MESSAGE_BUFFERS + 1,
340                      5000); 
341    assert( status == E_ID );
342
343    puts( "Init - trcv_mbf - NULL msg returns E_PAR" );
344    status = trcv_mbf(NULL, &s, 1, 5000);
345    assert( status == E_PAR );
346
347    puts( "Init - trcv_mbf - NULL p_msgsz returns E_PAR" );
348    status = trcv_mbf(buffer, 0, 1, 5000);
349    assert( status == E_PAR );
350
351    puts( "Init - trcv_mbf - tmout <-2  returns E_PAR" );
352    status = trcv_mbf(buffer, &s, 1, -2);
353    assert( status == E_PAR );
354
355    puts("\nInit - trcv_mbf -- E_TMOUT");
356    put_time( "Init - starting to block at ");
357    status = trcv_mbf(buffer, &s, 1, 1000);
358    assert(status == E_TMOUT);
359    put_time( "Init - time out at ");
360}
361
362
Note: See TracBrowser for help on using the repository browser.