source: rtems/testsuites/sptests/sp62/init.c @ 3c8eda7

4.115
Last change on this file since 3c8eda7 was 3c8eda7, checked in by Joel Sherrill <joel.sherrill@…>, on 05/12/12 at 16:01:26

sptests - Eliminate missing prototype warnings

  • Property mode set to 100644
File size: 3.8 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2012.
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
10#ifdef HAVE_CONFIG_H
11#include "config.h"
12#endif
13
14#include <tmacros.h>
15#include <unistd.h>
16
17/* forward declarations to avoid warnings */
18rtems_task Init(rtems_task_argument argument);
19rtems_task Blocker(rtems_task_argument ignored);
20
21rtems_id      Region;
22uint32_t      Region_Memory[256] CPU_STRUCTURE_ALIGNMENT;
23volatile bool case_hit;
24
25#define    FIRST_ALLOC 980
26#define    BLOCK_ALLOC 900
27#define    RESIZE      16
28
29rtems_task Blocker(
30  rtems_task_argument ignored
31)
32{
33  rtems_status_code  sc;
34  void              *segment_address_1;
35
36  puts( "Blocker - rtems_region_get_segment - OK");
37  sc = rtems_region_get_segment(
38    Region,
39    BLOCK_ALLOC,
40    RTEMS_DEFAULT_OPTIONS,
41    RTEMS_NO_TIMEOUT,
42    &segment_address_1
43  );
44  directive_failed( sc, "rtems_region_get_segment" );
45
46  puts( "Blocker - Got memory after resize" );
47  case_hit = true;
48
49  (void) rtems_task_delete( RTEMS_SELF );
50}
51
52rtems_task Init(
53  rtems_task_argument ignored
54)
55{
56  rtems_id           task_id;
57  rtems_status_code  sc;
58  void              *segment_address_1;
59  uintptr_t          old_size;
60  size_t             size;
61
62  puts( "\n\n*** TEST 62 ***" );
63
64  puts( "Init - rtems_task_create Blocker - OK" );
65  sc = rtems_task_create(
66    rtems_build_name( 'B', 'L', 'C', 'K' ),
67    1,
68    RTEMS_MINIMUM_STACK_SIZE,
69    RTEMS_DEFAULT_MODES,
70    RTEMS_DEFAULT_ATTRIBUTES,
71    &task_id
72  );
73  directive_failed( sc, "rtems_task_create of Blocker" );
74
75  puts( "Init - rtems_task_start Blocker - OK" );
76  sc = rtems_task_start( task_id, Blocker, 0 );
77  directive_failed( sc, "rtems_task_start of Blocker" );
78
79  puts( "Init - rtems_task_create Region - OK" );
80  sc = rtems_region_create(
81    rtems_build_name( 'R', 'N', '1', ' ' ),
82    Region_Memory,
83    sizeof(Region_Memory),
84    16,
85    RTEMS_DEFAULT_ATTRIBUTES,
86    &Region
87  );
88  directive_failed( sc, "rtems_region_create" );
89
90  puts( "Init - rtems_region_get_segment - OK");
91  sc = rtems_region_get_segment(
92    Region,
93    FIRST_ALLOC,
94    RTEMS_DEFAULT_OPTIONS,
95    RTEMS_NO_TIMEOUT,
96    &segment_address_1
97  );
98  directive_failed( sc, "rtems_region_get_segment" );
99
100  puts( "Init - sleep 1 second for Blocker - OK");
101  sleep(1);
102
103  /* Check resize_segment errors */
104  sc = rtems_region_resize_segment(
105    Region, segment_address_1, RESIZE, &old_size);
106  directive_failed( sc, "rtems_region_resize_segment" );
107
108  case_hit = false;
109
110  puts( "Init - sleep 1 second for Blocker to run again - OK");
111  sleep(1);
112
113  if ( case_hit ) {
114    puts( "Init - successfully resized and unblocked a task" );
115  } else {
116    puts( "Init - failed to resize and unblock a task" );
117    rtems_test_exit(0);
118  }
119
120  /*
121   *  Now resize and take all of memory so there is no need to
122   *  process any blocked tasks waiting for memory.
123   */
124
125  size = sizeof(Region_Memory);
126  while (1) {
127    sc = rtems_region_resize_segment(
128      Region, segment_address_1, size, &old_size);
129    if ( sc == RTEMS_UNSATISFIED ) {
130      size --;
131      if ( size )
132        continue;
133    }
134    directive_failed( sc, "rtems_region_resize_segment" );
135    if ( sc == RTEMS_SUCCESSFUL )
136      break;
137
138  }
139  if ( sc == RTEMS_SUCCESSFUL && size != 0 )
140    puts( "Init - resized to all of available memory" );
141
142  puts( "*** END OF TEST 62 ***" );
143  rtems_test_exit(0);
144}
145
146/* configuration information */
147
148#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
149#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
150
151#define CONFIGURE_MAXIMUM_TASKS         2
152#define CONFIGURE_MAXIMUM_REGIONS       1
153#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
154
155#define CONFIGURE_INIT
156#include <rtems/confdefs.h>
157
158/* global variables */
Note: See TracBrowser for help on using the repository browser.