Skip to content

Commit d1b4d34

Browse files
committed
[fuzz] Copy crashing outputs before failing
Also try to avoid lots of purple timeouts until google/oss-fuzz#4548 is fixed Change-Id: I6a98352b3f5a583a137f915a4c3adf6954a35777 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/328989 Reviewed-by: Eric Boren <borenet@google.com>
1 parent 38a93e6 commit d1b4d34

File tree

1 file changed

+31
-27
lines changed

1 file changed

+31
-27
lines changed

infra/bots/task_drivers/cifuzz/cifuzz.go

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,9 @@ func main() {
6969
td.Fatal(ctx, skerr.Wrap(err))
7070
}
7171

72-
// build and run fuzzers
73-
if err := buildAndRunCIFuzz(ctx, workDir, skiaAbsPath, *fuzzDuration); err != nil {
74-
fatalOrSleep(ctx, skerr.Wrap(err))
75-
}
72+
// build and run fuzzers. If it fails (errors), hold that until we cleanup and copy the output.
73+
// That way, developers can have access to the crashes.
74+
runErr := buildAndRunCIFuzz(ctx, workDir, skiaAbsPath, *fuzzDuration)
7675

7776
if err := extractOutput(ctx, workDir, outAbsPath); err != nil {
7877
fatalOrSleep(ctx, skerr.Wrap(err))
@@ -82,6 +81,10 @@ func main() {
8281
if err := os_steps.RemoveAll(ctx, workDir); err != nil {
8382
fatalOrSleep(ctx, skerr.Wrap(err))
8483
}
84+
85+
if runErr != nil {
86+
fatalOrSleep(ctx, skerr.Wrap(runErr))
87+
}
8588
}
8689

8790
func fatalOrSleep(ctx context.Context, err error) {
@@ -130,7 +133,7 @@ func setupCIFuzzRepoAndDocker(ctx context.Context, workdir, gitAbsPath string) e
130133
}
131134

132135
func prepareSkiaCheckout(ctx context.Context, skiaAbsPath, workDir, gitAbsPath string) error {
133-
ctx = td.StartStep(ctx, td.Props("prepare skia checkout for build"))
136+
ctx = td.StartStep(ctx, td.Props("prepare skia checkout for build").Infra())
134137
defer td.EndStep(ctx)
135138

136139
swiftshaderDir := filepath.Join(skiaAbsPath, "third_party", "externals", "swiftshader")
@@ -148,14 +151,6 @@ func prepareSkiaCheckout(ctx context.Context, skiaAbsPath, workDir, gitAbsPath s
148151
return nil
149152
}
150153

151-
//// docker run --name build_fuzzers --rm --env MANUAL_SRC_PATH=/mnt/pd0/s/w/ir/skia --env OSS_FUZZ_PROJECT_NAME=skia \
152-
//--env GITHUB_WORKSPACE=/mnt/pd0/s/w/ir/cifuzz_work/cifuzz --env GITHUB_REPOSITORY=skia \
153-
//--env GITHUB_EVENT_NAME=push --env DRY_RUN=false --env CI=true --env SANITIZER=address \
154-
//--env GITHUB_SHA=does_nothing --volume /var/run/docker.sock:/var/run/docker.sock \
155-
//--mount "type=bind,source=/mnt/pd0/s/w/ir/skia,destination=/mnt/pd0/s/w/ir/skia" \
156-
//--mount "type=bind,source=/mnt/pd0/s/w/ir/cifuzz_work/cifuzz,destination=/mnt/pd0/s/w/ir/cifuzz_work/cifuzz" \
157-
//local_build_fuzzers
158-
159154
func buildAndRunCIFuzz(ctx context.Context, workDir, skiaAbsPath string, duration time.Duration) error {
160155
ctx = td.StartStep(ctx, td.Props("build skia fuzzers and run them"))
161156
defer td.EndStep(ctx)
@@ -181,25 +176,43 @@ func buildAndRunCIFuzz(ctx context.Context, workDir, skiaAbsPath string, duratio
181176
return td.FailStep(ctx, skerr.Wrap(err))
182177
}
183178

184-
if _, err := exec.RunCwd(ctx, workDir, dockerExe, "run",
179+
args := []string{"run",
185180
"--name", "run_fuzzers", "--rm",
186181
"--env", "OSS_FUZZ_PROJECT_NAME=skia",
187-
"--env", "GITHUB_WORKSPACE="+workDir,
182+
"--env", "GITHUB_WORKSPACE=" + workDir,
188183
"--env", "GITHUB_REPOSITORY=skia", // TODO(metzman) make this not required
189184
"--env", "GITHUB_EVENT_NAME=push", // TODO(metzman) make this not required
190185
"--env", "DRY_RUN=false",
191186
"--env", "CI=true",
192187
"--env", "CIFUZZ=true",
193-
"--env", "FUZZ_TIME="+fmt.Sprintf("%d", duration/time.Second), // This is split up between all affected fuzzers.
188+
"--env", "FUZZ_TIME=" + fmt.Sprintf("%d", duration/time.Second), // This is split up between all affected fuzzers.
194189
"--env", "SANITIZER=address",
195190
"--env", "GITHUB_SHA=does_nothing",
196191
"--volume", "/var/run/docker.sock:/var/run/docker.sock",
197192
"--mount", fmt.Sprintf("type=bind,source=%s,destination=%s", workDir, workDir),
198193
runFuzzersDockerImage,
199-
); err != nil {
200-
return td.FailStep(ctx, skerr.Wrap(err))
201194
}
202195

196+
cmd := exec.Command{
197+
Name: dockerExe,
198+
Args: args,
199+
Dir: workDir,
200+
Timeout: duration + 10*time.Minute, // Give a little padding in case fuzzing takes some extra time.
201+
}
202+
if _, err := exec.RunCommand(ctx, &cmd); err != nil {
203+
if !exec.IsTimeout(err) {
204+
return td.FailStep(ctx, skerr.Wrap(err))
205+
} else {
206+
sklog.Warningf("Fuzzing timed out: %s", err)
207+
}
208+
}
209+
return nil
210+
}
211+
212+
func extractOutput(ctx context.Context, workDir, outAbsPath string) error {
213+
ctx = td.StartStep(ctx, td.Props("copy output directory").Infra())
214+
defer td.EndStep(ctx)
215+
203216
cifuzzOutDir := filepath.Join(workDir, "out")
204217

205218
// Fix up permissions of output directory (we need to delete extra folders here so we can
@@ -212,20 +225,11 @@ func buildAndRunCIFuzz(ctx context.Context, workDir, skiaAbsPath string, duratio
212225
return td.FailStep(ctx, skerr.Wrap(err))
213226
}
214227

215-
return nil
216-
}
217-
218-
func extractOutput(ctx context.Context, workDir, outAbsPath string) error {
219-
ctx = td.StartStep(ctx, td.Props("copy output directory"))
220-
defer td.EndStep(ctx)
221-
222228
// Make these directories for cifuzz exist so docker does not create it w/ root permissions.
223229
if err := os_steps.MkdirAll(ctx, outAbsPath); err != nil {
224230
return td.FailStep(ctx, skerr.Wrap(err))
225231
}
226232

227-
cifuzzOutDir := filepath.Join(workDir, "out")
228-
229233
files, err := os_steps.ReadDir(ctx, cifuzzOutDir)
230234
if err != nil {
231235
return td.FailStep(ctx, skerr.Wrapf(err, "getting output from %s", cifuzzOutDir))

0 commit comments

Comments
 (0)