From ff12ea01d5441f85abac9ac0b3891ece102329a2 Mon Sep 17 00:00:00 2001 From: Sebastian Sumpf Date: Thu, 7 May 2015 13:09:25 +0200 Subject: [PATCH] blk_cli: add support for test size 'test_size' can be set as parameter in node. --- repos/os/run/ahci_blk.run | 125 ++++++++++++++++++++++++++++ repos/os/src/test/blk/cli/main.cc | 43 ++++++---- repos/os/src/test/blk/cli/target.mk | 2 +- 3 files changed, 155 insertions(+), 15 deletions(-) create mode 100644 repos/os/run/ahci_blk.run diff --git a/repos/os/run/ahci_blk.run b/repos/os/run/ahci_blk.run new file mode 100644 index 000000000..98b386446 --- /dev/null +++ b/repos/os/run/ahci_blk.run @@ -0,0 +1,125 @@ + +set mke2fs [check_installed mke2fs] +set dd [check_installed dd] + +# +# Build +# +set build_components { + core init + drivers/timer + drivers/ahci + drivers/platform + test/blk/cli +} + +lappend_if [have_spec acpi] build_components drivers/acpi +lappend_if [have_spec pci] build_components drivers/pci + +build $build_components +# +# Build EXT2-file-system image +# +catch { exec $dd if=/dev/zero of=bin/ext2.raw bs=1M count=16 } +catch { exec $mke2fs -F bin/ext2.raw } + +create_boot_directory + +# +# Generate config +# +set config { + + + + + + + + + + + + + + + + + + + + + +} +append_if [expr ![have_spec acpi] && ![have_spec pci]] config { + + + + } + +append_if [have_spec acpi] config { + + + + + + + + + + + + + + + +} + +append_if [expr ![have_spec acpi] && [have_spec pci]] config { + + + + + + + } + +append config { + + + + + + + + + + + + + + + + + + } + +install_config $config + +# +# Boot modules +# +set boot_modules { core init timer ahci_drv test-blk-cli } + +lappend_if [expr ![have_spec acpi] && ![have_spec pci]] boot_modules platform_drv +lappend_if [have_spec pci] boot_modules pci_drv +lappend_if [have_spec nova] boot_modules pci_device_pd +lappend_if [have_spec acpi] boot_modules acpi_drv + +build_boot_image $boot_modules + +append qemu_args " -nographic -m 256 " +append qemu_args " -drive id=disk,file=bin/ext2.raw,if=none -device ahci,id=ahci -device ide-hd,drive=disk,bus=ahci.0 -boot d" +append qemu_args " -drive id=cd,file=[run_dir]/../ahci_blk.iso,if=none,media=cdrom -device ide-cd,drive=cd,bus=ahci.1" + +run_genode_until "Tests finished successfully!" 100 diff --git a/repos/os/src/test/blk/cli/main.cc b/repos/os/src/test/blk/cli/main.cc index 3b8d503a5..4476c1a10 100644 --- a/repos/os/src/test/blk/cli/main.cc +++ b/repos/os/src/test/blk/cli/main.cc @@ -7,9 +7,11 @@ #include #include #include +#include #include static Genode::size_t blk_sz; /* block size of the device */ +static Block::sector_t test_cnt; /* number test blocks */ static Block::sector_t blk_cnt; /* number of blocks of device */ static Block::Session::Operations blk_ops; /* supported operations */ @@ -118,15 +120,15 @@ struct Read_test : Test void perform() { PINF("reading block 0 - %llu, %u per request", - blk_cnt - 1, NR_PER_REQ); + test_cnt - 1, NR_PER_REQ); - for (Block::sector_t nr = 0, cnt = NR_PER_REQ; nr < blk_cnt; + for (Block::sector_t nr = 0, cnt = NR_PER_REQ; nr < test_cnt; nr += cnt) { while (!_session.tx()->ready_to_submit()) _handle_signal(); - cnt = Genode::min(NR_PER_REQ, blk_cnt-nr); + cnt = Genode::min(NR_PER_REQ, test_cnt-nr); try { Block::Packet_descriptor p( @@ -154,7 +156,7 @@ struct Read_test : Test throw Block_exception(p.block_number(), p.block_count(), false); - if ((p.block_number() + p.block_count()) == blk_cnt) + if ((p.block_number() + p.block_count()) == test_cnt) done = true; _session.tx()->release_packet(p); @@ -213,10 +215,13 @@ struct Write_test : Test if (!compare(r,w)) throw Integrity_exception(r.block_number(), r.block_count()); + + _session.tx()->release_packet(w); break; } write_packets.add(w); } + _session.tx()->release_packet(r); } } @@ -233,6 +238,7 @@ struct Write_test : Test for (Genode::size_t i = 0; i < blk_sz; i++) dst[i] = src[i] + val; _session.tx()->submit_packet(w); + _session.tx()->release_packet(r); } while (write_packets.avail_capacity()) _handle_signal(); @@ -242,9 +248,9 @@ struct Write_test : Test { using namespace Block; - for (sector_t nr = start, cnt = NR_PER_REQ; nr < end; - cnt = Genode::min(NR_PER_REQ, end-nr), - nr += cnt) { + for (sector_t nr = start, cnt = Genode::min(NR_PER_REQ, end - start); nr < end; + nr += cnt, + cnt = Genode::min(NR_PER_REQ, end-nr)) { Block::Packet_descriptor p(_session.dma_alloc_packet(cnt*blk_sz), Block::Packet_descriptor::READ, nr, cnt); _session.tx()->submit_packet(p); @@ -267,11 +273,11 @@ struct Write_test : Test return; PINF("read/write/compare block 0 - %llu, %u per request", - blk_cnt - 1, NR_PER_REQ); + test_cnt - 1, NR_PER_REQ); - for (Block::sector_t nr = 0, cnt = BATCH*NR_PER_REQ; nr < blk_cnt; - cnt = Genode::min(BATCH*NR_PER_REQ, blk_cnt-nr), - nr += cnt) { + for (Block::sector_t nr = 0, cnt = BATCH*NR_PER_REQ; nr < test_cnt; + nr += cnt, + cnt = Genode::min(BATCH*NR_PER_REQ, test_cnt-nr)) { batch(nr, nr + cnt, 1); batch(nr, nr + cnt, -1); } @@ -290,7 +296,6 @@ struct Write_test : Test write_packets.add(p); else read_packets.add(p); - _session.tx()->release_packet(p); } } }; @@ -375,10 +380,20 @@ int main() Genode::Allocator_avl alloc(Genode::env()->heap()); Block::Connection blk(&alloc); blk.info(&blk_cnt, &blk_sz, &blk_ops); + } - PINF("block device with block size %zd sector count %lld", - blk_sz, blk_cnt); + try { + Genode::Number_of_bytes test_size;; + Genode::config()->xml_node().attribute("test_size").value(&test_size); + test_cnt = Genode::min(test_size / blk_sz, blk_cnt); + } catch (...) { test_cnt = blk_cnt; } + + /* must be multiple of 16 */ + test_cnt &= ~0xfLLU; + + PINF("block device with block size %zd sector count %lld (testing %lld sectors)", + blk_sz, blk_cnt, test_cnt); perform >(); diff --git a/repos/os/src/test/blk/cli/target.mk b/repos/os/src/test/blk/cli/target.mk index 9e8ae2c31..bf75486ca 100644 --- a/repos/os/src/test/blk/cli/target.mk +++ b/repos/os/src/test/blk/cli/target.mk @@ -1,3 +1,3 @@ TARGET = test-blk-cli SRC_CC = main.cc -LIBS = base +LIBS = base config