-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun-randoop-evosuite.sh
executable file
·217 lines (179 loc) · 7.25 KB
/
run-randoop-evosuite.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/bin/bash
DIR_SF_110=$1
PROJECT=$2
LOCAL_TIMEOUT_EVOSUITE=$3
GLOBAL_TIMEOUT_RANDOOP=$4
SEED=$5
ALGO=$6
if [[ -z "$PROJECT" || -z "$DIR_SF_110" || -z "$LOCAL_TIMEOUT_EVOSUITE" || -z "GLOBAL_TIMEOUT_RANDOOP" || -z "$SEED" || -z "$ALGO" ]];
then
echo "missing variable. please check and set before calling!"
echo DIR_SF_110=$DIR_SF_110
echo PROJECT=$PROJECT
echo LOCAL_TIMEOUT_EVOSUITE=$LOCAL_TIMEOUT_EVOSUITE
echo GLOBAL_TIMEOUT_RANDOOP=$GLOBAL_TIMEOUT_RANDOOP
echo SEED=$SEED
echo ALGO=$ALGO
exit
fi
## this directory
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
RANDOOP_JAR=${DIR}/libs/randoop/randoop-all-4.1.1.jar
EVOSUITE_JAR=${DIR}/libs/evosuite/evosuite-1.0.6.jar
## output directory
TIMESTAMP=`date +%s`
OUTPUT_DIR=${DIR}/output-tests/${ALGO}-${PROJECT}-$TIMESTAMP
mkdir ${OUTPUT_DIR}
## output directory randoop test suite
# OUTPUT_DIR_RANDOOP_TEST_SUITE=$DIR_SF_110/${PROJECT}
# mkdir ${OUTPUT_DIR_RANDOOP_TEST_SUITE}
## change directory to project directory
cd $DIR_SF_110/${PROJECT};
## setting project classpath
PROJECT_JAR=$(echo "$PROJECT" | cut -f2 -d\_)".jar"
PROJECT_CLASSPATH="$DIR_SF_110/${PROJECT}/$PROJECT_JAR"
for x in `find $DIR_SF_110/${PROJECT}/lib -name "*.jar"`;
do
PROJECT_CLASSPATH=$x:${PROJECT_CLASSPATH}
done
## defining some important paths
JACOCO_DIR=${DIR}/libs/jacoco
JACOCO_AGENT=${JACOCO_DIR}/jacocoagent.jar
JACOCO_CLI=${JACOCO_DIR}/jacococli.jar
JUNIT_JARS=${DIR}/libs/junit/hamcrest-core-1.3.jar:${DIR}/libs/junit/junit-4.13-beta-2.jar
## list of files to check coverage (Evosuite SF110)
TOBETESTED=${OUTPUT_DIR}/files_to_test.txt
grep "${PROJECT}" "$DIR_SF_110/classes.txt" | cut -f2 -d" " | grep -v -e '^$' > $TOBETESTED
## Entire list of files in a particular project, for use with Randoop
TOBETESTED_RANDOOP=${OUTPUT_DIR}/files_to_test_randoop.txt
jar tf ${PROJECT_JAR} | grep .class | sed 's/.class//g'| sed 's/\//./g' >>$TOBETESTED_RANDOOP
## entering maven-generated class directory
case $ALGO in
"randoop")
#################################################################
## TODO: confirm if we should restrict search to a list of classes
#################################################################
java -ea -cp .:$PROJECT_JAR:$RANDOOP_JAR \
randoop.main.Main gentests \
--classlist=${TOBETESTED_RANDOOP} \
--randomseed=${SEED} \
--time-limit=${GLOBAL_TIMEOUT_RANDOOP} \
--junit-output-dir=${OUTPUT_DIR} \
--junit-package-name=synapse \
--flaky-test-behavior="OUTPUT"
(cd $DIR;
./run-coverage.sh ${OUTPUT_DIR} ${PROJECT} ${DIR_SF_110}
)
;;
"evosuite")
## delete old test files
find $DIR_SF_110/${PROJECT}/evosuite-tests/ -name "*.java" | xargs rm
while IFS= read -r classfile
do
java -jar ${EVOSUITE_JAR} -generateSuite \
-class=$classfile \
-target=${PROJECT_JAR} \
-seed=${SEED} \
-criterion=branch \
-Dsearch_budget=${LOCAL_TIMEOUT_EVOSUITE} \
-Dstopping_condition=MaxTime \
-Dno_runtime_dependency=true \
-Dshow_progress=false
done < "${TOBETESTED}"
## Moving tests to output_dir
mv $DIR_SF_110/${PROJECT}/evosuite-tests/ ${OUTPUT_DIR}
(cd $DIR;
./run-coverage.sh ${OUTPUT_DIR} ${PROJECT} ${DIR_SF_110}
)
##################################################
# preparing to run randoop after evosuite
#
# (1) create factory methods for every subsequence
# (2) compile
# (3) run randoop considering those subsequences as regular files
# (4) compute coverage
##################################################
## generating test with all test subsequences
tmpfile=/tmp/tests.txt
(cd ${OUTPUT_DIR};
## create file with list of paths to test files
echo >$tmpfile # clear file
for x in `find . -name "*.java" | sed 's/\.\///g' | grep -vE "ToRandoop"`
do
echo ${OUTPUT_DIR}/$x >>$tmpfile ## append to file
done
)
## build evosuite processor (fast)
(cd ${DIR}/junit-parser;
gradle clean fatjar
)
SUBDIR=${OUTPUT_DIR}-sub
mkdir -p $SUBDIR
(cd $SUBDIR;
## generate file!
java -jar ${DIR}/junit-parser/build/libs/evosuite-testprocessor.jar Main $tmpfile
## compile
CP=${PROJECT_CLASSPATH}:${JUNIT_JARS}:${EVOSUITE_JAR}
find . -name "*.java" | xargs javac -cp $CP -d .
)
## calling randoop
echo "fromevosuite.ToRandoop" >> $TOBETESTED_RANDOOP
OUTPUT_DIR=${DIR}/output-tests/randoop_after_evosuite-${PROJECT}-$TIMESTAMP
mkdir -p $OUTPUT_DIR
cp $TOBETESTED_RANDOOP $OUTPUT_DIR
java -ea -cp .:$PROJECT_JAR:$RANDOOP_JAR:${EVOSUITE_JAR}:${SUBDIR} \
randoop.main.Main gentests \
--classlist=${TOBETESTED_RANDOOP} \
--randomseed=${SEED} \
--time-limit=${GLOBAL_TIMEOUT_RANDOOP} \
--junit-output-dir=${OUTPUT_DIR} \
--junit-package-name=synapse \
--flaky-test-behavior="OUTPUT"
#########################
## jacoco csv
#########################
(cd ${OUTPUT_DIR};
## compile all tests
CP=.:$PROJECT_JAR:$RANDOOP_JAR:${EVOSUITE_JAR}:${SUBDIR}:${PROJECT_CLASSPATH}:${JUNIT_JARS}:${EVOSUITE_JAR}
find . -name "*.java" | xargs javac -cp $CP -d .
java -cp ${CP} -javaagent:${JACOCO_AGENT} org.junit.runner.JUnitCore synapse.RegressionTest
java -jar $JACOCO_CLI report jacoco.exec \
--classfiles ${PROJECT_CLASSPATH} \
--csv jacoco.csv
rm jacoco.exec
)
;;
"randoop+evosuite")
# TODO: This is copy-and-paste from avove code. Consider revising it.
java -ea -cp .:$PROJECT_JAR:$RANDOOP_JAR \
randoop.main.Main gentests \
--classlist=${TOBETESTED_RANDOOP} \
--randomseed=${SEED} \
--time-limit=${GLOBAL_TIMEOUT_RANDOOP} \
--junit-output-dir=${OUTPUT_DIR} \
--junit-package-name=synapse \
--flaky-test-behavior="OUTPUT"
find $DIR_SF_110/${PROJECT}/evosuite-tests/ -name "*.java" | xargs rm
while IFS= read -r classfile
do
java -jar ${EVOSUITE_JAR} -generateSuite \
-class=$classfile \
-target=${PROJECT_JAR} \
-seed=${SEED} \
-criterion=branch \
-Dsearch_budget=${LOCAL_TIMEOUT_EVOSUITE} \
-Dstopping_condition=MaxTime \
-Dno_runtime_dependency=true \
-Dshow_progress=false
done < "${TOBETESTED}"
## Moving tests to output_dir
mv $DIR_SF_110/${PROJECT}/evosuite-tests/ ${OUTPUT_DIR}
(cd $DIR;
./run-coverage.sh ${OUTPUT_DIR} ${PROJECT} ${DIR_SF_110}
)
;;
*)
echo "Fatal error. Should not reach this point!"
exit 1
;;
esac