File indexing completed on 2025-05-11 08:24:48
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
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
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
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