Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  *  @file
0005  *  Odd Object Name/Id Error Cases
0006  */
0007 
0008 /*
0009  *  COPYRIGHT (c) 1989-2012.
0010  *  On-Line Applications Research Corporation (OAR).
0011  *
0012  * Redistribution and use in source and binary forms, with or without
0013  * modification, are permitted provided that the following conditions
0014  * are met:
0015  * 1. Redistributions of source code must retain the above copyright
0016  *    notice, this list of conditions and the following disclaimer.
0017  * 2. Redistributions in binary form must reproduce the above copyright
0018  *    notice, this list of conditions and the following disclaimer in the
0019  *    documentation and/or other materials provided with the distribution.
0020  *
0021  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0022  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0023  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0024  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0025  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0026  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0027  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0028  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0029  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0030  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0031  * POSSIBILITY OF SUCH DAMAGE.
0032  */
0033 
0034 #ifdef HAVE_CONFIG_H
0035 #include "config.h"
0036 #endif
0037 
0038 #include <tmacros.h>
0039 
0040 #include <rtems/score/objectimpl.h>
0041 
0042 const char rtems_test_name[] = "PSXOBJ 1";
0043 
0044 typedef struct {
0045   Objects_Control Object;
0046 } Test_Control;
0047 
0048 /* very fake object class to test with */
0049 OBJECTS_INFORMATION_DEFINE( Test, 1, 4, Test_Control, 0, 10, NULL );
0050 
0051 static rtems_task Init(
0052   rtems_task_argument ignored
0053 )
0054 {
0055   Objects_Get_by_name_error  error;
0056   Objects_Control           *the_object;
0057   char                       name[64];
0058   size_t                     name_len;
0059   Status_Control             status;
0060 
0061   TEST_BEGIN();
0062 
0063   puts( "INIT - _Objects_Get_by_name - NULL name" );
0064   _Objects_Allocator_lock();
0065   the_object = _Objects_Get_by_name( &Test_Information, NULL, NULL, &error );
0066   _Objects_Allocator_unlock();
0067   rtems_test_assert( the_object == NULL );
0068   rtems_test_assert( error == OBJECTS_GET_BY_NAME_INVALID_NAME );
0069 
0070   puts( "INIT - _Objects_Get_by_name - name too long" );
0071   strcpy( name, "TOOOOOOOOOOOOOOOOOO LONG" );
0072   _Objects_Allocator_lock();
0073   the_object = _Objects_Get_by_name( &Test_Information, name, NULL, &error );
0074   _Objects_Allocator_unlock();
0075   rtems_test_assert( the_object == NULL );
0076   rtems_test_assert( error == OBJECTS_GET_BY_NAME_NAME_TOO_LONG );
0077 
0078   puts( "INIT - _Objects_Get_by_name - name of non-existent object" );
0079   strcpy( name, "NOT FOUND" );
0080   name_len = 123;
0081   _Objects_Allocator_lock();
0082   the_object = _Objects_Get_by_name( &Test_Information, name, &name_len, &error );
0083   _Objects_Allocator_unlock();
0084   rtems_test_assert( the_object == NULL );
0085   rtems_test_assert( error == OBJECTS_GET_BY_NAME_NO_OBJECT );
0086   rtems_test_assert( name_len == 9 );
0087 
0088   /* out of memory error ONLY when POSIX is enabled */
0089   puts( "INIT - _Objects_Set_name fails - out of memory" );
0090   rtems_workspace_greedy_allocate( NULL, 0 );
0091 
0092   status = _Objects_Set_name(
0093     &Test_Information,
0094     &_Thread_Get_executing()->Object,
0095     name
0096   );
0097   rtems_test_assert( status == STATUS_NO_MEMORY );
0098 
0099   TEST_END();
0100   rtems_test_exit(0);
0101 }
0102 
0103 /* configuration information */
0104 
0105 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0106 #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
0107 
0108 #define CONFIGURE_MAXIMUM_TASKS  1
0109 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0110 
0111 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0112 
0113 #define CONFIGURE_INIT
0114 #include <rtems/confdefs.h>
0115 
0116 /* global variables */