Skip to content

Commit 58fdaa4

Browse files
committed
ci: run fuzz test in ci
The fuzz job caches the fuzz corpus and uploads any failure as artifact (manual download is required to integrate this to testdata/fuzz). At this moment, this is run only on pull requests and merge to master. Signed-off-by: Frederic BIDON <[email protected]>
1 parent 3eb4edd commit 58fdaa4

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed

.github/release.yml

Lines changed: 0 additions & 1 deletion
This file was deleted.

.github/workflows/go-test.yml

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,71 @@ jobs:
8989
name: 'unit.report.${{ matrix.os }}-${{ matrix.go }}'
9090
retention-days: 1
9191

92+
fuzz-test:
93+
name: fuzz test
94+
runs-on: ubuntu-latest
95+
env:
96+
CORPUS_MAX_SIZE_MB: 100
97+
steps:
98+
-
99+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
100+
-
101+
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
102+
with:
103+
go-version: stable
104+
check-latest: true
105+
cache: true
106+
-
107+
name: Locate go fuzz cache
108+
run: |
109+
GOCACHE=$(go env GOCACHE)
110+
echo "CORPUS_DIR=${GOCACHE}/fuzz" >> "${GITHUB_ENV}"
111+
-
112+
uses: actions/cache@v3
113+
with:
114+
key: ${{ runner.os }}-go-fuzz
115+
path:
116+
${{ env.CORPUS_DIR }}
117+
-
118+
name: Manage fuzz corpus cache size
119+
run: |
120+
mkdir -p "${CORPUS_DIR}"
121+
CURRENT_SIZE=$(du -sm "${CORPUS_DIR}"|cut -f1)
122+
echo "corpus size: ${CURRENT_SIZE}MB"
123+
if [[ "${CURRENT_SIZE}" -gt "${CORPUS_MAX_SIZE}" ]] ; then
124+
# remove the 50 oldest corpus files
125+
echo "::warning:Large fuzz corpus pruned"
126+
find "${CORPUS_DIR}" -type f|ls -t|tail -n +50|xargs rm -f
127+
fi
128+
-
129+
name: Run go fuzz tests
130+
run: >
131+
go test
132+
-fuzz=Fuzz
133+
-run=Fuzz
134+
-fuzztime=1m30s
135+
-fuzzminimizetime=5m
136+
./...
137+
-
138+
name: Upload failed corpus
139+
if: ${{ failure() }}
140+
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
141+
with:
142+
path: ${{ env.CORPUS_DIR }}
143+
name: '${{ runner.os }}-fuzz-corpus-failure'
144+
retention-days: 60
145+
-
146+
name: Report fuzz corpus cache size
147+
run: |
148+
FINAL_SIZE=$(du -m "${CORPUS_DIR}"|cut -f1)
149+
echo "::notice title=fuzz corpus size:${FINAL_SIZE}MB"
150+
151+
92152
test-complete:
93153
# description: |
94154
# Be explicit about all tests being passed. This allows for setting up only a few status checks on PRs.
95155
name: tests completed
96-
needs: [test]
156+
needs: [test,fuzz-test]
97157
runs-on: ubuntu-latest
98158
steps:
99159
-

fuzz_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
)
1414

1515
func FuzzParse(f *testing.F) {
16+
// initial seed
1617
cumulated := make([]string, 0, 100)
1718
for generator := range generators() {
1819
f.Add(generator)

0 commit comments

Comments
 (0)