@@ -56,20 +56,21 @@ pub fn main() void {
5656 }
5757 }
5858
59- fba .reset ();
6059 if (builtin .fuzz ) {
6160 const cache_dir = opt_cache_dir orelse @panic ("missing --cache-dir=[path] argument" );
6261 fuzz_abi .fuzzer_init (.fromSlice (cache_dir ));
6362 }
6463
64+ fba .reset ();
65+
6566 if (listen ) {
66- return mainServer (opt_cache_dir ) catch @panic ("internal test runner failure" );
67+ return mainServer () catch @panic ("internal test runner failure" );
6768 } else {
6869 return mainTerminal ();
6970 }
7071}
7172
72- fn mainServer (opt_cache_dir : ? [] const u8 ) ! void {
73+ fn mainServer () ! void {
7374 @disableInstrumentation ();
7475 var stdin_reader = std .fs .File .stdin ().readerStreaming (& stdin_buffer );
7576 var stdout_writer = std .fs .File .stdout ().writerStreaming (& stdout_buffer );
@@ -79,66 +80,14 @@ fn mainServer(opt_cache_dir: ?[]const u8) !void {
7980 .zig_version = builtin .zig_version_string ,
8081 });
8182
82- if (builtin .fuzz ) blk : {
83- const cache_dir = opt_cache_dir .? ;
84- const coverage_id = fuzz_abi .fuzzer_coverage_id ();
85- const coverage_file_path : std.Build.Cache.Path = .{
86- .root_dir = .{
87- .path = cache_dir ,
88- .handle = std .fs .cwd ().openDir (cache_dir , .{}) catch | err | {
89- if (err == error .FileNotFound ) {
90- try server .serveCoverageIdMessage (coverage_id , 0 , 0 , 0 );
91- break :blk ;
92- }
93-
94- fatal ("failed to access cache dir '{s}': {s}" , .{
95- cache_dir , @errorName (err ),
96- });
97- },
98- },
99- .sub_path = "v/" ++ std .fmt .hex (coverage_id ),
100- };
101-
102- var coverage_file = coverage_file_path .root_dir .handle .openFile (coverage_file_path .sub_path , .{}) catch | err | {
103- if (err == error .FileNotFound ) {
104- try server .serveCoverageIdMessage (coverage_id , 0 , 0 , 0 );
105- break :blk ;
106- }
107-
108- fatal ("failed to load coverage file '{f}': {s}" , .{
109- coverage_file_path , @errorName (err ),
110- });
111- };
112- defer coverage_file .close ();
113-
114- var rbuf : [0x1000 ]u8 = undefined ;
115- var r = coverage_file .reader (& rbuf );
116-
117- var header : fuzz_abi.SeenPcsHeader = undefined ;
118- r .interface .readSliceAll (std .mem .asBytes (& header )) catch | err | {
119- fatal ("failed to read from coverage file '{f}': {s}" , .{
120- coverage_file_path , @errorName (err ),
121- });
122- };
123-
124- if (header .pcs_len == 0 ) {
125- fatal ("corrupted coverage file '{f}': pcs_len was zero" , .{
126- coverage_file_path ,
127- });
128- }
129-
130- var seen_count : usize = 0 ;
131- const chunk_count = fuzz_abi .SeenPcsHeader .seenElemsLen (header .pcs_len );
132- for (0.. chunk_count ) | _ | {
133- const seen = r .interface .takeInt (usize , .little ) catch | err | {
134- fatal ("failed to read from coverage file '{f}': {s}" , .{
135- coverage_file_path , @errorName (err ),
136- });
137- };
138- seen_count += @popCount (seen );
139- }
140-
141- try server .serveCoverageIdMessage (coverage_id , header .n_runs , header .unique_runs , seen_count );
83+ if (builtin .fuzz ) {
84+ const coverage = fuzz_abi .fuzzer_coverage ();
85+ try server .serveCoverageIdMessage (
86+ coverage .id ,
87+ coverage .runs ,
88+ coverage .unique ,
89+ coverage .seen ,
90+ );
14291 }
14392
14493 while (true ) {
@@ -235,7 +184,7 @@ fn mainServer(opt_cache_dir: ?[]const u8) !void {
235184 if (@errorReturnTrace ()) | trace | {
236185 std .debug .dumpStackTrace (trace .* );
237186 }
238- std .debug .print ("failed with error.{s }\n " , .{@errorName ( err ) });
187+ std .debug .print ("failed with error.{t }\n " , .{err });
239188 std .process .exit (1 );
240189 },
241190 };
@@ -305,11 +254,11 @@ fn mainTerminal() void {
305254 else = > {
306255 fail_count += 1 ;
307256 if (have_tty ) {
308- std .debug .print ("{d}/{d} {s}...FAIL ({s })\n " , .{
309- i + 1 , test_fn_list .len , test_fn .name , @errorName ( err ) ,
257+ std .debug .print ("{d}/{d} {s}...FAIL ({t })\n " , .{
258+ i + 1 , test_fn_list .len , test_fn .name , err ,
310259 });
311260 } else {
312- std .debug .print ("FAIL ({s })\n " , .{@errorName ( err ) });
261+ std .debug .print ("FAIL ({t })\n " , .{err });
313262 }
314263 if (@errorReturnTrace ()) | trace | {
315264 std .debug .dumpStackTrace (trace .* );
@@ -450,7 +399,7 @@ pub fn fuzz(
450399 else = > {
451400 std .debug .lockStdErr ();
452401 if (@errorReturnTrace ()) | trace | std .debug .dumpStackTrace (trace .* );
453- std .debug .print ("failed with error.{s }\n " , .{@errorName ( err ) });
402+ std .debug .print ("failed with error.{t }\n " , .{err });
454403 std .process .exit (1 );
455404 },
456405 };
0 commit comments