1#!/bin/sh
2# Copyright (c) 2016, Google Inc.
3#
4# Permission to use, copy, modify, and/or distribute this software for any
5# purpose with or without fee is hereby granted, provided that the above
6# copyright notice and this permission notice appear in all copies.
7#
8# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11# SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13# OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
16set -xe
17
18SRC=$PWD
19
20BUILD=$(mktemp -d '/tmp/boringssl.XXXXXX')
21BUILD_SRC=$(mktemp -d '/tmp/boringssl-src.XXXXXX')
22LCOV=$(mktemp -d '/tmp/boringssl-lcov.XXXXXX')
23
24if [ -n "$1" ]; then
25  LCOV=$(readlink -f "$1")
26  mkdir -p "$LCOV"
27fi
28
29cd "$BUILD"
30cmake "$SRC" -GNinja -DCMAKE_C_FLAGS='-fprofile-arcs -ftest-coverage' \
31  -DCMAKE_CXX_FLAGS='-fprofile-arcs -ftest-coverage' -DCMAKE_ASM_FLAGS='-Wa,-g'
32ninja
33
34cp -r "$SRC/crypto" "$SRC/decrepit" "$SRC/include" "$SRC/ssl" "$SRC/tool" \
35  "$BUILD_SRC"
36cp -r "$BUILD"/* "$BUILD_SRC"
37mkdir "$BUILD/callgrind/"
38
39cd "$SRC"
40go run "$SRC/util/all_tests.go" -build-dir "$BUILD" -callgrind -num-workers 16
41util/generate-asm-lcov.py "$BUILD/callgrind" "$BUILD" > "$BUILD/asm.info"
42
43go run "util/all_tests.go" -build-dir "$BUILD"
44
45cd "$SRC/ssl/test/runner"
46go test -shim-path "$BUILD/ssl/test/bssl_shim" -num-workers 1
47
48cd "$LCOV"
49lcov -c -d "$BUILD" -b "$BUILD" -o "$BUILD/lcov.info"
50lcov -r "$BUILD/lcov.info" "*_test.c" -o "$BUILD/lcov-1.info"
51lcov -r "$BUILD/lcov-1.info" "*_test.cc" -o "$BUILD/lcov-2.info"
52cat "$BUILD/lcov-2.info" "$BUILD/asm.info" > "$BUILD/final.info"
53sed -i "s;$BUILD;$BUILD_SRC;g" "$BUILD/final.info"
54sed -i "s;$SRC;$BUILD_SRC;g" "$BUILD/final.info"
55genhtml -p "$BUILD_SRC" "$BUILD/final.info"
56
57rm -rf "$BUILD"
58rm -rf "$BUILD_SRC"
59
60xdg-open index.html
61