From e1435a3f57e2bf961da82aaaa3c0357742d98f8a Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Mon, 9 Jul 2012 15:00:57 +0200 Subject: [PATCH] Replace old test/block with test/ahci The block test at test/ahci is indeed not AHCI-specific. It is a generic block read/write test for the block-session interface. But in contrast to the original test/block, it restores the block device content (at least when the test succeeds). Hence, we remove the original (dangerous) block test and always use code of test/ahci. --- dde_linux/run/usb_storage.run | 6 +- os/run/ahci.run | 78 +++++++-------- os/src/test/ahci/main.cc | 183 ---------------------------------- os/src/test/ahci/target.mk | 3 - os/src/test/block/main.cc | 166 ++++++++++++++++++++---------- 5 files changed, 157 insertions(+), 279 deletions(-) delete mode 100644 os/src/test/ahci/main.cc delete mode 100644 os/src/test/ahci/target.mk diff --git a/dde_linux/run/usb_storage.run b/dde_linux/run/usb_storage.run index adec08c04..33896a4fa 100644 --- a/dde_linux/run/usb_storage.run +++ b/dde_linux/run/usb_storage.run @@ -13,7 +13,7 @@ build { drivers/pci drivers/timer drivers/usb - test/ahci + test/block } create_boot_directory @@ -55,7 +55,7 @@ set config { - + } @@ -67,7 +67,7 @@ install_config $config # generic modules set boot_modules { - core init timer usb_drv pci_drv test-ahci + core init timer usb_drv pci_drv test-block } diff --git a/os/run/ahci.run b/os/run/ahci.run index aa57e207f..7a66616c5 100644 --- a/os/run/ahci.run +++ b/os/run/ahci.run @@ -8,7 +8,7 @@ if {![have_spec x86_32]} { # set build_components { core init drivers/timer drivers/pci drivers/acpi - drivers/ahci test/ahci + drivers/ahci test/block } build $build_components @@ -65,7 +65,7 @@ set config { - + @@ -82,7 +82,7 @@ install_config $config # set boot_modules { - core init timer pci_drv ahci_drv test-ahci acpi_drv + core init timer pci_drv ahci_drv test-block acpi_drv } build_boot_image $boot_modules @@ -110,43 +110,43 @@ if { [file exists $disk_image] == 0 } then { run_genode_until "child exited with exit value 0.*\n" 10 -# pay only attention to the output of test-ahci -grep_output {^\[init -> test-ahci} +# pay only attention to the output of test-block +grep_output {^\[init -> test-block} compare_output_to { - [init -> test-ahci] --- AHCI block driver test --- - [init -> test-ahci] We have 20480 blocks with a size of 512 bytes (10 MB) - [init -> test-ahci] Comparing block 0000000000: success - [init -> test-ahci] Comparing block 0000000640: success - [init -> test-ahci] Comparing block 0000001280: success - [init -> test-ahci] Comparing block 0000001920: success - [init -> test-ahci] Comparing block 0000002560: success - [init -> test-ahci] Comparing block 0000003200: success - [init -> test-ahci] Comparing block 0000003840: success - [init -> test-ahci] Comparing block 0000004480: success - [init -> test-ahci] Comparing block 0000005120: success - [init -> test-ahci] Comparing block 0000005760: success - [init -> test-ahci] Comparing block 0000006400: success - [init -> test-ahci] Comparing block 0000007040: success - [init -> test-ahci] Comparing block 0000007680: success - [init -> test-ahci] Comparing block 0000008320: success - [init -> test-ahci] Comparing block 0000008960: success - [init -> test-ahci] Comparing block 0000009600: success - [init -> test-ahci] Comparing block 0000010240: success - [init -> test-ahci] Comparing block 0000010880: success - [init -> test-ahci] Comparing block 0000011520: success - [init -> test-ahci] Comparing block 0000012160: success - [init -> test-ahci] Comparing block 0000012800: success - [init -> test-ahci] Comparing block 0000013440: success - [init -> test-ahci] Comparing block 0000014080: success - [init -> test-ahci] Comparing block 0000014720: success - [init -> test-ahci] Comparing block 0000015360: success - [init -> test-ahci] Comparing block 0000016000: success - [init -> test-ahci] Comparing block 0000016640: success - [init -> test-ahci] Comparing block 0000017280: success - [init -> test-ahci] Comparing block 0000017920: success - [init -> test-ahci] Comparing block 0000018560: success - [init -> test-ahci] Comparing block 0000019200: success - [init -> test-ahci] Comparing block 0000019840: success + [init -> test-block] --- AHCI block driver test --- + [init -> test-block] We have 20480 blocks with a size of 512 bytes (10 MB) + [init -> test-block] Comparing block 0000000000: success + [init -> test-block] Comparing block 0000000640: success + [init -> test-block] Comparing block 0000001280: success + [init -> test-block] Comparing block 0000001920: success + [init -> test-block] Comparing block 0000002560: success + [init -> test-block] Comparing block 0000003200: success + [init -> test-block] Comparing block 0000003840: success + [init -> test-block] Comparing block 0000004480: success + [init -> test-block] Comparing block 0000005120: success + [init -> test-block] Comparing block 0000005760: success + [init -> test-block] Comparing block 0000006400: success + [init -> test-block] Comparing block 0000007040: success + [init -> test-block] Comparing block 0000007680: success + [init -> test-block] Comparing block 0000008320: success + [init -> test-block] Comparing block 0000008960: success + [init -> test-block] Comparing block 0000009600: success + [init -> test-block] Comparing block 0000010240: success + [init -> test-block] Comparing block 0000010880: success + [init -> test-block] Comparing block 0000011520: success + [init -> test-block] Comparing block 0000012160: success + [init -> test-block] Comparing block 0000012800: success + [init -> test-block] Comparing block 0000013440: success + [init -> test-block] Comparing block 0000014080: success + [init -> test-block] Comparing block 0000014720: success + [init -> test-block] Comparing block 0000015360: success + [init -> test-block] Comparing block 0000016000: success + [init -> test-block] Comparing block 0000016640: success + [init -> test-block] Comparing block 0000017280: success + [init -> test-block] Comparing block 0000017920: success + [init -> test-block] Comparing block 0000018560: success + [init -> test-block] Comparing block 0000019200: success + [init -> test-block] Comparing block 0000019840: success } diff --git a/os/src/test/ahci/main.cc b/os/src/test/ahci/main.cc deleted file mode 100644 index 4a8d6b317..000000000 --- a/os/src/test/ahci/main.cc +++ /dev/null @@ -1,183 +0,0 @@ -/* - * \brief Block driver interface test - * \author Sebastian Sumpf - * \date 2011-08-11 - * - * Test block device, read blocks add one to the data, write block back, read - * block again and compare outputs - */ - -/* - * Copyright (C) 2011-2012 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU General Public License version 2. - */ - -#include -#include -#include -#include -#include -#include - - -static const bool read_only = false; - -class Worker : public Genode::Thread<8192> -{ - private: - - Block::Connection _blk_con; - Genode::size_t _blk_size; - - public: - - /** - * Constructor - */ - Worker(Genode::Allocator_avl *block_alloc) - : _blk_con(block_alloc) { } - - void dump(Block::Packet_descriptor &p1, Block::Packet_descriptor &p2) - { - Block::Session::Tx::Source *source = _blk_con.tx(); - unsigned *d1 = (unsigned *)source->packet_content(p1); - unsigned *d2 = (unsigned *)source->packet_content(p2); - for (int i = 0; i < 128; i += 8) { - Genode::printf("1 0x%02x: %08x %08x %08x %08x %08x %08x %08x %08x\n", i, - d1[i], d1[i+1], d1[i+2], d1[i+3], d1[i+4], d1[i+5], d1[i+6], d1[i+7]); - Genode::printf("2 0x%02x: %08x %08x %08x %08x %08x %08x %08x %08x\n\n", i, - d2[i], d2[i+1], d2[i+2], d2[i+3], d2[i+4], d2[i+5], d2[i+6], d2[i+7]); - } - - } - - void compare(Genode::size_t block, Block::Packet_descriptor &p1, Block::Packet_descriptor &p2) - { - using namespace Genode; - Block::Session::Tx::Source *source = _blk_con.tx(); - char *d1 = source->packet_content(p1); - char *d2 = source->packet_content(p2); - - bool equal = true; - for (size_t i = 0; i < _blk_size / sizeof(unsigned); i++) - if (d1[i] != d2[i]) { - equal = false; - - if (!read_only) - PERR("%zu: %x != %x", i, d1[i], d2[i]); - } - - printf("Comparing block %010zu: ", block); - if (equal) - printf("success\n"); - else { - printf("failed\n"); - dump(p1, p2); - } - } - - void modify(Block::Packet_descriptor &src, Block::Packet_descriptor &dst, int val) - { - Block::Session::Tx::Source *source = _blk_con.tx(); - for (unsigned j = 0; j < _blk_size; j++) - source->packet_content(dst)[j] = source->packet_content(src)[j] + val; - } - - void submit(Block::Packet_descriptor &src, - Block::Packet_descriptor &dst, - int val, Genode::size_t block, bool cmp) - { - Block::Session::Tx::Source *source = _blk_con.tx(); - - source->submit_packet(src); - src = source->get_acked_packet(); - - /* check for success of operation */ - if (!src.succeeded()) { - PWRN("Could not read block %zu", block); - return; - } - - if (cmp) - compare(block, src, dst); - - modify(src, dst, val); - - if (read_only) - return; - - source->submit_packet(dst); - dst = source->get_acked_packet(); - - /* check for success of operation */ - if (!dst.succeeded()) - PWRN("Could not write block %zu", block); - } - - /** - * Thread's entry function. - */ - void entry() - { - using namespace Genode; - - Block::Session::Tx::Source *source = _blk_con.tx(); - size_t blk_cnt = 0; - Block::Session::Operations ops; - _blk_con.info(&blk_cnt, &_blk_size, &ops); - - /* check for read- and write-capability */ - if (!ops.supported(Block::Packet_descriptor::READ)) { - PERR("Block device not readable!"); - return; - } - if (!ops.supported(Block::Packet_descriptor::WRITE)) { - PERR("Block device not writeable!"); - return; - } - - printf("We have %zu blocks with a size of %zu bytes (%zu MB)\n", - blk_cnt, _blk_size, blk_cnt / (2 * 1024)); - - /* now, repeatedly invert each single block of the device */ - size_t step = blk_cnt / 32; - for (size_t i = 0; i < blk_cnt; i += step) { - try { - /* allocate packet-descriptor for reading */ - Block::Packet_descriptor p(source->alloc_packet(_blk_size), - Block::Packet_descriptor::READ, i); - - /* allocate a packet-descriptor for writing */ - Block::Packet_descriptor q(source->alloc_packet(_blk_size), - Block::Packet_descriptor::WRITE, i); - - submit(p, q, 1, i, false); - submit(p, q, -1, i, true); - - /* release packets */ - source->release_packet(q); - source->release_packet(p); - } catch (Block::Session::Tx::Source::Packet_alloc_failed) { - PWRN("Mmh, strange we run out of packets"); - source->release_packet(source->get_acked_packet()); - } - } - - env()->parent()->close(_blk_con.cap()); - env()->parent()->exit(0); - } -}; - - -int main(int argc, char **argv) -{ - Genode::printf("--- AHCI block driver test ---\n"); - - Genode::Allocator_avl block_alloc(Genode::env()->heap()); - Worker th(&block_alloc); - th.start(); - Genode::sleep_forever(); - return 0; -} diff --git a/os/src/test/ahci/target.mk b/os/src/test/ahci/target.mk deleted file mode 100644 index 29e8d576f..000000000 --- a/os/src/test/ahci/target.mk +++ /dev/null @@ -1,3 +0,0 @@ -TARGET = test-ahci -LIBS = env cxx signal -SRC_CC = main.cc diff --git a/os/src/test/block/main.cc b/os/src/test/block/main.cc index 79ac27c60..4a8d6b317 100644 --- a/os/src/test/block/main.cc +++ b/os/src/test/block/main.cc @@ -1,13 +1,14 @@ /* - * \brief Block session test implementation - * \author Stefan Kalkowski - * \date 2010-07-07 + * \brief Block driver interface test + * \author Sebastian Sumpf + * \date 2011-08-11 * - * The test program inverts the bits block-by-block of a block-device. + * Test block device, read blocks add one to the data, write block back, read + * block again and compare outputs */ /* - * Copyright (C) 2010-2012 Genode Labs GmbH + * Copyright (C) 2011-2012 Genode Labs GmbH * * This file is part of the Genode OS framework, which is distributed * under the terms of the GNU General Public License version 2. @@ -18,21 +19,103 @@ #include #include #include +#include -class Inverter : public Genode::Thread<8192> + +static const bool read_only = false; + +class Worker : public Genode::Thread<8192> { private: Block::Connection _blk_con; + Genode::size_t _blk_size; public: /** * Constructor */ - Inverter(Genode::Allocator_avl *block_alloc) + Worker(Genode::Allocator_avl *block_alloc) : _blk_con(block_alloc) { } + void dump(Block::Packet_descriptor &p1, Block::Packet_descriptor &p2) + { + Block::Session::Tx::Source *source = _blk_con.tx(); + unsigned *d1 = (unsigned *)source->packet_content(p1); + unsigned *d2 = (unsigned *)source->packet_content(p2); + for (int i = 0; i < 128; i += 8) { + Genode::printf("1 0x%02x: %08x %08x %08x %08x %08x %08x %08x %08x\n", i, + d1[i], d1[i+1], d1[i+2], d1[i+3], d1[i+4], d1[i+5], d1[i+6], d1[i+7]); + Genode::printf("2 0x%02x: %08x %08x %08x %08x %08x %08x %08x %08x\n\n", i, + d2[i], d2[i+1], d2[i+2], d2[i+3], d2[i+4], d2[i+5], d2[i+6], d2[i+7]); + } + + } + + void compare(Genode::size_t block, Block::Packet_descriptor &p1, Block::Packet_descriptor &p2) + { + using namespace Genode; + Block::Session::Tx::Source *source = _blk_con.tx(); + char *d1 = source->packet_content(p1); + char *d2 = source->packet_content(p2); + + bool equal = true; + for (size_t i = 0; i < _blk_size / sizeof(unsigned); i++) + if (d1[i] != d2[i]) { + equal = false; + + if (!read_only) + PERR("%zu: %x != %x", i, d1[i], d2[i]); + } + + printf("Comparing block %010zu: ", block); + if (equal) + printf("success\n"); + else { + printf("failed\n"); + dump(p1, p2); + } + } + + void modify(Block::Packet_descriptor &src, Block::Packet_descriptor &dst, int val) + { + Block::Session::Tx::Source *source = _blk_con.tx(); + for (unsigned j = 0; j < _blk_size; j++) + source->packet_content(dst)[j] = source->packet_content(src)[j] + val; + } + + void submit(Block::Packet_descriptor &src, + Block::Packet_descriptor &dst, + int val, Genode::size_t block, bool cmp) + { + Block::Session::Tx::Source *source = _blk_con.tx(); + + source->submit_packet(src); + src = source->get_acked_packet(); + + /* check for success of operation */ + if (!src.succeeded()) { + PWRN("Could not read block %zu", block); + return; + } + + if (cmp) + compare(block, src, dst); + + modify(src, dst, val); + + if (read_only) + return; + + source->submit_packet(dst); + dst = source->get_acked_packet(); + + /* check for success of operation */ + if (!dst.succeeded()) + PWRN("Could not write block %zu", block); + } + /** * Thread's entry function. */ @@ -41,10 +124,9 @@ class Inverter : public Genode::Thread<8192> using namespace Genode; Block::Session::Tx::Source *source = _blk_con.tx(); - size_t blk_size = 0; size_t blk_cnt = 0; Block::Session::Operations ops; - _blk_con.info(&blk_cnt, &blk_size, &ops); + _blk_con.info(&blk_cnt, &_blk_size, &ops); /* check for read- and write-capability */ if (!ops.supported(Block::Packet_descriptor::READ)) { @@ -56,63 +138,45 @@ class Inverter : public Genode::Thread<8192> return; } - PLOG("We have %zu blocks with a size of %zu bytes", - blk_cnt, blk_size); + printf("We have %zu blocks with a size of %zu bytes (%zu MB)\n", + blk_cnt, _blk_size, blk_cnt / (2 * 1024)); /* now, repeatedly invert each single block of the device */ - for (unsigned round = 1; ; ++round) { - PLOG("ROUND %d", round); - for (size_t i = 0; i < blk_cnt; i++) { - try { - /* allocate packet-descriptor for reading */ - Block::Packet_descriptor p(source->alloc_packet(blk_size), - Block::Packet_descriptor::READ, i); - source->submit_packet(p); - p = source->get_acked_packet(); + size_t step = blk_cnt / 32; + for (size_t i = 0; i < blk_cnt; i += step) { + try { + /* allocate packet-descriptor for reading */ + Block::Packet_descriptor p(source->alloc_packet(_blk_size), + Block::Packet_descriptor::READ, i); - /* check for success of operation */ - if (!p.succeeded()) { - PWRN("Could not read block %zu", i); - continue; - } + /* allocate a packet-descriptor for writing */ + Block::Packet_descriptor q(source->alloc_packet(_blk_size), + Block::Packet_descriptor::WRITE, i); - /* allocate a packet-descriptor for writing */ - Block::Packet_descriptor q(source->alloc_packet(blk_size), - Block::Packet_descriptor::WRITE, i); + submit(p, q, 1, i, false); + submit(p, q, -1, i, true); - /* - * Copy inverted bytes of the read-block - * into the packet payload. - */ - for (unsigned j = 0; j < blk_size; j++) - source->packet_content(q)[j] = - ~source->packet_content(p)[j]; - source->submit_packet(q); - q = source->get_acked_packet(); - - /* check for success of operation */ - if (!q.succeeded()) - PWRN("Could not write block %zu", i); - - /* release packets */ - source->release_packet(p); - source->release_packet(q); - } catch (Block::Session::Tx::Source::Packet_alloc_failed) { - PWRN("Mmh, strange we run out of packets"); - source->release_packet(source->get_acked_packet()); - } + /* release packets */ + source->release_packet(q); + source->release_packet(p); + } catch (Block::Session::Tx::Source::Packet_alloc_failed) { + PWRN("Mmh, strange we run out of packets"); + source->release_packet(source->get_acked_packet()); } } + + env()->parent()->close(_blk_con.cap()); + env()->parent()->exit(0); } }; int main(int argc, char **argv) { - Genode::printf("--- Block session test ---\n"); + Genode::printf("--- AHCI block driver test ---\n"); Genode::Allocator_avl block_alloc(Genode::env()->heap()); - Inverter th(&block_alloc); + Worker th(&block_alloc); th.start(); Genode::sleep_forever(); return 0;