-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·117 lines (94 loc) · 3.33 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/sh
if [ ! -d "build" ]; then
mkdir build
fi
echo ""
echo "Building C map2Check-library ... "
echo ""
cd build
usage()
{
echo "usage: [-r | --release ] | [-d | --debug] | [-t | --travis] | [-h | --help]"
}
build_release()
{
cmake .. -DCMAKE_INSTALL_PREFIX=../release-library/ -DENABLE_TEST=OFF -DENABLE_COVCODE=OFF -DBUILD_DOC=ON
make
make install
}
build_debug()
{
cmake .. -DCMAKE_C_COMPILER=/usr/bin/clang-8 -DCMAKE_CXX_COMPILER="/usr/bin/clang++-8" -DCMAKE_INSTALL_PREFIX=../release-library/ -DENABLE_TEST=ON -DENABLE_COVCODE=ON -DBUILD_DOC=OFF
cmake --build . -- VERBOSE=1
echo ""
echo "\e[32m>>> Generating LLVM BC library with KLEE"
echo ""
files_klee_bc=`ls src/*.bc | sed -e s'/src\/ftoa.bc//' | sed -e s'/src\/nondet_gen_libfuzzer.bc//'`
llvm-link-8 ${files_klee_bc} -o libmap2check_klee.bc
echo ""
echo "\e[32m>>> Generating LLVM BC library with LibFuzzer"
echo ""
files_fuzzer_bc=`ls src/*.bc | sed -e s'/src\/ftoa.bc//'`
llvm-link-8 ${files_fuzzer_bc} -o libmap2check_libfuzzer.bc
# Unit Testing
cd test
LLVM_PROFILE_FILE="map2check.profraw" ./unit_tests
llvm-profdata-8 merge -sparse map2check.profraw -o map2check.profdata
llvm-cov-8 report ./unit_tests -instr-profile=map2check.profdata
llvm-cov-8 export -format=lcov ./unit_tests -instr-profile=map2check.profdata > lcov.info
cd .. # back to root
if [ $istravis -eq 1 ]; then
echo "\e[32m>>> Travis build is ON"
echo "\e[32m>>> KLEE testing skipped"
echo "\e[32m>>> Libfuzzer testing skipped"
else
# Build for KLEE testing
echo ""
echo "\e[32m>>> Build KLEE testing ..."
clang-8 -c -emit-llvm -O0 -Xclang -disable-O0-optnone ../test/codeklee_by_caller_test.c
llvm-link-8 codeklee_by_caller_test.bc libmap2check_klee.bc > fullprogram_2.bc
# Build for LibFuzzer testing
# echo ""
# echo "\e[32m>>> Build LibFuzzer testing ..."
# # ls
# clang-8 ../test/codefuzz_by_caller_test.c -lm -fsanitize=address,fuzzer -g -fprofile-instr-generate -fcoverage-mapping libmap2check_libfuzzer.bc
fi
}
build_simple()
{
cmake .. -DCMAKE_INSTALL_PREFIX=../release-library/ -DENABLE_TEST=OFF -DENABLE_COVCODE=OFF -DBUILD_DOC=OFF
make
}
##### Main
type_builds=""
istravis=0
while [ "$1" != "" ]; do
case $1 in
-r | --release ) shift
type_builds="release"
;;
-d | --debug ) type_builds="debug"
;;
-t | --travis ) istravis=1
;;
-s | --simple-build ) type_builds="simple"
;;
-h | --help ) usage
exit
;;
* ) usage
exit 1
esac
shift
done
# Test code to verify command line processing
if [ "$type_builds" = "debug" ]; then
echo ">> Debug build is on"
build_debug
elif [ "$type_builds" = "debug" ]; then
echo ">> Release build is on"
build_release
elif [ "$type_builds" = "simple" ]; then
echo ">> Simple build is on"
build_simple
fi