2323# ------------------------------------------------------------------------------
2424# Options (command-line arguments):
2525# ------------------------------------------------------------------------------
26- USAGE_STRING=" usage: mutation-randoop.sh [-f features] [-o RESULTS_CSV] [-t total_time] [-c time_per_class] [-n num_iterations] [-r] [-v] [-h] TEST-CASE-NAME
26+ USAGE_STRING=" usage: mutation-randoop.sh [-f features] [-o RESULTS_CSV] [-t total_time] [-c time_per_class] [-n num_iterations] [-s] [- r] [-v] [-h] TEST-CASE-NAME
2727 -f Specify the Randoop features to use.
2828 Available features: BASELINE, BLOODHOUND, ORIENTEERING, DETECTIVE, GRT_FUZZING, ELEPHANT_BRAIN, CONSTANT_MINING.
2929 example usage: -f BASELINE,BLOODHOUND
@@ -34,6 +34,7 @@ USAGE_STRING="usage: mutation-randoop.sh [-f features] [-o RESULTS_CSV] [-t tota
3434 -c N Per-class time limit (in seconds, default: 2s/class).
3535 Mutually exclusive with -t.
3636 -n N Number of iterations to run the experiment (default: 1).
37+ -s Skip mutation analysis (only run test generation and coverage).
3738 -r Redirect logs and diagnostics to results/result/mutation_output.txt.
3839 -v Enables verbose mode.
3940 -h Displays this help message.
9293NUM_LOOP=1 # Number of experiment runs (10 in GRT paper)
9394VERBOSE=0 # Verbose option
9495REDIRECT=0 # Redirect output to mutation_output.txt
96+ SKIP_MUTATION=0 # Skip mutation analysis
9597UUID=$( uuidgen) # Generate a unique identifier per instance
9698
9799# Parse command-line arguments
98- while getopts " :hvrf :o:t:c:n:" opt; do
100+ while getopts " :hvrsf :o:t:c:n:" opt; do
99101 case ${opt} in
100102 h)
101103 # Display help message
@@ -110,6 +112,10 @@ while getopts ":hvrf:o:t:c:n:" opt; do
110112 # Redirect output to a log file
111113 REDIRECT=1
112114 ;;
115+ s)
116+ # Skip mutation analysis
117+ SKIP_MUTATION=1
118+ ;;
113119 f)
114120 FEATURES_OPT=" $OPTARG "
115121 ;;
@@ -161,10 +167,10 @@ declare -A FEATURE_FLAGS
161167FEATURE_FLAGS=(
162168 [" BLOODHOUND" ]=" --method-selection=BLOODHOUND"
163169 [" ORIENTEERING" ]=" --input-selection=ORIENTEERING"
164- [" DETECTIVE" ]=" --demand-driven =true"
170+ [" DETECTIVE" ]=" --call-non-sut-methods =true"
165171 [" GRT_FUZZING" ]=" --grt-fuzzing=true"
166172 [" ELEPHANT_BRAIN" ]=" --cast-to-run-time-type=true"
167- [" CONSTANT_MINING" ]=" --constant-mining =true"
173+ [" CONSTANT_MINING" ]=" --literal-tfidf=true --literal-tfidf-probability=1.0 --include-superclass-literals =true"
168174 [" BASELINE" ]=" "
169175)
170176
@@ -174,7 +180,10 @@ for feat in "${RANDOOP_FEATURES[@]}"; do
174180 if [[ " ${FEATURE_FLAGS[$feat]+exists} " ]]; then
175181 flag=" ${FEATURE_FLAGS[$feat]} "
176182 if [[ -n " $flag " ]]; then
177- EXPANDED_FEATURE_FLAGS+=(" $flag " )
183+ # Split multi-argument feature strings into separate array entries
184+ # shellcheck disable=SC2206
185+ split_flags=($flag )
186+ EXPANDED_FEATURE_FLAGS+=(" ${split_flags[@]} " )
178187 fi
179188 else
180189 echo " ${SCRIPT_NAME} : error: unknown feature '$feat '"
@@ -610,6 +619,13 @@ for i in $(seq 1 "$NUM_LOOP"); do
610619 " $MAJOR_HOME " /bin/ant -f " $SCRIPT_DIR " /program-config/" $1 " /${buildfile} -Dbasedir=" $SCRIPT_DIR " -Dbindir=" $SCRIPT_DIR /build/bin/$FILE_SUFFIX " -Dresultdir=" $RESULT_DIR " -Dmutator=" mml:$MAJOR_HOME /mml/all.mml.bin" -Dsrc=" $JAVA_SRC_DIR " -Dtargetdir=" $COVERAGE_DIRECTORY " -Dlibdir=" $SCRIPT_DIR /build/lib/$UUID " compile.mutation
611620 " $MAJOR_HOME " /bin/ant -f " $SCRIPT_DIR " /program-config/" $1 " /${buildfile} -Dbasedir=" $SCRIPT_DIR " -Dbindir=" $SCRIPT_DIR /build/bin/$FILE_SUFFIX " -Dresultdir=" $RESULT_DIR " -Dmutator=" mml:$MAJOR_HOME /mml/all.mml.bin" -Dsrc=" $JAVA_SRC_DIR " -Dtargetdir=" $COVERAGE_DIRECTORY " -Dlibdir=" $SCRIPT_DIR /build/lib/$UUID " compile.jacoco
612621
622+ PYTHON_EXECUTABLE=$( command -v python3 2> /dev/null || command -v python 2> /dev/null)
623+ if [ -z " $PYTHON_EXECUTABLE " ]; then
624+ echo " Error: Python is not installed." >&2
625+ exit 2
626+ fi
627+ " $PYTHON_EXECUTABLE " " $SCRIPT_DIR " /trim_mutants.py " $RESULT_DIR /mutants.log"
628+
613629 echo
614630 echo " Compiling tests..."
615631 if [[ " $VERBOSE " -eq 1 ]]; then
@@ -653,28 +669,30 @@ for i in $(seq 1 "$NUM_LOOP"); do
653669 # proper isolation and compatibility for accurate mutant coverage.
654670
655671 if [ " $SUBJECT_PROGRAM " == " hamcrest-core-1.3" ]; then
656- PYTHON_EXECUTABLE=$( command -v python3 2> /dev/null || command -v python 2> /dev/null)
657- if [ -z " $PYTHON_EXECUTABLE " ]; then
658- echo " Error: Python is not installed." >&2
659- exit 1
660- fi
661672 " $PYTHON_EXECUTABLE " " $SCRIPT_DIR " /convert_test_runners.py " $TEST_DIRECTORY " --mode randoop-to-evosuite
662673 fi
663674
664- echo
665- echo " Running tests with mutation analysis..."
666- if [[ " $VERBOSE " -eq 1 ]]; then
667- echo command:
668- echo " $MAJOR_HOME " /bin/" $ANT " -f " $SCRIPT_DIR " /program-config/" $1 " /${buildfile} -Dbasedir=" $SCRIPT_DIR " -Dbindir=" $SCRIPT_DIR /build/bin/$FILE_SUFFIX " -Dresultdir=" $RESULT_DIR " -Dtest=" $TEST_DIRECTORY " -Dlibdir=" $SCRIPT_DIR /build/lib/$UUID " mutation.test
675+ # Run mutation analysis unless -s flag is set
676+ if [[ " $SKIP_MUTATION " -eq 0 ]]; then
677+ echo
678+ echo " Running tests with mutation analysis..."
679+ if [[ " $VERBOSE " -eq 1 ]]; then
680+ echo command:
681+ echo " $MAJOR_HOME " /bin/" $ANT " -f " $SCRIPT_DIR " /program-config/" $1 " /${buildfile} -Dbasedir=" $SCRIPT_DIR " -Dbindir=" $SCRIPT_DIR /build/bin/$FILE_SUFFIX " -Dresultdir=" $RESULT_DIR " -Dtest=" $TEST_DIRECTORY " -Dlibdir=" $SCRIPT_DIR /build/lib/$UUID " mutation.test
682+ fi
683+ echo
684+ " $MAJOR_HOME " /bin/" $ANT " -f " $SCRIPT_DIR " /program-config/" $1 " /${buildfile} -Dbasedir=" $SCRIPT_DIR " -Dbindir=" $SCRIPT_DIR /build/bin/$FILE_SUFFIX " -Dresultdir=" $RESULT_DIR " -Dtest=" $TEST_DIRECTORY " -Dlibdir=" $SCRIPT_DIR /build/lib/$UUID " mutation.test
685+
686+ # Calculate Mutation Score
687+ mutants_generated=$( awk -F, ' NR==2 {print $2}' " $RESULT_DIR " /summary.csv)
688+ mutants_killed=$( awk -F, ' NR==2 {print $4}' " $RESULT_DIR " /summary.csv)
689+ mutation_score=$( echo " scale=4; $mutants_killed / $mutants_generated * 100" | bc)
690+ mutation_score=$( printf " %.2f" " $mutation_score " )
691+ else
692+ echo
693+ echo " Skipping mutation analysis (use -s flag)."
694+ mutation_score=" N/A"
669695 fi
670- echo
671- " $MAJOR_HOME " /bin/" $ANT " -f " $SCRIPT_DIR " /program-config/" $1 " /${buildfile} -Dbasedir=" $SCRIPT_DIR " -Dbindir=" $SCRIPT_DIR /build/bin/$FILE_SUFFIX " -Dresultdir=" $RESULT_DIR " -Dtest=" $TEST_DIRECTORY " -Dlibdir=" $SCRIPT_DIR /build/lib/$UUID " mutation.test
672-
673- # Calculate Mutation Score
674- mutants_generated=$( awk -F, ' NR==2 {print $1}' " $RESULT_DIR " /summary.csv)
675- mutants_killed=$( awk -F, ' NR==2 {print $4}' " $RESULT_DIR " /summary.csv)
676- mutation_score=$( echo " scale=4; $mutants_killed / $mutants_generated * 100" | bc)
677- mutation_score=$( printf " %.2f" " $mutation_score " )
678696
679697 echo " Instruction Coverage: $instruction_coverage %"
680698 echo " Branch Coverage: $branch_coverage %"
0 commit comments