-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun
More file actions
executable file
·141 lines (117 loc) · 4.3 KB
/
run
File metadata and controls
executable file
·141 lines (117 loc) · 4.3 KB
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
#!/usr/bin/env bash
set -e
shopt -s globstar
# Default values
target_dir="integration-tests"
overwrite=0
verbose=0
# Parse arguments
while [ "$#" -gt 0 ]; do
case "$1" in
--overwrite)
overwrite=1
;;
-v|--verbose)
verbose=1
;;
*)
target_dir="$1"
;;
esac
shift
done
judge="$PWD"
exact_match=0
description_changed=0
minor_change=0
major_change=0
err_out="/dev/null"
if [ $verbose -gt 0 ]; then
err_out="/dev/stderr"
fi
# Find all config.json files in target directory
for config in $target_dir/**/config.json; do
test_dir="$(dirname "$config")"
# Extract config values
filename="$(jq -r '.evaluation.filename // .filename' "$config")"
allow_compilation_warnings="$(jq -r '.allow_compilation_warnings == true' "$config")"
lang="$(jq -r '.natural_language // "en"' "$config")"
# Determine submission source and result file
submission_source="$test_dir/submission.java"
config_source="$test_dir/solution/$filename"
if [ -f "$submission_source" ]; then
source="$submission_source"
elif [ -f "$config_source" ]; then
source="$config_source"
else
echo "Warning: No submission.java or $filename found in $test_dir. Skipping." >&2
continue
fi
result_file="$test_dir/result.json"
echo -en "Testing ${test_dir} ...\t"
workdir="$(mktemp -d)"
cd "$workdir"
# Copy workdir contents if they exist
if [ -d "$judge/$test_dir/workdir" ]; then
find "$judge/$test_dir/workdir" -mindepth 1 -maxdepth 1 -exec cp -r \{\} . \;
fi
# Run the judge
output=$(echo '{ "resources": "'"$judge/$test_dir/evaluation/"'"
, "judge": "'"$judge"'"
, "natural_language": "'"$lang"'"
, "workdir": "'"$workdir"'"
, "allow_compilation_warnings": "'"$allow_compilation_warnings"'"
, "filename": "'"$filename"'"
, "time_limit": 30
, "memory_limit": 1000000000
, "source": "'"$judge/$source"'"
}' \
| (timeout -k 10s 60s "$judge/run" 2> "$err_out") \
| jq --sort-keys 'if(.command == "append-message")
then .message.description |= gsub("\n at [^\n]+\\([^)]+\\)"; "")
else .
end'
)
cd "$judge"
rm -r "$workdir"
# Count accepted and failed in output
accepted_output="$(echo "$output" | jq -s 'map(select(.accepted == true)) | length')"
failed_output="$(echo "$output" | jq -s 'map(select(.accepted == false)) | length')"
echo -en "$accepted_output accepted, $failed_output failed\t"
if [ -f "$result_file" ]; then
# Count accepted and failed in result
accepted_result="$(jq -s 'map(select(.accepted == true)) | length' "$result_file" )"
failed_result="$(jq -s 'map(select(.accepted == true)) | length' "$result_file" )"
# First check if files are exact using diff, then check if they differ except '.description', then check they differ in accepted or failed
if diff -c "$result_file" <(echo "$output") > "$err_out"; then
echo "[EXACT MATCH]"
exact_match=$((exact_match + 1))
elif diff -c <(jq "del(.description)" "$result_file") <(echo "$output" | jq "del(.description)") > "$err_out"; then
echo "[DESCRIPTION CHANGED]"
description_changed=$((description_changed + 1))
elif [ "$accepted_output" -eq "$accepted_result" ] && [ "$failed_output" -eq "$failed_result" ]; then
echo "[MINOR CHANGE] (accepted/failed unchanged)"
minor_change=$((minor_change + 1))
else
echo "[MAJOR CHANGE] (accepted/failed changed, was $accepted_result/$failed_result)"
major_change=$((major_change + 1))
fi
fi
# Check or overwrite results
if [ "$overwrite" -eq 1 ]; then
echo "$output" > "$result_file"
echo "[OVERWRITE]"
fi
done
# Report results
echo
echo "=== RESULTS ==="
echo "Exact matches: $exact_match"
echo "Description changed: $description_changed"
echo "Minor changes: $minor_change"
echo "Major changes: $major_change"
# Exit with error on minor or major changes
if [ "$minor_change" -gt 0 ] || [ "$major_change" -gt 0 ]; then
echo "FAIL. Run with --overwrite to update the results."
exit 1
fi