source: rtems/testsuites/psxtests/psxkey02/init.c @ 33c46f1

4.115
Last change on this file since 33c46f1 was 33c46f1, checked in by Joel Sherrill <joel.sherrill@…>, on 10/21/10 at 21:22:25

2010-10-21 Joel Sherrill <joel.sherrill@…>

  • psx02/init.c, psx02/task.c, psx03/init.c, psx04/init.c, psx04/task1.c, psx04/task2.c, psx04/task3.c, psx05/init.c, psx05/task.c, psx05/task2.c, psx05/task3.c, psx06/init.c, psx06/task.c, psx06/task2.c, psx07/init.c, psx08/init.c, psx08/task2.c, psx08/task3.c, psx09/init.c, psx10/init.c, psx10/task.c, psx10/task2.c, psx10/task3.c, psx11/init.c, psx11/task.c, psx12/init.c, psxalarm01/init.c, psxbarrier01/test.c, psxcancel01/init.c, psxchroot01/test.c, psxitimer/init.c, psxkey01/task.c, psxkey02/init.c, psxkey03/init.c, psxmount/test.c, psxmsgq01/init.c, psxmsgq03/init.c, psxmsgq04/init.c, psxrwlock01/test.c, psxsem01/init.c, psxsignal01/init.c, psxsignal01/task1.c, psxsignal02/init.c, psxsignal03/init.c, psxsignal05/init.c, psxspin01/test.c, psxspin02/test.c, psxstack01/init.c, psxstack02/init.c, psxualarm/init.c: Eliminate double space after parenthesis on rtems_test_assert().
  • Property mode set to 100644
File size: 3.5 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 <pthread.h>
13#include <errno.h>
14#include "tmacros.h"
15#include "pmacros.h"
16
17void *POSIX_Init(
18  void *ignored
19)
20{
21  pthread_key_t           key;
22  int                     sc;
23  bool                    sb;
24  Heap_Information_block  start;
25  Heap_Information_block  info;
26  size_t                  to_alloc;
27  void                   *alloced;
28
29  puts( "\n\n*** TEST KEY 02 ***" );
30
31  puts( "Init - rtems_workspace_get_information - OK" );
32  sb = rtems_workspace_get_information( &start );
33  rtems_test_assert( sb );
34
35  #if 0
36    printf( "Init - workspace free = %d\n", start.Free.largest );
37    printf( "Init - workspace free blocks = %d\n", start.Free.number );
38  #endif
39  rtems_test_assert( start.Free.number == 1 );
40  to_alloc = start.Free.largest;
41
42  /* find the largest we can actually allocate */
43  while ( 1 ) {
44    sb = rtems_workspace_allocate( to_alloc, &alloced );
45    if ( sb )
46      break;
47    to_alloc -= 4;
48  }
49
50  rtems_workspace_free( alloced );
51
52  #if 0
53    printf( "Init - start with to_alloc of = %d\n", to_alloc );
54  #endif
55
56  /*
57   * Verify heap is still in same shape if we couldn't allocate a task
58   */
59  sb = rtems_workspace_get_information( &info );
60  rtems_test_assert( sb );
61  rtems_test_assert( info.Free.largest == start.Free.largest );
62  rtems_test_assert( info.Free.number  == start.Free.number  );
63
64  puts( "Init - pthread_key_create - ENOMEM" );
65  while (1) {
66
67    sb = rtems_workspace_allocate( to_alloc, &alloced );
68    rtems_test_assert( sb );
69
70    sc = pthread_key_create( &key, NULL );
71
72    /* free the memory we snagged, then check the status */
73    rtems_workspace_free( alloced );
74
75    if ( !sc )
76      break;
77
78    if ( sc != ENOMEM ) {
79      printf( "key create returned %s\n", strerror(sc) );
80      rtems_test_exit(0);
81    }
82
83    /*
84     * Verify heap is still in same shape if we couldn't allocate a task
85     */
86    sb = rtems_workspace_get_information( &info );
87    #if 0
88      printf( "Init - workspace free/blocks = %d/%d\n",
89        info.Free.largest, info.Free.number );
90    #endif
91    rtems_test_assert( sb );
92    rtems_test_assert( info.Free.largest == start.Free.largest );
93    rtems_test_assert( info.Free.number  == start.Free.number  );
94
95    to_alloc -= 8;
96    if ( to_alloc == 0 )
97     break;
98  }
99
100  if ( sc )
101    rtems_test_exit(0);
102
103  /*
104   * Verify heap is still in same shape after we free the task
105   */
106  puts( "Init - pthread_key_delete - OK" );
107  sc = pthread_key_delete( key );
108  rtems_test_assert( sc == 0 );
109
110  puts( "Init - verify workspace has same memory" );
111  sb = rtems_workspace_get_information( &info );
112  #if 0
113    printf( "Init - workspace free/blocks = %d/%d\n",
114      info.Free.largest, info.Free.number );
115  #endif
116  rtems_test_assert( sb );
117  rtems_test_assert( info.Free.largest == start.Free.largest );
118  rtems_test_assert( info.Free.number  == start.Free.number  );
119
120  puts( "*** END OF TEST KEY 02 ***" );
121  rtems_test_exit(0);
122}
123
124/* configuration information */
125
126#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
127#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
128
129#define CONFIGURE_MAXIMUM_POSIX_THREADS  1
130#define CONFIGURE_MAXIMUM_POSIX_KEYS     1
131
132#define CONFIGURE_POSIX_INIT_THREAD_TABLE
133
134#define CONFIGURE_INIT
135#include <rtems/confdefs.h>
136
137/* global variables */
Note: See TracBrowser for help on using the repository browser.