source: rtems/testsuites/itrontests/itronmbf01/init.c @ 9d9a3dd

4.104.114.84.95
Last change on this file since 9d9a3dd was 9d9a3dd, checked in by Jennifer Averett <Jennifer.Averett@…>, on Nov 17, 1999 at 4:47:58 PM

+ Updated copyright information.

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