Newer
Older
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
#! /bin/bash
###############################################################
# BASH Script to generate EvoSuite JUnit test source code. #
# It is run from the build_test.xml Ant script using the #
# create-evotests target. Re-generating all tests can #
# take several hours. #
# Generated JUnit tests are placed in the evosuite-tests #
# folder and can be RUN via the ant script. #
# #
# Author: K. Pepper #
# #
###############################################################
PROGNAME=$0
EVOSUITE_JAR=$1
EVOSUITE_CLASSPATH=$2
EVOSUITE_ARGS=$3
EVOSUITE_REPORT_DIR=$4
if [ "$#" -ne 4 ]
then
echo
echo "Usage: $PROGNAME <EvoSuite jar path> <Classpath for EvoSuite to use> <EvoSuite command line arguments> <Coverage reports folder>"
echo "NOTE: This script is only intended to be used from an ant build."
echo
exit 255
fi
RC=0
LOG_FILE="/tmp/evosuite-run.log"
CLASSPATH=$EVOSUITE_CLASSPATH
#
# Run POOL_SIZE number of EvoSuite invocations is parallel
#
POOL_SIZE=4
CLASS_LIST=`find ../uk/ac/sanger -name *.java -print`
function printLogs {
FROMIDX=$1
TOIDX=$2
for ((x=$FROMIDX; x<=$TOIDX; x++))
do
if [ -e "${LOG_FILE}.${x}" ]
then
echo "$PROGNAME: Replaying log ${x}"
cat ${LOG_FILE}.${x}
rm ${LOG_FILE}.${x}
fi
done
}
echo "$PROGNAME: Building EvoSuite JUnit test cases with arguments: $EVOSUITE_ARGS"
i=0
BATCH_START_IDX=1
END_OF_BATCH_FLAG=0
for CLASS_FILE in $CLASS_LIST
do
i=$(($i+1))
if [ $END_OF_BATCH_FLAG -eq 1 ]
then
END_OF_BATCH_FLAG=0
BATCH_START_IDX=$i
fi
#
# Determine next class name (including package)
#
TMP1=`echo $CLASS_FILE | tr '/' '.'`
TMP2=${TMP1%%'.java'}
CLASS=${TMP2#'...'}
echo "${PROGNAME}: ProcessIndex: ${i} - Executing for class $CLASS"
#
# Execute the Java EvoSuite jar to create a unit test.
#
CMD="java -noverify -jar $EVOSUITE_JAR -class $CLASS $EVOSUITE_ARGS -class $CLASS"
$CMD 2>&1 > ${LOG_FILE}.${i} &
RC=$?
if [ $RC -ne 0 ]
then
echo "${PROGNAME} [ERROR]: EvoSuite process returned error status: $RC for class $CLASS"
fi
CHECK=$(($i % $POOL_SIZE))
if [ $CHECK -eq 0 ]
then
echo "${PROGNAME}: Waiting for $POOL_SIZE background processes to complete..."
wait
printLogs $BATCH_START_IDX $i
END_OF_BATCH_FLAG=1
echo "${PROGNAME}: Background processes completed"
fi
done
if [ $END_OF_BATCH_FLAG -eq 0 ] && [ $i -gt 0 ]
then
wait
printLogs $BATCH_START_IDX $i
fi
echo "${PROGNAME}: Finished"
exit 0