Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
/*
|
2013-12-13 11:54:50 +01:00
|
|
|
* \brief Block session tests - client side.
|
|
|
|
* \author Stefan Kalkowski
|
|
|
|
* \date 2013-12-10
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <base/allocator_avl.h>
|
2016-08-12 15:10:50 +02:00
|
|
|
#include <base/attached_rom_dataspace.h>
|
|
|
|
#include <base/component.h>
|
|
|
|
#include <base/heap.h>
|
|
|
|
#include <base/log.h>
|
2013-12-13 11:54:50 +01:00
|
|
|
#include <block_session/connection.h>
|
|
|
|
#include <timer_session/connection.h>
|
|
|
|
#include <os/ring_buffer.h>
|
|
|
|
|
2019-04-03 16:05:10 +02:00
|
|
|
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 bool writeable;
|
2013-12-13 11:54:50 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Virtual base class of all test scenarios, provides basic signal handling
|
|
|
|
*/
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
class Test : Genode::Interface
|
2013-12-13 11:54:50 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
struct Exception : private Genode::Exception, Genode::Interface
|
2013-12-13 11:54:50 +01:00
|
|
|
{
|
|
|
|
virtual void print_error() = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Block_exception : public Exception
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
|
|
|
|
Block::sector_t _nr;
|
|
|
|
Genode::size_t _cnt;
|
|
|
|
bool _write;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
Block_exception(Block::sector_t nr, Genode::size_t cnt,
|
|
|
|
bool write)
|
|
|
|
: _nr(nr), _cnt(cnt), _write(write) {}
|
|
|
|
|
2019-02-14 22:39:08 +01:00
|
|
|
void print_error() override
|
2016-08-12 15:10:50 +02:00
|
|
|
{
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
Genode::error("couldn't ", _write ? "write" : "read", " "
|
|
|
|
"block ", _nr, " - ", _nr+_cnt);
|
2016-08-12 15:10:50 +02:00
|
|
|
}
|
2013-12-13 11:54:50 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Submit_queue_full : Exception {
|
2019-02-14 22:39:08 +01:00
|
|
|
void print_error() override {
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
Genode::error("submit queue is full!"); } };
|
2013-12-13 11:54:50 +01:00
|
|
|
|
|
|
|
struct Timeout : Exception {
|
2019-02-14 22:39:08 +01:00
|
|
|
void print_error() override {
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
Genode::error("test timed out!"); } };
|
2013-12-13 11:54:50 +01:00
|
|
|
|
|
|
|
virtual void perform() = 0;
|
|
|
|
virtual void ack_avail() = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
Genode::Entrypoint &_ep;
|
|
|
|
Genode::Allocator_avl _alloc;
|
|
|
|
Block::Connection _session;
|
|
|
|
|
2017-04-03 10:45:51 +02:00
|
|
|
Genode::Io_signal_handler<Test> _disp_ack;
|
|
|
|
Genode::Io_signal_handler<Test> _disp_submit;
|
|
|
|
Genode::Io_signal_handler<Test> _disp_timeout;
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
|
|
|
|
Timer::Connection _timer;
|
|
|
|
bool _handle = false;
|
2013-12-13 11:54:50 +01:00
|
|
|
|
|
|
|
Genode::size_t _shared_buffer_size(Genode::size_t bulk)
|
|
|
|
{
|
|
|
|
return bulk +
|
|
|
|
sizeof(Block::Session::Tx_policy::Ack_queue) +
|
2013-12-18 16:13:29 +01:00
|
|
|
sizeof(Block::Session::Tx_policy::Submit_queue) +
|
|
|
|
(1 << Block::Packet_descriptor::PACKET_ALIGNMENT) - 1;
|
2013-12-13 11:54:50 +01:00
|
|
|
}
|
|
|
|
|
2016-08-12 15:10:50 +02:00
|
|
|
void _ack_avail() { ack_avail(); }
|
|
|
|
void _ready_to_submit() { _handle = false; }
|
|
|
|
void _timeout() { throw Timeout(); }
|
2013-12-13 11:54:50 +01:00
|
|
|
|
2017-01-06 15:38:25 +01:00
|
|
|
Test(Genode::Env &env,
|
2016-08-12 15:10:50 +02:00
|
|
|
Genode::Heap &heap,
|
|
|
|
Genode::size_t bulk_buffer_size,
|
2013-12-13 11:54:50 +01:00
|
|
|
unsigned timeout_ms)
|
2017-01-06 15:38:25 +01:00
|
|
|
: _ep(env.ep()),
|
2016-08-12 15:10:50 +02:00
|
|
|
_alloc(&heap),
|
2017-01-06 15:38:25 +01:00
|
|
|
_session(env, &_alloc, _shared_buffer_size(bulk_buffer_size)),
|
|
|
|
_disp_ack(env.ep(), *this, &Test::_ack_avail),
|
|
|
|
_disp_submit(env.ep(), *this, &Test::_ready_to_submit),
|
|
|
|
_disp_timeout(env.ep(), *this, &Test::_timeout),
|
|
|
|
_timer(env)
|
2013-12-13 11:54:50 +01:00
|
|
|
{
|
|
|
|
_session.tx_channel()->sigh_ack_avail(_disp_ack);
|
|
|
|
_session.tx_channel()->sigh_ready_to_submit(_disp_submit);
|
|
|
|
|
|
|
|
if (timeout_ms) {
|
|
|
|
_timer.sigh(_disp_timeout);
|
|
|
|
_timer.trigger_once(1000*timeout_ms);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void _handle_signal()
|
|
|
|
{
|
|
|
|
_handle = true;
|
2017-04-03 10:45:51 +02:00
|
|
|
while (_handle) _ep.wait_and_dispatch_one_io_signal();
|
2013-12-13 11:54:50 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template <unsigned BULK_BLK_NR, unsigned NR_PER_REQ>
|
|
|
|
struct Read_test : Test
|
|
|
|
{
|
|
|
|
bool done;
|
|
|
|
|
2017-01-06 15:38:25 +01:00
|
|
|
Read_test(Genode::Env &env, Genode::Heap &heap, unsigned timeo_ms)
|
|
|
|
: Test(env, heap, BULK_BLK_NR*blk_sz, timeo_ms), done(false) { }
|
2013-12-13 11:54:50 +01:00
|
|
|
|
2019-02-14 22:39:08 +01:00
|
|
|
void perform() override
|
2013-12-13 11:54:50 +01:00
|
|
|
{
|
2016-08-12 15:10:50 +02:00
|
|
|
Genode::log("reading block 0 - ", test_cnt - 1, ", ", NR_PER_REQ,
|
|
|
|
" per request");
|
2013-12-13 11:54:50 +01:00
|
|
|
|
2015-05-07 13:09:25 +02:00
|
|
|
for (Block::sector_t nr = 0, cnt = NR_PER_REQ; nr < test_cnt;
|
2013-12-13 11:54:50 +01:00
|
|
|
nr += cnt) {
|
|
|
|
|
|
|
|
while (!_session.tx()->ready_to_submit())
|
|
|
|
_handle_signal();
|
|
|
|
|
2015-05-07 13:09:25 +02:00
|
|
|
cnt = Genode::min<Block::sector_t>(NR_PER_REQ, test_cnt-nr);
|
2013-12-13 11:54:50 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
Block::Packet_descriptor p(
|
|
|
|
_session.dma_alloc_packet(cnt*blk_sz),
|
|
|
|
Block::Packet_descriptor::READ, nr, cnt);
|
|
|
|
_session.tx()->submit_packet(p);
|
|
|
|
} catch(Block::Session::Tx::Source::Packet_alloc_failed) {
|
|
|
|
cnt = 0; /* retry the current block number */
|
|
|
|
_handle_signal();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (!done)
|
|
|
|
_handle_signal();
|
|
|
|
}
|
|
|
|
|
2019-02-14 22:39:08 +01:00
|
|
|
void ack_avail() override
|
2013-12-13 11:54:50 +01:00
|
|
|
{
|
|
|
|
_handle = false;
|
|
|
|
|
|
|
|
while (_session.tx()->ack_avail()) {
|
|
|
|
Block::Packet_descriptor p = _session.tx()->get_acked_packet();
|
|
|
|
|
|
|
|
if (!p.succeeded())
|
|
|
|
throw Block_exception(p.block_number(), p.block_count(),
|
|
|
|
false);
|
|
|
|
|
2015-05-07 13:09:25 +02:00
|
|
|
if ((p.block_number() + p.block_count()) == test_cnt)
|
2013-12-13 11:54:50 +01:00
|
|
|
done = true;
|
|
|
|
|
|
|
|
_session.tx()->release_packet(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template <unsigned BULK_BLK_NR, unsigned NR_PER_REQ, unsigned BATCH>
|
|
|
|
struct Write_test : Test
|
|
|
|
{
|
|
|
|
struct Invalid_dimensions : Exception {
|
2019-02-14 22:39:08 +01:00
|
|
|
void print_error() override {
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
Genode::error("invalid bulk buffer, or batch size!"); } };
|
2013-12-13 11:54:50 +01:00
|
|
|
|
|
|
|
struct Integrity_exception : Block_exception
|
|
|
|
{
|
|
|
|
Integrity_exception(Block::sector_t nr, Genode::size_t cnt)
|
|
|
|
: Block_exception(nr, cnt, false) {}
|
|
|
|
|
2019-02-14 22:39:08 +01:00
|
|
|
void print_error() override
|
2016-08-12 15:10:50 +02:00
|
|
|
{
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
Genode::error("integrity check failed: block ", _nr, " - ",
|
2016-08-12 15:10:50 +02:00
|
|
|
_nr+_cnt);
|
|
|
|
}
|
2013-12-13 11:54:50 +01:00
|
|
|
};
|
|
|
|
|
2015-04-14 10:51:53 +02:00
|
|
|
typedef Genode::Ring_buffer<Block::Packet_descriptor, BATCH+1,
|
|
|
|
Genode::Ring_buffer_unsynchronized> Req_buffer;
|
2013-12-13 11:54:50 +01:00
|
|
|
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
Req_buffer read_packets { };
|
|
|
|
Req_buffer write_packets { };
|
2013-12-13 11:54:50 +01:00
|
|
|
|
2017-01-06 15:38:25 +01:00
|
|
|
Write_test(Genode::Env &env, Genode::Heap &heap, unsigned timeo_ms)
|
|
|
|
: Test(env, heap, BULK_BLK_NR*blk_sz, timeo_ms)
|
2013-12-13 11:54:50 +01:00
|
|
|
{
|
|
|
|
if (BULK_BLK_NR < BATCH*NR_PER_REQ ||
|
|
|
|
BATCH > Block::Session::TX_QUEUE_SIZE ||
|
|
|
|
BULK_BLK_NR % BATCH != 0)
|
|
|
|
throw Invalid_dimensions();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool compare(Block::Packet_descriptor &r, Block::Packet_descriptor &w)
|
|
|
|
{
|
|
|
|
signed char *dst = (signed char*)_session.tx()->packet_content(w),
|
|
|
|
*src = (signed char*)_session.tx()->packet_content(r);
|
|
|
|
for (Genode::size_t i = 0; i < blk_sz; i++)
|
|
|
|
if (dst[i] != src[i])
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void compare()
|
|
|
|
{
|
|
|
|
while (!read_packets.empty()) {
|
|
|
|
Block::Packet_descriptor r = read_packets.get();
|
|
|
|
while (true) {
|
|
|
|
Block::Packet_descriptor w = write_packets.get();
|
|
|
|
if (r.block_number() == w.block_number()) {
|
|
|
|
if (!compare(r,w))
|
|
|
|
throw Integrity_exception(r.block_number(),
|
|
|
|
r.block_count());
|
2015-05-07 13:09:25 +02:00
|
|
|
|
|
|
|
_session.tx()->release_packet(w);
|
2013-12-13 11:54:50 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
write_packets.add(w);
|
|
|
|
}
|
2015-05-07 13:09:25 +02:00
|
|
|
_session.tx()->release_packet(r);
|
2013-12-13 11:54:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void write(signed char val)
|
|
|
|
{
|
|
|
|
while (!read_packets.empty()) {
|
|
|
|
Block::Packet_descriptor r = read_packets.get();
|
|
|
|
Block::Packet_descriptor w(_session.dma_alloc_packet(r.block_count()
|
|
|
|
*blk_sz),
|
|
|
|
Block::Packet_descriptor::WRITE,
|
|
|
|
r.block_number(), r.block_count());
|
|
|
|
signed char *dst = (signed char*)_session.tx()->packet_content(w),
|
|
|
|
*src = (signed char*)_session.tx()->packet_content(r);
|
|
|
|
for (Genode::size_t i = 0; i < blk_sz; i++)
|
|
|
|
dst[i] = src[i] + val;
|
|
|
|
_session.tx()->submit_packet(w);
|
2015-05-07 13:09:25 +02:00
|
|
|
_session.tx()->release_packet(r);
|
2013-12-13 11:54:50 +01:00
|
|
|
}
|
|
|
|
while (write_packets.avail_capacity())
|
|
|
|
_handle_signal();
|
|
|
|
}
|
|
|
|
|
|
|
|
void read(Block::sector_t start, Block::sector_t end)
|
|
|
|
{
|
|
|
|
using namespace Block;
|
|
|
|
|
2015-05-07 13:09:25 +02:00
|
|
|
for (sector_t nr = start, cnt = Genode::min(NR_PER_REQ, end - start); nr < end;
|
|
|
|
nr += cnt,
|
|
|
|
cnt = Genode::min<sector_t>(NR_PER_REQ, end-nr)) {
|
2013-12-13 11:54:50 +01:00
|
|
|
Block::Packet_descriptor p(_session.dma_alloc_packet(cnt*blk_sz),
|
|
|
|
Block::Packet_descriptor::READ, nr, cnt);
|
|
|
|
_session.tx()->submit_packet(p);
|
|
|
|
}
|
|
|
|
while (read_packets.avail_capacity())
|
|
|
|
_handle_signal();
|
|
|
|
}
|
|
|
|
|
|
|
|
void batch(Block::sector_t start, Block::sector_t end, signed char val)
|
|
|
|
{
|
|
|
|
read(start, end);
|
|
|
|
write(val);
|
|
|
|
read(start, end);
|
|
|
|
compare();
|
|
|
|
}
|
|
|
|
|
2019-02-14 22:39:08 +01:00
|
|
|
void perform() override
|
2013-12-13 11:54:50 +01:00
|
|
|
{
|
2019-04-03 16:05:10 +02:00
|
|
|
if (!writeable)
|
2013-12-13 11:54:50 +01:00
|
|
|
return;
|
|
|
|
|
2016-08-12 15:10:50 +02:00
|
|
|
Genode::log("read/write/compare block 0 - ", test_cnt - 1,
|
|
|
|
", ", NR_PER_REQ, " per request");
|
2013-12-13 11:54:50 +01:00
|
|
|
|
2015-05-07 13:09:25 +02:00
|
|
|
for (Block::sector_t nr = 0, cnt = BATCH*NR_PER_REQ; nr < test_cnt;
|
|
|
|
nr += cnt,
|
|
|
|
cnt = Genode::min<Block::sector_t>(BATCH*NR_PER_REQ, test_cnt-nr)) {
|
2013-12-13 11:54:50 +01:00
|
|
|
batch(nr, nr + cnt, 1);
|
|
|
|
batch(nr, nr + cnt, -1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-14 22:39:08 +01:00
|
|
|
void ack_avail() override
|
2013-12-13 11:54:50 +01:00
|
|
|
{
|
|
|
|
_handle = false;
|
|
|
|
|
|
|
|
while (_session.tx()->ack_avail()) {
|
|
|
|
Block::Packet_descriptor p = _session.tx()->get_acked_packet();
|
|
|
|
bool write = p.operation() == Block::Packet_descriptor::WRITE;
|
|
|
|
if (!p.succeeded())
|
|
|
|
throw Block_exception(p.block_number(), p.block_count(), write);
|
|
|
|
if (write)
|
|
|
|
write_packets.add(p);
|
|
|
|
else
|
|
|
|
read_packets.add(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct Violation_test : Test
|
|
|
|
{
|
|
|
|
struct Write_on_read_only : Exception {
|
2019-02-14 22:39:08 +01:00
|
|
|
void print_error() override {
|
2016-08-12 15:10:50 +02:00
|
|
|
Genode::error("write on read-only device succeeded!"); } };
|
2013-12-13 11:54:50 +01:00
|
|
|
|
|
|
|
struct Range_check_failed : Block_exception
|
|
|
|
{
|
|
|
|
Range_check_failed(Block::sector_t nr, Genode::size_t cnt)
|
|
|
|
: Block_exception(nr, cnt, false) {}
|
|
|
|
|
2019-02-14 22:39:08 +01:00
|
|
|
void print_error() override
|
2016-08-12 15:10:50 +02:00
|
|
|
{
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
Genode::error("range check failed: access to block ", _nr,
|
2016-08-12 15:10:50 +02:00
|
|
|
" - ", _nr+_cnt, " succeeded");
|
|
|
|
}
|
2013-12-13 11:54:50 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
int p_in_fly;
|
|
|
|
|
2017-01-06 15:38:25 +01:00
|
|
|
Violation_test(Genode::Env &env, Genode::Heap &heap, unsigned timeo)
|
|
|
|
: Test(env, heap, 20*blk_sz, timeo), p_in_fly(0) {}
|
2013-12-13 11:54:50 +01:00
|
|
|
|
|
|
|
void req(Block::sector_t nr, Genode::size_t cnt, bool write)
|
|
|
|
{
|
|
|
|
Block::Packet_descriptor p(_session.dma_alloc_packet(blk_sz),
|
|
|
|
write ? Block::Packet_descriptor::WRITE
|
|
|
|
: Block::Packet_descriptor::READ,
|
|
|
|
nr, cnt);
|
|
|
|
_session.tx()->submit_packet(p);
|
|
|
|
p_in_fly++;
|
|
|
|
}
|
|
|
|
|
2019-02-14 22:39:08 +01:00
|
|
|
void perform() override
|
2013-12-13 11:54:50 +01:00
|
|
|
{
|
2019-04-03 16:05:10 +02:00
|
|
|
if (!writeable)
|
2013-12-13 11:54:50 +01:00
|
|
|
req(0, 1, true);
|
|
|
|
|
|
|
|
req(blk_cnt, 1, false);
|
|
|
|
req(blk_cnt-1, 2, false);
|
|
|
|
|
|
|
|
while (p_in_fly > 0)
|
|
|
|
_handle_signal();
|
|
|
|
}
|
|
|
|
|
2019-02-14 22:39:08 +01:00
|
|
|
void ack_avail() override
|
2013-12-13 11:54:50 +01:00
|
|
|
{
|
|
|
|
_handle = false;
|
|
|
|
|
|
|
|
while (_session.tx()->ack_avail()) {
|
|
|
|
Block::Packet_descriptor p = _session.tx()->get_acked_packet();
|
|
|
|
if (p.succeeded()) {
|
|
|
|
if (p.operation() == Block::Packet_descriptor::WRITE)
|
|
|
|
throw Write_on_read_only();
|
|
|
|
throw Range_check_failed(p.block_number(), p.block_count());
|
|
|
|
}
|
|
|
|
_session.tx()->release_packet(p);
|
|
|
|
p_in_fly--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template <typename TEST>
|
2017-01-06 15:38:25 +01:00
|
|
|
void perform(Genode::Env &env, Genode::Heap &heap, unsigned timeo_ms = 0)
|
2013-12-13 11:54:50 +01:00
|
|
|
{
|
2017-01-06 15:38:25 +01:00
|
|
|
TEST * test = new (&heap) TEST(env, heap, timeo_ms);
|
2016-08-12 15:10:50 +02:00
|
|
|
test->perform();
|
|
|
|
destroy(&heap, test);
|
2013-12-13 11:54:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-12 15:10:50 +02:00
|
|
|
void Component::construct(Genode::Env &env)
|
2013-12-13 11:54:50 +01:00
|
|
|
{
|
2017-03-15 15:40:55 +01:00
|
|
|
/* XXX execute constructors of global statics */
|
|
|
|
env.exec_static_constructors();
|
|
|
|
|
2016-08-12 15:10:50 +02:00
|
|
|
using namespace Genode;
|
|
|
|
|
2013-12-13 11:54:50 +01:00
|
|
|
try {
|
2016-08-12 15:10:50 +02:00
|
|
|
|
|
|
|
static Heap heap(env.ram(), env.rm());
|
|
|
|
|
2013-12-13 11:54:50 +01:00
|
|
|
/**
|
|
|
|
* First we ask for the block size of the driver to dimension
|
|
|
|
* the queue size for our tests. Moreover, we implicitely test,
|
|
|
|
* whether closing and opening again works for the driver
|
|
|
|
*/
|
|
|
|
{
|
2016-08-12 15:10:50 +02:00
|
|
|
Allocator_avl alloc(&heap);
|
2017-01-06 15:38:25 +01:00
|
|
|
Block::Connection blk(env, &alloc);
|
2019-04-03 16:05:10 +02:00
|
|
|
|
|
|
|
Block::Session::Info const info { blk.info() };
|
|
|
|
|
|
|
|
blk_sz = info.block_size;
|
|
|
|
blk_cnt = info.block_count;
|
|
|
|
writeable = info.writeable;
|
2013-12-13 11:54:50 +01:00
|
|
|
}
|
|
|
|
|
2015-05-07 13:09:25 +02:00
|
|
|
try {
|
|
|
|
Genode::Number_of_bytes test_size;;
|
2016-08-12 15:10:50 +02:00
|
|
|
Genode::Attached_rom_dataspace config { env, "config" };
|
2019-01-21 10:48:39 +01:00
|
|
|
config.xml().attribute("test_size").value(test_size);
|
2015-05-07 13:09:25 +02:00
|
|
|
test_cnt = Genode::min(test_size / blk_sz, blk_cnt);
|
|
|
|
} catch (...) { test_cnt = blk_cnt; }
|
|
|
|
|
|
|
|
/* must be multiple of 16 */
|
|
|
|
test_cnt &= ~0xfLLU;
|
|
|
|
|
2016-08-12 15:10:50 +02:00
|
|
|
log("block device with block size ", blk_sz, " sector count ",
|
|
|
|
blk_cnt, " (testing ", test_cnt, " sectors)");
|
2013-12-13 11:54:50 +01:00
|
|
|
|
|
|
|
perform<Read_test<Block::Session::TX_QUEUE_SIZE-10,
|
2017-01-06 15:38:25 +01:00
|
|
|
Block::Session::TX_QUEUE_SIZE-10> >(env, heap);
|
|
|
|
perform<Read_test<Block::Session::TX_QUEUE_SIZE*5, 1> >(env, heap);
|
|
|
|
perform<Read_test<Block::Session::TX_QUEUE_SIZE, 1> >(env, heap);
|
|
|
|
perform<Write_test<Block::Session::TX_QUEUE_SIZE, 8, 16> >(env, heap);
|
|
|
|
perform<Violation_test>(env, heap, 1000);
|
2013-12-13 11:54:50 +01:00
|
|
|
|
2016-08-12 15:10:50 +02:00
|
|
|
log("Tests finished successfully!");
|
Streamline exception types
This patch reduces the number of exception types by facilitating
globally defined exceptions for common usage patterns shared by most
services. In particular, RPC functions that demand a session-resource
upgrade not longer reflect this condition via a session-specific
exception but via the 'Out_of_ram' or 'Out_of_caps' types.
Furthermore, the 'Parent::Service_denied', 'Parent::Unavailable',
'Root::Invalid_args', 'Root::Unavailable', 'Service::Invalid_args',
'Service::Unavailable', and 'Local_service::Factory::Denied' types have
been replaced by the single 'Service_denied' exception type defined in
'session/session.h'.
This consolidation eases the error handling (there are fewer exceptions
to handle), alleviates the need to convert exceptions along the
session-creation call chain, and avoids possible aliasing problems
(catching the wrong type with the same name but living in a different
scope).
2017-05-07 22:03:22 +02:00
|
|
|
}
|
|
|
|
catch (Genode::Service_denied) {
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
error("opening block session was denied!");
|
Streamline exception types
This patch reduces the number of exception types by facilitating
globally defined exceptions for common usage patterns shared by most
services. In particular, RPC functions that demand a session-resource
upgrade not longer reflect this condition via a session-specific
exception but via the 'Out_of_ram' or 'Out_of_caps' types.
Furthermore, the 'Parent::Service_denied', 'Parent::Unavailable',
'Root::Invalid_args', 'Root::Unavailable', 'Service::Invalid_args',
'Service::Unavailable', and 'Local_service::Factory::Denied' types have
been replaced by the single 'Service_denied' exception type defined in
'session/session.h'.
This consolidation eases the error handling (there are fewer exceptions
to handle), alleviates the need to convert exceptions along the
session-creation call chain, and avoids possible aliasing problems
(catching the wrong type with the same name but living in a different
scope).
2017-05-07 22:03:22 +02:00
|
|
|
}
|
|
|
|
catch (Test::Exception &e) {
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
error("test failed!");
|
2013-12-13 11:54:50 +01:00
|
|
|
e.print_error();
|
|
|
|
}
|
|
|
|
}
|
2016-08-12 15:10:50 +02:00
|
|
|
|