]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/testdata/script: consistently set GOCACHE in fuzz tests
authorRoland Shoemaker <roland@golang.org>
Wed, 15 Mar 2023 22:37:26 +0000 (15:37 -0700)
committerGopher Robot <gobot@golang.org>
Thu, 16 Mar 2023 16:53:11 +0000 (16:53 +0000)
The fuzzing cache for interesting inputs is shared across all
invocations of scripts by default. When 'go clean -fuzzcache' is called,
or fuzz targets in different scripts have the same names, we can get
race-y unexpected behavior.

Since there isn't a easy way to set just the fuzz cache directory (test
has the flag -test.fuzzcachedir, but it requires setting it on each call
to 'go test'), instead we just consistently set GOCACHE to point to a
directory in the WORK dir. As a byproduct this also prevents usage of a
shared build cache, so we see an increase in build time for these tests.

Updates #59062

Change-Id: Ie78f2943b94f3302c5bdf1f8a1e93b207853666a
Reviewed-on: https://go-review.googlesource.com/c/go/+/476755
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Roland Shoemaker <roland@golang.org>
Auto-Submit: Roland Shoemaker <roland@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>

19 files changed:
src/cmd/go/testdata/script/test_fuzz.txt
src/cmd/go/testdata/script/test_fuzz_chatty.txt
src/cmd/go/testdata/script/test_fuzz_cleanup.txt
src/cmd/go/testdata/script/test_fuzz_cov.txt
src/cmd/go/testdata/script/test_fuzz_deadline.txt
src/cmd/go/testdata/script/test_fuzz_dup_cache.txt
src/cmd/go/testdata/script/test_fuzz_fuzztime.txt
src/cmd/go/testdata/script/test_fuzz_io_error.txt
src/cmd/go/testdata/script/test_fuzz_limit_dup_entry.txt
src/cmd/go/testdata/script/test_fuzz_match.txt
src/cmd/go/testdata/script/test_fuzz_multiple.txt
src/cmd/go/testdata/script/test_fuzz_mutate_crash.txt
src/cmd/go/testdata/script/test_fuzz_mutate_fail.txt
src/cmd/go/testdata/script/test_fuzz_mutator.txt
src/cmd/go/testdata/script/test_fuzz_mutator_repeat.txt
src/cmd/go/testdata/script/test_fuzz_non_crash_signal.txt
src/cmd/go/testdata/script/test_fuzz_parallel.txt
src/cmd/go/testdata/script/test_fuzz_setenv.txt
src/cmd/go/testdata/script/test_fuzz_test_race.txt

index 3e048e00c55c39e1598d32d4b896c22f899ab270..37170bfb2f8ff1d0cda6651665c1b006ff6412f0 100644 (file)
@@ -1,4 +1,6 @@
 [!fuzz] skip
+[short] skip
+env GOCACHE=$WORK/cache
 
 # Test that running a fuzz target that returns without failing or calling
 # f.Fuzz fails and causes a non-zero exit status.
index d07fe50f95e71a637db2833301e0172fc485a123..01a68cb700f44480564de93d32987ffa86d57cae 100644 (file)
@@ -1,5 +1,6 @@
 [!fuzz] skip
 [short] skip
+env GOCACHE=$WORK/cache
 
 # Run chatty fuzz targets with an error.
 ! go test -v chatty_error_fuzz_test.go
index b65022bd74e7a060478918783caa03673fd49bc9..5f864987cb6facd0e517ca4bec704e33c8004648 100644 (file)
@@ -1,5 +1,6 @@
 [!fuzz] skip
 [short] skip
+env GOCACHE=$WORK/cache
 
 # Cleanup should run after F.Skip.
 go test -run=FuzzTargetSkip
index e38912ba7c672acd422cf1b284f60461e19de3cc..c0844a3db63518d98e79fa9ce08b882a7f35d08e 100644 (file)
@@ -4,10 +4,10 @@
 
 [short] skip
 [!fuzz-instrumented] skip
+env GOCACHE=$WORK/cache
 
 # TODO(#51484): enabled debugging info to help diagnose a deadlock in the fuzzer
 env GODEBUG=fuzzdebug=1
-go clean --fuzzcache
 ! go test -fuzz=FuzzCov -v
 ! stderr 'cov instrumentation working'
 
index 5ba76a3d4fea9af135b17d6284ca579ee6dde186..46d3521558fe33e3909d40dd365de71493639f2b 100644 (file)
@@ -1,5 +1,6 @@
 [!fuzz] skip
 [short] skip
+env GOCACHE=$WORK/cache
 
 # The fuzz function should be able to detect whether -timeout
 # was set with T.Deadline. Note there is no F.Deadline, and
index 52d44a26ff8c827a5a2a4f642696f9861a02a34c..f54a77c5bb332f4c85f40a5bc17aaa2afdec7400 100644 (file)
@@ -1,5 +1,6 @@
 [!fuzz] skip
 [short] skip
+env GOCACHE=$WORK/cache
 
 # This test checks that cached corpus loading properly handles duplicate entries (this can
 # happen when a f.Add value has a duplicate entry in the cached corpus.) Duplicate entries
index 56d94a4bcf58e6cab05961c1e2b42853bcbfa993..28ef3bf7debf19a2923f2c6f64bd2cbe8b70ea88 100644 (file)
@@ -1,5 +1,6 @@
 [!fuzz] skip
 [short] skip
+env GOCACHE=$WORK/cache
 
 # There are no seed values, so 'go test' should finish quickly.
 go test
@@ -14,8 +15,6 @@ exec ./fuzz.test$GOEXE -test.timeout=3s -test.fuzz=FuzzFast -test.fuzztime=5s -t
 # Timeout should not cause inputs to be written as crashers.
 ! exists testdata/fuzz
 
-env GOCACHE=$WORK/tmp
-
 # When we use fuzztime with an "x" suffix, it runs a specific number of times.
 # This fuzz function creates a file with a unique name ($pid.$count) on each
 # run. We count the files to find the number of runs.
index 1a0aa6427e89f69cb09ab99353a5082a63d60d4d..01b4da6a89ab3beffc7ec23905903ce417a6959d 100644 (file)
@@ -7,6 +7,7 @@
 # due to ^C and EOF errors which are more common. We don't report those.
 [short] skip
 [!fuzz] skip
+env GOCACHE=$WORK/cache
 
 # If the I/O error occurs before F.Fuzz is called, the coordinator should
 # stop the worker and say that.
index 83235f4b6d5970d794ff4d5cfd9fb970d8efb273..01217aed527d90e72c44dc35934d796b0206abe5 100644 (file)
@@ -1,12 +1,12 @@
 [!fuzz] skip
 [short] skip
+env GOCACHE=$WORK/cache
 
 # FuzzA attempts to cause the mutator to create duplicate inputs that generate
 # new coverage. Previously this would trigger a corner case when the fuzzer
 # had a execution limit, causing it to deadlock and sit in the coordinator
 # loop indefinitely, failing to exit once the limit had been exhausted.
 
-go clean --fuzzcache
 go test -fuzz=FuzzA -fuzztime=100x -parallel=1
 
 -- go.mod --
index dbf987605f30fbdd992385f47b5af59481f034e4..d1495863960c98ddc082b13f01e366a18ac45260 100644 (file)
@@ -1,4 +1,6 @@
 [!fuzz] skip
+[short] skip
+env GOCACHE=$WORK/cache
 
 # Matches only fuzz targets to test.
 go test standalone_fuzz_test.go
index 1ec4985613fd36eb9f9913e1f13e61fdedb88e52..c96112f91b6206363a23563d60a59888ab6e8cdd 100644 (file)
@@ -4,6 +4,7 @@
 
 [!fuzz] skip
 [short] skip
+env GOCACHE=$WORK/cache
 
 # With fuzzing disabled, multiple targets can be tested.
 go test ./...
index e0bfdbb408046dc649a0eedcfff6907f563604e2..4b9b36dc7531dd86fd13aa800987f03780481afc 100644 (file)
@@ -6,6 +6,7 @@
 # to the seed corpus in testdata, and failing the next time the test is run.
 
 [short] skip
+env GOCACHE=$WORK/cache
 
 # Running the seed corpus for all of the targets should pass the first
 # time, since nothing in the seed corpus will cause a crash.
index b5eab17349456cdffae387307772d54f933ccc89..213b73a1b39c075d5f7dc89678c3e33225515d7a 100644 (file)
@@ -4,6 +4,7 @@
 # 'go test' exits non-zero and no crasher is recorded.
 
 [short] skip
+env GOCACHE=$WORK/cache
 
 ! go test -fuzz=FuzzReturn
 ! exists testdata
index 76b86488ad8ba5b29082493675344c549e804151..cc1f98990e9e97b7abf9b1c85e94eb2255faefe1 100644 (file)
@@ -8,6 +8,7 @@
 # tests seed values and the worker tests mutated values on the fuzz target.
 
 [short] skip
+env GOCACHE=$WORK/cache
 
 go test -fuzz=FuzzA -fuzztime=100x -parallel=1 -log=fuzz
 go run check_logs.go fuzz fuzz.worker
index b413f938a68a6628319fc237560ede467c940ed4..3b005c960194729dd191208ac31f47a89e4ca0a0 100644 (file)
@@ -6,6 +6,7 @@
 # to the coordinator.
 
 [short] skip
+env GOCACHE=$WORK/cache
 
 # Start fuzzing. The worker crashes after 100 iterations.
 # The fuzz function writes the crashing input to "want" before exiting.
index 6f1eeab42407f62566a517f870109be3c89f1e29..94a0421361fd84ecd63cff1d57fd6e7c062980df 100644 (file)
@@ -3,6 +3,7 @@
 [GOOS:windows] skip
 [!fuzz] skip
 [short] skip
+env GOCACHE=$WORK/cache
 
 # FuzzNonCrash sends itself a signal that does not appear to be a crash.
 # We should not save a crasher.
index e6325208d008ada1f0735ff8137fedc12ed6026d..8ff965a9b3bef4931b7670c9a9becf31ac6b4617 100644 (file)
@@ -1,5 +1,6 @@
 [!fuzz] skip
 [short] skip
+env GOCACHE=$WORK/cache
 
 # When running seed inputs, T.Parallel should let multiple inputs run in
 # parallel.
index 2924569de119029083c2a2d5bef7352adc8a9bd1..1370cd8680f4c1967aa966f3fe6d3102a527998d 100644 (file)
@@ -1,5 +1,6 @@
 [!fuzz] skip
 [short] skip
+env GOCACHE=$WORK/cache
 
 go test -fuzz=FuzzA -fuzztime=100x fuzz_setenv_test.go
 
index 9d39cd684e7d19ce82b3f38b452d6548a4620b42..1bed47d458bc390212d1726b5234a158afbb47ca 100644 (file)
@@ -5,6 +5,7 @@
 [short] skip
 [!fuzz] skip
 [!race] skip
+env GOCACHE=$WORK/cache
 
 # Test with coverage instrumentation enabled (-fuzz) and race instrumentation
 # but without actually fuzzing the target (by using a non-matching pattern)