fix(kernel)/improve(utest):fix the legacy issue related to the length of the object name version #10537
ToolsCI / Tools (push) Has been cancelled
AutoTestCI / components/cpp11 (push) Has been cancelled
AutoTestCI / kernel/atomic (push) Has been cancelled
AutoTestCI / kernel/atomic/riscv64 (push) Has been cancelled
AutoTestCI / kernel/atomic_c11 (push) Has been cancelled
AutoTestCI / kernel/atomic_c11/riscv64 (push) Has been cancelled
AutoTestCI / kernel/device (push) Has been cancelled
AutoTestCI / kernel/ipc (push) Has been cancelled
AutoTestCI / kernel/irq (push) Has been cancelled
AutoTestCI / kernel/mem (push) Has been cancelled
AutoTestCI / kernel/mem/riscv64 (push) Has been cancelled
AutoTestCI / kernel/thread (push) Has been cancelled
AutoTestCI / kernel/timer (push) Has been cancelled
AutoTestCI / rtsmart/aarch64 (push) Has been cancelled
AutoTestCI / rtsmart/arm (push) Has been cancelled
AutoTestCI / rtsmart/riscv64 (push) Has been cancelled
AutoTestCI / components/utest (push) Has been cancelled
RT-Thread BSP Static Build Check / 🔍 Summary of Git Diff Changes (push) Has been cancelled
RT-Thread BSP Static Build Check / ${{ matrix.legs.RTT_BSP }} (push) Has been cancelled
RT-Thread BSP Static Build Check / collect-artifacts (push) Has been cancelled
doc_doxygen / doxygen_doc generate (push) Has been cancelled
doc_doxygen / deploy (push) Has been cancelled
pkgs_test / change (push) Has been cancelled
utest_auto_run / AARCH64-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / A9-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / RISCV-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / XUANTIE-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / AARCH64 :default.cfg (push) Has been cancelled
utest_auto_run / A9 :default.cfg (push) Has been cancelled
utest_auto_run / A9-smp :default.cfg (push) Has been cancelled
utest_auto_run / RISCV :default.cfg (push) Has been cancelled

This commit is contained in:
Yuqiang Wang
2025-07-30 10:58:49 +08:00
committed by GitHub
parent dc89417229
commit 62f3fb4ce5
8 changed files with 350 additions and 64 deletions
+6
View File
@@ -0,0 +1,6 @@
CONFIG_UTEST_OBJECT_TC=y
# dependencies
CONFIG_RT_USING_CI_ACTION=y
CONFIG_RT_USING_DEVICE=y
CONFIG_RT_USING_SEMAPHORE=y
+3
View File
@@ -47,6 +47,9 @@ jobs:
config_file:
- "default.cfg"
# kernel
# - "kernel/object.cfg"
# cpp11
# - "cpp11/cpp11.cfg"
+21 -1
View File
@@ -108,7 +108,7 @@
# CONFIG_RT_UTEST_TC_USING_KLIBC is not set
# end of klibc options
CONFIG_RT_NAME_MAX=8
CONFIG_RT_NAME_MAX=16
# CONFIG_RT_USING_ARCH_DATA_TYPE is not set
# CONFIG_RT_USING_NANO is not set
# CONFIG_RT_USING_SMART is not set
@@ -496,6 +496,7 @@ CONFIG_RT_PAGE_MAX_ORDER=11
# CONFIG_PKG_USING_FREEMODBUS is not set
# CONFIG_PKG_USING_NANOPB is not set
# CONFIG_PKG_USING_WIFI_HOST_DRIVER is not set
# CONFIG_PKG_USING_ESP_HOSTED is not set
#
# Wi-Fi
@@ -603,6 +604,7 @@ CONFIG_RT_PAGE_MAX_ORDER=11
# CONFIG_PKG_USING_QMODBUS is not set
# CONFIG_PKG_USING_PNET is not set
# CONFIG_PKG_USING_OPENER is not set
# CONFIG_PKG_USING_FREEMQTT is not set
# end of IoT - internet of things
#
@@ -831,6 +833,7 @@ CONFIG_RT_PAGE_MAX_ORDER=11
# CONFIG_PKG_USING_RMP is not set
# CONFIG_PKG_USING_R_RHEALSTONE is not set
# CONFIG_PKG_USING_HEARTBEAT is not set
# CONFIG_PKG_USING_MICRO_ROS_RTTHREAD_PACKAGE is not set
# end of system packages
#
@@ -954,6 +957,8 @@ CONFIG_RT_PAGE_MAX_ORDER=11
#
# HC32 DDL Drivers
#
# CONFIG_PKG_USING_HC32F4_CMSIS_DRIVER is not set
# CONFIG_PKG_USING_HC32F4_SERIES_DRIVER is not set
# end of HC32 DDL Drivers
#
@@ -967,6 +972,21 @@ CONFIG_RT_PAGE_MAX_ORDER=11
# CONFIG_PKG_USING_NXP_IMX6UL_DRIVER is not set
# CONFIG_PKG_USING_NXP_IMXRT_DRIVER is not set
# end of NXP HAL & SDK Drivers
#
# NUVOTON Drivers
#
# CONFIG_PKG_USING_NUVOTON_CMSIS_DRIVER is not set
# CONFIG_PKG_USING_NUVOTON_SERIES_DRIVER is not set
# CONFIG_PKG_USING_NUVOTON_ARM926_LIB is not set
# end of NUVOTON Drivers
#
# GD32 Drivers
#
# CONFIG_PKG_USING_GD32_ARM_CMSIS_DRIVER is not set
# CONFIG_PKG_USING_GD32_ARM_SERIES_DRIVER is not set
# end of GD32 Drivers
# end of HAL & SDK Drivers
#
+9 -1
View File
@@ -61,7 +61,7 @@
/* end of rt_strnlen options */
/* end of klibc options */
#define RT_NAME_MAX 8
#define RT_NAME_MAX 16
#define RT_CPUS_NR 1
#define RT_ALIGN_SIZE 8
#define RT_THREAD_PRIORITY_256
@@ -410,6 +410,14 @@
/* NXP HAL & SDK Drivers */
/* end of NXP HAL & SDK Drivers */
/* NUVOTON Drivers */
/* end of NUVOTON Drivers */
/* GD32 Drivers */
/* end of GD32 Drivers */
/* end of HAL & SDK Drivers */
/* sensors drivers */
+6 -4
View File
@@ -1,9 +1,5 @@
menu "Kernel Testcase"
config UTEST_OBJECT_TC
bool "object test"
default y
config UTEST_MEMHEAP_TC
bool "memheap stability test"
default y
@@ -14,6 +10,12 @@ config UTEST_SMALL_MEM_TC
default y
depends on RT_USING_SMALL_MEM
config UTEST_OBJECT_TC
select RT_USING_DEVICE
select RT_USING_SEMAPHORE
bool "object test"
default n
config UTEST_SLAB_TC
bool "slab test"
default n
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -121,7 +121,7 @@ static void TC_rt_memcmp_partial_match(void)
uassert_int_not_equal(rt_memcmp(arr1, arr2, sizeof(arr1)), 0);
}
#define LARGE_ARRAY_SIZE 1000
#define LARGE_ARRAY_SIZE 500
static void TC_rt_memcmp_large_array(void)
{
+36 -14
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
* Copyright (c) 2006-2025, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -29,6 +29,10 @@
#include <lwp.h>
#endif
#define DBG_TAG "kernel.obj"
#define DBG_LVL DBG_ERROR
#include <rtdbg.h>
struct rt_custom_object
{
struct rt_object parent;
@@ -355,7 +359,7 @@ void rt_object_init(struct rt_object *object,
const char *name)
{
rt_base_t level;
rt_size_t len;
rt_size_t obj_name_len;
#ifdef RT_DEBUGING_ASSERT
struct rt_list_node *node = RT_NULL;
#endif /* RT_DEBUGING_ASSERT */
@@ -393,10 +397,14 @@ void rt_object_init(struct rt_object *object,
#if RT_NAME_MAX > 0
if (name)
{
len = rt_strlen(name);
len = len > RT_NAME_MAX - 1 ? RT_NAME_MAX - 1 : len;
rt_memcpy(object->name, name, len);
object->name[len] = '\0';
obj_name_len = rt_strlen(name);
if(obj_name_len > RT_NAME_MAX - 1)
{
LOG_E("Object name %s exceeds RT_NAME_MAX=%d, consider increasing RT_NAME_MAX.", name, RT_NAME_MAX);
RT_ASSERT(obj_name_len <= RT_NAME_MAX - 1);
}
rt_memcpy(object->name, name, obj_name_len);
object->name[obj_name_len] = '\0';
}
else
{
@@ -472,7 +480,7 @@ rt_object_t rt_object_allocate(enum rt_object_class_type type, const char *name)
{
struct rt_object *object;
rt_base_t level;
rt_size_t len;
rt_size_t obj_name_len;
struct rt_object_information *information;
#ifdef RT_USING_MODULE
struct rt_dlmodule *module = dlmodule_self();
@@ -505,10 +513,14 @@ rt_object_t rt_object_allocate(enum rt_object_class_type type, const char *name)
#if RT_NAME_MAX > 0
if (name)
{
len = rt_strlen(name);
len = len > RT_NAME_MAX - 1 ? RT_NAME_MAX - 1 : len;
rt_memcpy(object->name, name, len);
object->name[len] = '\0';
obj_name_len = rt_strlen(name);
if(obj_name_len > RT_NAME_MAX - 1)
{
LOG_E("Object name %s exceeds RT_NAME_MAX=%d, consider increasing RT_NAME_MAX.", name, RT_NAME_MAX);
RT_ASSERT(obj_name_len <= RT_NAME_MAX - 1);
}
rt_memcpy(object->name, name, obj_name_len);
object->name[obj_name_len] = '\0';
}
else
{
@@ -672,7 +684,13 @@ static rt_err_t _match_name(struct rt_object *obj, void *data)
{
struct _obj_find_param *param = data;
const char *name = param->match_name;
if (rt_strncmp(obj->name, name, RT_NAME_MAX) == 0)
char truncated_name[RT_NAME_MAX];
/* Truncate input name to RT_NAME_MAX - 1 to match object name storage */
rt_strncpy(truncated_name, name, RT_NAME_MAX - 1);
truncated_name[RT_NAME_MAX - 1] = '\0';
if (rt_strcmp(obj->name, truncated_name) == 0)
{
param->matched_obj = obj;
@@ -705,7 +723,8 @@ rt_object_t rt_object_find(const char *name, rt_uint8_t type)
};
/* parameter check */
if (name == RT_NULL) return RT_NULL;
if (name == RT_NULL || rt_object_get_information(type) == RT_NULL)
return RT_NULL;
/* which is invoke in interrupt status */
RT_DEBUG_NOT_IN_INTERRUPT;
@@ -731,7 +750,9 @@ rt_err_t rt_object_get_name(rt_object_t object, char *name, rt_uint8_t name_size
if ((object != RT_NULL) && (name != RT_NULL) && (name_size != 0U))
{
const char *obj_name = object->name;
(void) rt_strncpy(name, obj_name, (rt_size_t)name_size);
rt_strncpy(name, obj_name, (rt_size_t)name_size);
/* Ensure null-termination */
name[name_size - 1] = '\0';
result = RT_EOK;
}
@@ -794,3 +815,4 @@ rt_err_t rt_custom_object_destroy(rt_object_t obj)
#endif
/**@}*/