212 print_every=32):
213
214
215
216
217
218
219
220 p = subprocess.Popen(
221 dartfuzz_cmd + " --mini " + dart_test,
222 shell=True,
223 stdout=subprocess.PIPE)
224 p_stdout, p_stderr = p.communicate()
225 if do_expr:
226
227 nstmts =
int(p_stdout.decode().splitlines()[EXPRESSION_NUMBER_LINE])
228 mask_gen = MaskGen(nstmts, emask)
229 else:
230
231 nstmts =
int(p_stdout.decode().splitlines()[STATEMENT_NUMBER_LINE])
232 mask_gen = MaskGen(nstmts, smask)
233
234 min_mask = 0
235
236 max_bits = 0
237
238 cntr = 0
239
240 last_err = True
241
242
243 error_match_p1 = re.compile(error_match1)
244 error_match_p2 = None
245 if error_match2 is not None:
246 error_match_p2 = re.compile(error_match2)
247 for mask in mask_gen:
248 if (verbose):
249 print(
"Mask: %x" % mask)
250 cntr += 1
251 if cntr % print_every == 0:
252 cntr = 0
253 print(
"Best I could do so far is mask %d/%d" \
254 % (max_bits, nstmts))
255 if do_expr:
256 print(dartfuzz_cmd +
" " + dart_test +
257 " --mini --smask 0x%x --emask 0x%x" % (smask, min_mask))
258 else:
259 print(dartfuzz_cmd +
" " + dart_test +
260 " --mini --smask 0x%x --emask 0" % (min_mask))
261
262
263
264
265 mask_new = generate_dart(dartfuzz_cmd, dart_test, smask, mask, do_expr)
266
267 err = run_dart_mp(dart_cmd, dart_test, error_match_p1, tries, threads,
268 timeout)
269 if err and verbose:
270 print(
"Matched error 1 " + error_match1)
271 err_ref = True
272 if (dart_cmd_ref is not None) and (error_match_p2 is not None):
273 err_ref = run_dart_mp(dart_cmd_ref, dart_test, error_match_p2,
274 tries_ref, threads, timeout)
275 if err_ref and verbose:
276 print(
"Matched error 2 " + error_match2)
277 if err and err_ref:
278
279
280 mask_gen.update_mask(mask)
281
282
283 mask_gen.update_mask(mask_new)
284 max_bits = mask_gen.count_bits()
285 min_mask = mask_gen.mask
286 elif last_err:
287
288 invMaskNew = mask_gen.mask | (mask_gen.max & ~mask_new)
289 if invMaskNew != mask_gen.mask and \
290 invMaskNew not in mask_gen.tested:
291 if (verbose):
292 print(
"Mask: %x (i)" % invMaskNew)
293 mask_new = generate_dart(dartfuzz_cmd, dart_test, smask,
294 invMaskNew, do_expr)
295 err = run_dart_mp(dart_cmd, dart_test, error_match_p1, tries,
296 threads, timeout)
297 if err and verbose:
298 print(
"Matched error 1 " + error_match1)
299 err_ref = True
300 if (dart_cmd_ref is not None) and (error_match_p2 is not None):
301 err_ref = run_dart_mp(dart_cmd_ref, dart_test,
302 error_match_p2, tries_ref, threads,
303 timeout)
304 if err_ref and verbose:
305 print(
"Matched error 2 " + error_match2)
306 if err and err_ref:
307 mask_gen.update_mask(invMaskNew)
308 mask_gen.update_mask(mask_new)
309 max_bits = mask_gen.count_bits()
310 min_mask = mask_gen.mask
311 last_err = err and err_ref
312
313 mask_gen.update_tested(mask_new)
314
315 print(
"Best I could do is %d/%d" \
316 % (max_bits,nstmts))
317
318 if do_expr:
319 print(dartfuzz_cmd +
" " + dart_test +
320 " --mini --smask 0x%x --emask 0x%x" % (smask, min_mask))
321 else:
322 print(dartfuzz_cmd +
" " + dart_test +
323 " --mini --smask 0x%x --emask 0" % (min_mask))
324
325 return min_mask
326
327