-
Notifications
You must be signed in to change notification settings - Fork 306
/
get_stats.sh
executable file
·118 lines (103 loc) · 3.61 KB
/
get_stats.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 computes code-level stats for all bugs or a subset of
# bugs for a given project.
#
# Examples for Lang:
# * All bugs: ./get_stats.sh -pLang
# * Bugs 1-10: ./get_stats.sh -pLang -b1..10
# * Bugs 1 and 3: ./get_stats.sh -pLang -b1 -b3
# * Bugs 1-10 and 20: ./get_stats.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
}
# Check arguments
while getopts ":p:b:" opt; do
case $opt in
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
# Make sure cloc is available
cloc --version > /dev/null 2>&1 || die "Cannot execute cloc -- make sure it is executable and on the PATH!"
# 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" $$).stats"
mkdir -p "$OUT_DIR"
# 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"
# All test cases
defects4j test -w "$work_dir" || die "test (all): $PID-$vid"
cp "$work_dir/all_tests" "$OUT_DIR/$PID-$bid.tests.all"
# Relevant test cases
defects4j test -r -w "$work_dir" || die "test (rel): $PID-$vid"
cp "$work_dir/all_tests" "$OUT_DIR/$PID-$bid.tests.relevant"
# Trigger test cases; NOTE the missing newline at the end of the output
defects4j export -p tests.trigger -w "$work_dir" > "$OUT_DIR/$PID-$bid.tests.trigger"
echo >> "$OUT_DIR/$PID-$bid.tests.trigger"
# CLOC
dir_src=$(defects4j export -p dir.src.classes -w "$work_dir")
dir_test=$(defects4j export -p dir.src.tests -w "$work_dir")
cloc "$work_dir/$dir_src" --json > "$OUT_DIR/$PID-$bid.cloc.src.json"
cloc "$work_dir/$dir_test" --json > "$OUT_DIR/$PID-$bid.cloc.test.json"
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