Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 1989-2011.
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 "test_support.h"
0035 #include <rtems/libio_.h>
0036 #include <rtems/malloc.h>
0037 #include <rtems/libcsupport.h>
0038 
0039 const char rtems_test_name[] = "SPPRIVENV 1";
0040 
0041 /* forward declarations to avoid warnings */
0042 rtems_task Init(rtems_task_argument argument);
0043 rtems_task task_routine(rtems_task_argument not_used);
0044 
0045 rtems_task task_routine(rtems_task_argument not_used)
0046 {
0047   rtems_status_code sc;
0048 
0049   puts( "task_routine - setting up a private environment" );
0050 
0051   sc = rtems_libio_set_private_env();
0052   directive_failed( sc, "set private env" );
0053   rtems_test_assert( sc == RTEMS_SUCCESSFUL );
0054   rtems_test_assert( rtems_current_user_env != &rtems_global_user_env );
0055 
0056   sleep( 1 );
0057 
0058   rtems_task_exit();
0059 }
0060 
0061 rtems_task Init(
0062   rtems_task_argument argument
0063 )
0064 {
0065   rtems_status_code       sc;
0066   void                   *opaque;
0067   rtems_id                task_id;
0068   rtems_name              another_task_name;
0069   rtems_user_env_t       *current_env;
0070 
0071   TEST_BEGIN();
0072 
0073   puts( "Init - allocating most of heap -- OK" );
0074   opaque = rtems_heap_greedy_allocate( NULL, 0 );
0075 
0076   puts( "Init - attempt to reset env - expect RTEMS_NO_MEMORY" );
0077   sc = rtems_libio_set_private_env();
0078   rtems_test_assert( sc == RTEMS_NO_MEMORY );
0079 
0080   puts( "Init - freeing the allocated memory" );
0081   rtems_heap_greedy_free( opaque );
0082 
0083   puts( "Init - allocating most of workspace memory" );
0084   opaque = rtems_workspace_greedy_allocate( NULL, 0 );
0085 
0086   puts( "Init - attempt to reset env - expect RTEMS_SUCCESSFUL" );
0087   sc = rtems_libio_set_private_env();
0088   rtems_test_assert( sc == RTEMS_SUCCESSFUL );
0089   rtems_test_assert( rtems_current_user_env != &rtems_global_user_env );
0090 
0091   puts( "Init - freeing the workspace memory" );
0092   rtems_workspace_greedy_free( opaque );
0093 
0094   puts( "Init - Reset to global environment" );
0095   rtems_libio_use_global_env();
0096   rtems_test_assert( rtems_current_user_env == &rtems_global_user_env );
0097 
0098   puts( "Init - Attempt to get a private environment" );
0099   sc = rtems_libio_set_private_env();
0100   rtems_test_assert( sc == RTEMS_SUCCESSFUL );
0101   current_env = rtems_current_user_env;
0102   rtems_test_assert( current_env != &rtems_global_user_env );
0103 
0104   puts( "Init - creating a task name and a task -- OK" );
0105 
0106   another_task_name = 
0107     rtems_build_name( 'T','S','K','D' );
0108 
0109   sc = rtems_task_create( another_task_name,
0110               1,
0111               RTEMS_MINIMUM_STACK_SIZE * 2,
0112               RTEMS_DEFAULT_MODES,
0113               RTEMS_DEFAULT_ATTRIBUTES,
0114               &task_id
0115               );
0116 
0117   puts( "Init - starting the task_routine, to set its private environment" );
0118   sc = rtems_task_start( task_id, task_routine, 0);
0119   rtems_test_assert( sc == RTEMS_SUCCESSFUL );
0120 
0121   sleep( 1 );
0122 
0123   puts( "Init - Check current private environment. Should be same as before." );
0124   rtems_test_assert( rtems_current_user_env == current_env );
0125 
0126   puts( "Init - Reset to global environment" );
0127   rtems_libio_use_global_env();
0128   rtems_test_assert( rtems_current_user_env == &rtems_global_user_env );
0129 
0130   TEST_END();
0131 
0132   rtems_test_exit(0);
0133 }
0134 
0135 /* configuration information */
0136 
0137 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0138 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0139 
0140 #define CONFIGURE_MAXIMUM_TASKS             3
0141 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0142 
0143 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0144 
0145 #define CONFIGURE_INIT
0146 
0147 #include <rtems/confdefs.h>
0148 /* end of file */