File indexing completed on 2025-05-11 08:24:49
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
0030
0031 #ifdef HAVE_CONFIG_H
0032 #include "config.h"
0033 #endif
0034
0035 #include <tmacros.h>
0036
0037 #include <string.h>
0038
0039 #include <rtems/score/wkspace.h>
0040
0041 const char rtems_test_name[] = "SPWKSPACE";
0042
0043
0044 rtems_task Init(rtems_task_argument argument);
0045
0046 static void test_workspace_string_duplicate(void)
0047 {
0048 char a [] = "abcd";
0049 char b [] = "abc";
0050 char c [] = "ab";
0051 char d [] = "a";
0052 char e [] = "";
0053 size_t maxlen = 3;
0054 char *dup_a = _Workspace_String_duplicate( a, maxlen );
0055 char *dup_b = _Workspace_String_duplicate( b, maxlen );
0056 char *dup_c = _Workspace_String_duplicate( c, maxlen );
0057 char *dup_d = _Workspace_String_duplicate( d, maxlen );
0058 char *dup_e = _Workspace_String_duplicate( e, maxlen );
0059
0060 rtems_test_assert( dup_a != NULL );
0061 rtems_test_assert( dup_b != NULL );
0062 rtems_test_assert( dup_c != NULL );
0063 rtems_test_assert( dup_d != NULL );
0064 rtems_test_assert( dup_e != NULL );
0065 rtems_test_assert( strcmp( dup_a, b ) == 0 );
0066 rtems_test_assert( strcmp( dup_b, b ) == 0 );
0067 rtems_test_assert( strcmp( dup_c, c ) == 0 );
0068 rtems_test_assert( strcmp( dup_d, d ) == 0 );
0069 rtems_test_assert( strcmp( dup_e, e ) == 0 );
0070
0071 _Workspace_Free( dup_a );
0072 _Workspace_Free( dup_b );
0073 _Workspace_Free( dup_c );
0074 _Workspace_Free( dup_d );
0075 _Workspace_Free( dup_e );
0076 }
0077
0078 rtems_task Init(
0079 rtems_task_argument argument
0080 )
0081 {
0082 void *p1;
0083 bool retbool;
0084 Heap_Information_block info;
0085
0086 TEST_BEGIN();
0087
0088 puts( "rtems_workspace_get_information - null pointer" );
0089 retbool = rtems_workspace_get_information( NULL );
0090 rtems_test_assert( retbool == false );
0091
0092 puts( "rtems_workspace_get_information - OK" );
0093 retbool = rtems_workspace_get_information( &info );
0094 rtems_test_assert( retbool == true );
0095
0096 puts( "rtems_workspace_allocate - null pointer" );
0097 retbool = rtems_workspace_allocate( 42, NULL );
0098 rtems_test_assert( retbool == false );
0099
0100 puts( "rtems_workspace_allocate - 0 bytes" );
0101 retbool = rtems_workspace_allocate( 0, &p1 );
0102 rtems_test_assert( retbool == false );
0103
0104 puts( "rtems_workspace_allocate - too many bytes" );
0105 retbool = rtems_workspace_allocate( info.Free.largest * 2, &p1 );
0106 rtems_test_assert( retbool == false );
0107
0108 puts( "rtems_workspace_allocate - 42 bytes" );
0109 retbool = rtems_workspace_allocate( 42, &p1 );
0110 rtems_test_assert( retbool == true );
0111 rtems_test_assert( p1 != NULL );
0112
0113 puts( "rtems_workspace_free - NULL" );
0114 retbool = rtems_workspace_free( NULL );
0115 rtems_test_assert( retbool == true );
0116
0117 puts( "rtems_workspace_free - previous pointer to 42 bytes" );
0118 retbool = rtems_workspace_free( p1 );
0119 rtems_test_assert( retbool == true );
0120
0121 puts( "_Workspace_String_duplicate - samples" );
0122 test_workspace_string_duplicate();
0123
0124 TEST_END();
0125 rtems_test_exit( 0 );
0126 }
0127
0128
0129
0130 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0131 #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
0132
0133 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0134
0135 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0136
0137 #define CONFIGURE_MAXIMUM_TASKS 1
0138
0139 #define CONFIGURE_MEMORY_OVERHEAD 1
0140
0141 #define CONFIGURE_INIT
0142 #include <rtems/confdefs.h>