Added some record-keeping / printing to fuzzer to assist with backtracking.
This commit is contained in:
16
tests/fuzz
16
tests/fuzz
@@ -30,6 +30,13 @@ end
|
||||
@serve = FlexNBD.new(binary, "127.0.0.1", 41234)
|
||||
@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|
|
||||
|
||||
begin
|
||||
@@ -44,6 +51,7 @@ repetitions.times do |n|
|
||||
|
||||
if md5_local != md5_serve
|
||||
STDERR.print "Before pass #{n}: MD5 error: local=#{md5_local} serve=#{md5_serve}\n"
|
||||
print_record
|
||||
STDERR.print "**** Local contents:\n"
|
||||
system("hexdump #{testname_local}")
|
||||
STDERR.print "**** Serve contents:\n"
|
||||
@@ -51,12 +59,14 @@ repetitions.times do |n|
|
||||
exit 1
|
||||
end
|
||||
|
||||
length = rand(max_length)
|
||||
length = rand(max_length/8)
|
||||
length &= 0xfffff000 if CHEAT_AND_ROUND_DOWN
|
||||
offset = rand(test_size - length)
|
||||
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.write(content)
|
||||
@@ -67,6 +77,7 @@ repetitions.times do |n|
|
||||
check_read = @serve.read(offset, length)
|
||||
if check_read != content
|
||||
STDERR.print "After pass #{n}: Didn't read back what we wrote!\n"
|
||||
print_record
|
||||
STDERR.print "*** We wrote these #{content.length} bytes...\n"
|
||||
IO.popen("hexdump", "w") { |io| io.print(content) }
|
||||
STDERR.print "*** But we got back these #{check_read.length} bytes...\n"
|
||||
@@ -76,6 +87,7 @@ repetitions.times do |n|
|
||||
|
||||
rescue StandardError => ex
|
||||
STDERR.print "During pass #{n}: Exception: #{ex}"
|
||||
print_record
|
||||
STDERR.print ex.backtrace.join("\n") + "\n"
|
||||
exit 2
|
||||
end
|
||||
|
Reference in New Issue
Block a user