mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-04-26 13:01:34 +03:00
add -Dfuzz-only
Runs only one configuration suitable for fuzzing.
This commit is contained in:
@@ -85,6 +85,7 @@ pub fn build(b: *std.Build) !void {
|
||||
docs_step.dependOn(std_docs_step);
|
||||
|
||||
const no_matrix = b.option(bool, "no-matrix", "Limit test matrix to exactly one target configuration") orelse false;
|
||||
const fuzz_only = b.option(bool, "fuzz-only", "Limit test matrix to one target suitable for fuzzing") orelse false;
|
||||
const skip_debug = b.option(bool, "skip-debug", "Main test suite skips debug builds") orelse false;
|
||||
const skip_release = b.option(bool, "skip-release", "Main test suite skips release builds") orelse no_matrix;
|
||||
const skip_release_small = b.option(bool, "skip-release-small", "Main test suite skips release-small builds") orelse skip_release;
|
||||
@@ -417,6 +418,13 @@ pub fn build(b: *std.Build) !void {
|
||||
}
|
||||
const optimization_modes = chosen_opt_modes_buf[0..chosen_mode_index];
|
||||
|
||||
const test_only: ?tests.ModuleTestOptions.TestOnly = if (no_matrix)
|
||||
.default
|
||||
else if (fuzz_only)
|
||||
.{ .fuzz = optimize }
|
||||
else
|
||||
null;
|
||||
|
||||
const fmt_include_paths = &.{ "lib", "src", "test", "tools", "build.zig", "build.zig.zon" };
|
||||
const fmt_exclude_paths = &.{ "test/cases", "test/behavior/zon" };
|
||||
const do_fmt = b.addFmt(.{
|
||||
@@ -472,7 +480,7 @@ pub fn build(b: *std.Build) !void {
|
||||
.include_paths = &.{},
|
||||
.skip_single_threaded = skip_single_threaded,
|
||||
.skip_non_native = skip_non_native,
|
||||
.test_default_only = no_matrix,
|
||||
.test_only = test_only,
|
||||
.skip_spirv = skip_spirv,
|
||||
.skip_wasm = skip_wasm,
|
||||
.skip_freebsd = skip_freebsd,
|
||||
@@ -497,7 +505,7 @@ pub fn build(b: *std.Build) !void {
|
||||
.include_paths = &.{},
|
||||
.skip_single_threaded = true,
|
||||
.skip_non_native = skip_non_native,
|
||||
.test_default_only = no_matrix,
|
||||
.test_only = test_only,
|
||||
.skip_spirv = skip_spirv,
|
||||
.skip_wasm = skip_wasm,
|
||||
.skip_freebsd = skip_freebsd,
|
||||
@@ -523,7 +531,7 @@ pub fn build(b: *std.Build) !void {
|
||||
.include_paths = &.{},
|
||||
.skip_single_threaded = true,
|
||||
.skip_non_native = skip_non_native,
|
||||
.test_default_only = no_matrix,
|
||||
.test_only = test_only,
|
||||
.skip_spirv = skip_spirv,
|
||||
.skip_wasm = skip_wasm,
|
||||
.skip_freebsd = skip_freebsd,
|
||||
@@ -549,7 +557,7 @@ pub fn build(b: *std.Build) !void {
|
||||
.include_paths = &.{},
|
||||
.skip_single_threaded = skip_single_threaded,
|
||||
.skip_non_native = skip_non_native,
|
||||
.test_default_only = no_matrix,
|
||||
.test_only = test_only,
|
||||
.skip_spirv = skip_spirv,
|
||||
.skip_wasm = skip_wasm,
|
||||
.skip_freebsd = skip_freebsd,
|
||||
|
||||
+17
-6
@@ -2310,7 +2310,7 @@ pub fn addCliTests(b: *std.Build) *Step {
|
||||
return step;
|
||||
}
|
||||
|
||||
const ModuleTestOptions = struct {
|
||||
pub const ModuleTestOptions = struct {
|
||||
test_filters: []const []const u8,
|
||||
test_target_filters: []const []const u8,
|
||||
test_extra_targets: bool,
|
||||
@@ -2319,7 +2319,7 @@ const ModuleTestOptions = struct {
|
||||
desc: []const u8,
|
||||
optimize_modes: []const OptimizeMode,
|
||||
include_paths: []const []const u8,
|
||||
test_default_only: bool,
|
||||
test_only: ?TestOnly,
|
||||
skip_single_threaded: bool,
|
||||
skip_non_native: bool,
|
||||
skip_spirv: bool,
|
||||
@@ -2335,20 +2335,31 @@ const ModuleTestOptions = struct {
|
||||
max_rss: usize = 0,
|
||||
no_builtin: bool = false,
|
||||
build_options: ?*Step.Options = null,
|
||||
|
||||
pub const TestOnly = union(enum) {
|
||||
default: void,
|
||||
fuzz: OptimizeMode,
|
||||
};
|
||||
};
|
||||
|
||||
pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
|
||||
const step = b.step(b.fmt("test-{s}", .{options.name}), options.desc);
|
||||
|
||||
if (options.test_default_only) {
|
||||
const test_target = &test_targets[0];
|
||||
if (options.test_only) |test_only| {
|
||||
const test_target: TestTarget = switch (test_only) {
|
||||
.default => test_targets[0],
|
||||
.fuzz => |optimize| .{
|
||||
.optimize_mode = optimize,
|
||||
.use_llvm = true,
|
||||
},
|
||||
};
|
||||
const resolved_target = b.resolveTargetQuery(test_target.target);
|
||||
const triple_txt = resolved_target.query.zigTriple(b.allocator) catch @panic("OOM");
|
||||
addOneModuleTest(b, step, test_target, &resolved_target, triple_txt, options);
|
||||
return step;
|
||||
}
|
||||
|
||||
for_targets: for (&test_targets) |*test_target| {
|
||||
for_targets: for (test_targets) |test_target| {
|
||||
if (test_target.skip_modules.len > 0) {
|
||||
for (test_target.skip_modules) |skip_mod| {
|
||||
if (std.mem.eql(u8, options.name, skip_mod)) continue :for_targets;
|
||||
@@ -2425,7 +2436,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
|
||||
fn addOneModuleTest(
|
||||
b: *std.Build,
|
||||
step: *Step,
|
||||
test_target: *const TestTarget,
|
||||
test_target: TestTarget,
|
||||
resolved_target: *const std.Build.ResolvedTarget,
|
||||
triple_txt: []const u8,
|
||||
options: ModuleTestOptions,
|
||||
|
||||
Reference in New Issue
Block a user