-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patht33.sh
298 lines (266 loc) · 9.39 KB
/
t33.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
#!/bin/bash
#################################################
# FILE NAME: KVStoreGrader.sh
#
# DESCRIPTION: Grader for MP2
#
# RUN PROCEDURE:
# $ chmod +x KVStoreGrader.sh
# $ ./KVStoreGrader.sh
#################################################
function contains () {
local e
for e in "${@:2}"
do
if [ "$e" == "$1" ]; then
echo 1
return 1;
fi
done
echo 0
}
####
# Main function
####
verbose=0
###
# Global variables
###
SUCCESS=0
FAILURE=-1
RF=3
RFPLUSONE=4
CREATE_OPERATION="CREATE OPERATION"
CREATE_SUCCESS="create success"
GRADE=0
DELETE_OPERATION="DELETE OPERATION"
DELETE_SUCCESS="delete success"
DELETE_FAILURE="delete fail"
INVALID_KEY="invalidKey"
READ_OPERATION="READ OPERATION"
READ_SUCCESS="read success"
READ_FAILURE="read fail"
QUORUM=2
QUORUMPLUSONE=3
UPDATE_OPERATION="UPDATE OPERATION"
UPDATE_SUCCESS="update success"
UPDATE_FAILURE="update fail"
echo ""
echo "############################"
echo " READ TEST"
echo "############################"
echo ""
READ_TEST1_STATUS="${FAILURE}"
READ_TEST1_SCORE=0
READ_TEST2_STATUS="${FAILURE}"
READ_TEST2_SCORE=0
READ_TEST3_PART1_STATUS="${FAILURE}"
READ_TEST3_PART1_SCORE=0
READ_TEST3_PART2_STATUS="${FAILURE}"
READ_TEST3_PART2_SCORE=0
READ_TEST4_STATUS="${FAILURE}"
READ_TEST4_SCORE=0
READ_TEST5_STATUS="${FAILURE}"
READ_TEST5_SCORE=0
if [ "${verbose}" -eq 0 ]
then
make clean > /dev/null 2>&1
make > /dev/null 2>&1
if [ $? -ne "${SUCCESS}" ]
then
echo "COMPILATION ERROR !!!"
exit
fi
./Application ./testcases/read.conf > /dev/null 2>&1
else
make clean
make
if [ $? -ne "${SUCCESS}" ]
then
echo "COMPILATION ERROR !!!"
exit
fi
./Application ./testcases/read.conf
fi
read_operations=`grep -i "${READ_OPERATION}" dbg.log | cut -d" " -f3 | tr -s ']' ' ' | tr -s '[' ' ' | sort`
cnt=1
#echo "read_operations=${read_operations}"
for time in ${read_operations}
do
echo "cnt=${cnt}"
if [ ${cnt} -eq 1 ]
then
echo "TEST 1: Read a key. Check for correct value being read at least in quorum of replicas"
read_op_test1_time="${time}"
read_op_test1_key=`grep -i "${READ_OPERATION}" dbg.log | grep "${read_op_test1_time}" | cut -d" " -f7`
read_op_test1_value=`grep -i "${READ_OPERATION}" dbg.log | grep "${read_op_test1_time}" | cut -d" " -f9`
elif [ ${cnt} -eq 2 ]
then
echo "TEST 2: Read a key after failing a replica. Check for correct value being read at least in quorum of replicas"
read_op_test2_time="${time}"
read_op_test2_key=`grep -i "${READ_OPERATION}" dbg.log | grep "${read_op_test2_time}" | cut -d" " -f7`
read_op_test2_value=`grep -i "${READ_OPERATION}" dbg.log | grep "${read_op_test2_time}" | cut -d" " -f9`
elif [ ${cnt} -eq 3 ]
then
echo "TEST 3 PART 1: Read a key after failing two replicas. Read should fail"
read_op_test3_part1_time="${time}"
echo "read_op_test3_part1_time= ${read_op_test3_part1_time}"
read_op_test3_part1_key=`grep -i "${READ_OPERATION}" dbg.log | grep "${read_op_test3_part1_time}" | cut -d" " -f7`
echo "read_op_test3_part1_key= ${read_op_test3_part1_key}"
read_op_test3_part1_value=`grep -i "${READ_OPERATION}" dbg.log | grep "${read_op_test3_part1_time}" | cut -d" " -f9`
echo "read_op_test3_part1_value= ${read_op_test3_part1_value}"
elif [ ${cnt} -eq 4 ]
then
echo "TEST 3 PART 2: Read the key after allowing stabilization protocol to kick in. Check for correct value being read at least in quorum of replicas"
read_op_test3_part2_time="${time}"
read_op_test3_part2_key=`grep -i "${READ_OPERATION}" dbg.log | grep "${read_op_test3_part2_time}" | cut -d" " -f7`
read_op_test3_part2_value=`grep -i "${READ_OPERATION}" dbg.log | grep "${read_op_test3_part2_time}" | cut -d" " -f9`
elif [ ${cnt} -eq 5 ]
then
echo "TEST 4: Read a key after failing a non-replica. Check for correct value being read at least in quorum of replicas"
read_op_test4_time="${time}"
read_op_test4_key="${read_op_test1_key}"
read_op_test4_value="${read_op_test1_value}"
elif [ ${cnt} -eq 6 ]
then
echo "TEST 5: Attempt read of an invalid key read_op_test5_time=${time}"
read_op_test5_time="${time}"
fi
cnt=$(( ${cnt} + 1 ))
done
read_test1_success_count=0
read_test2_success_count=0
read_test3_part2_success_count=0
read_test4_success_count=0
read_successes=`grep -i "${READ_SUCCESS}" dbg.log | grep ${read_op_test1_key} | grep ${read_op_test1_value} 2>/dev/null`
#echo "read_successes=${read_successes}"
if [ "${read_successes}" ]
then
while read success
do
time_of_this_success=`echo "${success}" | cut -d" " -f2 | tr -s '[' ' ' | tr -s ']' ' '`
#echo "time_of_this_success= ${time_of_this_success}"
#echo "success= ${success}"
#echo "test3p2_time=${read_op_test3_part2_time} test4_time=${read_op_test4_time}"
if [ "${time_of_this_success}" -ge "${read_op_test1_time}" -a "${time_of_this_success}" -lt "${read_op_test2_time}" ]
then
read_test1_success_count=`expr ${read_test1_success_count} + 1`
elif [ "${time_of_this_success}" -ge "${read_op_test2_time}" -a "${time_of_this_success}" -lt "${read_op_test3_part1_time}" ]
then
read_test2_success_count=`expr ${read_test2_success_count} + 1`
elif [ "${time_of_this_success}" -ge "${read_op_test3_part2_time}" -a "${time_of_this_success}" -lt "${read_op_test4_time}" ]
then
read_test3_part2_success_count=`expr ${read_test3_part2_success_count} + 1`
echo "read_test3_part2_success_count =${read_test3_part2_success_count}"
elif [ "${time_of_this_success}" -ge "${read_op_test4_time}" ]
then
read_test4_success_count=`expr ${read_test4_success_count} + 1`
#echo "read_test4_success_count= ${read_test4_success_count}"
fi
done <<<"${read_successes}"
fi
#echo "read_test1_success_count= ${read_test1_success_count} read_test2_success_count= ${read_test2_success_count} read_test3_part2_success_count= ${read_test3_part2_success_count} read_test4_success_count= ${read_test4_success_count}"
read_test3_part1_fail_count=0
read_test5_fail_count=0
read_fails=`grep -i "${READ_FAILURE}" dbg.log 2>/dev/null`
#echo "read_fails= ${read_fails}"
if [ "${read_fails}" ]
then
while read fail
do
time_of_this_fail=`echo "${fail}" | cut -d" " -f2 | tr -s '[' ' ' | tr -s ']' ' '`
#echo "time_of_this_fail=${time_of_this_fail} read_op_test3_part1_time=${read_op_test3_part1_time} read_op_test3_part2_time=${read_op_test3_part2_time}"
if [ "${time_of_this_fail}" -ge "${read_op_test3_part1_time}" -a "${time_of_this_fail}" -lt "${read_op_test3_part2_time}" ]
then
actual_key=`echo "${fail}" | grep "${read_op_test3_part1_key}" | wc -l`
echo "1actual_key= ${actual_key}"
if [ "${actual_key}" -eq 1 ]
then
read_test3_part1_fail_count=`expr ${read_test3_part1_fail_count} + 1`
echo "read_test3_part1_fail_count= ${read_test3_part1_fail_count}"
fi
elif [ "${time_of_this_fail}" -ge "${read_op_test5_time}" ]
then
actual_key=`echo "${fail}" | grep "${INVALID_KEY}" | wc -l`
echo "2actual_key= ${actual_key}"
if [ "${actual_key}" -eq 1 ]
then
read_test5_fail_count=`expr ${read_test5_fail_count} + 1`
echo "read_test5_fail_count= ${read_test5_fail_count}"
fi
fi
done <<<"${read_fails}"
fi
echo "read_test3_part1_fail_count =${read_test3_part1_fail_count} read_test5_fail_count =${read_test5_fail_count}"
if [ "${read_test1_success_count}" -eq "${QUORUMPLUSONE}" -o "${read_test1_success_count}" -eq "${RFPLUSONE}" ]
then
READ_TEST1_STATUS="${SUCCESS}"
fi
if [ "${read_test2_success_count}" -eq "${QUORUMPLUSONE}" ]
then
READ_TEST2_STATUS="${SUCCESS}"
fi
if [ "${read_test3_part1_fail_count}" -eq 1 ]
then
READ_TEST3_PART1_STATUS="${SUCCESS}"
fi
if [ "${read_test3_part2_success_count}" -eq "${QUORUMPLUSONE}" -o "${read_test3_part2_success_count}" -eq "${RFPLUSONE}" ]
then
READ_TEST3_PART2_STATUS="${SUCCESS}"
fi
if [ "${read_test4_success_count}" -eq "${QUORUMPLUSONE}" -o "${read_test4_success_count}" -eq "${RFPLUSONE}" ]
then
READ_TEST4_STATUS="${SUCCESS}"
fi
if [ "${read_test5_fail_count}" -eq "${QUORUMPLUSONE}" -o "${read_test5_fail_count}" -eq "${RFPLUSONE}" ]
then
READ_TEST5_STATUS="${SUCCESS}"
fi
if [ "${READ_TEST1_STATUS}" -eq "${SUCCESS}" ]
then
READ_TEST1_SCORE=3
fi
if [ "${READ_TEST2_STATUS}" -eq "${SUCCESS}" ]
then
READ_TEST2_SCORE=9
fi
if [ "${READ_TEST3_PART1_STATUS}" -eq "${SUCCESS}" ]
then
READ_TEST3_PART1_SCORE=9
fi
if [ "${READ_TEST3_PART2_STATUS}" -eq "${SUCCESS}" ]
then
READ_TEST3_PART2_SCORE=10
fi
if [ "${READ_TEST4_STATUS}" -eq "${SUCCESS}" ]
then
READ_TEST4_SCORE=6
fi
if [ "${READ_TEST5_STATUS}" -eq "${SUCCESS}" ]
then
READ_TEST5_SCORE=3
fi
# Display score
echo "TEST 1 SCORE..................: ${READ_TEST1_SCORE} / 3"
echo "TEST 2 SCORE..................: ${READ_TEST2_SCORE} / 9"
echo "TEST 3 PART 1 SCORE..................: ${READ_TEST3_PART1_SCORE} / 9"
echo "TEST 3 PART 2 SCORE..................: ${READ_TEST3_PART2_SCORE} / 10"
echo "TEST 4 SCORE..................: ${READ_TEST4_SCORE} / 6"
echo "TEST 5 SCORE..................: ${READ_TEST5_SCORE} / 3"
# Add to grade
GRADE=`expr ${GRADE} + ${READ_TEST1_SCORE}`
GRADE=`expr ${GRADE} + ${READ_TEST2_SCORE}`
GRADE=`echo ${GRADE} ${READ_TEST3_PART1_SCORE} | awk '{print $1 + $2}'`
GRADE=`echo ${GRADE} ${READ_TEST3_PART2_SCORE} | awk '{print $1 + $2}'`
GRADE=`echo ${GRADE} ${READ_TEST4_SCORE} | awk '{print $1 + $2}'`
GRADE=`echo ${GRADE} ${READ_TEST5_SCORE} | awk '{print $1 + $2}'`
#echo ""
#echo "############################"
#echo " READ TEST ENDS"
#echo "############################"
#echo ""
echo ""
echo "############################"
echo " UPDATE TEST"
echo "############################"
echo ""