Skip to content

补充 build/run 调用契约测试#103

Merged
ZR233 merged 1 commit into
drivercraft:mainfrom
MRNIU:feature/build-run-contract-tests
May 21, 2026
Merged

补充 build/run 调用契约测试#103
ZR233 merged 1 commit into
drivercraft:mainfrom
MRNIU:feature/build-run-contract-tests

Conversation

@MRNIU
Copy link
Copy Markdown
Contributor

@MRNIU MRNIU commented May 14, 2026

摘要

  • 补充 Cargo artifact 选择、runtime artifact 状态记录和 CLI Cargo selector 的 build/run 契约测试。
  • 稳定 QEMU byte stream、WebSocket session lifecycle 和 uboot-shell QEMU smoke 测试。
  • 精简掉纯 clap/serde 等框架映射类测试,只保留 ostool 自身行为边界。

Review 对齐

  • QEMU byte-stream 匹配不再依赖 U-Boot 自然启动日志;改为由测试主动输出 marker,保留真实 TCP serial 字节流验证,同时避开 arch/FDT/bootflow 文案漂移。
  • 对 clap 结构体字段映射这类显而易见的解析行为不再单独测试;保留 apply_cargo_selector 对 build config/runtime state 的实际影响。
  • 对 serde/config 反序列化本身不做重复验证;CargoBuilder 测试聚焦 artifact 选择和 resolved artifact 写入 runtime state。

验证

cargo fmt --all -- --check
cargo test -p ostool apply_cargo_selector -- --nocapture
cargo test -p ostool handle_output_records_runtime_artifact_state_without_objcopy -- --nocapture
cargo test -p ostool --test qemu_byte_stream -- --nocapture --test-threads=1

@MRNIU
Copy link
Copy Markdown
Contributor Author

MRNIU commented May 15, 2026

@ZR233 hi,请问可以 review 一下吗

Comment thread ostool/tests/qemu_byte_stream.rs Outdated
fn qemu_byte_stream_success_matches_before_newline() -> Result<()> {
let Some(outcome) = run_case(
&[r"Hit any key to stop autoboot:"],
&[r"Scanning bootdev 'fw-cfg@9020000\.bootdev':"],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

为什么要换匹配?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

这个最开始是因为 qemu 用了 nowait,如果连接晚了会错过这一条,现在改成了主动触发

Comment thread ostool/src/main.rs Outdated

/// Verifies board run parsing accepts Cargo package and bin selectors.
#[test]
fn parse_board_run_with_cargo_selector_args() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

有结构体 clap,似乎没必要做这种测试

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

已删除

#[tokio::test]
/// Verifies Cargo artifact state is recorded without forced BIN conversion.
async fn handle_output_writes_cargo_artifact_state_without_runtime_conversion() {
let temp = tempfile::tempdir().unwrap();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

有 serde 序列化,似乎没必要做这种测试

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

这个主要是验证产物的,已经更新描述

@MRNIU MRNIU force-pushed the feature/build-run-contract-tests branch 3 times, most recently from 0131662 to ae214f6 Compare May 16, 2026 07:26
补齐 build/run 路径上的测试护栏,并根据 review 收敛测试边界。

- 使用显式 virtio-net QEMU fixture 稳定 byte-stream 集成测试,避免默认 NIC ROM 依赖导致串口不可用。

- 使用测试主动输出的 U-Boot marker 验证真实 TCP serial 字节流匹配,避免依赖 arch、FDT 或 bootflow 日志。

- 用 apply_cargo_selector 行为测试替换低价值 clap 字段映射断言。

- 澄清 CargoBuilder 测试覆盖 resolved artifact 写入 runtime state,而非 serde 配置解析。
@MRNIU MRNIU force-pushed the feature/build-run-contract-tests branch from ae214f6 to 8fd71e8 Compare May 16, 2026 07:33
@ZR233 ZR233 merged commit ba080f7 into drivercraft:main May 21, 2026
1 check passed
@MRNIU MRNIU deleted the feature/build-run-contract-tests branch May 21, 2026 07:32
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.

2 participants