test(syscall): test-open-family +2 modules — device-node targets & fd offset#651
Conversation
… & fd offset/positioned I/O 为已合并的 test-open-family(rcore-os#730,28 模块)补 2 个未覆盖维度的模块,作为 open/openat 测例族收尾(reopen rcore-os#651): - open_dev_null_zero:open() 打开「字符设备节点」目标。/dev/null(read→EOF、write→接受并丢弃)+ /dev/zero(read→全 0、write→丢弃)+ O_CLOEXEC / O_DIRECTORY 在设备 fd 上的行为。现有 28 模块覆盖普通文件 / 目录 / symlink 目标,未覆盖字符设备节点。 - open_pread_pwrite:open() 返回 fd 的「文件偏移 / 定位 I/O」语义。初始 offset=0、read 推进 offset、pread/pwrite 不改 offset、lseek SEEK_SET/END 定位。现有 open_fd_semantics 覆盖 fd 表(dup / 最低可用 fd),未覆盖偏移维度。 每模块附 man 2 open / pread / pwrite + man 4 null 原文依据,自管私有 /tmp 目录、自计 __pass/__fail、run() 末尾汇总。host(glibc Linux)实测:-Wall -Wextra -Werror 0 警告,全 30 模块 0 fail。 Signed-off-by: Leo Cheng <chengkelfan@qq.com>
There was a problem hiding this comment.
Review 总结
本 PR 为 test-open-family 测试套新增 2 个阶段④补充模块(28 → 30 模块),覆盖了原有套件的两个盲区:
open_dev_null_zero.c(+118 行)—— 字符设备节点目标(/dev/null、/dev/zero)的 open + read/write 语义 + O_CLOEXEC / O_DIRECTORY flag 验证open_pread_pwrite.c(+110 行)—— open 返回 fd 的文件偏移语义:初始 offset=0、read 推进 offset、pread/pwrite 不改 offset、lseek 定位
验证结果
- ✅
gcc -std=c11 -Wall -Wextra -Werror编译零警告 - ✅ Host 全量运行 30 模块 ALL PASS(
open_dev_null_zero16 pass/0 fail,open_pread_pwrite18 pass/0 fail) - ✅ 代码风格与现有 28 模块一致,注释含 man page 原文引用,CHECK/CHECK_ERR 用法规范
- ✅ fd 生命周期管理正确(open 后 early return on failure、close 配对)
- ✅
open_pread_pwrite使用私有M_DIR+cleanup_tree()隔离,不污染全局环境 - ✅ main.c 的模块计数和 COLLECT 注册一致(30 模块)
一个小建议(不阻塞合并)
CMakeLists.txt 顶部注释仍写「28 模块」,实际已 30 个源文件,建议顺手同步为 30,保持文档准确。
LGTM,批准合并。
Powered by glm-5.1
|
@codex review 本 PR 为方案一 open/openat 测例族收尾:给已合并的 test-open-family(#730,28 模块)补 2 个未覆盖维度的模块 ——
每模块附 man 2 open/pread/pwrite + man 4 null 原文依据,自管私有 /tmp 目录、自计 __pass/__fail。host(glibc Linux) 实测 -Wall -Wextra -Werror 0 警告、全 30 模块 0 fail。 |
|
Codex Review: Didn't find any major issues. What shall we delve into next? ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
… & fd offset/positioned I/O 为已合并的 test-open-family(rcore-os#730,28 模块)补 2 个未覆盖维度的模块,作为 open/openat 测例族收尾(reopen rcore-os#651): - open_dev_null_zero:open() 打开「字符设备节点」目标。/dev/null(read→EOF、write→接受并丢弃)+ /dev/zero(read→全 0、write→丢弃)+ O_CLOEXEC / O_DIRECTORY 在设备 fd 上的行为。现有 28 模块覆盖普通文件 / 目录 / symlink 目标,未覆盖字符设备节点。 - open_pread_pwrite:open() 返回 fd 的「文件偏移 / 定位 I/O」语义。初始 offset=0、read 推进 offset、pread/pwrite 不改 offset、lseek SEEK_SET/END 定位。现有 open_fd_semantics 覆盖 fd 表(dup / 最低可用 fd),未覆盖偏移维度。 每模块附 man 2 open / pread / pwrite + man 4 null 原文依据,自管私有 /tmp 目录、自计 __pass/__fail、run() 末尾汇总。host(glibc Linux)实测:-Wall -Wextra -Werror 0 警告,全 30 模块 0 fail。 Signed-off-by: Leo Cheng <chengkelfan@qq.com>
There was a problem hiding this comment.
Review 总结
本 PR 为已合入 dev 的 test-open-family(#730,28 模块)补 2 个未覆盖维度的模块,作为 open/openat 测例族收尾(28 → 30 模块):
变更内容
-
open_dev_null_zero.c(+118 行)—— 阶段④补充:字符设备节点目标/dev/null:O_RDONLY read → EOF、O_WRONLY write → 接受并丢弃、O_RDWR 双向/dev/zero:read → 全零字节填充(验证二次 read 仍全零)、write → 接受丢弃- O_CLOEXEC 在设备 fd 上生效(
fcntl F_GETFD验证 FD_CLOEXEC) - O_DIRECTORY 在非目录字符设备上 → ENOTDIR
- 引用 man 2 open + man 4 null 原文
-
open_pread_pwrite.c(+110 行)—— 阶段④补充:fd 文件偏移 / 定位 I/O 语义- open 后初始 offset = 0
- read 按读取字节数推进 offset
- pread 在指定 offset 读且不改 fd offset(读后验证 offset 仍为 0 + 后续 read 从 0 开始)
- pwrite 写到指定 offset 且不改 fd offset(写后 pread 验证落地位置)
- lseek SEEK_END / SEEK_SET 定位
- 使用私有
M_DIR+cleanup_tree()隔离 - 引用 man 2 open / pread / pwrite 原文
-
CMakeLists.txt/main.c—— 模块计数 28 → 30、声明 + COLLECT 注册一致
验证结果
- ✅
gcc -std=c11 -Wall -Wextra -Werror编译 零警告(全部 32 个 .c 文件) - ✅ Host 全量运行 30 模块 ALL PASS:
open_dev_null_zero16 pass/0 fail,open_pread_pwrite19 pass/0 fail - ✅ 代码风格与现有 28 模块完全一致(CHECK/CHECK_ERR 用法、
__pass/__fail自计、run()末尾汇总) - ✅ fd 生命周期管理正确(open 后 early return on failure、close 配对)
- ✅ 私有目录隔离不污染全局环境
语义正确性
/dev/nullread→0(EOF)、write→count:符合 man 4 null 原文/dev/zeroread→全零字节:符合 man 4 null 原文- O_DIRECTORY on char device → ENOTDIR:符合 man 2 open("O_DIRECTORY ... If pathname is not a directory, ... cause the error ENOTDIR")
- pread/pwrite 不改 fd offset:符合 man 2 pread/pwrite 原文
- lseek SEEK_END == file size、SEEK_SET 定位后 read 数据正确
重复/重叠分析
- dev 分支:
test-open-family仅有 #730(28 模块),无open_dev_null_zero或open_pread_pwrite。本 PR 无重复。 - 其他测试套件:
test-ftruncate、test-select-poll-family、test-socket-dataplane等套件虽引用/dev/null,但测的是不同 syscall 族(ftruncate/poll/socket),语义层面无重叠。 - 其他 open PR:当前无 open PR 触及
test-open-family同一路径。本 PR 独立。
小建议(不阻塞合并)
CMakeLists.txt 顶部注释已更新为「30 模块」,main.c 注释也已同步。代码本身无遗留问题。
结论:实现正确、语义符合 POSIX/Linux man page、验证充分、与现有模块风格一致、无重复。批准合并。
Powered by glm-5.1
给 test-open-family 补两个之前没测到的小点,作为 open/openat 测例的收尾(28 模块主体已随 #730 合入 dev):
open_dev_null_zero:打开 /dev/null、/dev/zero 这类字符设备节点(read/write 语义、O_CLOEXEC/O_DIRECTORY)。open_pread_pwrite:open 出来的 fd 的偏移语义(初始 0、read 推进、pread/pwrite 不改 offset、lseek 定位)。host 上 -Wall -Wextra -Werror 编过、全 30 模块 0 fail。
Closes #573