source: rtems/testsuites/psxtests/psxmsgq04/init.c @ c005d41

4.104.115
Last change on this file since c005d41 was c005d41, checked in by Joel Sherrill <joel.sherrill@…>, on 08/06/09 at 19:24:38

2009-08-06 Joel Sherrill <joel.sherrill@…>

  • psxmsgq04/init.c, psxmsgq04/psxmsgq04.scn: Tinker with test to ensure that it hits both failing to allocate memory for the message queue name and message buffers.
  • Property mode set to 100644
File size: 3.7 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2009.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.com/license/LICENSE.
8 *
9 *  $Id$
10 */
11
12#include <pmacros.h>
13#include <unistd.h>
14#include <errno.h>
15#include <tmacros.h>
16
17#include <fcntl.h>           /* For O_* constants */
18#include <sys/stat.h>        /* For mode constants */
19#include <mqueue.h>
20
21#include "test_support.h"
22
23void *POSIX_Init(
24  void *argument
25)
26{
27  struct mq_attr          attr;
28  mqd_t                   Queue, second_Queue;
29  int                     sc;
30  Heap_Information_block  start;
31  Heap_Information_block  info;
32  size_t                  to_alloc;
33  void                   *alloced;
34  bool                    sb;
35  const char             *name;
36
37  puts( "\n\n*** POSIX MESSAGE QUEUE TEST 4 ***" );
38
39  attr.mq_maxmsg = 1;
40  attr.mq_msgsize = sizeof(int);
41
42  puts( "Init - Open message queue instance 1" );
43  Queue = mq_open( "Queue", O_CREAT | O_RDWR, 0x777, &attr );
44  if ( Queue == (-1) )
45    perror( "mq_open failed" );
46  assert( Queue != (-1) );
47
48  puts( "Init - Open message queue instance 2 - FAIL - ENFILE " );
49  second_Queue = mq_open( "Queue2", O_CREAT | O_RDWR, 0x777, &attr );
50  if ( second_Queue != (-1) )
51    puts( "mq_open did not failed" );
52  assert( second_Queue == (-1) );
53  assert( errno == ENFILE );
54
55  puts( "Init - Unlink message queue instance 1" );
56  sc = mq_unlink( "Queue" );
57  if ( sc != 0 )
58    perror( "mq_unlink failed" );
59  assert( sc == 0 );
60
61  puts( "Init - Close message queue instance 1" );
62  sc = mq_close( Queue );
63  if ( sc != 0 )
64    perror( "mq_close failed" );
65  assert( sc == 0 );
66
67  sb = rtems_workspace_get_information( &start );
68  assert( start.Free.number == 1 );
69  to_alloc = start.Free.largest;
70
71  /* find the largest we can actually allocate */
72  while ( 1 ) {
73    sb = rtems_workspace_allocate( to_alloc, &alloced );
74    if ( sb )
75      break;
76    to_alloc -= 4;
77  }
78
79  rtems_workspace_free( alloced );
80
81  /*
82   * Now do the test
83   */
84  puts( "Init - Memory allocation error test" );
85
86  sb = rtems_workspace_get_information( &info );
87
88  attr.mq_maxmsg = 1;
89  attr.mq_msgsize = 200;
90
91  name = Get_Longest_Name();
92  while ( attr.mq_msgsize > 0 ) {
93    sb = rtems_workspace_allocate( to_alloc, &alloced );
94    assert( sb );
95   
96    second_Queue = mq_open(name,O_CREAT | O_RDWR, 0x777, &attr );
97
98    /* free the memory we snagged, then check the status */
99    rtems_workspace_free( alloced );
100
101    if ( second_Queue != (-1) )
102      break;
103
104    /* attr.mq_msgsize -= 48; */
105    to_alloc -= 4;
106  }
107
108  if ( second_Queue == -1 )
109    rtems_test_exit(0);
110
111  puts( "Init - Message Queue created" );
112
113  puts( "Init - Unlink message queue" );
114    sc = mq_unlink( name );
115    if ( sc != 0 )
116      perror( "mq_unlink failed" );
117    assert( sc == 0 );
118
119  puts( "Init - Close message queue" );
120    sc = mq_close( second_Queue );
121    if ( sc != 0 )
122      perror( "mq_close failed" );
123    assert( sc == 0 );
124
125  puts( "*** END OF POSIX MESSAGE QUEUE TEST 4 ***" );
126  rtems_test_exit( 0 );
127
128  return NULL; /* just so the compiler thinks we returned something */
129}
130
131/* configuration information */
132
133#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
134#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
135
136#define CONFIGURE_POSIX_INIT_THREAD_TABLE
137
138/* account for message buffers and string names */
139#define CONFIGURE_MESSAGE_BUFFER_MEMORY \
140    CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(1, sizeof(int))
141
142#define CONFIGURE_MAXIMUM_POSIX_THREADS                   1
143#define CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES            1
144#define CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUE_DESCRIPTORS 2
145
146#define CONFIGURE_POSIX_INIT_THREAD_TABLE
147
148#define CONFIGURE_INIT
149#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.