@@ -67,8 +67,8 @@ type InternalFuzzTarget struct {
67
67
// that are allowed in the (*F).Fuzz function are (*F).Failed and (*F).Name.
68
68
type F struct {
69
69
common
70
- fuzzContext * fuzzContext
71
- testContext * testContext
70
+ fstate * fuzzState
71
+ tstate * testState
72
72
73
73
// inFuzzFn is true when the fuzz function is running. Most F methods cannot
74
74
// be called when inFuzzFn is true.
@@ -244,22 +244,22 @@ func (f *F) Fuzz(ff any) {
244
244
// corpus and entries declared with F.Add.
245
245
//
246
246
// Don't load the seed corpus if this is a worker process; we won't use it.
247
- if f .fuzzContext .mode != fuzzWorker {
247
+ if f .fstate .mode != fuzzWorker {
248
248
for _ , c := range f .corpus {
249
- if err := f .fuzzContext .deps .CheckCorpus (c .Values , types ); err != nil {
249
+ if err := f .fstate .deps .CheckCorpus (c .Values , types ); err != nil {
250
250
// TODO(#48302): Report the source location of the F.Add call.
251
251
f .Fatal (err )
252
252
}
253
253
}
254
254
255
255
// Load seed corpus
256
- c , err := f .fuzzContext .deps .ReadCorpus (filepath .Join (corpusDir , f .name ), types )
256
+ c , err := f .fstate .deps .ReadCorpus (filepath .Join (corpusDir , f .name ), types )
257
257
if err != nil {
258
258
f .Fatal (err )
259
259
}
260
260
for i := range c {
261
261
c [i ].IsSeed = true // these are all seed corpus values
262
- if f .fuzzContext .mode == fuzzCoordinator {
262
+ if f .fstate .mode == fuzzCoordinator {
263
263
// If this is the coordinator process, zero the values, since we don't need
264
264
// to hold onto them.
265
265
c [i ].Values = nil
@@ -285,12 +285,12 @@ func (f *F) Fuzz(ff any) {
285
285
if e .Path != "" {
286
286
testName = fmt .Sprintf ("%s/%s" , testName , filepath .Base (e .Path ))
287
287
}
288
- if f .testContext .isFuzzing {
288
+ if f .tstate .isFuzzing {
289
289
// Don't preserve subtest names while fuzzing. If fn calls T.Run,
290
290
// there will be a very large number of subtests with duplicate names,
291
291
// which will use a large amount of memory. The subtest names aren't
292
292
// useful since there's no way to re-run them deterministically.
293
- f .testContext .match .clearSubNames ()
293
+ f .tstate .match .clearSubNames ()
294
294
}
295
295
296
296
// Record the stack trace at the point of this call so that if the subtest
@@ -308,7 +308,7 @@ func (f *F) Fuzz(ff any) {
308
308
creator : pc [:n ],
309
309
chatty : f .chatty ,
310
310
},
311
- context : f .testContext ,
311
+ tstate : f .tstate ,
312
312
}
313
313
if captureOut != nil {
314
314
// t.parent aliases f.common.
@@ -328,9 +328,9 @@ func (f *F) Fuzz(ff any) {
328
328
// we make sure it is called right before the tRunner function
329
329
// exits, regardless of whether it was executed cleanly, panicked,
330
330
// or if the fuzzFn called t.Fatal.
331
- if f .testContext .isFuzzing {
332
- defer f .fuzzContext .deps .SnapshotCoverage ()
333
- f .fuzzContext .deps .ResetCoverage ()
331
+ if f .tstate .isFuzzing {
332
+ defer f .fstate .deps .SnapshotCoverage ()
333
+ f .fstate .deps .ResetCoverage ()
334
334
}
335
335
fn .Call (args )
336
336
})
@@ -342,14 +342,14 @@ func (f *F) Fuzz(ff any) {
342
342
return ! t .Failed ()
343
343
}
344
344
345
- switch f .fuzzContext .mode {
345
+ switch f .fstate .mode {
346
346
case fuzzCoordinator :
347
347
// Fuzzing is enabled, and this is the test process started by 'go test'.
348
348
// Act as the coordinator process, and coordinate workers to perform the
349
349
// actual fuzzing.
350
350
corpusTargetDir := filepath .Join (corpusDir , f .name )
351
351
cacheTargetDir := filepath .Join (* fuzzCacheDir , f .name )
352
- err := f .fuzzContext .deps .CoordinateFuzzing (
352
+ err := f .fstate .deps .CoordinateFuzzing (
353
353
fuzzDuration .d ,
354
354
int64 (fuzzDuration .n ),
355
355
minimizeDuration .d ,
@@ -376,7 +376,7 @@ func (f *F) Fuzz(ff any) {
376
376
case fuzzWorker :
377
377
// Fuzzing is enabled, and this is a worker process. Follow instructions
378
378
// from the coordinator.
379
- if err := f .fuzzContext .deps .RunFuzzWorker (func (e corpusEntry ) error {
379
+ if err := f .fstate .deps .RunFuzzWorker (func (e corpusEntry ) error {
380
380
// Don't write to f.w (which points to Stdout) if running from a
381
381
// fuzz worker. This would become very verbose, particularly during
382
382
// minimization. Return the error instead, and let the caller deal
@@ -398,7 +398,7 @@ func (f *F) Fuzz(ff any) {
398
398
// corpus now.
399
399
for _ , e := range f .corpus {
400
400
name := fmt .Sprintf ("%s/%s" , f .name , filepath .Base (e .Path ))
401
- if _ , ok , _ := f .testContext .match .fullName (nil , name ); ok {
401
+ if _ , ok , _ := f .tstate .match .fullName (nil , name ); ok {
402
402
run (f .w , e )
403
403
}
404
404
}
@@ -451,8 +451,8 @@ type fuzzCrashError interface {
451
451
CrashPath () string
452
452
}
453
453
454
- // fuzzContext holds fields common to all fuzz tests.
455
- type fuzzContext struct {
454
+ // fuzzState holds fields common to all fuzz tests.
455
+ type fuzzState struct {
456
456
deps testDeps
457
457
mode fuzzMode
458
458
}
@@ -486,9 +486,9 @@ func runFuzzTests(deps testDeps, fuzzTests []InternalFuzzTarget, deadline time.T
486
486
break
487
487
}
488
488
489
- tctx := newTestContext (* parallel , m )
490
- tctx .deadline = deadline
491
- fctx := & fuzzContext {deps : deps , mode : seedCorpusOnly }
489
+ tstate := newTestState (* parallel , m )
490
+ tstate .deadline = deadline
491
+ fstate := & fuzzState {deps : deps , mode : seedCorpusOnly }
492
492
root := common {w : os .Stdout } // gather output in one place
493
493
if Verbose () {
494
494
root .chatty = newChattyPrinter (root .w )
@@ -497,7 +497,7 @@ func runFuzzTests(deps testDeps, fuzzTests []InternalFuzzTarget, deadline time.T
497
497
if shouldFailFast () {
498
498
break
499
499
}
500
- testName , matched , _ := tctx .match .fullName (nil , ft .Name )
500
+ testName , matched , _ := tstate .match .fullName (nil , ft .Name )
501
501
if ! matched {
502
502
continue
503
503
}
@@ -517,8 +517,8 @@ func runFuzzTests(deps testDeps, fuzzTests []InternalFuzzTarget, deadline time.T
517
517
level : root .level + 1 ,
518
518
chatty : root .chatty ,
519
519
},
520
- testContext : tctx ,
521
- fuzzContext : fctx ,
520
+ tstate : tstate ,
521
+ fstate : fstate ,
522
522
}
523
523
f .w = indenter {& f .common }
524
524
if f .chatty != nil {
@@ -554,17 +554,17 @@ func runFuzzing(deps testDeps, fuzzTests []InternalFuzzTarget) (ok bool) {
554
554
return true
555
555
}
556
556
m := newMatcher (deps .MatchString , * matchFuzz , "-test.fuzz" , * skip )
557
- tctx := newTestContext (1 , m )
558
- tctx .isFuzzing = true
559
- fctx := & fuzzContext {
557
+ tstate := newTestState (1 , m )
558
+ tstate .isFuzzing = true
559
+ fstate := & fuzzState {
560
560
deps : deps ,
561
561
}
562
562
root := common {w : os .Stdout }
563
563
if * isFuzzWorker {
564
564
root .w = io .Discard
565
- fctx .mode = fuzzWorker
565
+ fstate .mode = fuzzWorker
566
566
} else {
567
- fctx .mode = fuzzCoordinator
567
+ fstate .mode = fuzzCoordinator
568
568
}
569
569
if Verbose () && ! * isFuzzWorker {
570
570
root .chatty = newChattyPrinter (root .w )
@@ -573,7 +573,7 @@ func runFuzzing(deps testDeps, fuzzTests []InternalFuzzTarget) (ok bool) {
573
573
var testName string
574
574
var matched []string
575
575
for i := range fuzzTests {
576
- name , ok , _ := tctx .match .fullName (nil , fuzzTests [i ].Name )
576
+ name , ok , _ := tstate .match .fullName (nil , fuzzTests [i ].Name )
577
577
if ! ok {
578
578
continue
579
579
}
@@ -599,8 +599,8 @@ func runFuzzing(deps testDeps, fuzzTests []InternalFuzzTarget) (ok bool) {
599
599
level : root .level + 1 ,
600
600
chatty : root .chatty ,
601
601
},
602
- fuzzContext : fctx ,
603
- testContext : tctx ,
602
+ fstate : fstate ,
603
+ tstate : tstate ,
604
604
}
605
605
f .w = indenter {& f .common }
606
606
if f .chatty != nil {
@@ -694,7 +694,7 @@ func fRunner(f *F, fn func(*F)) {
694
694
// This only affects fuzz tests run as normal tests.
695
695
// While fuzzing, T.Parallel has no effect, so f.sub is empty, and this
696
696
// branch is not taken. f.barrier is nil in that case.
697
- f .testContext .release ()
697
+ f .tstate .release ()
698
698
close (f .barrier )
699
699
// Wait for the subtests to complete.
700
700
for _ , sub := range f .sub {
0 commit comments