Added some record-keeping / printing to fuzzer to assist with backtracking.

This commit is contained in:
Matthew Bloch
2012-06-07 12:25:56 +01:00
parent 5710431780
commit 3810a8210f

View File

@@ -30,6 +30,13 @@ end
@serve = FlexNBD.new(binary, "127.0.0.1", 41234) @serve = FlexNBD.new(binary, "127.0.0.1", 41234)
@serve.serve(testname_serve) @serve.serve(testname_serve)
$record = []
def print_record
$record.each do |offset, length, byte|
STDERR.print " wrote #{byte} to #{offset}+#{length}\n"
end
end
repetitions.times do |n| repetitions.times do |n|
begin begin
@@ -44,6 +51,7 @@ repetitions.times do |n|
if md5_local != md5_serve if md5_local != md5_serve
STDERR.print "Before pass #{n}: MD5 error: local=#{md5_local} serve=#{md5_serve}\n" STDERR.print "Before pass #{n}: MD5 error: local=#{md5_local} serve=#{md5_serve}\n"
print_record
STDERR.print "**** Local contents:\n" STDERR.print "**** Local contents:\n"
system("hexdump #{testname_local}") system("hexdump #{testname_local}")
STDERR.print "**** Serve contents:\n" STDERR.print "**** Serve contents:\n"
@@ -51,12 +59,14 @@ repetitions.times do |n|
exit 1 exit 1
end end
length = rand(max_length) length = rand(max_length/8)
length &= 0xfffff000 if CHEAT_AND_ROUND_DOWN length &= 0xfffff000 if CHEAT_AND_ROUND_DOWN
offset = rand(test_size - length) offset = rand(test_size - length)
offset &= 0xfffff000 if CHEAT_AND_ROUND_DOWN offset &= 0xfffff000 if CHEAT_AND_ROUND_DOWN
content = (n%2 == 0) ? ("\0" * length) : ( ((n/2)&255).chr * length) content = (n%2 == 0) ? ("\0" * length) : ( (n&255).chr * length)
$record << [offset, length, content[0]]
@local.seek(offset, IO::SEEK_SET) @local.seek(offset, IO::SEEK_SET)
@local.write(content) @local.write(content)
@@ -67,6 +77,7 @@ repetitions.times do |n|
check_read = @serve.read(offset, length) check_read = @serve.read(offset, length)
if check_read != content if check_read != content
STDERR.print "After pass #{n}: Didn't read back what we wrote!\n" STDERR.print "After pass #{n}: Didn't read back what we wrote!\n"
print_record
STDERR.print "*** We wrote these #{content.length} bytes...\n" STDERR.print "*** We wrote these #{content.length} bytes...\n"
IO.popen("hexdump", "w") { |io| io.print(content) } IO.popen("hexdump", "w") { |io| io.print(content) }
STDERR.print "*** But we got back these #{check_read.length} bytes...\n" STDERR.print "*** But we got back these #{check_read.length} bytes...\n"
@@ -76,6 +87,7 @@ repetitions.times do |n|
rescue StandardError => ex rescue StandardError => ex
STDERR.print "During pass #{n}: Exception: #{ex}" STDERR.print "During pass #{n}: Exception: #{ex}"
print_record
STDERR.print ex.backtrace.join("\n") + "\n" STDERR.print ex.backtrace.join("\n") + "\n"
exit 2 exit 2
end end