oss-fuzz/infra/libfuzzer-pipeline.groovy

138 lines
5.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 gitUrl = config["git"]
2016-10-19 20:59:47 +00:00
def svnUrl = config["svn"]
2016-07-21 18:38:38 +00:00
// Optional configuration
def projectName = config["name"] ?: env.JOB_BASE_NAME
2016-10-25 02:39:13 +00:00
def dockerfile = config["dockerfile"] ?: "oss-fuzz/targets/$projectName/Dockerfile"
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-11-15 04:44:01 +00:00
// Flags configuration
def sanitizerFlags = [
"address":"-fsanitize=address",
2016-11-15 04:58:29 +00:00
"undefined":"-fsanitize=bool,signed-integer-overflow,shift,vptr"
2016-11-15 04:44:01 +00:00
]
def date = java.time.format.DateTimeFormatter.ofPattern("yyyyMMddHHmm")
2016-08-12 00:13:19 +00:00
.format(java.time.LocalDateTime.now())
2016-07-21 18:38:38 +00:00
node {
def workspace = pwd()
// def uid = sh(returnStdout: true, script: 'id -u $USER').trim()
def uid = 0 // TODO: try to make $USER to work
echo "using uid $uid"
2016-10-20 00:20:28 +00:00
def srcmapFile = "$workspace/srcmap.json"
def dockerTag = "ossfuzz/$projectName"
echo "Building $dockerTag"
2016-07-21 18:38:38 +00:00
sh "rm -rf $workspace/out"
sh "mkdir -p $workspace/out"
2016-10-12 23:36:38 +00:00
stage("docker image") {
2016-11-03 20:31:45 +00:00
def ossfuzzRev
dir('oss-fuzz') {
git url: "https://github.com/google/oss-fuzz.git"
2016-11-03 20:31:45 +00:00
ossfuzzRev = sh(returnStdout: true, script: 'git rev-parse HEAD').trim()
}
2016-10-12 23:57:11 +00:00
if (gitUrl != null) {
dir(checkoutDir) {
git url: gitUrl
}
2016-10-19 20:59:47 +00:00
}
if (svnUrl != null) {
dir(checkoutDir) {
svn url: svnUrl
}
2016-10-19 20:59:47 +00:00
}
2016-07-21 18:38:38 +00:00
if (dockerContextDir == null) {
dockerContextDir = new File(dockerfile)
.getParentFile()
.getPath();
}
2016-10-19 20:59:47 +00:00
sh "docker build --no-cache -t $dockerTag -f $dockerfile $dockerContextDir"
2016-11-03 20:50:21 +00:00
sh "docker run --rm $dockerTag srcmap > $workspace/srcmap.json.tmp"
2016-11-03 23:20:04 +00:00
// use classic slurper: http://stackoverflow.com/questions/37864542/jenkins-pipeline-notserializableexception-groovy-json-internal-lazymap
2016-11-03 23:17:19 +00:00
def srcmap = new groovy.json.JsonSlurperClassic().parse(
2016-11-03 20:50:21 +00:00
new File("$workspace/srcmap.json.tmp"))
2016-11-03 21:40:29 +00:00
srcmap['/src'] = [ type: 'git',
2016-11-03 20:50:21 +00:00
rev: ossfuzzRev,
url: 'https://github.com/google/oss-fuzz.git',
2016-11-03 22:08:58 +00:00
path: "targets/$projectName" ]
2016-11-03 20:31:45 +00:00
echo "srcmap: $srcmap"
2016-11-04 04:43:44 +00:00
// sh "cp $workspace/srcmap.json.tmp $srcmapFile"
writeFile file: srcmapFile, text: groovy.json.JsonOutput.toJson(srcmap)
} // stage("docker image")
2016-08-11 22:54:48 +00:00
for (int i = 0; i < sanitizers.size(); i++) {
2016-10-10 20:36:13 +00:00
def sanitizer = sanitizers[i]
dir(sanitizer) {
def out = "$workspace/out/$sanitizer"
2016-10-26 21:22:20 +00:00
def junit_reports = "$workspace/junit_reports/$sanitizer"
sh "mkdir -p $out"
sh "mkdir -p $junit_reports"
stage("$sanitizer sanitizer") {
// Run image to produce fuzzers
2016-11-15 04:33:35 +00:00
def flags = sanitizerFlags[sanitizer]
sh "docker run --rm --user $uid -v $out:/out -e SANITIZER_FLAGS=\"${flags}\" -t $dockerTag compile"
sh "docker run --rm --user $uid -v $out:/out -v $junit_reports:/junit_reports -t ossfuzz/base-runner test_all"
2016-10-26 21:22:20 +00:00
sh "ls -al $junit_reports/"
2016-10-10 20:36:13 +00:00
}
2016-08-11 23:04:20 +00:00
}
2016-08-11 22:54:48 +00:00
}
2016-08-12 00:13:19 +00:00
2016-10-10 20:36:13 +00:00
stage("uploading") {
2016-10-27 17:03:49 +00:00
step([$class: 'JUnitResultArchiver', testResults: 'junit_reports/**/*.xml'])
2016-10-13 16:27:23 +00:00
dir('out') {
for (int i = 0; i < sanitizers.size(); i++) {
def sanitizer = sanitizers[i]
dir (sanitizer) {
def zipFile = "$projectName-$sanitizer-${date}.zip"
sh "zip -j $zipFile *"
sh "gsutil cp $zipFile gs://clusterfuzz-builds/$projectName/"
2016-10-20 21:39:55 +00:00
def stampedSrcmap = "$projectName-$sanitizer-${date}.srcmap.json"
sh "cp $srcmapFile $stampedSrcmap"
sh "gsutil cp $stampedSrcmap gs://clusterfuzz-builds/$projectName/"
}
2016-10-13 16:27:23 +00:00
}
}
} // stage("uploading")
2016-10-06 21:26:09 +00:00
2016-10-10 20:36:13 +00:00
stage("pushing image") {
docker.withRegistry('', 'docker-login') {
docker.image(dockerTag).push()
}
} // stage("pushing image")
} // node
} // call
2016-07-21 18:38:38 +00:00
return this;