-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcov_script.sh
executable file
·96 lines (78 loc) · 3.32 KB
/
cov_script.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
#!/bin/bash
folder=$1 #fuzzer result folder
pno=$2 #port number
step=$3 #step to skip running gcovr and outputting data to covfile
#e.g., step=5 means we run gcovr after every 5 test cases
covfile=$4 #path to coverage file
fmode=$5 #file mode -- structured or not
#fmode = 0: the test case is a concatenated message sequence -- there is no message boundary
#fmode = 1: the test case is a structured file keeping several request messages
#delete the existing coverage file
rm $covfile; touch $covfile
#clear gcov data
#since the source files of LightFTP are stored in the parent folder of the current folder
#we use '..' instead of '.' as usual. You may need to update this accordingly for your subject
gcovr -r .. -s -d > /dev/null 2>&1
#output the header of the coverage file which is in the CSV format
#Time: timestamp, l_per/b_per and l_abs/b_abs: line/branch coverage in percentage and absolutate number
echo "Time,l_per,l_abs,b_per,b_abs" >> $covfile
#clear ftp data
#this is a LightFTP-specific step
#we need to clean the ftp shared folder to prevent underterministic behaviors.
ftpclean
#files stored in replayable-* folders are structured
#in such a way that messages are separated
if [ $fmode -eq "1" ]; then
testdir="replayable-queue"
replayer="aflnet-replay"
else
testdir="queue"
replayer="afl-replay"
fi
#process initial seed corpus first
for f in $(echo $folder/$testdir/*.raw); do
time=$(stat -c %Y $f)
#terminate running server(s)
pkill fftp
ftpclean
$replayer $f FTP $pno 1 > /dev/null 2>&1 &
timeout -k 0 -s SIGUSR1 3s ./fftp fftp.conf $pno > /dev/null 2>&1
wait
cov_data=$(gcovr -r .. -s | grep "[lb][a-z]*:")
l_per=$(echo "$cov_data" | grep lines | cut -d" " -f2 | rev | cut -c2- | rev)
l_abs=$(echo "$cov_data" | grep lines | cut -d" " -f3 | cut -c2-)
b_per=$(echo "$cov_data" | grep branch | cut -d" " -f2 | rev | cut -c2- | rev)
b_abs=$(echo "$cov_data" | grep branch | cut -d" " -f3 | cut -c2-)
echo "$time,$l_per,$l_abs,$b_per,$b_abs" >> $covfile
done
#process fuzzer-generated testcases
count=0
for f in $(echo $folder/$testdir/id*); do
time=$(stat -c %Y $f)
#terminate running server(s)
pkill fftp
ftpclean
$replayer $f FTP $pno 1 > /dev/null 2>&1 &
timeout -k 0 -s SIGUSR1 3s ./fftp fftp.conf $pno > /dev/null 2>&1
wait
count=$(expr $count + 1)
rem=$(expr $count % $step)
if [ "$rem" != "0" ]; then continue; fi
cov_data=$(gcovr -r .. -s | grep "[lb][a-z]*:")
l_per=$(echo "$cov_data" | grep lines | cut -d" " -f2 | rev | cut -c2- | rev)
l_abs=$(echo "$cov_data" | grep lines | cut -d" " -f3 | cut -c2-)
b_per=$(echo "$cov_data" | grep branch | cut -d" " -f2 | rev | cut -c2- | rev)
b_abs=$(echo "$cov_data" | grep branch | cut -d" " -f3 | cut -c2-)
echo "$time,$l_per,$l_abs,$b_per,$b_abs" >> $covfile
done
#ouput cov data for the last testcase(s) if step > 1
if [[ $step -gt 1 ]]
then
time=$(stat -c %Y $f)
cov_data=$(gcovr -r .. -s | grep "[lb][a-z]*:")
l_per=$(echo "$cov_data" | grep lines | cut -d" " -f2 | rev | cut -c2- | rev)
l_abs=$(echo "$cov_data" | grep lines | cut -d" " -f3 | cut -c2-)
b_per=$(echo "$cov_data" | grep branch | cut -d" " -f2 | rev | cut -c2- | rev)
b_abs=$(echo "$cov_data" | grep branch | cut -d" " -f3 | cut -c2-)
echo "$time,$l_per,$l_abs,$b_per,$b_abs" >> $covfile
fi