-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_benchmarks.sh
executable file
·147 lines (126 loc) · 4.83 KB
/
run_benchmarks.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/bin/bash
CC=gcc
CFLAGS="-Wall -Wextra -Wno-unused-function -O4"
SRC_DIR=src
benchmark_DIR=benchmarks
BIN_DIR=bin
TEXT_BOLD=$(tput bold)
TEXT_RESET=$(tput sgr0)
TEXT_RED=$(tput setaf 1)
global_success=0
# Compile benchmark.c into an object file
$CC $CFLAGS -c $benchmark_DIR/benchmark.c -o $BIN_DIR/benchmark.o
# Check if the --valgrind flag is present
valgrind=0
if [ "$1" == "--valgrind" ]; then
valgrind=1
shift
fi
callgrind=0
if [ "$1" == "--callgrind" ]; then
callgrind=1
shift
fi
# If you have only one argument : run that benchmark only
if [ $# -eq 1 ]; then
filename=$1
echo "Found benchmark file: $filename"
# Remove old benchmark file
rm -f $BIN_DIR/benchmark_$filename
rm -f $BIN_DIR/$filename.a
rm -f $BIN_DIR/$filename.o
# If the src file.c does not exist, compile the benchmark file into an executable (header only library)
#if [ ! -f $SRC_DIR/$filename.c ]; then
#$CC $CFLAGS -o $BIN_DIR/benchmark_$filename $benchmark_DIR/$filename.c $BIN_DIR/benchmark.o
#else
# TODO: check if the file is a header only library
make $filename
if [ -f $BIN_DIR/$filename.a ]; then
$CC $CFLAGS -o $BIN_DIR/benchmark_$filename $benchmark_DIR/$filename.c -L$BIN_DIR -l:$filename.a $BIN_DIR/benchmark.o
else
$CC $CFLAGS -o $BIN_DIR/benchmark_$filename $benchmark_DIR/$filename.c $BIN_DIR/$filename.o $BIN_DIR/benchmark.o
fi
#fi
# if [ $valgrind -ne 1 ]; then
# $BIN_DIR/benchmark_$filename
# else
# valgrind --tool=callgrind $BIN_DIR/benchmark_$filename --callgrind-out-file=benchmarks/callgrind/$filename.out
# fi
if [ $callgrind -eq 1 ]; then
valgrind --tool=callgrind $BIN_DIR/benchmark_$filename --callgrind-out-file=benchmarks/callgrind/$filename.out
else
if [ $valgrind -eq 1 ]; then
valgrind -s --leak-check=full --show-leak-kinds=all --track-origins=yes $BIN_DIR/benchmark_$filename
else
$BIN_DIR/benchmark_$filename
fi
fi
# Check the return code
if [ $? -ne 0 ]; then
global_success=1
fi
echo ""
if [ $global_success -eq 0 ]; then
echo "All benchmarks passed!"
else
echo "${TEXT_BOLD}${TEXT_RED}benchmark FAILED FOR $filename !!!${TEXT_RESET}"
fi
exit $global_success
fi
# Iterate over all files in the benchmarks directory
every_benchmark_that_failed=""
for file in $benchmark_DIR/*.c; do
# If it is benchmark.c or a file that does not end in .c, skip it
if [ $(basename $file) == "benchmark.c" ] || [ $(grep -q ".c" $file | wc -l) != 0 ]; then
continue
fi
# Get the filename without the extension
filename=$(basename $file .c)
echo "Found benchmark file: $filename"
# Remove old benchmark file
rm -f $BIN_DIR/benchmark_$filename
# If the src file.c does not exist, compile the benchmark file into an executable
# if [ ! -f $SRC_DIR/$filename.c ]; then
# $CC $CFLAGS -o $BIN_DIR/benchmark_$filename $file $BIN_DIR/benchmark.o
# else
make $filename
# If the compilation produced a .a file, use it instead of the .o file
if [ -f $BIN_DIR/$filename.a ]; then
$CC -Wno-unused-function -g -o $BIN_DIR/benchmark_$filename $file -L$BIN_DIR -l:$filename.a $BIN_DIR/benchmark.o
else
$CC -Wno-unused-function -g -o $BIN_DIR/benchmark_$filename $file $BIN_DIR/$filename.o $BIN_DIR/benchmark.o
fi
# fi
# If the file is present but not the benchmark, the compilation of the benchmark failed
# If neither are present, the compilation of the file failed
if [ ! -f $BIN_DIR/benchmark_$filename ] && [ -f $BIN_DIR/$filename.o ]; then
echo "${TEXT_BOLD}${TEXT_RED}COMPILATION FAILED FOR benchmark OF $filename !!!${TEXT_RESET}"
every_benchmark_that_failed="$every_benchmark_that_failed compilation_benchmark_$filename"
global_success=1
continue
elif [ ! -f $BIN_DIR/benchmark_$filename ]; then
echo "${TEXT_BOLD}${TEXT_RED}COMPILATION FAILED FOR $filename !!!${TEXT_RESET}"
every_benchmark_that_failed="$every_benchmark_that_failed compilation_$filename"
global_success=1
continue
fi
# $BIN_DIR/benchmark_$filename
# Check if the --valgrind flag is present
if [ $valgrind -ne 1 ]; then
$BIN_DIR/benchmark_$filename
else
valgrind --tool=callgrind $BIN_DIR/benchmark_$filename --callgrind-out-file=benchmarks/callgrind/$filename.out
fi
# Check the return code
if [ $? -ne 0 ]; then
every_benchmark_that_failed="$every_benchmark_that_failed $filename"
global_success=1
fi
echo ""
done
if [ $global_success -eq 0 ]; then
echo "All benchmarks passed!"
else
echo "${TEXT_BOLD} ${TEXT_RED} benchmarks that failed: $every_benchmark_that_failed ${TEXT_RESET}"
fi
exit $global_success