-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-grading.sh
executable file
·112 lines (95 loc) · 4.33 KB
/
run-grading.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
#!/bin/bash
abort() {
echo "$1"
echo "aborting..."
exit 1
}
# delimiter used in csv
delimiter='\t'
# assert pwd to be repository root
project_root="$PWD"
[ -f "$project_root/assignment.conf" ] || abort "please run this script from the repository root"
[ -f "$project_root/run-grading.sh" ] || abort "please run this script from the repository root"
submission_repos_root="$project_root/submissions"
build_root="$project_root/build"
mkdir -p "$submission_repos_root"
mkdir -p "$build_root"
source ./assignment.conf
# setup wraps
wrap_cmake_file="$submission_repos_root/wraps.cmake"
echo "generating compiler options for function wrapping in $wrap_cmake_file"
echo "# automatically generated wrap compiler options based on assignment.conf, which should be edited instead of this file" > "$wrap_cmake_file"
linker_flags="-Wl"
for func in "${wrap_functions[@]}"; do
echo "adding wrapping for $func"
linker_flags="$linker_flags,--wrap=$func"
done
[ "$linker_flags" = "-Wl" ] || echo "set(BIN_LINK_OPTIONS $linker_flags)" >> "$wrap_cmake_file"
# gather all available zip files
submission_zips=()
for filename in $submission_zips_location/*; do
[[ "$filename" == *.zip ]] && submission_zips+=("$filename")
done
echo "processing ${#submission_zips[@]} submissions"
# output of results
output=()
output+=("folder $delimiter github_name $delimiter score $delimiter error_output")
# loop over all zips
current_submission=0
for zip_file in "${submission_zips[@]}"; do
echo "processing submission $current_submission associated with $zip_file"
current_submission_repo_dir="$submission_repos_root/$current_submission"
((current_submission++))
echo "moving zip contents to $current_submission_repo_dir"
mkdir -p "$current_submission_repo_dir"
unzip -o "$zip_file" -d "$current_submission_repo_dir" > /dev/null
[ $? -eq 0 ] || abort "error during unzipping of submission"
# setup appication sources
submission_files=()
submission_cmake_file="$submission_repos_root/submission.cmake"
echo "writing include dirs and submission source files to $submission_cmake_file"
echo "# automatically generated include dirs and application files based on assignment.conf, which should be edited instead of this file" > "$submission_cmake_file"
for file in "${assignment_source_files[@]}"; do
full_file="$current_submission_repo_dir/$file"
# File content replacements could be done here following the below format
[[ "$full_file" == */main.c ]] && [ -f $full_file ] && sed -i 's/ *int *main *.int/int assignment_main(int argc, const char *argv[]);int assignment_main(int/' "$full_file"
submission_files+=("$full_file")
done
echo "set(APP_SRC_FILES ${submission_files[*]})" >> "$submission_cmake_file"
echo "set(INCLUDE_DIRS \$INCLUDE_DIRS $current_submission_repo_dir)" >> "$submission_cmake_file"
# extract git user
cd "$current_submission_repo_dir" && commit_user_name="$(git log -1 | grep Author | cut -d "<" -f 1 | cut -c 9-)" && cd - || abort "unable to extract author from most recent commit"
echo "identified user $commit_user_name based on latest commit user"
# build cmake project
cd "$build_root" && cmake .. -DDEBUG_BUILD=ON && cd - || abort "cmake did not initialize correctly"
# build and run binary
test_result=0
error_output=""
cd "$build_root"
make_output=$(make 2>&1 > /dev/null)
if [ $? -eq 0 ]; then
# build successfull. run tests and calculate score
test_err_output="$(../out/assignment-test 2>&1 > /dev/null)"
num_correct_tests=$(($max_points - $?))
test_result=$((num_correct_tests * 100 / $max_points))
[ $test_result -ne 100 ] && error_output="$test_err_output"
else
echo "error during compilation"
error_output="$make_output"
fi
cd -
# remove new lines from error output
error_output=$(echo "$error_output" | tr -d \\n)
echo "$error_output" > "$current_submission_repo_dir/err.log"
output+=("$current_submission_repo_dir$delimiter$commit_user_name$delimiter$test_result$delimiter$error_output")
done
# output results to file and stdout
result_file="$submission_repos_root/result.csv"
> "$result_file"
echo ""
echo "Results:"
for line in "${output[@]}"; do
echo -e "$line"
echo -e "$line" >> "$result_file"
done
echo "results have also been written to $result_file"