Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:45

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 1989-2012.
0005  *  On-Line Applications Research Corporation (OAR).
0006  *
0007  * Redistribution and use in source and binary forms, with or without
0008  * modification, are permitted provided that the following conditions
0009  * are met:
0010  * 1. Redistributions of source code must retain the above copyright
0011  *    notice, this list of conditions and the following disclaimer.
0012  * 2. Redistributions in binary form must reproduce the above copyright
0013  *    notice, this list of conditions and the following disclaimer in the
0014  *    documentation and/or other materials provided with the distribution.
0015  *
0016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0017  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0019  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0020  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0021  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0022  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0023  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0024  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0025  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0026  * POSSIBILITY OF SUCH DAMAGE.
0027  */
0028 
0029 #ifdef HAVE_CONFIG_H
0030 #include "config.h"
0031 #endif
0032 
0033 #include <tmacros.h>
0034 #include <unistd.h>
0035 
0036 const char rtems_test_name[] = "SP 62";
0037 
0038 /* forward declarations to avoid warnings */
0039 rtems_task Init(rtems_task_argument argument);
0040 rtems_task Blocker(rtems_task_argument ignored);
0041 
0042 rtems_id      Region;
0043 uint32_t      Region_Memory[256] CPU_STRUCTURE_ALIGNMENT;
0044 volatile bool case_hit;
0045 
0046 #define    SECOND_ALLOC (sizeof(Region_Memory) / 2)
0047 #define    RESIZE 1
0048 
0049 rtems_task Blocker(
0050   rtems_task_argument ignored
0051 )
0052 {
0053   rtems_status_code  sc;
0054   void              *segment_address_2;
0055 
0056   puts( "Blocker - rtems_region_get_segment - OK");
0057   sc = rtems_region_get_segment(
0058     Region,
0059     SECOND_ALLOC,
0060     RTEMS_DEFAULT_OPTIONS,
0061     RTEMS_NO_TIMEOUT,
0062     &segment_address_2
0063   );
0064   directive_failed( sc, "rtems_region_get_segment" );
0065 
0066   sc = rtems_region_return_segment( Region, segment_address_2 );
0067   rtems_test_assert( sc == RTEMS_SUCCESSFUL );
0068 
0069   puts( "Blocker - Got memory after resize" );
0070   case_hit = true;
0071 
0072   rtems_task_exit();
0073 }
0074 
0075 rtems_task Init(
0076   rtems_task_argument ignored
0077 )
0078 {
0079   rtems_id           task_id;
0080   rtems_status_code  sc;
0081   void              *segment_address_1;
0082   uintptr_t          old_size;
0083   size_t             first_alloc_size;
0084 
0085   TEST_BEGIN();
0086 
0087   puts( "Init - rtems_task_create Blocker - OK" );
0088   sc = rtems_task_create(
0089     rtems_build_name( 'B', 'L', 'C', 'K' ),
0090     1,
0091     RTEMS_MINIMUM_STACK_SIZE,
0092     RTEMS_DEFAULT_MODES,
0093     RTEMS_DEFAULT_ATTRIBUTES,
0094     &task_id
0095   );
0096   directive_failed( sc, "rtems_task_create of Blocker" );
0097 
0098   puts( "Init - rtems_task_start Blocker - OK" );
0099   sc = rtems_task_start( task_id, Blocker, 0 );
0100   directive_failed( sc, "rtems_task_start of Blocker" );
0101 
0102   puts( "Init - rtems_task_create Region - OK" );
0103   sc = rtems_region_create(
0104     rtems_build_name( 'R', 'N', '1', ' ' ),
0105     Region_Memory,
0106     sizeof(Region_Memory),
0107     16,
0108     RTEMS_DEFAULT_ATTRIBUTES,
0109     &Region
0110   );
0111   directive_failed( sc, "rtems_region_create" );
0112 
0113   puts( "Init - rtems_region_get_segment - OK");
0114   first_alloc_size = sizeof( Region_Memory );
0115   do {
0116     --first_alloc_size;
0117     sc = rtems_region_get_segment(
0118       Region,
0119       first_alloc_size,
0120       RTEMS_NO_WAIT,
0121       RTEMS_NO_TIMEOUT,
0122       &segment_address_1
0123     );
0124   } while ( sc == RTEMS_UNSATISFIED || sc == RTEMS_INVALID_SIZE );
0125   rtems_test_assert( sc == RTEMS_SUCCESSFUL );
0126 
0127   puts( "Init - sleep 1 second for Blocker - OK");
0128   sleep(1);
0129 
0130   /* Check resize_segment errors */
0131   sc = rtems_region_resize_segment(
0132     Region, segment_address_1, RESIZE, &old_size);
0133   directive_failed( sc, "rtems_region_resize_segment" );
0134 
0135   case_hit = false;
0136 
0137   puts( "Init - sleep 1 second for Blocker to run again - OK");
0138   sleep(1);
0139 
0140   if ( case_hit ) {
0141     puts( "Init - successfully resized and unblocked a task" );
0142   } else {
0143     puts( "Init - failed to resize and unblock a task" );
0144     rtems_test_exit(0);
0145   }
0146 
0147   /*
0148    *  Now resize and take all of memory so there is no need to
0149    *  process any blocked tasks waiting for memory.
0150    */
0151   puts( "Init - resized to all of available memory" );
0152   sc = rtems_region_resize_segment(
0153     Region,
0154     segment_address_1,
0155     first_alloc_size,
0156     &old_size
0157   );
0158   rtems_test_assert( sc == RTEMS_SUCCESSFUL );
0159 
0160   TEST_END();
0161   rtems_test_exit(0);
0162 }
0163 
0164 /* configuration information */
0165 
0166 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0167 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0168 
0169 #define CONFIGURE_MAXIMUM_TASKS         2
0170 #define CONFIGURE_MAXIMUM_REGIONS       1
0171 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0172 
0173 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0174 
0175 #define CONFIGURE_INIT
0176 #include <rtems/confdefs.h>
0177 
0178 /* global variables */