mirror of
https://github.com/genodelabs/genode.git
synced 2025-04-08 20:05:54 +00:00
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.
This commit is contained in:
parent
5cd099ed90
commit
e1435a3f57
@ -13,7 +13,7 @@ build {
|
||||
drivers/pci
|
||||
drivers/timer
|
||||
drivers/usb
|
||||
test/ahci
|
||||
test/block
|
||||
}
|
||||
|
||||
create_boot_directory
|
||||
@ -55,7 +55,7 @@ set config {
|
||||
</start>
|
||||
<start name="test-usb">
|
||||
<resource name="RAM" quantum="1M" />
|
||||
<binary name="test-ahci" />
|
||||
<binary name="test-block" />
|
||||
</start>
|
||||
</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
|
||||
}
|
||||
|
||||
|
||||
|
@ -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 {
|
||||
<any-service> <parent /> <any-child /></any-service>
|
||||
</route>
|
||||
</start>
|
||||
<start name="test-ahci">
|
||||
<start name="test-block">
|
||||
<resource name="RAM" quantum="2M" />
|
||||
<route>
|
||||
<service name="Block"><child name="ahci"/></service>
|
||||
@ -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
|
||||
}
|
||||
|
||||
|
@ -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 <base/allocator_avl.h>
|
||||
#include <base/printf.h>
|
||||
#include <base/sleep.h>
|
||||
#include <base/thread.h>
|
||||
#include <block_session/connection.h>
|
||||
#include <util/string.h>
|
||||
|
||||
|
||||
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;
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
TARGET = test-ahci
|
||||
LIBS = env cxx signal
|
||||
SRC_CC = 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 <base/sleep.h>
|
||||
#include <base/thread.h>
|
||||
#include <block_session/connection.h>
|
||||
#include <util/string.h>
|
||||
|
||||
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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user