mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-09-23 12:15:32 +08:00
fix: move tty_ptmx regression test to utest framework
ToolsCI / Tools (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
pkgs_test / change (push) Has been cancelled
utest_auto_run / A9 :components/dfs.cfg (push) Has been cancelled
utest_auto_run / A9 :components/lwip.cfg (push) Has been cancelled
utest_auto_run / A9 :components/netdev.cfg (push) Has been cancelled
utest_auto_run / A9 :components/sal.cfg (push) Has been cancelled
utest_auto_run / A9 :cpp11/cpp11.cfg (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 / AARCH64-smp :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
utest_auto_run / RISCV-smp :default.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/atomic_c11.cfg (push) Has been cancelled
utest_auto_run / RISCV :kernel/atomic_c11.cfg (push) Has been cancelled
utest_auto_run / A9-rtsmart :kernel/ipc.cfg (push) Has been cancelled
utest_auto_run / RISCV-rtsmart :kernel/ipc.cfg (push) Has been cancelled
utest_auto_run / XUANTIE-rtsmart :kernel/ipc.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/ipc.cfg (push) Has been cancelled
utest_auto_run / A9-smp :kernel/ipc.cfg (push) Has been cancelled
utest_auto_run / RISCV :kernel/ipc.cfg (push) Has been cancelled
utest_auto_run / A9-rtsmart :kernel/kernel_basic.cfg (push) Has been cancelled
utest_auto_run / RISCV-rtsmart :kernel/kernel_basic.cfg (push) Has been cancelled
utest_auto_run / XUANTIE-rtsmart :kernel/kernel_basic.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/kernel_basic.cfg (push) Has been cancelled
utest_auto_run / A9-smp :kernel/kernel_basic.cfg (push) Has been cancelled
utest_auto_run / RISCV :kernel/kernel_basic.cfg (push) Has been cancelled
utest_auto_run / AARCH64-rtsmart :kernel/mem.cfg (push) Has been cancelled
utest_auto_run / A9-rtsmart :kernel/mem.cfg (push) Has been cancelled
utest_auto_run / RISCV-rtsmart :kernel/mem.cfg (push) Has been cancelled
utest_auto_run / XUANTIE-rtsmart :kernel/mem.cfg (push) Has been cancelled
utest_auto_run / AARCH64 :kernel/mem.cfg (push) Has been cancelled
utest_auto_run / AARCH64-smp :kernel/mem.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/mem.cfg (push) Has been cancelled
utest_auto_run / A9-smp :kernel/mem.cfg (push) Has been cancelled
utest_auto_run / RISCV :kernel/mem.cfg (push) Has been cancelled
utest_auto_run / RISCV-smp :kernel/mem.cfg (push) Has been cancelled
ToolsCI / Tools (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
pkgs_test / change (push) Has been cancelled
utest_auto_run / A9 :components/dfs.cfg (push) Has been cancelled
utest_auto_run / A9 :components/lwip.cfg (push) Has been cancelled
utest_auto_run / A9 :components/netdev.cfg (push) Has been cancelled
utest_auto_run / A9 :components/sal.cfg (push) Has been cancelled
utest_auto_run / A9 :cpp11/cpp11.cfg (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 / AARCH64-smp :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
utest_auto_run / RISCV-smp :default.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/atomic_c11.cfg (push) Has been cancelled
utest_auto_run / RISCV :kernel/atomic_c11.cfg (push) Has been cancelled
utest_auto_run / A9-rtsmart :kernel/ipc.cfg (push) Has been cancelled
utest_auto_run / RISCV-rtsmart :kernel/ipc.cfg (push) Has been cancelled
utest_auto_run / XUANTIE-rtsmart :kernel/ipc.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/ipc.cfg (push) Has been cancelled
utest_auto_run / A9-smp :kernel/ipc.cfg (push) Has been cancelled
utest_auto_run / RISCV :kernel/ipc.cfg (push) Has been cancelled
utest_auto_run / A9-rtsmart :kernel/kernel_basic.cfg (push) Has been cancelled
utest_auto_run / RISCV-rtsmart :kernel/kernel_basic.cfg (push) Has been cancelled
utest_auto_run / XUANTIE-rtsmart :kernel/kernel_basic.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/kernel_basic.cfg (push) Has been cancelled
utest_auto_run / A9-smp :kernel/kernel_basic.cfg (push) Has been cancelled
utest_auto_run / RISCV :kernel/kernel_basic.cfg (push) Has been cancelled
utest_auto_run / AARCH64-rtsmart :kernel/mem.cfg (push) Has been cancelled
utest_auto_run / A9-rtsmart :kernel/mem.cfg (push) Has been cancelled
utest_auto_run / RISCV-rtsmart :kernel/mem.cfg (push) Has been cancelled
utest_auto_run / XUANTIE-rtsmart :kernel/mem.cfg (push) Has been cancelled
utest_auto_run / AARCH64 :kernel/mem.cfg (push) Has been cancelled
utest_auto_run / AARCH64-smp :kernel/mem.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/mem.cfg (push) Has been cancelled
utest_auto_run / A9-smp :kernel/mem.cfg (push) Has been cancelled
utest_auto_run / RISCV :kernel/mem.cfg (push) Has been cancelled
utest_auto_run / RISCV-smp :kernel/mem.cfg (push) Has been cancelled
The previous commit placed the test in a new top-level tests/ directory that does not exist in the RT-Thread repo structure and used the external check library. Move the test to examples/utest/testcases/lwp/ and rewrite it using RT-Thread's native utest framework, add a Kconfig symbol (RT_UTEST_LWP_TTY_PTMX), and wire it into Kconfig.utestcases. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
committed by
Rbb666
co-authored by
Claude Sonnet 4.6
parent
b6007e1f9c
commit
72a09a6aca
@@ -5,4 +5,12 @@ config RT_UTEST_LWP
|
||||
depends on RT_USING_SMART
|
||||
default n
|
||||
|
||||
config RT_UTEST_LWP_TTY_PTMX
|
||||
bool "Enable Utest for tty_ptmx buffer overflow regression (V-004)"
|
||||
depends on RT_USING_SMART
|
||||
default n
|
||||
help
|
||||
Regression guard for the snprintf buffer bounds fix in
|
||||
components/lwp/terminal/tty_ptmx.c.
|
||||
|
||||
endmenu
|
||||
|
||||
@@ -8,6 +8,9 @@ CPPPATH = [cwd]
|
||||
if GetDepend(['RT_UTEST_LWP', 'RT_USING_SMART']):
|
||||
src += ['condvar_timedwait_tc.c', 'condvar_broadcast_tc.c', 'condvar_signal_tc.c']
|
||||
|
||||
if GetDepend(['RT_UTEST_LWP_TTY_PTMX', 'RT_USING_SMART']):
|
||||
src += ['tty_ptmx_tc.c']
|
||||
|
||||
group = DefineGroup('utestcases', src, depend = ['RT_USING_UTESTCASES'], CPPPATH = CPPPATH)
|
||||
|
||||
Return('group')
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2026, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2026-06-09 OrbisAI Add regression test for V-004 snprintf fix
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test Case Name: tty_ptmx Buffer Bounds Regression Test
|
||||
*
|
||||
* Test Objectives:
|
||||
* - Verify that the snprintf-based device name formatting in
|
||||
* lwp_ptmx_init() never writes beyond the allocated buffer.
|
||||
* - Guard against regression to the original sprintf overflow (V-004).
|
||||
*
|
||||
* Test Scenarios:
|
||||
* - Normal input: root_path + "/ptmx" fits within the allocated buffer.
|
||||
* - Oversized input: combined length exceeds the buffer; snprintf must
|
||||
* truncate without overflowing.
|
||||
* - Canary bytes placed immediately after the buffer must remain intact.
|
||||
*
|
||||
* Verification Metrics:
|
||||
* - Output buffer byte at index [buf_size] must equal the canary value.
|
||||
* - snprintf return value must be < buf_size when input fits.
|
||||
* - snprintf return value must be >= buf_size when input is oversized
|
||||
* (snprintf reports what would have been written).
|
||||
*
|
||||
* Dependencies:
|
||||
* - Software configuration: RT_USING_SMART must be enabled.
|
||||
*
|
||||
* Expected Results:
|
||||
* - Final output: "[ PASSED ] [ result ] testcase (testcases.lwp.tty_ptmx.buffer_bounds)"
|
||||
* - No assertion failures during test execution.
|
||||
*/
|
||||
|
||||
#include "utest_assert.h"
|
||||
|
||||
#include <rtdef.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define DEV_REL_PATH "/ptmx"
|
||||
#define CANARY 0xAB
|
||||
|
||||
static void tty_ptmx_buffer_bounds_tc(void)
|
||||
{
|
||||
/* Simulate the allocation and snprintf call from lwp_ptmx_init(). */
|
||||
struct
|
||||
{
|
||||
const char *root_path;
|
||||
int should_fit; /* 1 = expect no truncation */
|
||||
} cases[] = {
|
||||
{ "/dev", 1 },
|
||||
{ "/dev/pts", 1 },
|
||||
{ "/", 1 },
|
||||
/* Oversized: root alone is longer than reasonable device name */
|
||||
{ "/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 0 },
|
||||
};
|
||||
|
||||
for (rt_size_t i = 0; i < sizeof(cases) / sizeof(cases[0]); i++)
|
||||
{
|
||||
const char *root_path = cases[i].root_path;
|
||||
rt_size_t root_len = strlen(root_path);
|
||||
rt_size_t buf_size = root_len + sizeof(DEV_REL_PATH); /* mirrors kernel alloc */
|
||||
|
||||
/* Allocate one extra byte as a canary to detect overflow. */
|
||||
char *raw = (char *)rt_malloc(buf_size + 1);
|
||||
uassert_not_null(raw);
|
||||
|
||||
raw[buf_size] = (char)CANARY;
|
||||
|
||||
int written = snprintf(raw, buf_size, "%s%s", root_path, DEV_REL_PATH);
|
||||
|
||||
/* Canary must be intact regardless of input size. */
|
||||
uassert_int_equal((unsigned char)raw[buf_size], CANARY);
|
||||
|
||||
if (cases[i].should_fit)
|
||||
{
|
||||
/* snprintf returns number of chars that would be written (excl. NUL). */
|
||||
uassert_true(written >= 0 && (rt_size_t)written < buf_size);
|
||||
/* Result must be null-terminated. */
|
||||
uassert_int_equal(raw[written], '\0');
|
||||
}
|
||||
|
||||
rt_free(raw);
|
||||
}
|
||||
}
|
||||
|
||||
static rt_err_t utest_tc_init(void)
|
||||
{
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static rt_err_t utest_tc_cleanup(void)
|
||||
{
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(tty_ptmx_buffer_bounds_tc);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "testcases.lwp.tty_ptmx.buffer_bounds", utest_tc_init, utest_tc_cleanup, 10);
|
||||
Reference in New Issue
Block a user