[thin_check] Start refactoring metadata_checker.

This commit is contained in:
Joe Thornber
2013-04-23 15:21:44 +01:00
parent 70fd048426
commit 20ff78c818
12 changed files with 302 additions and 123 deletions

View File

@@ -7,7 +7,20 @@ Given(/^valid metadata$/) do
run_simple("thin_restore -i #{xml_file} -o #{dev_file}")
end
When(/^I run thin_check with (.*?)$/) do |opts|
run "thin_check #{opts} #{dev_file}"
Given(/^a corrupt superblock$/) do
in_current_dir do
write_valid_xml(xml_file)
end
run_simple("dd if=/dev/zero of=#{dev_file} bs=4k count=1024")
run_simple("thin_restore -i #{xml_file} -o #{dev_file}")
in_current_dir do
corrupt_block(0)
end
end
When(/^I run thin_check with (.*?)$/) do |opts|
run_simple("thin_check #{opts} #{dev_file}", false)
end

View File

@@ -11,6 +11,10 @@ module ThinpWorld
'metadata.bin'
end
def corrupt_block(n)
write_block(n, change_random_byte(read_block(n)))
end
# FIXME: we should really break out the xml stuff from
# thinp-test-suite and put in a gem in this repo.
def write_valid_xml(path)
@@ -24,6 +28,32 @@ module ThinpWorld
EOF
end
end
private
def read_block(n)
b = nil
File.open(dev_file, "r") do |f|
f.seek(n * 4096)
b = f.read(4096)
end
b
end
def write_block(n, b)
File.open(dev_file, "w") do |f|
f.seek(n * 4096)
f.write(b)
end
end
def change_random_byte(b)
i = rand(b.size)
puts "changing byte #{i}"
b.setbyte(i, (b.getbyte(i) + 1) % 256)
b
end
end
World(ThinpWorld)

View File

@@ -40,8 +40,17 @@ Feature: thin_check
{--super-block-only}
"""
@announce
Scenario: Unrecognised option should cause failure
When I run `thin_check --hedeghogs-only`
Then it should fail
Scenario: --super-block-only check passes on valid metadata
Given valid metadata
When I run thin_check with --super-block-only
Then it should pass
Then it should pass
@announce
Scenario: --super-block-only check fails with corrupt superblock
Given a corrupt superblock
When I run thin_check with --super-block-only
Then it should fail