#!/usr/bin/env python2 import os import glob import subprocess COVERAGE_OPTIONS = '-Ccodegen-units=1 -Clink-dead-code -Zprofile -Cpanic=abort -Zpanic-abort-tests -Zinstrument-coverage' LCOVOPTS = '--gcov-tool ./admin/llvm-gcov --rc lcov_excl_line=assert'.split() def check_call(*args, **kwargs): subprocess.check_call(*args, **kwargs) def lcov_exe(*args): return ['lcov'] + LCOVOPTS + list(args) def sh(cmd): check_call(cmd, shell = True) def cleanup(): sh('cargo clean') sh("rm -rf *.gcda *.gcno") def run(which): exe = filter(lambda x: '.' not in x, glob.glob('target/debug/deps/' + which + '-*'))[0] sh('./' + exe) def rustc(*args): exe = ['cargo', 'rustc', '--all-features'] + list(args) env = dict(os.environ) env.update(RUSTC_WRAPPER = './admin/coverage-rustc', COVERAGE_OPTIONS = COVERAGE_OPTIONS, CARGO_INCREMENTAL = '0') check_call(exe, env = env) def lcov(outfile): exe = lcov_exe('--capture', '--directory', '.', '--base-directory', '.', '-o', outfile) check_call(exe) return outfile def merge(outfile, infiles): arg = [] for i in infiles: arg.append('--add') arg.append(i) arg.append('-o') arg.append(outfile) check_call(lcov_exe(*arg)) def remove(outfile, infile, pattern): check_call(lcov_exe('--remove', infile, os.getcwd() + pattern, '-o', outfile)) def extract(outfile, infile): check_call(lcov_exe('--extract', infile, os.getcwd() + '/rustls/src/*', '-o', outfile)) def genhtml(outdir, infile): check_call(['genhtml', '--branch-coverage', '--demangle-cpp', '--legend', infile, '-o', outdir, '--ignore-errors', 'source']) all_infos = [] # unit tests cleanup() rustc('--package', 'rustls', '--profile', 'test', '--lib') run('rustls') all_infos.append(lcov('rustls.info')) cleanup() for example in 'bench bogo_shim trytls_shim'.split(): rustc('--package', 'rustls', '--profile', 'dev', '--example', example) # crate-level tests for test in 'api'.split(): rustc('--package', 'rustls', '--profile', 'dev', '--test', test) run(test) # trytls/bogo #sh('cd trytls && ./runme') sh('cd bogo && ./runme') all_infos.append(lcov('tests.info')) merge('merged.info', all_infos) remove('coverage.info', 'merged.info', '/rustls/src/msgs/macros.rs') extract('final.info', 'coverage.info') genhtml('target/coverage/', 'final.info')