Skip to content

test(syscall): test-open-family +2 modules — device-node targets & fd offset#651

Merged
ZR233 merged 1 commit into
rcore-os:devfrom
Lfan-ke:test-open-family
May 24, 2026
Merged

test(syscall): test-open-family +2 modules — device-node targets & fd offset#651
ZR233 merged 1 commit into
rcore-os:devfrom
Lfan-ke:test-open-family

Conversation

@Lfan-ke

@Lfan-ke Lfan-ke commented May 15, 2026

Copy link
Copy Markdown
Contributor

给 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

@Lfan-ke
Lfan-ke requested a review from ZCShou as a code owner May 15, 2026 11:21
@Lfan-ke Lfan-ke closed this May 15, 2026
Lfan-ke added a commit to Lfan-ke/tgoskits that referenced this pull request May 22, 2026
… & 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>
@Lfan-ke Lfan-ke reopened this May 22, 2026
@Lfan-ke
Lfan-ke force-pushed the test-open-family branch from 4aa220d to d9ae9c8 Compare May 22, 2026 16:43

@mai-team-app mai-team-app Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review 总结

本 PR 为 test-open-family 测试套新增 2 个阶段④补充模块(28 → 30 模块),覆盖了原有套件的两个盲区:

  1. open_dev_null_zero.c(+118 行)—— 字符设备节点目标(/dev/null/dev/zero)的 open + read/write 语义 + O_CLOEXEC / O_DIRECTORY flag 验证
  2. 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_zero 16 pass/0 fail,open_pread_pwrite 18 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

@Lfan-ke

Lfan-ke commented May 22, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

本 PR 为方案一 open/openat 测例族收尾:给已合并的 test-open-family(#730,28 模块)补 2 个未覆盖维度的模块 ——

  • open_dev_null_zero:open() 打开「字符设备节点」目标(/dev/null read→EOF·write→丢弃;/dev/zero read→全 0;O_CLOEXEC/O_DIRECTORY 在设备 fd 上的行为)。现有 28 模块覆盖普通文件/目录/symlink 目标,未覆盖字符设备。
  • open_pread_pwrite:open() 返回 fd 的「文件偏移/定位 I/O」语义(初始 offset=0、read 推进 offset、pread/pwrite 不改 offset、lseek 定位)。现有 open_fd_semantics 覆盖 fd 表,未覆盖偏移维度。

每模块附 man 2 open/pread/pwrite + man 4 null 原文依据,自管私有 /tmp 目录、自计 __pass/__fail。host(glibc Linux) 实测 -Wall -Wextra -Werror 0 警告、全 30 模块 0 fail。

@Lfan-ke Lfan-ke changed the title test(syscall): add open/openat carpet-coverage test suite + 21 bug repros test(syscall): test-open-family 补 2 个小模块(设备节点 + fd 偏移) May 22, 2026
@Lfan-ke Lfan-ke changed the title test(syscall): test-open-family 补 2 个小模块(设备节点 + fd 偏移) test(syscall): test-open-family +2 modules — device-node targets & fd offset May 22, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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>
@Lfan-ke
Lfan-ke force-pushed the test-open-family branch from d9ae9c8 to 0a518a7 Compare May 22, 2026 16:54

@mai-team-app mai-team-app Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review 总结

本 PR 为已合入 dev 的 test-open-family#730,28 模块)补 2 个未覆盖维度的模块,作为 open/openat 测例族收尾(28 → 30 模块):

变更内容

  1. 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 原文
  2. 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 原文
  3. CMakeLists.txt / main.c —— 模块计数 28 → 30、声明 + COLLECT 注册一致

验证结果

  • gcc -std=c11 -Wall -Wextra -Werror 编译 零警告(全部 32 个 .c 文件)
  • ✅ Host 全量运行 30 模块 ALL PASSopen_dev_null_zero 16 pass/0 fail,open_pread_pwrite 19 pass/0 fail
  • ✅ 代码风格与现有 28 模块完全一致(CHECK/CHECK_ERR 用法、__pass/__fail 自计、run() 末尾汇总)
  • ✅ fd 生命周期管理正确(open 后 early return on failure、close 配对)
  • ✅ 私有目录隔离不污染全局环境

语义正确性

  • /dev/null read→0(EOF)、write→count:符合 man 4 null 原文
  • /dev/zero read→全零字节:符合 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_zeroopen_pread_pwrite。本 PR 无重复。
  • 其他测试套件test-ftruncatetest-select-poll-familytest-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

@Lfan-ke

This comment was marked as resolved.

@ZR233
ZR233 merged commit a25ffaf into rcore-os:dev May 24, 2026
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[StarryOS] 方案一:Syscall 测例与语义完善

2 participants