-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate_submission.sh
160 lines (135 loc) · 3.87 KB
/
validate_submission.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/bin/bash
files=(Coordinator.java Participant.java UDPLoggerServer.java UDPLoggerClient.java Vote.java Coordinator.class Participant.class UDPLoggerServer.class UDPLoggerClient.class Vote.class)
lport=12344
cport=12345
n=3
pport1=12346
pport2=12347
pport3=12348
timeout=500
options="A B"
check_status() {
if [ ! $? -eq 0 ]
then
echo "Error, script terminated"
exit 1
fi
}
silently_kill() {
{ kill -9 $1 && wait $1; } 2>/dev/null
}
echo
echo "This script will validate your COMP2207 1920 coursework submission by checking whether:"
echo -e "\t - the zip file can be unzipped (this requires unzip command to be installed)"
echo -e "\t - all required files are there"
echo -e "\t - all the included Java source files can be compiled"
echo -e "\t - UDPLoggerServer, Coordinator and Participant processes can be started"
echo -e "\t - required log files are created"
echo
echo "Please make sure that your zip file is successfully validated with this script before submitting it."
echo
echo "This script will unzip files in ./tmp/ directory, and compile and execute your software in ./run/ directory. Both folders will be created in the current working directory. If those directories already exist, they will first be deleted, together with all their content."
read -p "Are you sure you want to continue (y/n)" -n 1 -r
echo
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo "Validation started"
else
echo "Script not executed"
exit 0
fi
if [ -d tmp/ ]; then
echo -n "tmp directory already exists, deleting it..."
rm -fdr tmp/
check_status
echo "ok"
fi
echo -n "Creating tmp directory..."
mkdir tmp
check_status
echo "ok"
echo -n "Unzipping submission file..."
unzip $1 -d tmp/ > /dev/null
check_status
echo "ok"
echo -n "Checking all required files exist..."
cd tmp/
for f in ${files[@]}; do
if [ ! -f "$f" ]; then
echo "$f does not exist"
exit 1
fi
done
echo "ok"
cd ..
if [ -d run/ ]; then
echo -n "run directory already exists, deleting it..."
rm -fdr run/
check_status
echo "ok"
fi
echo -n "Creating run directory..."
mkdir run
check_status
echo "ok"
cd run/
echo -n "Compiling Java sources..."
javac ../tmp/*.java -d .
check_status
echo "ok"
echo -n "Starting UDPLoggerServer on port ${lport}..."
java UDPLoggerServer $lport > /dev/null &
loggerId=$!
check_status
sleep 1s
echo "ok"
echo -n "Starting Coordinator on port ${cport} with ${n} participants, timout ${timeout}ms and options ${options} ..."
java Coordinator $cport $lport 3 $timeout $options > /dev/null &
coordinatorId=$!
check_status
sleep 1s
echo "ok"
echo -n "Starting ${n} Participant processes on ports ${pport1}, ${pport2} and ${pport3} with timout ${timeout}ms..."
java Participant $cport $lport $pport1 $timeout > /dev/null &
p1Id=$!
check_status
java Participant $cport $lport $pport2 $timeout > /dev/null &
p2Id=$!
check_status
java Participant $cport $lport $pport3 $timeout > /dev/null &
p3Id=$!
check_status
echo "ok"
echo -n "Wait 10s..."
sleep 10s
check_status
echo "ok"
echo -n "Kill all Java processes still running..."
silently_kill $p1Id
silently_kill $p2Id
silently_kill $p3Id
silently_kill $coordinatorId
silently_kill $loggerId
echo "ok"
echo -n "Checking all required log files exist..."
if [ ! -n "$(find . -name 'logger_server_*.log' | head -1)" ]; then
echo "log file of logger server not found"
fi
if [ ! -n "$(find . -name 'coordinator_*.log' | head -1)" ]; then
echo "log file of coordinator not found"
fi
p1log="participant_${pport1}_*.log"
if [ ! -n "$(find . -name ${p1log} | head -1)" ]; then
echo "log file of participant ${pport1} not found"
fi
p2log="participant_${pport2}_*.log"
if [ ! -n "$(find . -name ${p2log} | head -1)" ]; then
echo "log file of participant ${pport2} not found"
fi
p3log="participant_${pport3}_*.log"
if [ ! -n "$(find . -name ${p3log} | head -1)" ]; then
echo "log file of participant ${pport3} not found"
fi
echo "ok"
echo "Validation successfully completed."