1 | /** |
---|
2 | * @file |
---|
3 | * Odd Object Name/Id Error Cases |
---|
4 | */ |
---|
5 | |
---|
6 | /* |
---|
7 | * COPYRIGHT (c) 1989-2012. |
---|
8 | * On-Line Applications Research Corporation (OAR). |
---|
9 | * |
---|
10 | * The license and distribution terms for this file may be |
---|
11 | * found in the file LICENSE in this distribution or at |
---|
12 | * http://www.rtems.org/license/LICENSE. |
---|
13 | */ |
---|
14 | |
---|
15 | #ifdef HAVE_CONFIG_H |
---|
16 | #include "config.h" |
---|
17 | #endif |
---|
18 | |
---|
19 | #include <tmacros.h> |
---|
20 | |
---|
21 | #include <rtems/score/objectimpl.h> |
---|
22 | |
---|
23 | const char rtems_test_name[] = "PSXOBJ 1"; |
---|
24 | |
---|
25 | typedef struct { |
---|
26 | Objects_Control Object; |
---|
27 | } Test_Control; |
---|
28 | |
---|
29 | /* very fake object class to test with */ |
---|
30 | OBJECTS_INFORMATION_DEFINE( Test, 1, 4, Test_Control, 0, 10, NULL ); |
---|
31 | |
---|
32 | static rtems_task Init( |
---|
33 | rtems_task_argument ignored |
---|
34 | ) |
---|
35 | { |
---|
36 | Objects_Get_by_name_error error; |
---|
37 | Objects_Control *the_object; |
---|
38 | char name[64]; |
---|
39 | size_t name_len; |
---|
40 | bool bc; |
---|
41 | |
---|
42 | TEST_BEGIN(); |
---|
43 | |
---|
44 | puts( "INIT - _Objects_Get_by_name - NULL name" ); |
---|
45 | _Objects_Allocator_lock(); |
---|
46 | the_object = _Objects_Get_by_name( &Test_Information, NULL, NULL, &error ); |
---|
47 | _Objects_Allocator_unlock(); |
---|
48 | rtems_test_assert( the_object == NULL ); |
---|
49 | rtems_test_assert( error == OBJECTS_GET_BY_NAME_INVALID_NAME ); |
---|
50 | |
---|
51 | puts( "INIT - _Objects_Get_by_name - name too long" ); |
---|
52 | strcpy( name, "TOOOOOOOOOOOOOOOOOO LONG" ); |
---|
53 | _Objects_Allocator_lock(); |
---|
54 | the_object = _Objects_Get_by_name( &Test_Information, name, NULL, &error ); |
---|
55 | _Objects_Allocator_unlock(); |
---|
56 | rtems_test_assert( the_object == NULL ); |
---|
57 | rtems_test_assert( error == OBJECTS_GET_BY_NAME_NAME_TOO_LONG ); |
---|
58 | |
---|
59 | puts( "INIT - _Objects_Get_by_name - name of non-existent object" ); |
---|
60 | strcpy( name, "NOT FOUND" ); |
---|
61 | name_len = 123; |
---|
62 | _Objects_Allocator_lock(); |
---|
63 | the_object = _Objects_Get_by_name( &Test_Information, name, &name_len, &error ); |
---|
64 | _Objects_Allocator_unlock(); |
---|
65 | rtems_test_assert( the_object == NULL ); |
---|
66 | rtems_test_assert( error == OBJECTS_GET_BY_NAME_NO_OBJECT ); |
---|
67 | rtems_test_assert( name_len == 9 ); |
---|
68 | |
---|
69 | /* out of memory error ONLY when POSIX is enabled */ |
---|
70 | puts( "INIT - _Objects_Set_name fails - out of memory" ); |
---|
71 | rtems_workspace_greedy_allocate( NULL, 0 ); |
---|
72 | |
---|
73 | bc = _Objects_Set_name( |
---|
74 | &Test_Information, |
---|
75 | &_Thread_Get_executing()->Object, |
---|
76 | name |
---|
77 | ); |
---|
78 | rtems_test_assert( bc == false ); |
---|
79 | |
---|
80 | TEST_END(); |
---|
81 | rtems_test_exit(0); |
---|
82 | } |
---|
83 | |
---|
84 | /* configuration information */ |
---|
85 | |
---|
86 | #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER |
---|
87 | #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER |
---|
88 | |
---|
89 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
90 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
91 | |
---|
92 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
93 | |
---|
94 | #define CONFIGURE_INIT |
---|
95 | #include <rtems/confdefs.h> |
---|
96 | |
---|
97 | /* global variables */ |
---|