Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  Exercise Classic API Workspace Wrappers
0005  *
0006  *  COPYRIGHT (c) 1989-2009.
0007  *  On-Line Applications Research Corporation (OAR).
0008  *
0009  * Redistribution and use in source and binary forms, with or without
0010  * modification, are permitted provided that the following conditions
0011  * are met:
0012  * 1. Redistributions of source code must retain the above copyright
0013  *    notice, this list of conditions and the following disclaimer.
0014  * 2. Redistributions in binary form must reproduce the above copyright
0015  *    notice, this list of conditions and the following disclaimer in the
0016  *    documentation and/or other materials provided with the distribution.
0017  *
0018  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0019  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0020  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0021  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0022  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0023  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0024  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0025  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0026  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0027  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0028  * POSSIBILITY OF SUCH DAMAGE.
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 /* forward declarations to avoid warnings */
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 /* configuration information */
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>