From b75a43df9e3bcabcbb1ba6a1eb494dd4043e9997 Mon Sep 17 00:00:00 2001 From: Yaodong Han <189000603+HANYAODONG@users.noreply.github.com> Date: Sat, 26 Sep 2026 19:51:39 +0800 Subject: [PATCH 1/8] [HUST CSE][dfs] fix stack buffer overflow on long path components in devtmpfs _path_separate() and _get_subdir() copied an unbounded path component into caller-provided buffers, so a single component longer than DIRENT_NAME_MAX (256) bytes overran the 256-byte file_name[]/subdir_name[] stack arrays used by devtmpfs_create_vnode() and devtmpfs_file_lookup(). dentry->pathname can be up to DFS_PATH_MAX - 4 = 4092 bytes because _dentry_create() only strips the mount point prefix, so the overflow length and its contents are attacker controlled. It is reachable from open("/dev/", O_CREAT) - including from user mode through sys_open() - and from the msh command mkdir /dev/. On bsp/qemu-vexpress-a9 an over-long single component produced a data abort whose backtrace contained 0x41414141, i.e. the saved return address overwritten with the attacker supplied path bytes. The tmpfs implementation already validates these lengths and returns -ENAMETOOLONG (dfs_tmpfs.c), this brings devtmpfs in line with it: - pass parent_size/file_size to _path_separate() and name_size to _get_subdir(), rejecting oversized components with -ENAMETOOLONG - check the return value at both call sites; create_vnode() and file_lookup() now fail cleanly instead of corrupting the stack [HUST CSE] --- .../dfs/dfs_v2/filesystems/devfs/devtmpfs.c | 56 ++++++++++++++++--- 1 file changed, 48 insertions(+), 8 deletions(-) diff --git a/components/dfs/dfs_v2/filesystems/devfs/devtmpfs.c b/components/dfs/dfs_v2/filesystems/devfs/devtmpfs.c index b60e5c5d0f1c..a540375cb78a 100644 --- a/components/dfs/dfs_v2/filesystems/devfs/devtmpfs.c +++ b/components/dfs/dfs_v2/filesystems/devfs/devtmpfs.c @@ -54,13 +54,22 @@ struct devtmpfs_sb static struct dfs_file_ops _default_fops = { 0 }; -static int _path_separate(const char *path, char *parent_path, char *file_name) +static int _path_separate(const char *path, char *parent_path, rt_size_t parent_size, + char *file_name, rt_size_t file_size) { const char *path_p, *path_q; + rt_size_t parent_len, file_len; RT_ASSERT(path[0] == '/'); + if (parent_path == RT_NULL || file_name == RT_NULL || + parent_size < 2 || file_size == 0) + { + return -EINVAL; + } + file_name[0] = '\0'; + parent_path[0] = '\0'; path_p = path_q = &path[1]; __next_dir: while (*path_q != '/' && *path_q != '\0') @@ -77,10 +86,17 @@ static int _path_separate(const char *path, char *parent_path, char *file_name) } else /* Last level dir */ { - rt_memcpy(parent_path, path, path_p - path - 1); - parent_path[path_p - path - 1] = '\0'; - rt_memcpy(file_name, path_p, path_q - path_p); - file_name[path_q - path_p] = '\0'; + parent_len = path_p - path - 1; + file_len = path_q - path_p; + if (parent_len >= parent_size || file_len >= file_size) + { + return -ENAMETOOLONG; + } + + rt_memcpy(parent_path, path, parent_len); + parent_path[parent_len] = '\0'; + rt_memcpy(file_name, path_p, file_len); + file_name[file_len] = '\0'; } } if (parent_path[0] == 0) @@ -94,17 +110,31 @@ static int _path_separate(const char *path, char *parent_path, char *file_name) return 0; } -static int _get_subdir(const char *path, char *name) +static int _get_subdir(const char *path, char *name, rt_size_t name_size) { const char *subpath = path; + rt_size_t name_len = 0; + + if (path == RT_NULL || name == RT_NULL || name_size == 0) + { + return -EINVAL; + } + while (*subpath == '/' && *subpath) subpath ++; while (*subpath != '/' && *subpath) { + if (name_len + 1 >= name_size) + { + name[0] = '\0'; + return -ENAMETOOLONG; + } *name = *subpath; name ++; subpath ++; + name_len++; } + *name = '\0'; return 0; } @@ -213,7 +243,10 @@ static struct devtmpfs_file *devtmpfs_file_lookup(struct devtmpfs_sb *superblock subpath ++; /* skip '/' */ memset(subdir_name, 0, DIRENT_NAME_MAX); - _get_subdir(curpath, subdir_name); + if (_get_subdir(curpath, subdir_name, sizeof(subdir_name)) != 0) + { + return NULL; + } rt_spin_lock(&superblock->lock); @@ -490,6 +523,7 @@ static struct dfs_vnode *devtmpfs_create_vnode(struct dfs_dentry *dentry, int ty struct devtmpfs_sb *superblock; struct devtmpfs_file *d_file, *p_file; char parent_path[DFS_PATH_MAX], file_name[DIRENT_NAME_MAX]; + int ret; if (dentry == NULL || dentry->mnt == NULL || dentry->mnt->data == NULL) { @@ -503,7 +537,13 @@ static struct dfs_vnode *devtmpfs_create_vnode(struct dfs_dentry *dentry, int ty if (vnode) { /* find parent file */ - _path_separate(dentry->pathname, parent_path, file_name); + ret = _path_separate(dentry->pathname, parent_path, sizeof(parent_path), + file_name, sizeof(file_name)); + if (ret != RT_EOK) + { + dfs_vnode_destroy(vnode); + return NULL; + } if (file_name[0] == '\0') /* it's root dir */ { dfs_vnode_destroy(vnode); From 6b5e2f7f5f6975fe3b689db9158c6932ab220294 Mon Sep 17 00:00:00 2001 From: Yaodong Han <189000603+HANYAODONG@users.noreply.github.com> Date: Sat, 17 Oct 2026 16:13:49 +0800 Subject: [PATCH 2/8] [HUST CSE][dfs] validate path before dereference and add devtmpfs boundary tests Address the review of #11842. _path_separate() dereferenced path[0] in RT_ASSERT before any of its arguments had been validated, so the helper was not robust against a NULL path from a malformed internal caller. Move the argument checks ahead of the assertion, which also makes the helper consistent with the tmpfs one. Add a boundary regression test for the path components of devtmpfs, with the cases the review asked for: - component lengths DIRENT_NAME_MAX - 2 (254) and DIRENT_NAME_MAX - 1 (255) must still create the node, - DIRENT_NAME_MAX (256) and 300 bytes must be rejected with an error the caller can observe, and must not create anything, - both entry points are covered for every length: devtmpfs_file_lookup() through dfs_file_stat() and devtmpfs_create_vnode() through open(), - a guard pattern around the call verifies that an overlong component does not modify neighbouring stack data. The test lives in components/dfs/utest/tc_devtmpfs_path.c behind its own Kconfig option (RT_UTEST_TC_USING_DEVTMPFS_PATH, depends on DFS v2) so it does not change any existing utest configuration. Verified on bsp/qemu-vexpress-a9 with the real utest framework compiled into the image: the fixed tree passes all five cases (0 failure), while the tree without the fix fails at the 256-byte case and then aborts with the 0x41414141 backtrace, which is the overflow this patch prevents. [HUST CSE] --- .../dfs/dfs_v2/filesystems/devfs/devtmpfs.c | 7 +- components/dfs/utest/Kconfig | 11 + components/dfs/utest/SConscript | 4 + components/dfs/utest/tc_devtmpfs_path.c | 246 ++++++++++++++++++ 4 files changed, 265 insertions(+), 3 deletions(-) create mode 100644 components/dfs/utest/tc_devtmpfs_path.c diff --git a/components/dfs/dfs_v2/filesystems/devfs/devtmpfs.c b/components/dfs/dfs_v2/filesystems/devfs/devtmpfs.c index a540375cb78a..5764eb877b9c 100644 --- a/components/dfs/dfs_v2/filesystems/devfs/devtmpfs.c +++ b/components/dfs/dfs_v2/filesystems/devfs/devtmpfs.c @@ -60,14 +60,15 @@ static int _path_separate(const char *path, char *parent_path, rt_size_t parent_ const char *path_p, *path_q; rt_size_t parent_len, file_len; - RT_ASSERT(path[0] == '/'); - - if (parent_path == RT_NULL || file_name == RT_NULL || + /* validate the arguments before the path is dereferenced below */ + if (path == RT_NULL || parent_path == RT_NULL || file_name == RT_NULL || parent_size < 2 || file_size == 0) { return -EINVAL; } + RT_ASSERT(path[0] == '/'); + file_name[0] = '\0'; parent_path[0] = '\0'; path_p = path_q = &path[1]; diff --git a/components/dfs/utest/Kconfig b/components/dfs/utest/Kconfig index 32acadbf1a70..94ad954366ac 100644 --- a/components/dfs/utest/Kconfig +++ b/components/dfs/utest/Kconfig @@ -41,6 +41,17 @@ if RT_USING_DFS endif + config RT_UTEST_TC_USING_DEVTMPFS_PATH + bool "devtmpfs path component boundary Test" + default n + depends on RT_USING_DFS_V2 + help + Enable boundary regression tests for devtmpfs path components. + Verifies that a path component of DIRENT_NAME_MAX bytes or more is + rejected with -ENAMETOOLONG instead of overrunning the stack buffers + used by devtmpfs_create_vnode() and devtmpfs_file_lookup(), and that + shorter components keep working. Requires devtmpfs mounted on /dev. + rsource "v2/af_unix/Kconfig" endmenu diff --git a/components/dfs/utest/SConscript b/components/dfs/utest/SConscript index bb8fa66a35d4..e6c5bf6caed2 100644 --- a/components/dfs/utest/SConscript +++ b/components/dfs/utest/SConscript @@ -15,6 +15,10 @@ if GetDepend('RT_UTEST_TC_USING_DFS_API'): if GetDepend('RT_UTEST_TC_USING_POSIX_API'): src += ['tc_posix_api.c'] +# Add devtmpfs path component boundary test if enabled (requires DFS v2) +if GetDepend('RT_UTEST_TC_USING_DEVTMPFS_PATH'): + src += ['tc_devtmpfs_path.c'] + # Define the test group with proper dependencies objs = DefineGroup('utestcases', src, depend = ['RT_USING_UTESTCASES', 'RT_USING_DFS'], CPPPATH = CPPPATH) objs = objs + SConscript(os.path.join('v2', 'af_unix', 'SConscript')) diff --git a/components/dfs/utest/tc_devtmpfs_path.c b/components/dfs/utest/tc_devtmpfs_path.c new file mode 100644 index 000000000000..4f1b9b93c53d --- /dev/null +++ b/components/dfs/utest/tc_devtmpfs_path.c @@ -0,0 +1,246 @@ +/* + * Copyright (c) 2006-2025, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2026-10-17 Yaodong Han boundary regression tests for devtmpfs path + * components (devtmpfs_create_vnode/_path_separate + * and devtmpfs_file_lookup/_get_subdir) + */ + +#include +#include "utest.h" + +#include +#include +#include +#include + +#ifdef RT_USING_DFS_V2 + +/* + * The devtmpfs helpers copy the last path component into char[DIRENT_NAME_MAX] + * buffers, so a component of DIRENT_NAME_MAX bytes or more must be rejected + * instead of overrunning the caller's stack frame. A component of + * DIRENT_NAME_MAX - 1 bytes (plus the terminator) still fits. + */ +#define TC_NAME_MAX DIRENT_NAME_MAX + +/* devtmpfs is mounted on /dev by the device filesystem, see devtmpfs_init() */ +#define TC_MNT_PATH "/dev" + +/* Path buffer: mount point + '/' + component + '\0'. + * Sized for the longest component the boundary sweep below uses (300 bytes), + * which is deliberately well past DIRENT_NAME_MAX. */ +#define TC_MAX_TEST_LEN 300 +#define TC_PATH_BUF_SIZE (sizeof(TC_MNT_PATH) + 1 + TC_MAX_TEST_LEN + 1) + +static char tc_path[TC_PATH_BUF_SIZE]; + +/* + * Caller-side stack guard. devtmpfs_create_vnode() and devtmpfs_file_lookup() + * keep their file_name[]/subdir_name[] buffers on their own frames; if the + * component were copied without a bounds check those frames - and the data + * that survives in the caller after the call - would be corrupted. Keeping a + * known pattern around the call and checking it afterwards is the observable + * "does not modify neighbouring stack data" assertion requested in review. + */ +#define TC_GUARD_SIZE 32 +#define TC_GUARD_PATTERN 0xA5 +#define TC_GUARD_MAGIC 0x5A5A1234UL + +static volatile rt_ubase_t tc_guard_magic; + +static void tc_guard_fill(rt_uint8_t *guard) +{ + rt_memset(guard, TC_GUARD_PATTERN, TC_GUARD_SIZE); + tc_guard_magic = TC_GUARD_MAGIC; +} + +static rt_bool_t tc_guard_intact(const rt_uint8_t *guard) +{ + rt_size_t i; + + if (tc_guard_magic != TC_GUARD_MAGIC) + { + return RT_FALSE; + } + + for (i = 0; i < TC_GUARD_SIZE; i++) + { + if (guard[i] != TC_GUARD_PATTERN) + { + return RT_FALSE; + } + } + + return RT_TRUE; +} + +/* + * Build "/" into tc_path and return its length. + * The mount point is taken from RT_UTEST_DFS_MNT_PATH so the test works for + * whatever filesystem/mount point the utest configuration uses. + */ +static rt_size_t tc_build_path(rt_size_t len) +{ + rt_size_t mnt_len = rt_strlen(TC_MNT_PATH); + rt_size_t i; + + RT_ASSERT(len <= TC_MAX_TEST_LEN); + + rt_memcpy(tc_path, TC_MNT_PATH, mnt_len); + tc_path[mnt_len] = '/'; + for (i = 0; i < len; i++) + { + tc_path[mnt_len + 1 + i] = 'A'; + } + tc_path[mnt_len + 1 + len] = '\0'; + + return mnt_len + 1 + len; +} + +/* + * Exercise both entry points for one component length: + * - devtmpfs_file_lookup() through dfs_file_stat() + * - devtmpfs_create_vnode() through open(O_CREAT) + * and verify that neither one touches neighbouring stack data. + * + * Returns the open() result (-1 on failure). + */ +static int tc_roundtrip(rt_size_t len, rt_bool_t expect_ok) +{ + rt_uint8_t guard[TC_GUARD_SIZE]; + struct stat st; + int fd; + + tc_build_path(len); + tc_guard_fill(guard); + + /* lookup path first: the node does not exist yet, this must not crash */ + (void)dfs_file_stat(tc_path, &st); + + /* creation path: this is where _path_separate() runs */ + fd = open(tc_path, O_CREAT | O_RDWR, 0644); + + if (!tc_guard_intact(guard)) + { + rt_kprintf("guard corrupted for component length %u\n", + (unsigned int)len); + return -2; + } + + if (expect_ok) + { + if (fd < 0) + { + rt_kprintf("expected success for component length %u, got %d\n", + (unsigned int)len, fd); + return -3; + } + close(fd); + + /* the node must now be visible through the lookup path */ + tc_guard_fill(guard); + if (dfs_file_stat(tc_path, &st) != 0) + { + if (tc_guard_intact(guard)) + { + rt_kprintf("node not found after creation, len %u\n", + (unsigned int)len); + return -4; + } + return -2; + } + } + else + { + if (fd >= 0) + { + close(fd); + rt_kprintf("expected rejection for component length %u\n", + (unsigned int)len); + return -5; + } + + /* a rejected component must not have created anything either */ + tc_guard_fill(guard); + if (dfs_file_stat(tc_path, &st) == 0) + { + if (tc_guard_intact(guard)) + { + rt_kprintf("overlong component still resolved, len %u\n", + (unsigned int)len); + return -6; + } + return -2; + } + } + + return tc_guard_intact(guard) ? 0 : -2; +} + +/* len == DIRENT_NAME_MAX - 2: comfortably inside the buffer */ +static void test_devtmpfs_component_254(void) +{ + uassert_int_equal(tc_roundtrip(TC_NAME_MAX - 2, RT_TRUE), 0); +} + +/* len == DIRENT_NAME_MAX - 1: the last length that still fits (+ terminator) */ +static void test_devtmpfs_component_255(void) +{ + uassert_int_equal(tc_roundtrip(TC_NAME_MAX - 1, RT_TRUE), 0); +} + +/* len == DIRENT_NAME_MAX: no room for the terminator, must be rejected */ +static void test_devtmpfs_component_256(void) +{ + uassert_int_equal(tc_roundtrip(TC_NAME_MAX, RT_FALSE), 0); +} + +/* well past the buffer: must be rejected as well */ +static void test_devtmpfs_component_300(void) +{ + uassert_int_equal(tc_roundtrip(TC_NAME_MAX + 44, RT_FALSE), 0); +} + +/* a normal, short component must keep working (no regression) */ +static void test_devtmpfs_component_short(void) +{ + uassert_int_equal(tc_roundtrip(8, RT_TRUE), 0); +} + +static rt_err_t utest_tc_init(void) +{ + struct stat st; + + /* devfs is mounted by the system; make sure the mount point exists */ + if (dfs_file_stat(TC_MNT_PATH, &st) != 0) + { + rt_kprintf("mount point %s not available, devtmpfs test skipped\n", + TC_MNT_PATH); + return -RT_ERROR; + } + + return RT_EOK; +} + +static rt_err_t utest_tc_cleanup(void) +{ + /* the successful cases only create device nodes; nothing is persisted */ + return RT_EOK; +} + +static void testcase(void) +{ + UTEST_UNIT_RUN(test_devtmpfs_component_short); + UTEST_UNIT_RUN(test_devtmpfs_component_254); + UTEST_UNIT_RUN(test_devtmpfs_component_255); + UTEST_UNIT_RUN(test_devtmpfs_component_256); + UTEST_UNIT_RUN(test_devtmpfs_component_300); +} +UTEST_TC_EXPORT(testcase, "components.dfs.devtmpfs_path_tc", utest_tc_init, utest_tc_cleanup, 30); + +#endif /* RT_USING_DFS_V2 */ From a4163bfd975f4ae42aedcc99aa3aad77c4e1b748 Mon Sep 17 00:00:00 2001 From: Yaodong Han <189000603+HANYAODONG@users.noreply.github.com> Date: Sat, 17 Oct 2026 21:58:11 +0800 Subject: [PATCH 3/8] [HUST CSE][dfs] format the devtmpfs boundary test with clang-format The new test file failed the "Check File Format and License" workflow because the macro alignment did not match the repository .clang-format. Run clang-format on it; whitespace only, no functional change. --- components/dfs/utest/tc_devtmpfs_path.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/components/dfs/utest/tc_devtmpfs_path.c b/components/dfs/utest/tc_devtmpfs_path.c index 4f1b9b93c53d..1cb215be3c96 100644 --- a/components/dfs/utest/tc_devtmpfs_path.c +++ b/components/dfs/utest/tc_devtmpfs_path.c @@ -26,16 +26,16 @@ * instead of overrunning the caller's stack frame. A component of * DIRENT_NAME_MAX - 1 bytes (plus the terminator) still fits. */ -#define TC_NAME_MAX DIRENT_NAME_MAX +#define TC_NAME_MAX DIRENT_NAME_MAX /* devtmpfs is mounted on /dev by the device filesystem, see devtmpfs_init() */ -#define TC_MNT_PATH "/dev" +#define TC_MNT_PATH "/dev" /* Path buffer: mount point + '/' + component + '\0'. * Sized for the longest component the boundary sweep below uses (300 bytes), * which is deliberately well past DIRENT_NAME_MAX. */ -#define TC_MAX_TEST_LEN 300 -#define TC_PATH_BUF_SIZE (sizeof(TC_MNT_PATH) + 1 + TC_MAX_TEST_LEN + 1) +#define TC_MAX_TEST_LEN 300 +#define TC_PATH_BUF_SIZE (sizeof(TC_MNT_PATH) + 1 + TC_MAX_TEST_LEN + 1) static char tc_path[TC_PATH_BUF_SIZE]; @@ -47,9 +47,9 @@ static char tc_path[TC_PATH_BUF_SIZE]; * known pattern around the call and checking it afterwards is the observable * "does not modify neighbouring stack data" assertion requested in review. */ -#define TC_GUARD_SIZE 32 -#define TC_GUARD_PATTERN 0xA5 -#define TC_GUARD_MAGIC 0x5A5A1234UL +#define TC_GUARD_SIZE 32 +#define TC_GUARD_PATTERN 0xA5 +#define TC_GUARD_MAGIC 0x5A5A1234UL static volatile rt_ubase_t tc_guard_magic; From 679fbdaf19baa34c436627b8d8bc1800e862402a Mon Sep 17 00:00:00 2001 From: Yaodong Han <189000603+HANYAODONG@users.noreply.github.com> Date: Tue, 17 Nov 2026 00:51:53 +0800 Subject: [PATCH 4/8] ci: re-trigger workflows after the previous runs expired awaiting approval From bcf1cd738afbae871a5b3774a9e557e41ac2b3ea Mon Sep 17 00:00:00 2001 From: Yaodong Han <189000603+HANYAODONG@users.noreply.github.com> Date: Wed, 18 Nov 2026 03:11:41 +0800 Subject: [PATCH 5/8] [HUST CSE][dfs] address review follow-up on devtmpfs path bounds Three non-blocking points from the second review. 1. _get_subdir(): the -ENAMETOOLONG path did name[0] = '\0' after the loop had already advanced name, so it cleared the current position instead of the first byte. Keep the start pointer and reset through it. Callers memset() the buffer today, so behaviour is unchanged, but the intent is now what the code says. 2. utest Kconfig: the case needs devtmpfs mounted on /dev and the utest case framework, so also depend on RT_USING_DFS_DEVFS and RT_USING_UTESTCASES. Otherwise it is compiled when devtmpfs is not mounted and can only be skipped at run time. 3. tc_devtmpfs_path.c: the comment claimed the mount point comes from RT_UTEST_DFS_MNT_PATH while tc_build_path() always uses /dev. Correct the comment: devtmpfs_init() always mounts devtmpfs on /dev, and that option only selects where the generic DFS API tests mount their own filesystem. --- components/dfs/dfs_v2/filesystems/devfs/devtmpfs.c | 3 ++- components/dfs/utest/Kconfig | 2 ++ components/dfs/utest/tc_devtmpfs_path.c | 5 +++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/components/dfs/dfs_v2/filesystems/devfs/devtmpfs.c b/components/dfs/dfs_v2/filesystems/devfs/devtmpfs.c index 5764eb877b9c..2d4cd64aa561 100644 --- a/components/dfs/dfs_v2/filesystems/devfs/devtmpfs.c +++ b/components/dfs/dfs_v2/filesystems/devfs/devtmpfs.c @@ -114,6 +114,7 @@ static int _path_separate(const char *path, char *parent_path, rt_size_t parent_ static int _get_subdir(const char *path, char *name, rt_size_t name_size) { const char *subpath = path; + char *name_start = name; rt_size_t name_len = 0; if (path == RT_NULL || name == RT_NULL || name_size == 0) @@ -127,7 +128,7 @@ static int _get_subdir(const char *path, char *name, rt_size_t name_size) { if (name_len + 1 >= name_size) { - name[0] = '\0'; + *name_start = '\0'; return -ENAMETOOLONG; } *name = *subpath; diff --git a/components/dfs/utest/Kconfig b/components/dfs/utest/Kconfig index 94ad954366ac..9684816fe6fc 100644 --- a/components/dfs/utest/Kconfig +++ b/components/dfs/utest/Kconfig @@ -45,6 +45,8 @@ if RT_USING_DFS bool "devtmpfs path component boundary Test" default n depends on RT_USING_DFS_V2 + depends on RT_USING_DFS_DEVFS + depends on RT_USING_UTESTCASES help Enable boundary regression tests for devtmpfs path components. Verifies that a path component of DIRENT_NAME_MAX bytes or more is diff --git a/components/dfs/utest/tc_devtmpfs_path.c b/components/dfs/utest/tc_devtmpfs_path.c index 1cb215be3c96..f443917ce400 100644 --- a/components/dfs/utest/tc_devtmpfs_path.c +++ b/components/dfs/utest/tc_devtmpfs_path.c @@ -81,8 +81,9 @@ static rt_bool_t tc_guard_intact(const rt_uint8_t *guard) /* * Build "/" into tc_path and return its length. - * The mount point is taken from RT_UTEST_DFS_MNT_PATH so the test works for - * whatever filesystem/mount point the utest configuration uses. + * The mount point is fixed to /dev (TC_MNT_PATH) because devtmpfs is always + * mounted there by devtmpfs_init(); RT_UTEST_DFS_MNT_PATH selects where the + * generic DFS API tests mount their own filesystem and does not apply here. */ static rt_size_t tc_build_path(rt_size_t len) { From 98b9cf3d59625fe190aa870b2b4f1cf918acfd4c Mon Sep 17 00:00:00 2001 From: Yaodong Han <189000603+HANYAODONG@users.noreply.github.com> Date: Tue, 24 Nov 2026 16:04:20 +0800 Subject: [PATCH 6/8] [HUST CSE][dfs] utest: prove the creation path and fit devtmpfs stack frames Two points from review. 1. The success cases left the /dev node behind, so a later round's open(O_CREAT) simply reopened it and devtmpfs_create_vnode() was never entered again. Open with O_CREAT | O_EXCL so that a successful open proves this round created the node, remove only the node this round created, and run every component length twice. 2. devtmpfs_create_vnode() keeps parent_path[DFS_PATH_MAX] and file_name[DIRENT_NAME_MAX] on its own frame: 4352 bytes before anything else is accounted for. The utest framework runs test cases on a 4096 byte thread, which cannot hold that frame. The filesystem calls now run on a worker thread with an 8 KB stack, and both a failed rt_thread_create() and a worker that does not finish in time are reported as test failures instead of quietly corrupting the utest stack. tc_path was already static, so no path buffer had to move. Verified with the real utest framework on bsp/qemu-vexpress-a9: utest_run components.dfs.devtmpfs_path_tc 2 both loops PASSED, and ls /dev afterwards shows no node left behind. With devtmpfs.c reverted to the unfixed version the same case fails: test_devtmpfs_component_256 asserts and test_devtmpfs_component_300 reaches 0x41414141 followed by a data abort, so the case still catches the defect. --- components/dfs/utest/tc_devtmpfs_path.c | 171 +++++++++++++++++++++--- 1 file changed, 155 insertions(+), 16 deletions(-) diff --git a/components/dfs/utest/tc_devtmpfs_path.c b/components/dfs/utest/tc_devtmpfs_path.c index f443917ce400..f0696633ba5c 100644 --- a/components/dfs/utest/tc_devtmpfs_path.c +++ b/components/dfs/utest/tc_devtmpfs_path.c @@ -8,11 +8,16 @@ * 2026-10-17 Yaodong Han boundary regression tests for devtmpfs path * components (devtmpfs_create_vnode/_path_separate * and devtmpfs_file_lookup/_get_subdir) + * 2026-11-24 Yaodong Han prove the creation path with O_EXCL, remove the + * node at the end of each round, run every length + * twice, and issue the filesystem calls from a + * thread whose stack fits devtmpfs frames */ #include #include "utest.h" +#include #include #include #include @@ -31,14 +36,33 @@ /* devtmpfs is mounted on /dev by the device filesystem, see devtmpfs_init() */ #define TC_MNT_PATH "/dev" -/* Path buffer: mount point + '/' + component + '\0'. +/* + * Path buffer: mount point + '/' + component + '\0'. * Sized for the longest component the boundary sweep below uses (300 bytes), - * which is deliberately well past DIRENT_NAME_MAX. */ + * which is deliberately well past DIRENT_NAME_MAX. It is static so that it + * never lands on the calling thread's stack. + */ #define TC_MAX_TEST_LEN 300 #define TC_PATH_BUF_SIZE (sizeof(TC_MNT_PATH) + 1 + TC_MAX_TEST_LEN + 1) static char tc_path[TC_PATH_BUF_SIZE]; +/* + * devtmpfs_create_vnode() keeps parent_path[DFS_PATH_MAX] and + * file_name[DIRENT_NAME_MAX] on its own frame - 4352 bytes before anything + * else is accounted for. The utest framework runs test cases on a 4096 byte + * thread, which cannot hold that frame, so every filesystem call below is + * issued from a worker thread with a stack large enough for it. + */ +#define TC_WORKER_STACK_SIZE 8192 +#define TC_WORKER_PRIORITY 20 + +/* give up if the worker has not finished within this many milliseconds */ +#define TC_WORKER_TIMEOUT_MS 5000 + +/* every length is exercised twice, to prove the state is clean between rounds */ +#define TC_ROUNDS 2 + /* * Caller-side stack guard. devtmpfs_create_vnode() and devtmpfs_file_lookup() * keep their file_name[]/subdir_name[] buffers on their own frames; if the @@ -106,25 +130,39 @@ static rt_size_t tc_build_path(rt_size_t len) /* * Exercise both entry points for one component length: * - devtmpfs_file_lookup() through dfs_file_stat() - * - devtmpfs_create_vnode() through open(O_CREAT) + * - devtmpfs_create_vnode() through open(O_CREAT | O_EXCL) * and verify that neither one touches neighbouring stack data. * - * Returns the open() result (-1 on failure). + * O_EXCL is what makes this meaningful across rounds: without it open() would + * happily return a node left over from an earlier round and the creation path + * would never run. A successful open() therefore proves that this round + * created the node, and the node is removed again before returning. + * + * Returns 0 on success, a negative code otherwise. */ static int tc_roundtrip(rt_size_t len, rt_bool_t expect_ok) { rt_uint8_t guard[TC_GUARD_SIZE]; struct stat st; + rt_bool_t created = RT_FALSE; int fd; tc_build_path(len); + + if (expect_ok) + { + /* drop whatever a previous round left behind, so that O_EXCL below + * really exercises the creation path */ + (void)unlink(tc_path); + } + tc_guard_fill(guard); /* lookup path first: the node does not exist yet, this must not crash */ (void)dfs_file_stat(tc_path, &st); /* creation path: this is where _path_separate() runs */ - fd = open(tc_path, O_CREAT | O_RDWR, 0644); + fd = open(tc_path, O_CREAT | O_EXCL | O_RDWR, 0644); if (!tc_guard_intact(guard)) { @@ -141,6 +179,7 @@ static int tc_roundtrip(rt_size_t len, rt_bool_t expect_ok) (unsigned int)len, fd); return -3; } + created = RT_TRUE; close(fd); /* the node must now be visible through the lookup path */ @@ -151,9 +190,9 @@ static int tc_roundtrip(rt_size_t len, rt_bool_t expect_ok) { rt_kprintf("node not found after creation, len %u\n", (unsigned int)len); - return -4; } - return -2; + (void)unlink(tc_path); + return -4; } } else @@ -161,6 +200,7 @@ static int tc_roundtrip(rt_size_t len, rt_bool_t expect_ok) if (fd >= 0) { close(fd); + (void)unlink(tc_path); rt_kprintf("expected rejection for component length %u\n", (unsigned int)len); return -5; @@ -174,43 +214,139 @@ static int tc_roundtrip(rt_size_t len, rt_bool_t expect_ok) { rt_kprintf("overlong component still resolved, len %u\n", (unsigned int)len); - return -6; } - return -2; + return -6; } } - return tc_guard_intact(guard) ? 0 : -2; + if (!tc_guard_intact(guard)) + { + return -2; + } + + if (created) + { + /* only the node this round created is removed, and it has to be gone + * afterwards - otherwise the next round would not create it again */ + if (unlink(tc_path) != 0) + { + rt_kprintf("cannot remove the node created for length %u\n", + (unsigned int)len); + return -7; + } + + if (dfs_file_stat(tc_path, &st) == 0) + { + rt_kprintf("node still present after unlink, len %u\n", + (unsigned int)len); + return -8; + } + } + + return 0; +} + +struct tc_worker_ctx +{ + rt_size_t len; + rt_bool_t expect_ok; + rt_bool_t finished; + int result; +}; + +static struct tc_worker_ctx tc_ctx; + +static void tc_worker_entry(void *parameter) +{ + tc_ctx.result = tc_roundtrip(tc_ctx.len, tc_ctx.expect_ok); + tc_ctx.finished = RT_TRUE; +} + +/* run one round on a worker thread with room for devtmpfs' stack frames */ +static int tc_run_once(rt_size_t len, rt_bool_t expect_ok) +{ + rt_thread_t tid; + rt_int32_t waited = 0; + + tc_ctx.len = len; + tc_ctx.expect_ok = expect_ok; + tc_ctx.finished = RT_FALSE; + tc_ctx.result = -100; + + tid = rt_thread_create("dtfstc", tc_worker_entry, RT_NULL, + TC_WORKER_STACK_SIZE, TC_WORKER_PRIORITY, 10); + if (tid == RT_NULL) + { + rt_kprintf("cannot create worker thread with a %d byte stack\n", + TC_WORKER_STACK_SIZE); + return -100; + } + + rt_thread_startup(tid); + + while (tc_ctx.finished != RT_TRUE && waited < TC_WORKER_TIMEOUT_MS) + { + rt_thread_mdelay(1); + waited++; + } + + if (tc_ctx.finished != RT_TRUE) + { + rt_kprintf("worker did not finish within %d ms\n", TC_WORKER_TIMEOUT_MS); + return -101; + } + + /* the worker returns from its entry, so rt_thread_exit() puts it on the + * defunct list and the idle thread reclaims it; nothing to delete here */ + + return tc_ctx.result; +} + +static int tc_run(rt_size_t len, rt_bool_t expect_ok) +{ + int round; + int ret; + + for (round = 0; round < TC_ROUNDS; round++) + { + ret = tc_run_once(len, expect_ok); + if (ret != 0) + { + return ret; + } + } + + return 0; } /* len == DIRENT_NAME_MAX - 2: comfortably inside the buffer */ static void test_devtmpfs_component_254(void) { - uassert_int_equal(tc_roundtrip(TC_NAME_MAX - 2, RT_TRUE), 0); + uassert_int_equal(tc_run(TC_NAME_MAX - 2, RT_TRUE), 0); } /* len == DIRENT_NAME_MAX - 1: the last length that still fits (+ terminator) */ static void test_devtmpfs_component_255(void) { - uassert_int_equal(tc_roundtrip(TC_NAME_MAX - 1, RT_TRUE), 0); + uassert_int_equal(tc_run(TC_NAME_MAX - 1, RT_TRUE), 0); } /* len == DIRENT_NAME_MAX: no room for the terminator, must be rejected */ static void test_devtmpfs_component_256(void) { - uassert_int_equal(tc_roundtrip(TC_NAME_MAX, RT_FALSE), 0); + uassert_int_equal(tc_run(TC_NAME_MAX, RT_FALSE), 0); } /* well past the buffer: must be rejected as well */ static void test_devtmpfs_component_300(void) { - uassert_int_equal(tc_roundtrip(TC_NAME_MAX + 44, RT_FALSE), 0); + uassert_int_equal(tc_run(TC_NAME_MAX + 44, RT_FALSE), 0); } /* a normal, short component must keep working (no regression) */ static void test_devtmpfs_component_short(void) { - uassert_int_equal(tc_roundtrip(8, RT_TRUE), 0); + uassert_int_equal(tc_run(8, RT_TRUE), 0); } static rt_err_t utest_tc_init(void) @@ -230,7 +366,10 @@ static rt_err_t utest_tc_init(void) static rt_err_t utest_tc_cleanup(void) { - /* the successful cases only create device nodes; nothing is persisted */ + /* every round removes the node it created; this is only a safety net in + * case a case aborted half way through */ + (void)unlink(tc_path); + return RT_EOK; } From 557c58deddd23a77ac21c41cc08ca5403b6d5d13 Mon Sep 17 00:00:00 2001 From: Yaodong Han <189000603+HANYAODONG@users.noreply.github.com> Date: Tue, 24 Nov 2026 22:51:22 +0800 Subject: [PATCH 7/8] [HUST CSE][dfs] utest: keep foreign nodes, aggregate results, isolate rounds Five points from the re-review. 1. Do not unlink before creating. A node that already exists is left alone: open(O_CREAT | O_EXCL) now reports it and the test fails instead of deleting somebody else's node and then counting its own creation. 2. Ownership and cleanup moved to a single exit path in tc_roundtrip(). created is set right after the exclusive create succeeds, so the descriptor is closed and the node removed even when a later check fails. utest_tc_cleanup() no longer unlinks tc_path, which only held the last attempted path and could not prove ownership. 3. All lengths run inside one UTEST_UNIT_RUN(). utest_unit_run() resets failed_num on every unit, so the five separate units could let a later passing unit report PASSED while an earlier one failed. Failures are now counted per length and asserted once at the end. 4. Each round takes its own job slot, and a worker that misses its timeout stops the sweep instead of letting the next round reuse the shared state. Four slots are rotated so a late worker can never overwrite a newer result, and the path buffer is only used while no worker is outstanding. 5. TC_WORKER_PRIORITY is RT_THREAD_PRIORITY_MAX / 2 instead of a fixed 20, which would be out of range on kernels configured with eight levels. Verified on bsp/qemu-vexpress-a9 with the real utest framework: utest_run components.dfs.devtmpfs_path_tc 2 both loops PASSED, and ls /dev afterwards shows no node left behind. Aggregate assertion checked by injecting a failure for the 254 byte length only (temporary hook, not committed): the case reports case 254 byte component, round 1 failed with -99 [ FAILED ] components.dfs.devtmpfs_path_tc even though the remaining lengths pass, so an early failure is no longer masked. With devtmpfs.c reverted to the unfixed version the 256 byte case is reported as "expected rejection, open() succeeded" and the following lookup and unlink on the overlong path end in 0x41414141 / data abort, so the case still catches the defect. --- components/dfs/utest/tc_devtmpfs_path.c | 255 +++++++++++++----------- 1 file changed, 142 insertions(+), 113 deletions(-) diff --git a/components/dfs/utest/tc_devtmpfs_path.c b/components/dfs/utest/tc_devtmpfs_path.c index f0696633ba5c..0ae185d05c48 100644 --- a/components/dfs/utest/tc_devtmpfs_path.c +++ b/components/dfs/utest/tc_devtmpfs_path.c @@ -8,10 +8,11 @@ * 2026-10-17 Yaodong Han boundary regression tests for devtmpfs path * components (devtmpfs_create_vnode/_path_separate * and devtmpfs_file_lookup/_get_subdir) - * 2026-11-24 Yaodong Han prove the creation path with O_EXCL, remove the - * node at the end of each round, run every length - * twice, and issue the filesystem calls from a - * thread whose stack fits devtmpfs frames + * 2026-11-24 Yaodong Han prove the creation path with O_EXCL, keep nodes + * that were already there, clean up on every exit + * path, collect the result of all lengths in a + * single test unit, and run the filesystem calls + * on a thread whose stack fits devtmpfs frames */ #include @@ -55,7 +56,9 @@ static char tc_path[TC_PATH_BUF_SIZE]; * issued from a worker thread with a stack large enough for it. */ #define TC_WORKER_STACK_SIZE 8192 -#define TC_WORKER_PRIORITY 20 + +/* a fixed priority would trip the range check on kernels with few levels */ +#define TC_WORKER_PRIORITY (RT_THREAD_PRIORITY_MAX / 2) /* give up if the worker has not finished within this many milliseconds */ #define TC_WORKER_TIMEOUT_MS 5000 @@ -63,6 +66,9 @@ static char tc_path[TC_PATH_BUF_SIZE]; /* every length is exercised twice, to prove the state is clean between rounds */ #define TC_ROUNDS 2 +/* rotating job slots, see tc_run_once() */ +#define TC_JOB_SLOTS 4 + /* * Caller-side stack guard. devtmpfs_create_vnode() and devtmpfs_file_lookup() * keep their file_name[]/subdir_name[] buffers on their own frames; if the @@ -127,16 +133,31 @@ static rt_size_t tc_build_path(rt_size_t len) return mnt_len + 1 + len; } +struct tc_case +{ + rt_size_t len; + rt_bool_t expect_ok; + const char *label; +}; + +static const struct tc_case tc_cases[] = { + { 8, RT_TRUE, "short component" }, + { TC_NAME_MAX - 2, RT_TRUE, "254 byte component" }, + { TC_NAME_MAX - 1, RT_TRUE, "255 byte component" }, + { TC_NAME_MAX, RT_FALSE, "256 byte component" }, + { TC_NAME_MAX + 44, RT_FALSE, "300 byte component" }, +}; + /* - * Exercise both entry points for one component length: + * Exercise both entry points for one component length and one round: * - devtmpfs_file_lookup() through dfs_file_stat() * - devtmpfs_create_vnode() through open(O_CREAT | O_EXCL) - * and verify that neither one touches neighbouring stack data. * - * O_EXCL is what makes this meaningful across rounds: without it open() would - * happily return a node left over from an earlier round and the creation path - * would never run. A successful open() therefore proves that this round - * created the node, and the node is removed again before returning. + * O_EXCL is what makes a round meaningful: without it open() would reopen a + * node left behind and the creation path would never run again. A node that + * already exists is deliberately left alone - the exclusive create reports it + * and the test fails, instead of removing somebody else's node. The node this + * round created is recorded in `created` and removed again on every exit path. * * Returns 0 on success, a negative code otherwise. */ @@ -145,108 +166,120 @@ static int tc_roundtrip(rt_size_t len, rt_bool_t expect_ok) rt_uint8_t guard[TC_GUARD_SIZE]; struct stat st; rt_bool_t created = RT_FALSE; - int fd; + int fd = -1; + int ret = 0; tc_build_path(len); - if (expect_ok) - { - /* drop whatever a previous round left behind, so that O_EXCL below - * really exercises the creation path */ - (void)unlink(tc_path); - } - tc_guard_fill(guard); /* lookup path first: the node does not exist yet, this must not crash */ (void)dfs_file_stat(tc_path, &st); - /* creation path: this is where _path_separate() runs */ fd = open(tc_path, O_CREAT | O_EXCL | O_RDWR, 0644); if (!tc_guard_intact(guard)) { - rt_kprintf("guard corrupted for component length %u\n", - (unsigned int)len); - return -2; + rt_kprintf("len %u: stack guard corrupted by open()\n", (unsigned int)len); + ret = -2; + goto out; } if (expect_ok) { if (fd < 0) { - rt_kprintf("expected success for component length %u, got %d\n", + rt_kprintf("len %u: expected creation, open() returned %d; a node " + "that already exists is not removed by this test\n", (unsigned int)len, fd); - return -3; + ret = -3; + goto out; } + created = RT_TRUE; close(fd); + fd = -1; /* the node must now be visible through the lookup path */ tc_guard_fill(guard); if (dfs_file_stat(tc_path, &st) != 0) { - if (tc_guard_intact(guard)) - { - rt_kprintf("node not found after creation, len %u\n", - (unsigned int)len); - } - (void)unlink(tc_path); - return -4; + rt_kprintf("len %u: node not found after creation\n", (unsigned int)len); + ret = -4; + goto out; + } + + if (!tc_guard_intact(guard)) + { + rt_kprintf("len %u: stack guard corrupted by lookup\n", (unsigned int)len); + ret = -2; + goto out; } } else { if (fd >= 0) { + /* an overlong component must never create anything */ + created = RT_TRUE; close(fd); - (void)unlink(tc_path); - rt_kprintf("expected rejection for component length %u\n", + fd = -1; + rt_kprintf("len %u: expected rejection, open() succeeded\n", (unsigned int)len); - return -5; + ret = -5; + goto out; } - /* a rejected component must not have created anything either */ tc_guard_fill(guard); if (dfs_file_stat(tc_path, &st) == 0) { - if (tc_guard_intact(guard)) - { - rt_kprintf("overlong component still resolved, len %u\n", - (unsigned int)len); - } - return -6; + rt_kprintf("len %u: overlong component still resolved\n", + (unsigned int)len); + ret = -6; + goto out; + } + + if (!tc_guard_intact(guard)) + { + rt_kprintf("len %u: stack guard corrupted by lookup\n", (unsigned int)len); + ret = -2; + goto out; } } - if (!tc_guard_intact(guard)) +out: + /* single exit: always close the descriptor, and remove only the node this + * round created - also when a later check already failed */ + if (fd >= 0) { - return -2; + close(fd); } if (created) { - /* only the node this round created is removed, and it has to be gone - * afterwards - otherwise the next round would not create it again */ if (unlink(tc_path) != 0) { - rt_kprintf("cannot remove the node created for length %u\n", + rt_kprintf("len %u: cannot remove the node created by this round\n", (unsigned int)len); - return -7; + if (ret == 0) + { + ret = -7; + } } - - if (dfs_file_stat(tc_path, &st) == 0) + else if (dfs_file_stat(tc_path, &st) == 0) { - rt_kprintf("node still present after unlink, len %u\n", - (unsigned int)len); - return -8; + rt_kprintf("len %u: node still present after unlink\n", (unsigned int)len); + if (ret == 0) + { + ret = -8; + } } } - return 0; + return ret; } -struct tc_worker_ctx +struct tc_job { rt_size_t len; rt_bool_t expect_ok; @@ -254,43 +287,53 @@ struct tc_worker_ctx int result; }; -static struct tc_worker_ctx tc_ctx; +static struct tc_job tc_jobs[TC_JOB_SLOTS]; +static rt_uint32_t tc_job_seq; static void tc_worker_entry(void *parameter) { - tc_ctx.result = tc_roundtrip(tc_ctx.len, tc_ctx.expect_ok); - tc_ctx.finished = RT_TRUE; + struct tc_job *job = (struct tc_job *)parameter; + + job->result = tc_roundtrip(job->len, job->expect_ok); + job->finished = RT_TRUE; } /* run one round on a worker thread with room for devtmpfs' stack frames */ static int tc_run_once(rt_size_t len, rt_bool_t expect_ok) { + struct tc_job *job = &tc_jobs[tc_job_seq % TC_JOB_SLOTS]; rt_thread_t tid; rt_int32_t waited = 0; - tc_ctx.len = len; - tc_ctx.expect_ok = expect_ok; - tc_ctx.finished = RT_FALSE; - tc_ctx.result = -100; + /* + * Every round takes its own slot, so a worker that overruns its timeout + * cannot write into the result of a later round. + */ + tc_job_seq++; + + job->len = len; + job->expect_ok = expect_ok; + job->finished = RT_FALSE; + job->result = -100; - tid = rt_thread_create("dtfstc", tc_worker_entry, RT_NULL, + tid = rt_thread_create("dtfstc", tc_worker_entry, job, TC_WORKER_STACK_SIZE, TC_WORKER_PRIORITY, 10); if (tid == RT_NULL) { - rt_kprintf("cannot create worker thread with a %d byte stack\n", + rt_kprintf("cannot create a worker thread with a %d byte stack\n", TC_WORKER_STACK_SIZE); return -100; } rt_thread_startup(tid); - while (tc_ctx.finished != RT_TRUE && waited < TC_WORKER_TIMEOUT_MS) + while (job->finished != RT_TRUE && waited < TC_WORKER_TIMEOUT_MS) { rt_thread_mdelay(1); waited++; } - if (tc_ctx.finished != RT_TRUE) + if (job->finished != RT_TRUE) { rt_kprintf("worker did not finish within %d ms\n", TC_WORKER_TIMEOUT_MS); return -101; @@ -299,54 +342,46 @@ static int tc_run_once(rt_size_t len, rt_bool_t expect_ok) /* the worker returns from its entry, so rt_thread_exit() puts it on the * defunct list and the idle thread reclaims it; nothing to delete here */ - return tc_ctx.result; + return job->result; } -static int tc_run(rt_size_t len, rt_bool_t expect_ok) +/* + * All component lengths are checked inside a single test unit: the utest + * framework resets its failure counter on every UTEST_UNIT_RUN(), so spreading + * the lengths over several units would let a later passing unit hide an + * earlier failing one. + */ +static void test_devtmpfs_path_components(void) { - int round; + rt_size_t i; + rt_size_t round; + rt_bool_t stop = RT_FALSE; + int failures = 0; int ret; - for (round = 0; round < TC_ROUNDS; round++) + for (i = 0; i < sizeof(tc_cases) / sizeof(tc_cases[0]) && stop == RT_FALSE; i++) { - ret = tc_run_once(len, expect_ok); - if (ret != 0) + for (round = 0; round < TC_ROUNDS; round++) { - return ret; + ret = tc_run_once(tc_cases[i].len, tc_cases[i].expect_ok); + if (ret != 0) + { + rt_kprintf("case %s, round %u failed with %d\n", + tc_cases[i].label, (unsigned int)(round + 1), ret); + failures++; + + /* a worker that did not come back still owns the shared path + * buffer; stop here instead of starting another round */ + if (ret == -101) + { + stop = RT_TRUE; + } + break; + } } } - return 0; -} - -/* len == DIRENT_NAME_MAX - 2: comfortably inside the buffer */ -static void test_devtmpfs_component_254(void) -{ - uassert_int_equal(tc_run(TC_NAME_MAX - 2, RT_TRUE), 0); -} - -/* len == DIRENT_NAME_MAX - 1: the last length that still fits (+ terminator) */ -static void test_devtmpfs_component_255(void) -{ - uassert_int_equal(tc_run(TC_NAME_MAX - 1, RT_TRUE), 0); -} - -/* len == DIRENT_NAME_MAX: no room for the terminator, must be rejected */ -static void test_devtmpfs_component_256(void) -{ - uassert_int_equal(tc_run(TC_NAME_MAX, RT_FALSE), 0); -} - -/* well past the buffer: must be rejected as well */ -static void test_devtmpfs_component_300(void) -{ - uassert_int_equal(tc_run(TC_NAME_MAX + 44, RT_FALSE), 0); -} - -/* a normal, short component must keep working (no regression) */ -static void test_devtmpfs_component_short(void) -{ - uassert_int_equal(tc_run(8, RT_TRUE), 0); + uassert_int_equal(failures, 0); } static rt_err_t utest_tc_init(void) @@ -366,20 +401,14 @@ static rt_err_t utest_tc_init(void) static rt_err_t utest_tc_cleanup(void) { - /* every round removes the node it created; this is only a safety net in - * case a case aborted half way through */ - (void)unlink(tc_path); - + /* every round removes the node it created; nothing is left to guess here, + * and a node this test did not create is deliberately not touched */ return RT_EOK; } static void testcase(void) { - UTEST_UNIT_RUN(test_devtmpfs_component_short); - UTEST_UNIT_RUN(test_devtmpfs_component_254); - UTEST_UNIT_RUN(test_devtmpfs_component_255); - UTEST_UNIT_RUN(test_devtmpfs_component_256); - UTEST_UNIT_RUN(test_devtmpfs_component_300); + UTEST_UNIT_RUN(test_devtmpfs_path_components); } UTEST_TC_EXPORT(testcase, "components.dfs.devtmpfs_path_tc", utest_tc_init, utest_tc_cleanup, 30); From 56382719ec63ba3cd6cccde4659e254b048bed0e Mon Sep 17 00:00:00 2001 From: Yaodong Han <189000603+HANYAODONG@users.noreply.github.com> Date: Wed, 25 Nov 2026 15:28:26 +0800 Subject: [PATCH 8/8] [HUST CSE][dfs] utest: enable the devtmpfs case in the utest CI config utest_auto_run appends .github/utest/configs/ to the BSP .config, but components/dfs.cfg did not turn on RT_UTEST_TC_USING_DEVTMPFS_PATH, so the new case was never compiled by CI even after the workflow was approved. Add the option to the dfs cfg. dfs.cfg also had no trailing newline, so the appended line would have been glued onto the last CONFIG_RT_UTEST_DFS_BLOCK_DEV value and dropped without a warning; the file now ends with a newline. Verified by replaying the workflow's config assembly on bsp/qemu-vexpress-a9: echo CONFIG_RT_USING_UTESTCASES=y >> .config cat .github/utest/configs/components/dfs.cfg >> .config scons --pyconfig-silent scons -j4 --strict rtconfig.h then defines RT_UTEST_TC_USING_DEVTMPFS_PATH and the built image contains components.dfs.devtmpfs_path_tc. --- .github/utest/configs/components/dfs.cfg | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/utest/configs/components/dfs.cfg b/.github/utest/configs/components/dfs.cfg index d78ea0df335c..c4d9ccaa4524 100644 --- a/.github/utest/configs/components/dfs.cfg +++ b/.github/utest/configs/components/dfs.cfg @@ -7,4 +7,5 @@ CONFIG_RT_UTEST_DFS_API_TC=y CONFIG_RT_UTEST_POSIX_API_TC=y CONFIG_RT_UTEST_DFS_MNT_PATH="" CONFIG_RT_UTEST_DFS_FS_TYPE="elm" -CONFIG_RT_UTEST_DFS_BLOCK_DEV="sd0" \ No newline at end of file +CONFIG_RT_UTEST_DFS_BLOCK_DEV="sd0" +CONFIG_RT_UTEST_TC_USING_DEVTMPFS_PATH=y