#!/usr/bin/env ruby

fmt = 'vdi'
size = 512

system("./qemu-img create -f #{fmt} test.#{fmt} #{size}M")
system("./qemu-img create -f raw test.raw #{size}M")

cmd = './qemu-io -f raw'

0.upto(size - 1).each do |i|
    cmd += " -c 'aio_write -P #{i % 256} #{i}M 1M'"
end

cmd += " blkverify:test.raw:test.#{fmt}"

system(cmd)


puts
puts '--- read raw ---'
puts


cmd = './qemu-io -f raw'

0.upto(511).each do |i|
    cmd += " -c 'read -P #{i % 256} #{i}M 1M'"
end

cmd += ' test.raw'

system(cmd)


puts
puts "--- read #{fmt} ---"
puts


cmd = "./qemu-io -f #{fmt}"

0.upto(511).each do |i|
    cmd += " -c 'read -P #{i % 256} #{i}M 1M'"
end

cmd += " test.#{fmt}"

system(cmd)
