| 110 | } |
| 111 | |
| 112 | static void test_object_find_operations(void) |
| 113 | { |
| 114 | rt_object_t found; |
| 115 | rt_thread_t found_thread; |
| 116 | rt_device_t found_device; |
| 117 | char name[TEST_RT_NAME_MAX]; |
| 118 | rt_err_t ret; |
| 119 | |
| 120 | /* Scenario 1: Object Name Within TEST_RT_NAME_MAX */ |
| 121 | /* Test 1.1: Find static thread object with rt_object_find */ |
| 122 | struct rt_object static_obj; |
| 123 | uassert_true(generate_unique_name(name, TEST_RT_NAME_MAX, "sobj") == RT_EOK); |
| 124 | rt_object_init(&static_obj, RT_Object_Class_Thread, name); |
| 125 | found = rt_object_find(name, RT_Object_Class_Thread); |
| 126 | uassert_not_null(found); |
| 127 | uassert_ptr_equal(found, &static_obj); |
| 128 | uassert_str_equal(found->name, name); |
| 129 | rt_object_detach(&static_obj); |
| 130 | |
| 131 | /* Test 1.2: Find thread object with rt_thread_find */ |
| 132 | uassert_true(generate_unique_name(name, TEST_RT_NAME_MAX, "thr") == RT_EOK); |
| 133 | rt_thread_t thread = rt_thread_create(name, RT_NULL, RT_NULL, 1024, 20, 10); |
| 134 | uassert_not_null(thread); |
| 135 | found_thread = rt_thread_find(name); |
| 136 | uassert_not_null(found_thread); |
| 137 | uassert_ptr_equal(found_thread, thread); |
| 138 | uassert_str_equal(found_thread->parent.name, name); |
| 139 | rt_thread_delete(thread); |
| 140 | |
| 141 | #ifdef RT_USING_DEVICE |
| 142 | /* Test 1.3: Find device object with rt_device_find */ |
| 143 | struct rt_device device; |
| 144 | uassert_true(generate_unique_name(name, TEST_RT_NAME_MAX, "dev") == RT_EOK); |
| 145 | ret = rt_device_register(&device, name, RT_DEVICE_FLAG_RDONLY); |
| 146 | uassert_int_equal(ret, RT_EOK); |
| 147 | found_device = rt_device_find(name); |
| 148 | uassert_not_null(found_device); |
| 149 | uassert_ptr_equal(found_device, &device); |
| 150 | uassert_str_equal(found_device->parent.name, name); |
| 151 | rt_device_unregister(&device); |
| 152 | #endif |
| 153 | |
| 154 | /* Test 2: Same Prefix Within TEST_RT_NAME_MAX */ |
| 155 | #ifdef RT_USING_DEVICE |
| 156 | struct rt_device dev1, dev2; |
| 157 | char name1[TEST_RT_NAME_MAX] = "norflash1"; |
| 158 | char name2[TEST_RT_NAME_MAX] = "norflash2"; |
| 159 | ret = rt_device_register(&dev1, name1, RT_DEVICE_FLAG_RDONLY); |
| 160 | uassert_int_equal(ret, RT_EOK); |
| 161 | ret = rt_device_register(&dev2, name2, RT_DEVICE_FLAG_RDONLY); |
| 162 | uassert_int_equal(ret, RT_EOK); /* Expect success if RT-Thread allows distinct names */ |
| 163 | found_device = rt_device_find(name1); |
| 164 | uassert_not_null(found_device); |
| 165 | uassert_ptr_equal(found_device, &dev1); |
| 166 | uassert_str_equal(found_device->parent.name, name1); |
| 167 | found_device = rt_device_find(name2); |
| 168 | uassert_not_null(found_device); |
| 169 | uassert_ptr_equal(found_device, &dev2); |
nothing calls this directly
no test coverage detected