oss-fuzz/infra/libfuzzer-pipeline.groovy

108 lines
3.4 KiB
Groovy
Raw Normal View History

2016-07-21 18:38:38 +00:00
// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////
def call(body) {
// evaluate the body block, and collect configuration into the object
def config = [:]
body.resolveStrategy = Closure.DELEGATE_FIRST
body.delegate = config
body()
// Mandatory configuration
def dockerfile = config["dockerfile"]
assert dockerfile : "dockerfile should be specified"
def gitUrl = config["git"]
assert gitUrl : "git should be specified"
// Optional configuration
def projectName = config["name"] ?: env.JOB_BASE_NAME
def sanitizers = config["sanitizers"] ?: ["address"]
2016-07-21 18:38:38 +00:00
def checkoutDir = config["checkoutDir"] ?: projectName
2016-08-01 21:21:46 +00:00
def dockerContextDir = config["dockerContextDir"]
2016-07-21 18:38:38 +00:00
2016-08-12 00:13:19 +00:00
def date = java.time.format.DateTimeFormatter.ofPattern("yyyyMMddHHmm")
.format(java.time.LocalDateTime.now())
2016-07-21 18:38:38 +00:00
node {
echo "Building project $projectName with Dockerfile=$dockerfile"
2016-08-11 22:51:28 +00:00
def wsPwd = pwd()
2016-07-21 18:38:38 +00:00
for (int i = 0; i < sanitizers.size(); i++) {
def sanitizer = sanitizers[i]
2016-07-21 21:01:57 +00:00
def dockerTag = "ossfuzz/$projectName-$sanitizer"
2016-07-21 18:38:38 +00:00
dir(sanitizer) {
2016-07-21 18:49:06 +00:00
stage name: "$sanitizer sanitizer"
2016-08-11 22:45:41 +00:00
def workspace = pwd();
2016-08-11 22:51:28 +00:00
def out = "$wsPwd/out/$sanitizer"
2016-07-21 18:38:38 +00:00
2016-08-01 21:14:13 +00:00
dir('oss-fuzz') {
git url: 'https://github.com/google/oss-fuzz.git'
}
2016-07-21 18:38:38 +00:00
2016-08-01 21:14:13 +00:00
dir(checkoutDir) {
git url: gitUrl
}
2016-07-21 18:38:38 +00:00
2016-08-01 21:21:46 +00:00
if (dockerContextDir == null) {
2016-08-01 21:46:50 +00:00
dockerContextDir = new File(dockerfile)
2016-08-01 21:44:02 +00:00
.getParentFile()
2016-08-01 21:46:50 +00:00
.getPath();
2016-08-01 21:21:46 +00:00
}
2016-08-11 22:45:41 +00:00
// Build docker image
2016-08-01 21:21:46 +00:00
sh "docker build -t $dockerTag -f $dockerfile $dockerContextDir"
2016-07-21 18:38:38 +00:00
2016-08-11 22:45:41 +00:00
// Run image to produce fuzzers"
2016-07-21 18:38:38 +00:00
sh "rm -rf $out"
sh "mkdir -p $out"
2016-08-08 02:53:25 +00:00
sh "docker run -v $workspace/$checkoutDir:/src/$checkoutDir -v $workspace/oss-fuzz:/src/oss-fuzz -v $out:/out -e SANITIZER_FLAGS=\"-fsanitize=$sanitizer\" -t $dockerTag"
2016-07-21 18:38:38 +00:00
}
}
2016-08-11 22:54:48 +00:00
dir ('out') {
2016-08-12 00:13:19 +00:00
stage name: "Running fuzzers"
2016-08-11 23:04:20 +00:00
for (int i = 0; i < sanitizers.size(); i++) {
def sanitizer = sanitizers[i]
dir (sanitizer) {
2016-08-11 23:22:10 +00:00
def d = pwd()
2016-08-11 23:04:20 +00:00
def files = findFiles()
for (int j = 0; j < files.size(); j++) {
def file = files[j]
2016-08-11 23:22:10 +00:00
echo "FILE: $file"
2016-08-11 23:37:01 +00:00
sh "docker run -v $d:/out -t ossfuzz/libfuzzer-runner /out/$file -runs=1"
2016-08-11 23:04:20 +00:00
}
}
2016-08-11 22:54:48 +00:00
}
2016-08-12 00:13:19 +00:00
stage name: "Uploading fuzzers"
for (int i = 0; i < sanitizers.size(); i++) {
def sanitizer = sanitizers[i]
dir (sanitizer) {
2016-08-12 00:22:14 +00:00
def zipFile = "$projectName-$sanitizer-$date.zip"
sh "zip -j $zipFile *"
2016-08-12 00:13:19 +00:00
sh "gsutil cp $zipFile gs://clusterfuzz-builds/$projectName/"
}
}
2016-08-11 22:54:48 +00:00
}
2016-07-21 18:38:38 +00:00
}
echo 'Done'
}
return this;