-
Notifications
You must be signed in to change notification settings - Fork 306
/
test_mutation_cmd.sh
executable file
·118 lines (104 loc) · 3.23 KB
/
test_mutation_cmd.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
#!/usr/bin/env bash
################################################################################
#
# This script runs the defects4j mutation command for all bugs or a subset of
# bugs for a given project.
#
# Examples for Lang:
# * All bugs: ./test_mutation_cmd.sh -pLang
# * Bugs 1-10: ./test_mutation_cmd.sh -pLang -b1..10
# * Bugs 1 and 3: ./test_mutation_cmd.sh -pLang -b1 -b3
# * Bugs 1-10 and 20: ./test_mutation_cmd.sh -pLang -b1..10 -b20
#
################################################################################
# Import helper subroutines and variables, and init Defects4J
source test.include
# Print usage message and exit
usage() {
local known_pids; known_pids=$(defects4j pids)
echo "usage: $0 -p <project id> [-b <bug id> ... | -b <bug id range> ... ]"
echo "Project ids:"
for pid in $known_pids; do
echo " * $pid"
done
exit 1
}
# Run only relevant tests by default
TEST_FLAG_OR_EMPTY="-r"
# Debugging is off by default
DEBUG=""
# Check arguments
while getopts ":p:b:AD" opt; do
case $opt in
A) TEST_FLAG_OR_EMPTY=""
;;
D) DEBUG="-D"
;;
p) PID="$OPTARG"
;;
b) if [[ "$OPTARG" =~ ^[0-9]*\.\.[0-9]*$ ]]; then
BUGS="$BUGS $(eval "echo {$OPTARG}")"
else
BUGS="$BUGS $OPTARG"
fi
;;
\?)
echo "Unknown option: -$OPTARG" >&2
usage
;;
:)
echo "No argument provided: -$OPTARG." >&2
usage
;;
esac
done
if [ "$PID" == "" ]; then
usage
fi
if [ ! -e "$BASE_DIR/framework/core/Project/$PID.pm" ]; then
usage
fi
init
# Run all bugs, unless otherwise specified
if [ "$BUGS" == "" ]; then
BUGS="$(get_bug_ids "$BASE_DIR/framework/projects/$PID/$BUGS_CSV_ACTIVE")"
fi
# Create log file
script_name_without_sh=${script//.sh/}
LOG="$TEST_DIR/${script_name_without_sh}$(printf '_%s_%s' "$PID" $$).log"
OUT_DIR="$TEST_DIR/${script_name_without_sh}$(printf '_%s_%s' "$PID" $$).mut"
mkdir -p "$OUT_DIR"
if [ "$DEBUG" == "-D" ]; then
export D4J_DEBUG=1
fi
# Reproduce all bugs (and log all results), regardless of whether errors occur
HALT_ON_ERROR=0
test_dir=$(mktemp -d)
for bid in $BUGS; do
# Skip all bug ids that do not exist in the active-bugs csv
if ! grep -q "^$bid," "$BASE_DIR/framework/projects/$PID/$BUGS_CSV_ACTIVE"; then
warn "Skipping bug ID that is not listed in active-bugs csv: $PID-$bid"
continue
fi
# Test mutation analysis for the fixed version only.
vid="${bid}f"
work_dir="$test_dir/$PID-$vid"
defects4j checkout -p "$PID" -v "$vid" -w "$work_dir" || die "checkout: $PID-$vid"
if defects4j mutation "$TEST_FLAG_OR_EMPTY" -w "$work_dir"; then
cp "$work_dir/summary.csv" "$OUT_DIR/$PID-$bid.summary.csv"
else
echo "ERROR: $PID-$bid" > "$OUT_DIR/$PID-$bid.summary.error"
fi
cp "$work_dir/testMap.csv" "$OUT_DIR/$PID-$bid.tests.csv"
done
rm -rf "$test_dir"
HALT_ON_ERROR=1
# Print a summary of what went wrong
if [ $ERROR != 0 ]; then
printf '=%.s' $(seq 1 80) 1>&2
echo 1>&2
echo "The following errors occurred:" 1>&2
cat "$LOG" 1>&2
fi
# Indicate whether an error occurred
exit $ERROR