Skip to content

Fuzz test runner causes assertion failure in evalZigProcess #25919

Description

@davnavr

Zig Version

0.16.0-dev.1234+74900e938

Steps to Reproduce and Observed Behavior

With the following Zig program and build script:

// main.zig
const std = @import("std");

fn testOne(_: void, input: []const u8) !void {
    if (std.mem.eql(u8, "can you find me?", input)) {
        @trap();
    }
}

test {
    try std.testing.fuzz({}, testOne, .{});
}
// build.zig
const std = @import("std");

fn testOne(_: void, input: []const u8) !void {
    if (std.mem.eql(u8, "can you find me?", input)) {
        @trap();
    }
}

test {
    try std.testing.fuzz({}, testOne, .{});
}

Run zig build test --fuzz, which crashes with the following output:

info(web_server): web interface listening at http://[::1]:36383/
info(web_server): hint: pass '--webui=[::1]:36383' to use the same port next time
Build Summary: 3/3 steps succeeded; 1/1 tests passed
thread 3839 panic: reached unreachable code
/home/nixos/installed/zig-x86_64-linux-0.16.0-dev.1234+74900e938/lib/std/debug.zig:416:14: 0x10965d9 in assert (std.zig)
    if (!ok) unreachable; // assertion failure
             ^
/home/nixos/installed/zig-x86_64-linux-0.16.0-dev.1234+74900e938/lib/std/Build/Step.zig:406:11: 0x12a4a96 in evalZigProcess (std.zig)
    assert(s.result_failed_command == null);
          ^
/home/nixos/installed/zig-x86_64-linux-0.16.0-dev.1234+74900e938/lib/std/Build/Step/Compile.zig:1940:60: 0x12a7a81 in rebuildInFuzzMode (std.zig)
    const maybe_output_bin_path = try c.step.evalZigProcess(zig_args, progress_node, false, null, gpa);
                                                           ^
/home/nixos/installed/zig-x86_64-linux-0.16.0-dev.1234+74900e938/lib/std/Build/Fuzz.zig:175:45: 0x12a7d4b in rebuildTestsWorkerRunFallible (std.zig)
    const result = compile.rebuildInFuzzMode(gpa, prog_node);
                                            ^
/home/nixos/installed/zig-x86_64-linux-0.16.0-dev.1234+74900e938/lib/std/Build/Fuzz.zig:162:34: 0x12a842a in rebuildTestsWorkerRun (std.zig)
    rebuildTestsWorkerRunFallible(run, gpa, ttyconf, parent_prog_node) catch |err| {
                                 ^
/home/nixos/installed/zig-x86_64-linux-0.16.0-dev.1234+74900e938/lib/std/Thread/Pool.zig:118:39: 0x12a8619 in runFn (std.zig)
            @call(.auto, func, closure.arguments);
                                      ^
/home/nixos/installed/zig-x86_64-linux-0.16.0-dev.1234+74900e938/lib/std/Thread/Pool.zig:293:27: 0x1309290 in worker (std.zig)
            runnable.runFn(runnable, id);
                          ^
/home/nixos/installed/zig-x86_64-linux-0.16.0-dev.1234+74900e938/lib/std/Thread.zig:558:13: 0x127ea90 in callFn__anon_81866 (std.zig)
            @call(.auto, f, args);
            ^
/home/nixos/installed/zig-x86_64-linux-0.16.0-dev.1234+74900e938/lib/std/Thread.zig:1534:30: 0x1247130 in entryFn (std.zig)
                return callFn(f, self.fn_args);
                             ^
/home/nixos/installed/zig-x86_64-linux-0.16.0-dev.1234+74900e938/lib/std/os/linux/x86_64.zig:105:5: 0x111cef5 in clone (std.zig)
    asm volatile (
    ^
error: the following build command crashed:
.zig-cache/o/350485f651f1fca21b2d66830745d7a2/build /home/nixos/installed/zig-x86_64-linux-0.16.0-dev.1234+74900e938/zig /home/nixos/installed/zig-x86_64-linux-0.16.0-dev.1234+74900e938/lib /home/nixos/cs/sandbox/zigzag .zig-cache /home/nixos/.cache/zig --seed 0x33a82362 -Z8e97b72f40bd48a2 test --fuzz

The problem seems to be in std.Build.Step.evalZigProcess, which is called twice. The first time s.result_failed_command is null, but the second time it is populated with the following string, which seems to be the initial zig test invocation to find all fuzz tests:

/home/nixos/installed/zig-x86_64-linux-0.16.0-dev.1234+74900e938/zig test -ODebug -Mroot=/home/nixos/cs/sandbox/zigzag/src/main.zig --cache-dir .zig-cache --global-cache-dir /home/nixos/.cache/zig --name test --zig-lib-dir /home/nixos/installed/zig-x86_64-linux-0.16.0-dev.1234+74900e938/lib/ --listen=-

Expected Behavior

The fuzz test runner should not crash.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions