@@ -56,20 +56,21 @@ pub fn main() void {
56
56
}
57
57
}
58
58
59
- fba .reset ();
60
59
if (builtin .fuzz ) {
61
60
const cache_dir = opt_cache_dir orelse @panic ("missing --cache-dir=[path] argument" );
62
61
fuzz_abi .fuzzer_init (.fromSlice (cache_dir ));
63
62
}
64
63
64
+ fba .reset ();
65
+
65
66
if (listen ) {
66
- return mainServer (opt_cache_dir ) catch @panic ("internal test runner failure" );
67
+ return mainServer () catch @panic ("internal test runner failure" );
67
68
} else {
68
69
return mainTerminal ();
69
70
}
70
71
}
71
72
72
- fn mainServer (opt_cache_dir : ? [] const u8 ) ! void {
73
+ fn mainServer () ! void {
73
74
@disableInstrumentation ();
74
75
var stdin_reader = std .fs .File .stdin ().readerStreaming (& stdin_buffer );
75
76
var stdout_writer = std .fs .File .stdout ().writerStreaming (& stdout_buffer );
@@ -79,66 +80,14 @@ fn mainServer(opt_cache_dir: ?[]const u8) !void {
79
80
.zig_version = builtin .zig_version_string ,
80
81
});
81
82
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
+ );
142
91
}
143
92
144
93
while (true ) {
@@ -235,7 +184,7 @@ fn mainServer(opt_cache_dir: ?[]const u8) !void {
235
184
if (@errorReturnTrace ()) | trace | {
236
185
std .debug .dumpStackTrace (trace .* );
237
186
}
238
- std .debug .print ("failed with error.{s }\n " , .{@errorName ( err ) });
187
+ std .debug .print ("failed with error.{t }\n " , .{err });
239
188
std .process .exit (1 );
240
189
},
241
190
};
@@ -305,11 +254,11 @@ fn mainTerminal() void {
305
254
else = > {
306
255
fail_count += 1 ;
307
256
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 ,
310
259
});
311
260
} else {
312
- std .debug .print ("FAIL ({s })\n " , .{@errorName ( err ) });
261
+ std .debug .print ("FAIL ({t })\n " , .{err });
313
262
}
314
263
if (@errorReturnTrace ()) | trace | {
315
264
std .debug .dumpStackTrace (trace .* );
@@ -450,7 +399,7 @@ pub fn fuzz(
450
399
else = > {
451
400
std .debug .lockStdErr ();
452
401
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 });
454
403
std .process .exit (1 );
455
404
},
456
405
};
0 commit comments