Notice: We have migrated to GitLab launching 2024-05-01 see here: https://gitlab.rtems.org/

Ticket #618: nulltest.c

File nulltest.c, 13.5 KB (added by Joel Sherrill, on 12/03/06 at 13:31:13)

nulltest.c

Line 
1/*
2 *  Exercise the Task Manager API for NULL checks.
3 *
4 * $Id$
5 */
6
7#undef  NDEBUG
8
9#include <bsp.h>
10#include <stdlib.h>
11#include <stdio.h>
12#include <stdlib.h>
13
14#include "tmacros.h"
15
16#if 1
17#define PUTS(_s) puts(_s)
18#endif
19
20rtems_task task1(
21  rtems_task_argument ignored
22)
23{
24  for(;;) {
25    printf("Should not get here\n" );
26  }
27}
28
29void check_task_nulls(void)
30{
31  rtems_status_code status;
32  rtems_id          id;
33  void             *p;
34
35  PUTS( "Testing task null checks" );
36
37  /*
38   *  task create -- id == NULL
39   */
40  status = rtems_task_create(
41    rtems_build_name( 'T', 'A', '1', ' ' ), 1,
42    RTEMS_MINIMUM_STACK_SIZE, RTEMS_DEFAULT_MODES,
43    RTEMS_DEFAULT_ATTRIBUTES, NULL
44  );
45  fatal_directive_status(status, RTEMS_INVALID_ADDRESS, "task create NULL id");
46
47  /*
48   *  ident -- NULL id
49   */
50  status = rtems_task_ident( 0x1234, RTEMS_SEARCH_ALL_NODES, NULL );
51  fatal_directive_status(status, RTEMS_INVALID_ADDRESS, "ident NULL id");
52
53  /*
54   *  SUCCESSFULLY Create the first task
55   */
56  status = rtems_task_create(
57    rtems_build_name( 'T', 'A', '1', ' ' ), 1,
58    RTEMS_MINIMUM_STACK_SIZE, RTEMS_DEFAULT_MODES,
59    RTEMS_DEFAULT_ATTRIBUTES, &id
60  );
61  directive_failed( status, "task create" );
62 
63  /*
64   *  task start -- NULL task body
65   */
66  status = rtems_task_start( id, NULL, 0 );
67  fatal_directive_status(status, RTEMS_INVALID_ADDRESS, "task start NULL id");
68
69  /*
70   *  SUCCESSFULLY Start the first task
71   */
72  status = rtems_task_start( id, task1, 0 );
73  assert( !status );
74
75  /*
76   *  task_get_node - bad return note
77   */
78  status = rtems_task_get_note( id, RTEMS_NOTEPAD_0, NULL );
79  fatal_directive_status(status, RTEMS_INVALID_ADDRESS, "task getnote NULL");
80
81  /*
82   *  task_mode - bad return mode
83   */
84  status = rtems_task_mode( RTEMS_DEFAULT_MODES, RTEMS_DEFAULT_MODES, NULL );
85  fatal_directive_status(status, RTEMS_INVALID_ADDRESS, "task mode NULL");
86
87  /*
88   *  task_variable_add - bad pointer
89   */
90  status = rtems_task_variable_add( RTEMS_SELF, NULL, NULL );
91  fatal_directive_status(status, RTEMS_INVALID_ADDRESS, "task var add NULL");
92
93  /*
94   *  task_variable_get - bad variable
95   */
96  status = rtems_task_variable_get( RTEMS_SELF, NULL, &p );
97  fatal_directive_status(status, RTEMS_INVALID_ADDRESS, "task var get NULL");
98
99  /*
100   *  task_variable_get - bad result
101   */
102  status = rtems_task_variable_get( RTEMS_SELF, &p, NULL );
103  fatal_directive_status(status, RTEMS_INVALID_ADDRESS, "task var get NULL");
104
105  /*
106   *  task_variable_delete - bad pointer
107   */
108  status = rtems_task_variable_delete( RTEMS_SELF, NULL );
109  fatal_directive_status(status, RTEMS_INVALID_ADDRESS, "task var delete NULL");
110
111  /*
112   * SUCCESSFULLY set the TOD
113   */
114  {
115    rtems_time_of_day time = { 2004, 4, 27, 16, 15, 0 };
116    status = rtems_clock_set( &time );
117    directive_failed( status, "clock set" );
118  }
119
120  /*
121   *  task_wake_when - bad time buffer
122   */
123  status = rtems_task_wake_when( NULL );
124  fatal_directive_status(status, RTEMS_INVALID_ADDRESS, "task wake when NULL");
125
126  /*
127   *  delete the task
128   */
129  status = rtems_task_delete( id );
130  directive_failed( status, "task delete" );
131}
132
133void check_clock_nulls(void)
134{
135  rtems_status_code status;
136
137  PUTS( "Testing clock null checks" );
138
139  /*
140   *  clock_get - bad time buffer
141   */
142  status = rtems_clock_get( RTEMS_CLOCK_GET_TOD, NULL );
143
144  /*
145   *  clock_set - bad time buffer
146   */
147  status = rtems_clock_set( NULL );
148  fatal_directive_status(status, RTEMS_INVALID_ADDRESS, "clock set when NULL");
149}
150
151void check_dpmem_nulls(void)
152{
153  rtems_status_code status;
154  rtems_id id;
155
156  PUTS( "Testing dpmem null checks" );
157
158  /*
159   *  port_create - NULL Id
160   */
161  status = rtems_port_create(
162      0x12345678, (void *)0x1000, (void *)0x2000, 1024, NULL );
163  fatal_directive_status(status, RTEMS_INVALID_ADDRESS, "port create NULL id");
164
165  /*
166   *  port_create - SUCCESSFUL
167   */
168  status = rtems_port_create(
169      0x12345678, (void *)0x1000, (void *)0x2000, 1024, &id );
170  directive_failed(status, "port create");
171
172  /*
173   *  ident -- NULL id
174   */
175  status = rtems_port_ident( 0x1234, NULL );
176  fatal_directive_status(status, RTEMS_INVALID_ADDRESS, "ident NULL id");
177
178  /*
179   *  port_external_to_internal - NULL internal pointer
180   */
181  status = rtems_port_external_to_internal( id, (void *) 0x1000, NULL );
182  fatal_directive_status(status, RTEMS_INVALID_ADDRESS, "port 2 int NULL arg");
183
184  /*
185   *  port_internal_to_external - NULL external pointer
186   */
187  status = rtems_port_internal_to_external( id, (void *) 0x2000, NULL );
188  fatal_directive_status(status, RTEMS_INVALID_ADDRESS, "port 2 ext NULL arg");
189
190  /*
191   *  port_delete - SUCCESSFUL
192   */
193  status = rtems_port_delete( id );
194  directive_failed(status, "port delete");
195}
196
197
198void check_event_nulls(void)
199{
200  rtems_status_code status;
201
202  PUTS( "Testing event null checks" );
203
204  /*
205   *  null event out
206   */
207  status = rtems_event_receive( 0xffffffff, RTEMS_DEFAULT_OPTIONS, 0, NULL );
208  fatal_directive_status(status, RTEMS_INVALID_ADDRESS, "task wake when NULL");
209}
210
211void check_msgq_nulls(void)
212{
213  rtems_status_code status;
214  rtems_id id;
215  unsigned int buffer;
216  unsigned32 count;
217
218  PUTS( "Testing msgq null checks" );
219
220  /*
221   *  message queue create - null id
222   */
223  status = rtems_message_queue_create(
224    0x1234, 10, 10, RTEMS_DEFAULT_ATTRIBUTES, NULL );
225  fatal_directive_status(status, RTEMS_INVALID_ADDRESS, "msgq create NULL id");
226
227  /*
228   *  message queue create - SUCCESSFUL
229   */
230  status = rtems_message_queue_create(
231    0x1234, 10, 10, RTEMS_DEFAULT_ATTRIBUTES, &id );
232  directive_failed(status, "msgq create");
233
234  /*
235   *  ident -- NULL id
236   */
237  status = rtems_message_queue_ident( 0x1234, RTEMS_SEARCH_ALL_NODES, NULL );
238  fatal_directive_status(status, RTEMS_INVALID_ADDRESS, "ident NULL id");
239
240  /*
241   * broadcast - null buffer
242   */
243  status = rtems_message_queue_broadcast( id, NULL, 10, &count );
244  fatal_directive_status(status, RTEMS_INVALID_ADDRESS, "mq brdcst NULL buff");
245
246  /*
247   * broadcast - null count
248   */
249  status = rtems_message_queue_broadcast( id, &buffer, 10, NULL );
250  fatal_directive_status(status, RTEMS_INVALID_ADDRESS, "mq brdcst NULL cnt");
251
252  /*
253   * flush - null count
254   */
255  status = rtems_message_queue_flush( id, NULL );
256  fatal_directive_status(status, RTEMS_INVALID_ADDRESS, "mq flush NULL cnt");
257
258  /*
259   * get number pending - null count
260   */
261  status = rtems_message_queue_get_number_pending( id, NULL );
262  fatal_directive_status(status, RTEMS_INVALID_ADDRESS, "mq get pend NULL cnt");
263
264  /*
265   * receive - null buffer
266   */
267  status = rtems_message_queue_receive( id, NULL, &count, 0, 0 );
268  fatal_directive_status(status, RTEMS_INVALID_ADDRESS, "mq recv NULL buff");
269
270  /*
271   * receive - null count
272   */
273  status = rtems_message_queue_receive( id, &buffer, NULL, 0, 0 );
274  fatal_directive_status(status, RTEMS_INVALID_ADDRESS, "mq recv NULL cnt");
275
276  /*
277   * send - null buffer
278   */
279  status = rtems_message_queue_send( id, NULL, 0 );
280  fatal_directive_status(status, RTEMS_INVALID_ADDRESS, "mq send NULL buffer");
281
282  /*
283   *  message queue delete - SUCCESSFUL
284   */
285  status = rtems_message_queue_delete( id );
286  directive_failed(status, "msgq delete");
287}
288
289void check_part_nulls(void)
290{
291  rtems_status_code status;
292  rtems_id id;
293  unsigned char buffer[32];
294
295  PUTS( "Testing part null checks" );
296
297  /*
298   *  create - null buffer
299   */
300  status = rtems_partition_create(
301    0x1234, NULL, 1, 1, RTEMS_DEFAULT_ATTRIBUTES, &id );
302  fatal_directive_status(status, RTEMS_INVALID_ADDRESS, "pt create NULL buff");
303
304  /*
305   *  create - null id
306   */
307  status = rtems_partition_create(
308    0x1234, &buffer, 1, 1, RTEMS_DEFAULT_ATTRIBUTES, NULL );
309  fatal_directive_status(status, RTEMS_INVALID_ADDRESS, "pt create NULL id");
310
311  /*
312   *  create - SUCCESSFUL
313   */
314  status = rtems_partition_create(
315    0x1234, &buffer, 24, 8, RTEMS_DEFAULT_ATTRIBUTES, &id );
316  directive_failed(status, "pt create");
317
318  /*
319   *  ident -- NULL id
320   */
321  status = rtems_partition_ident( 0x1234, RTEMS_SEARCH_ALL_NODES, NULL );
322  fatal_directive_status(status, RTEMS_INVALID_ADDRESS, "ident NULL id");
323
324  /*
325   *  get_buffer - null buffer
326   */
327  status = rtems_partition_get_buffer( id, NULL );
328  fatal_directive_status(status, RTEMS_INVALID_ADDRESS, "pt get NULL buff");
329
330  /*
331   *  return_buffer - null buffer
332   */
333  status = rtems_partition_return_buffer( id, NULL );
334  fatal_directive_status(status, RTEMS_INVALID_ADDRESS, "pt return NULL buff");
335
336  /*
337   *  delete - SUCCESSFUL
338   *  get_buffer - null buffer
339   */
340  status = rtems_partition_get_buffer( id, NULL );
341  fatal_directive_status(status, RTEMS_INVALID_ADDRESS, "pt get NULL buff");
342
343  /*
344   *  delete - SUCCESSFUL
345   */
346  status = rtems_partition_delete( id );
347  directive_failed(status, "pt delete");
348
349}
350
351void check_period_nulls(void)
352{
353  rtems_status_code status;
354
355  PUTS( "Testing period null checks" );
356
357  /*
358   *  create - null id
359   */
360  status = rtems_rate_monotonic_create( 0x1234, NULL );
361  fatal_directive_status(status, RTEMS_INVALID_ADDRESS, "rtmon create NULL id");
362}
363
364void check_region_nulls(void)
365{
366  rtems_status_code status;
367  rtems_id id;
368  unsigned char buffer[32];
369  unsigned32 size;
370
371  PUTS( "Testing region null checks" );
372
373  /*
374   *  create - null address
375   */
376  status = rtems_region_create(
377     0x1234, NULL, 8, 4, RTEMS_DEFAULT_ATTRIBUTES, &id );
378  fatal_directive_status(status, RTEMS_INVALID_ADDRESS,"regn create NULL addr");
379
380  /*
381   *  create - null id
382   */
383  status = rtems_region_create(
384     0x1234, buffer, 24, 4, RTEMS_DEFAULT_ATTRIBUTES, NULL );
385  fatal_directive_status(status, RTEMS_INVALID_ADDRESS,"regn create NULL id");
386
387  /*
388   *  create - SUCCESSFUL
389   */
390  status = rtems_region_create(
391      0x1234, buffer, 24, 8,  RTEMS_DEFAULT_ATTRIBUTES, &id );
392  directive_failed(status, "regn create");
393
394  /*
395   *  ident -- NULL id
396   */
397  status = rtems_region_ident( 0x1234, NULL );
398  fatal_directive_status(status, RTEMS_INVALID_ADDRESS, "ident NULL id");
399
400  /*
401   *  extend - null address
402   */
403  status = rtems_region_extend( id, NULL, 32 );
404  fatal_directive_status(status, RTEMS_INVALID_ADDRESS,"regn extend NULL");
405
406  /*
407   *  get segment - null segment
408   */
409  status = rtems_region_get_segment( id, 2, RTEMS_DEFAULT_OPTIONS, 0, NULL );
410  fatal_directive_status(status, RTEMS_INVALID_ADDRESS,"regn get seg NULL");
411
412  /*
413   *  get segment size - null segment
414   */
415  status = rtems_region_get_segment_size( id, NULL, &size );
416  fatal_directive_status(status, RTEMS_INVALID_ADDRESS,"regn get sz NULL seg");
417
418  /*
419   *  get segment size - null size
420   */
421  status = rtems_region_get_segment_size( id, &buffer[4], NULL );
422  fatal_directive_status(status, RTEMS_INVALID_ADDRESS,"regn get sz NULL sz");
423
424  /*
425   *  delete - SUCCESSFUL
426   */
427  status = rtems_region_delete( id );
428  directive_failed(status, "regn delete");
429}
430
431void check_sem_nulls(void)
432{
433  rtems_status_code status;
434
435  PUTS( "Testing sem null checks" );
436
437  /*
438   *  create - null id
439   */
440  status = rtems_semaphore_create(0x1234, 6, RTEMS_DEFAULT_ATTRIBUTES, 1, NULL);
441  fatal_directive_status(status, RTEMS_INVALID_ADDRESS, "sem create NULL id");
442
443  /*
444   *  ident -- NULL id
445   */
446  status = rtems_semaphore_ident( 0x1234, RTEMS_SEARCH_ALL_NODES, NULL );
447  fatal_directive_status(status, RTEMS_INVALID_ADDRESS, "ident NULL id");
448}
449
450void check_timer_nulls(void)
451{
452  rtems_status_code status;
453  rtems_id id;
454
455  PUTS( "Testing timer null checks" );
456
457  /*
458   *  create - null id
459   */
460  status = rtems_timer_create( 0x1234, NULL );
461  fatal_directive_status(status, RTEMS_INVALID_ADDRESS, "tmr create NULL id");
462
463  /*
464   *  create - SUCCESSFUL
465   */
466  status = rtems_timer_create( 0x1234, &id );
467  directive_failed(status, "tmr create");
468
469  /*
470   *  fire after - null routine
471   */
472  status = rtems_timer_fire_after( id, 1, NULL, NULL );
473  fatal_directive_status(
474      status, RTEMS_INVALID_ADDRESS, "tmr fire after NULL routine");
475
476  /*
477   *  initiate server - SUCCESSFUL
478   */
479  status = rtems_timer_initiate_server(
480    RTEMS_TIMER_SERVER_DEFAULT_PRIORITY, 0, RTEMS_DEFAULT_ATTRIBUTES );
481  directive_failed(status, "tmr server initiate");
482
483  /*
484   *  fire server after - null routine
485   */
486  status = rtems_timer_server_fire_after( id, 1, NULL, NULL );
487  fatal_directive_status(
488      status, RTEMS_INVALID_ADDRESS, "tmr server fire after NULL routine");
489
490  /*
491   *  fire when - null routine
492   */
493  {
494    rtems_time_of_day time = { 2004, 4, 27, 16, 15, 0 };
495
496    status = rtems_timer_fire_when( id, &time, NULL, NULL );
497    fatal_directive_status(
498        status, RTEMS_INVALID_ADDRESS, "tmr fire when NULL routine");
499
500    status = rtems_timer_server_fire_when( id, &time, NULL, NULL );
501    fatal_directive_status(
502        status, RTEMS_INVALID_ADDRESS, "tmr server fire when NULL routine");
503  }
504
505
506  /*
507   *  delete - SUCCESSFUL
508   */
509  status = rtems_timer_delete( id );
510  directive_failed(status, "tmr delete");
511}
512
513rtems_task Init(
514  rtems_task_argument ignored
515)
516{
517
518  check_task_nulls();
519  check_clock_nulls();
520  check_dpmem_nulls();
521  check_event_nulls();
522  check_msgq_nulls();
523  check_part_nulls();
524  check_period_nulls();
525  check_region_nulls();
526  check_sem_nulls();
527  check_timer_nulls();
528
529#if 0
530  status = rtems_task_delete( RTEMS_SELF );
531#endif
532
533  PUTS( "Testing complete" );
534  exit( 0 );
535}
536
537/* configuration information */
538
539#define CONFIGURE_TEST_NEEDS_CONSOLE_DRIVER
540#define CONFIGURE_TEST_NEEDS_CLOCK_DRIVER
541#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
542
543/* one main thread, one test thread, and a timer server */
544#define CONFIGURE_MAXIMUM_TASKS 3
545#define CONFIGURE_MAXIMUM_PORTS 1
546#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 1
547#define CONFIGURE_MAXIMUM_PARTITIONS 1
548#define CONFIGURE_MAXIMUM_REGIONS 1
549#define CONFIGURE_MAXIMUM_TIMERS 1
550
551#define CONFIGURE_INIT
552
553#include <confdefs.h>
554
555/* end of file */