--- lib/dmtest/suites/insitu-comp.rb | 1 lib/dmtest/tests/insitu-comp/insitu-comp_tests.rb | 120 ++++++++++++++++++++++ 2 files changed, 121 insertions(+) Index: device-mapper-test-suite/lib/dmtest/suites/insitu-comp.rb =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ device-mapper-test-suite/lib/dmtest/suites/insitu-comp.rb 2014-03-14 17:16:14.043519177 +0800 @@ -0,0 +1 @@ +require 'dmtest/tests/insitu-comp/insitu-comp_tests' Index: device-mapper-test-suite/lib/dmtest/tests/insitu-comp/insitu-comp_tests.rb =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ device-mapper-test-suite/lib/dmtest/tests/insitu-comp/insitu-comp_tests.rb 2014-03-14 17:16:14.043519177 +0800 @@ -0,0 +1,120 @@ +require 'dmtest/config' +require 'dmtest/git' +require 'dmtest/log' +require 'dmtest/utils' +require 'dmtest/fs' +require 'dmtest/tags' +require 'dmtest/thinp-test' +require 'dmtest/cache-status' +require 'dmtest/disk-units' +require 'dmtest/test-utils' +require 'dmtest/tests/cache/fio_subvolume_scenario' + +require 'pp' + +#------------------------------------------------------------ + +class InsitucompStack + include DM + include DM::LexicalOperators + include Utils + + def initialize(dm, dev, opts) + @dm = dm + @dev = dev + @opts = opts + end + + def activate(&block) + with_dev(table) do |comp| + @comp = comp + block.call(comp) + end + end + + def table + total_blocks = dev_size(@dev) >> 3 + data_blocks = total_blocks - 1 + rem = data_blocks % (4096 * 8 + 5) + data_blocks /= 4096 * 8 + 5 + meta_blocks = data_blocks * 5 + data_blocks *= 4096 * 8 + + cnt = rem + rem /= (4096 * 8 / 5 + 1) + data_blocks += rem * (4096 * 8 / 5) + meta_blocks += rem + + cnt %= (4096 * 8 / 5 + 1) + meta_blocks += 1 + data_blocks += cnt - 1 + + sector_count = data_blocks << 3 + + writethrough = @opts.fetch(:writethrough, true) + if writethrough + t = Table.new(Target.new('insitu_comp', sector_count, @dev, 'writethrough')) + else + wb_interval = @opts.fetch(:writeback_interval, 5) + t = Table.new(Target.new('insitu_comp', sector_count, @dev, 'writeback', wb_interval)) + end + t + end + + private + def dm_interface + @dm + end +end + +#------------------------------------------------------------ + +class InsitucompTests < ThinpTestCase + include Utils + include DiskUnits + include FioSubVolumeScenario + + def test_basic_setup_writethrough + test_basic_setup() + end + + def test_basic_setup_writeback + test_basic_setup(false, 5) + end + + def test_fio_writethrough + test_fio() + end + + def test_fio_writeback + test_fio(false, 5) + end + + private + def alloc_stack(writethrough, wbinterval) + if writethrough + stack = InsitucompStack.new(@dm, @data_dev, :writethrough => true) + else + stack = InsitucompStack.new(@dm, @data_dev, :writethrough => false, :writeback_interval => wbinterval) + end + stack + end + + private + def test_basic_setup(writethrough = true, wbinterval = 5) + stack = alloc_stack(writethrough, wbinterval) + stack.activate do |comp| + wipe_device(comp) + end + end + + private + def test_fio(writethrough = true, wbinterval = 5) + stack = alloc_stack(writethrough, wbinterval) + stack.activate do |comp| + do_fio(comp, :ext4, + :outfile => AP("fio_dm_insitu-comp" + (writethrough ? "-wt.out" : "-wb.out")), + :cfgfile => LP("tests/cache/database-funtime.fio")) + end + end +end