diff options
author | Timotej Kapus <k.apus@hotmail.com> | 2015-06-16 18:14:58 +0100 |
---|---|---|
committer | Timotej Kapus <k.apus@hotmail.com> | 2015-06-16 18:14:58 +0100 |
commit | 7844d5f9b9057197b7392efca46ed79c82e66dc5 (patch) | |
tree | 24c2a575e3b7f9b4cba4a900eea20805ce6687c1 | |
parent | c6d650e995058b6a5b9579fdd417984a984bad23 (diff) | |
download | klee-7844d5f9b9057197b7392efca46ed79c82e66dc5.tar.gz |
added COVERAGE=0 to dockerfile, factored out coverage build flags to be only set when COVERAGE is, added the python server script to scripts
-rwxr-xr-x | .travis/klee.sh | 8 | ||||
-rw-r--r-- | Dockerfile | 1 | ||||
-rw-r--r-- | scripts/coverageServer.py | 100 |
3 files changed, 107 insertions, 2 deletions
diff --git a/.travis/klee.sh b/.travis/klee.sh index 9aa6b1af..3008c7fb 100755 --- a/.travis/klee.sh +++ b/.travis/klee.sh @@ -39,6 +39,10 @@ else KLEE_UCLIBC_CONFIGURE_OPTION="" fi +COVERAGE_FLAGS="" +if [ ${COVERAGE} -eq 1 ]; then + COVERAGE_FLAGS='-fprofile-arcs -ftest-coverage' +fi ############################################################################### # KLEE ############################################################################### @@ -55,7 +59,7 @@ ${KLEE_SRC}/configure --with-llvmsrc=/usr/lib/llvm-${LLVM_VERSION}/build \ --with-llvmcxx=${KLEE_CXX} \ --with-stp="${BUILD_DIR}/stp/build" \ ${KLEE_UCLIBC_CONFIGURE_OPTION} \ - CXXFLAGS="-fprofile-arcs -ftest-coverage" \ + CXXFLAGS="${COVERAGE_FLAGS}" \ && make DISABLE_ASSERTIONS=${DISABLE_ASSERTIONS} \ ENABLE_OPTIMIZED=${ENABLE_OPTIMIZED} \ ENABLE_SHARED=0 @@ -99,7 +103,7 @@ RETURN="${RETURN}$?" if [ ${COVERAGE} -eq 1 ]; then #get zcov that works with gcov v4.8 - git clone https://github.com/kren1/zcov.git + git clone https://github.com/ddunbar/zcov.git cd zcov sudo python setup.py install sudo mkdir /usr/local/lib/python2.7/dist-packages/zcov-0.3.0.dev0-py2.7.egg/zcov/js diff --git a/Dockerfile b/Dockerfile index 07f1bb48..d9fdd02d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,6 +11,7 @@ ENV LLVM_VERSION=3.4 \ ENABLE_OPTIMIZED=1 \ KLEE_UCLIBC=1 \ KLEE_SRC=/home/klee/klee_src \ + COVERAGE=0 \ BUILD_DIR=/home/klee/klee_build RUN apt-get update && \ diff --git a/scripts/coverageServer.py b/scripts/coverageServer.py new file mode 100644 index 00000000..db708545 --- /dev/null +++ b/scripts/coverageServer.py @@ -0,0 +1,100 @@ +#!/usr/bin/python +from flask import * +from functools import wraps +from subprocess import call +from werkzeug import secure_filename +import json +import time +import os +import shutil +import tarfile + +##################### DESCRIPTION ################# +#This is the server to which coverage data is uploaded from travisCI. +#need to replace USER and PASSWORD with an actual username and passsword used to autheticate in /api +#Stored here, because it needs to be in version control somewhere +# +# Example of running the server +#uwsgi -s 127.0.0.1:3013 -w coverageServer:app --chmod=666 --post-buffering=81 --daemonize ./log +#where nginx is expecting uwsgi traffic at 127.0.0.1:3013 + + +#sample upload command +#curl --form "file=@coverage.tar.gz" -u USER:PASSWORD localhost:5000/api + + + + +UPLOAD_FOLDER = '.' + +#enable upload only every 5 minutes + +app = Flask(__name__) +app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER +app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 + +TIMEOUT = 0 + + +def check_auth(username, password): + return username == 'USER' and password == 'PASSWORD' + + +def authenticate(): + """Sends a 401 response that enables basic auth""" + return Response( + 'Could not verify your access level for that URL.\n' + 'You have to login with proper credentials', 401, + {'WWW-Authenticate': 'Basic realm="Login Required"'}) + + +def requires_auth(f): + @wraps(f) + def decorated(*args, **kwargs): + auth = request.authorization + if not auth or not check_auth(auth.username, auth.password): + return authenticate() + return f(*args, **kwargs) + return decorated + +@app.route("/<path:path>") +def serve_page(path): + return send_from_directory('./coverage', path) + +#check that the tar file has only one efolder named coverage +def check_tar(tar): + coverage_dir_num = 0 + for tarinfo in tar.getmembers(): + if 'coverage' in tarinfo.name and tarinfo.isdir(): + coverage_dir_num += 1 + elif not 'coverage/' in tarinfo.name: + return False + return coverage_dir_num == 1 + +@app.route("/api", methods=['POST']) +@requires_auth +def upload_coverage(): + global TIMEOUT +#only allow uploads every 5 minutes (a bit less than usuall travisCI build) + if time.time() - TIMEOUT < 300: + return "Time Out" + if request.method == 'POST': + file = request.files['file'] + if file.filename == "coverage.tar.gz": + filename = secure_filename(file.filename) + file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) + tar = tarfile.open("./coverage.tar.gz") + if not check_tar(tar): + return "NOK" +#remove the previous coverage folder if it existis + if os.path.isdir("./coverage"): + shutil.rmtree("./coverage") + tar.extractall() + tar.close() + TIMEOUT = time.time() + return "OK" + return "NOK" + +if __name__ == "__main__": + app.debug = True + app.run(host="0.0.0.0") |