deblasis/ziofuzz

GitHub: deblasis/ziofuzz

ziofuzz 是 Zig 语言的轻量级模糊测试库,提供无需构建步骤的属性测试和边界值生成能力。

Stars: 0 | Forks: 0

# ziofuzz ## `std.testing.fuzz` 能提供什么 ``` const std = @import("std"); // Coverage-guided fuzzing with structured input via Smith test "fuzz adder" { try std.testing.fuzz({}, struct { fn testOne(context: void, smith: *std.testing.Smith) !void { const a = smith.value(i32); const sum = try std.math.add(i32, a, 100); try std.testing.expect(sum >= a); } }.testOne, .{}); } ``` 运行命令:`zig build fuzz` - 覆盖率引导、并行执行、自动管理 corpus。 ## ziofuzz 什么时候仍然有用 - **无需 fuzz 构建步骤** - 像任何其他测试一样在 `zig test` 中运行 - **简单的基于属性的测试 (property-based testing)** - `fuzz1(T, property, config)` 编写起来非常快捷 - **边缘用例生成** - `edgeCases(T)` 无需设置 Smith 即可提供边界值 - **学习/参考** - 随机 + 边缘用例 + shrink 的直接实现 支持的类型包括 `bool`、最高 64 位的固定宽度整数、`usize`、 `f32`、`f64` 以及最多包含 5 个字段的 enum。任何其他类型都会导致编译错误。 ``` const ziofuzz = @import("ziofuzz"); // Quick property check - no build step, runs in `zig test` // The property takes the generated values and returns an error to fail. try ziofuzz.fuzz1(u8, struct { fn check(x: u8) !void { try std.testing.expect(x +| 0 == x); } }.check, .{ .max_iterations = 1000 }); // Edge cases for a type const cases = ziofuzz.edgeCases(u8); // [0, 1, 127, 255] ``` ## 许可证 MIT。版权所有 (c) 2026 Alessandro De Blasis。
标签:Zig, 属性测试, 测试工具, 边界测试