2013-08-10 03:44:55 +02:00
|
|
|
/*
|
|
|
|
* \brief Low-level test for TRACE service
|
|
|
|
* \author Norman Feske
|
|
|
|
* \author Josef Soentgen
|
2017-01-17 12:58:00 +01:00
|
|
|
* \author Martin Stein
|
2013-08-10 03:44:55 +02:00
|
|
|
* \date 2013-08-12
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-01-17 12:58:00 +01:00
|
|
|
* Copyright (C) 2013-2017 Genode Labs GmbH
|
2013-08-10 03:44:55 +02:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 13:23:52 +01:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2013-08-10 03:44:55 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Genode includes */
|
|
|
|
#include <trace_session/connection.h>
|
|
|
|
#include <timer_session/connection.h>
|
2017-01-17 12:58:00 +01:00
|
|
|
#include <base/attached_rom_dataspace.h>
|
|
|
|
#include <base/component.h>
|
|
|
|
#include <base/heap.h>
|
2017-02-27 14:59:41 +01:00
|
|
|
#include <base/sleep.h>
|
2013-08-10 03:44:55 +02:00
|
|
|
|
2017-01-17 12:58:00 +01:00
|
|
|
using namespace Genode;
|
2013-08-10 03:44:55 +02:00
|
|
|
|
|
|
|
|
2017-01-17 12:58:00 +01:00
|
|
|
struct Test_thread : Thread
|
2013-08-10 03:44:55 +02:00
|
|
|
{
|
2017-01-17 12:58:00 +01:00
|
|
|
Env &env;
|
|
|
|
Timer::Connection timer { env };
|
2013-08-10 03:44:55 +02:00
|
|
|
|
2019-02-14 22:39:08 +01:00
|
|
|
void entry() override
|
2013-08-10 03:44:55 +02:00
|
|
|
{
|
2017-01-17 12:58:00 +01:00
|
|
|
for (unsigned i = 0; ; i++) {
|
2013-08-10 03:44:55 +02:00
|
|
|
if (i & 0x3) {
|
2017-01-17 12:58:00 +01:00
|
|
|
Ram_dataspace_capability ds_cap = env.ram().alloc(1024);
|
|
|
|
env.ram().free(ds_cap);
|
2013-08-10 03:44:55 +02:00
|
|
|
}
|
2017-01-17 12:58:00 +01:00
|
|
|
timer.msleep(250);
|
2013-08-10 03:44:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-17 12:58:00 +01:00
|
|
|
Test_thread(Env &env, Name &name)
|
|
|
|
: Thread(env, name, 1024 * sizeof(addr_t)), env(env) { start(); }
|
2013-08-10 03:44:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Trace_buffer_monitor
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
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
|
|
|
/*
|
|
|
|
* Noncopyable
|
|
|
|
*/
|
|
|
|
Trace_buffer_monitor(Trace_buffer_monitor const &);
|
|
|
|
Trace_buffer_monitor &operator = (Trace_buffer_monitor const &);
|
|
|
|
|
|
|
|
static constexpr size_t MAX_ENTRY_BUF = 256;
|
2013-08-10 03:44:55 +02:00
|
|
|
|
2017-01-17 12:58:00 +01:00
|
|
|
char _buf[MAX_ENTRY_BUF];
|
|
|
|
Region_map &_rm;
|
2013-09-19 16:32:31 +02:00
|
|
|
Trace::Subject_id _id;
|
|
|
|
Trace::Buffer *_buffer;
|
2017-01-17 12:58:00 +01:00
|
|
|
Trace::Buffer::Entry _curr_entry;
|
2013-08-10 03:44:55 +02:00
|
|
|
|
2013-09-19 16:32:31 +02:00
|
|
|
const char *_terminate_entry(Trace::Buffer::Entry const &entry)
|
2013-08-10 03:44:55 +02:00
|
|
|
{
|
2013-09-19 16:32:31 +02:00
|
|
|
size_t len = min(entry.length() + 1, MAX_ENTRY_BUF);
|
|
|
|
memcpy(_buf, entry.data(), len);
|
|
|
|
_buf[len-1] = '\0';
|
|
|
|
return _buf;
|
2013-08-10 03:44:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2017-01-17 12:58:00 +01:00
|
|
|
Trace_buffer_monitor(Region_map &rm,
|
|
|
|
Trace::Subject_id id,
|
|
|
|
Dataspace_capability ds_cap)
|
2013-08-10 03:44:55 +02:00
|
|
|
:
|
2017-01-17 12:58:00 +01:00
|
|
|
_rm(rm), _id(id), _buffer(rm.attach(ds_cap)),
|
2013-09-19 16:32:31 +02:00
|
|
|
_curr_entry(_buffer->first())
|
2013-08-10 03:44:55 +02:00
|
|
|
{
|
2017-01-30 11:07:48 +01:00
|
|
|
log("monitor "
|
|
|
|
"subject:", _id.id, " "
|
|
|
|
"buffer:", Hex((addr_t)_buffer));
|
2013-08-10 03:44:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
~Trace_buffer_monitor()
|
|
|
|
{
|
2017-01-30 11:07:48 +01:00
|
|
|
if (_buffer) { _rm.detach(_buffer); }
|
2013-08-10 03:44:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Trace::Subject_id id() { return _id; };
|
|
|
|
|
2013-09-19 16:32:31 +02:00
|
|
|
void dump()
|
2013-08-10 03:44:55 +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
|
|
|
log("overflows: ", _buffer->wrapped());
|
|
|
|
log("read all remaining events");
|
2017-01-30 11:07:48 +01:00
|
|
|
|
2016-05-11 18:21:47 +02:00
|
|
|
for (; !_curr_entry.last(); _curr_entry = _buffer->next(_curr_entry)) {
|
2013-09-19 16:32:31 +02:00
|
|
|
/* omit empty entries */
|
|
|
|
if (_curr_entry.length() == 0)
|
|
|
|
continue;
|
|
|
|
|
2017-01-30 11:07:48 +01:00
|
|
|
char const * const data = _terminate_entry(_curr_entry);
|
|
|
|
if (data) { log(data); }
|
2013-08-10 03:44:55 +02:00
|
|
|
}
|
2017-01-30 11:07:48 +01:00
|
|
|
|
2013-09-19 16:32:31 +02:00
|
|
|
/* reset after we read all available entries */
|
|
|
|
_curr_entry = _buffer->first();
|
2013-08-10 03:44:55 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-01-17 12:58:00 +01:00
|
|
|
struct Test_out_of_metadata
|
2015-06-17 13:25:51 +02:00
|
|
|
{
|
2017-01-17 12:58:00 +01:00
|
|
|
Env &env;
|
2015-06-17 13:25:51 +02:00
|
|
|
|
2017-02-27 14:59:41 +01:00
|
|
|
struct Test_thread : Genode::Thread
|
|
|
|
{
|
2017-03-08 10:45:40 +01:00
|
|
|
Test_thread(Genode::Env &env, const char * name)
|
|
|
|
: Thread(env, Thread::Name(name), 4096) { start(); }
|
2017-02-27 14:59:41 +01:00
|
|
|
|
2017-03-08 10:45:40 +01:00
|
|
|
~Test_thread() { join(); }
|
|
|
|
|
2019-02-14 22:39:08 +01:00
|
|
|
void entry() override { }
|
2017-02-27 14:59:41 +01:00
|
|
|
};
|
|
|
|
|
2017-01-17 12:58:00 +01:00
|
|
|
Test_out_of_metadata(Env &env) : env(env)
|
|
|
|
{
|
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
|
|
|
log("test Out_of_ram exception of Trace::Session::subjects call");
|
2017-01-17 12:58:00 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The call of 'subjects' will prompt core's TRACE service to import those
|
|
|
|
* threads as trace subjects into the TRACE session. This step should fail
|
|
|
|
* because we dimensioned the TRACE session with a very low amount of
|
|
|
|
* session quota. The allocation failure is propagated to the TRACE client
|
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
|
|
|
* by the 'Out_of_ram' exception. The test validates this
|
2017-01-17 12:58:00 +01:00
|
|
|
* error-handling procedure.
|
|
|
|
*/
|
|
|
|
|
|
|
|
enum { MAX_SUBJECT_IDS = 16 };
|
|
|
|
Trace::Subject_id subject_ids[MAX_SUBJECT_IDS];
|
|
|
|
|
|
|
|
try {
|
|
|
|
Trace::Connection trace(env, sizeof(subject_ids) + 4096,
|
|
|
|
sizeof(subject_ids), 0);
|
|
|
|
|
|
|
|
/* we should never arrive here */
|
|
|
|
struct Unexpectedly_got_no_exception{};
|
|
|
|
throw Unexpectedly_got_no_exception();
|
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 (Service_denied) {
|
|
|
|
log("got Service_denied exception as expected"); }
|
2017-01-17 12:58:00 +01:00
|
|
|
|
|
|
|
try {
|
2017-02-27 14:59:41 +01:00
|
|
|
/*
|
|
|
|
* Create multiple threads because on some platforms there
|
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
|
|
|
* are not enough available subjects to trigger the Out_of_ram
|
2017-02-27 14:59:41 +01:00
|
|
|
* exception.
|
|
|
|
*/
|
2017-03-08 10:45:40 +01:00
|
|
|
Test_thread thread1 { env, "test-thread1" };
|
|
|
|
Test_thread thread2 { env, "test-thread2" };
|
|
|
|
Test_thread thread3 { env, "test-thread3" };
|
|
|
|
Test_thread thread4 { env, "test-thread4" };
|
|
|
|
Test_thread thread5 { env, "test-thread5" };
|
2017-02-27 14:59:41 +01:00
|
|
|
|
2017-01-17 12:58:00 +01:00
|
|
|
Trace::Connection trace(env, sizeof(subject_ids) + 5*4096,
|
|
|
|
sizeof(subject_ids), 0);
|
|
|
|
trace.subjects(subject_ids, MAX_SUBJECT_IDS);
|
|
|
|
|
|
|
|
/* we should never arrive here */
|
|
|
|
struct Unexpectedly_got_no_exception{};
|
|
|
|
throw Unexpectedly_got_no_exception();
|
|
|
|
|
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 (Out_of_ram) {
|
|
|
|
log("got Trace::Out_of_ram exception as expected"); }
|
2017-01-17 12:58:00 +01:00
|
|
|
|
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
|
|
|
log("passed Out_of_ram test");
|
2015-06-17 13:25:51 +02:00
|
|
|
}
|
2017-01-17 12:58:00 +01:00
|
|
|
};
|
2015-06-17 13:25:51 +02:00
|
|
|
|
|
|
|
|
2017-01-17 12:58:00 +01:00
|
|
|
struct Test_tracing
|
2013-08-10 03:44:55 +02:00
|
|
|
{
|
2017-01-30 11:07:48 +01:00
|
|
|
Env &env;
|
|
|
|
Attached_rom_dataspace config { env, "config" };
|
|
|
|
Trace::Connection trace { env, 1024*1024, 64*1024, 0 };
|
|
|
|
Timer::Connection timer { env };
|
|
|
|
Test_thread::Name thread_name { "test-thread" };
|
|
|
|
Test_thread thread { env, thread_name };
|
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
|
|
|
Trace::Policy_id policy_id { };
|
2017-01-30 11:07:48 +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
|
|
|
Constructible<Trace_buffer_monitor> test_monitor { };
|
2017-01-30 11:07:48 +01:00
|
|
|
|
|
|
|
typedef Genode::String<64> String;
|
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
|
|
|
String policy_label { };
|
|
|
|
String policy_module { };
|
|
|
|
|
|
|
|
Rom_dataspace_capability policy_module_rom_ds { };
|
2017-01-17 12:58:00 +01:00
|
|
|
|
|
|
|
char const *state_name(Trace::Subject_info::State state)
|
|
|
|
{
|
|
|
|
switch (state) {
|
|
|
|
case Trace::Subject_info::INVALID: return "INVALID";
|
|
|
|
case Trace::Subject_info::UNTRACED: return "UNTRACED";
|
|
|
|
case Trace::Subject_info::TRACED: return "TRACED";
|
|
|
|
case Trace::Subject_info::FOREIGN: return "FOREIGN";
|
|
|
|
case Trace::Subject_info::ERROR: return "ERROR";
|
|
|
|
case Trace::Subject_info::DEAD: return "DEAD";
|
|
|
|
}
|
|
|
|
return "undefined";
|
|
|
|
}
|
2013-08-10 03:44:55 +02:00
|
|
|
|
2017-01-30 11:07:48 +01:00
|
|
|
template <typename FUNC>
|
|
|
|
void for_each_subject(Trace::Subject_id subjects[],
|
|
|
|
size_t max_subjects, FUNC const &func)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < max_subjects; i++) {
|
|
|
|
Trace::Subject_info info = trace.subject_info(subjects[i]);
|
|
|
|
func(subjects[i].id, info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Failed : Genode::Exception { };
|
|
|
|
|
2017-01-17 12:58:00 +01:00
|
|
|
Test_tracing(Env &env) : env(env)
|
|
|
|
{
|
2017-01-30 11:07:48 +01:00
|
|
|
log("test Tracing");
|
|
|
|
|
2017-01-17 12:58:00 +01:00
|
|
|
try {
|
|
|
|
Xml_node policy = config.xml().sub_node("trace_policy");
|
2019-01-21 10:48:39 +01:00
|
|
|
policy.attribute("label").value(policy_label);
|
|
|
|
policy.attribute("module").value(policy_module);
|
2013-08-10 03:44:55 +02:00
|
|
|
|
2017-01-30 11:07:48 +01:00
|
|
|
Rom_connection policy_rom(env, policy_module.string());
|
|
|
|
policy_module_rom_ds = policy_rom.dataspace();
|
2013-08-10 03:44:55 +02:00
|
|
|
|
2017-01-30 11:07:48 +01:00
|
|
|
size_t rom_size = Dataspace_client(policy_module_rom_ds).size();
|
2013-08-10 03:44:55 +02:00
|
|
|
|
2017-01-30 11:07:48 +01:00
|
|
|
policy_id = trace.alloc_policy(rom_size);
|
|
|
|
Dataspace_capability ds_cap = trace.policy(policy_id);
|
2013-08-10 03:44:55 +02:00
|
|
|
|
2017-01-30 11:07:48 +01:00
|
|
|
if (ds_cap.valid()) {
|
|
|
|
void *ram = env.rm().attach(ds_cap);
|
|
|
|
void *rom = env.rm().attach(policy_module_rom_ds);
|
|
|
|
memcpy(ram, rom, rom_size);
|
2013-08-10 03:44:55 +02:00
|
|
|
|
2017-01-30 11:07:48 +01:00
|
|
|
env.rm().detach(ram);
|
|
|
|
env.rm().detach(rom);
|
2017-01-17 12:58:00 +01:00
|
|
|
}
|
2013-08-10 03:44:55 +02:00
|
|
|
|
2017-01-30 11:07:48 +01:00
|
|
|
log("load module: '", policy_module, "' for "
|
|
|
|
"label: '", policy_label, "'");
|
|
|
|
} catch (...) {
|
|
|
|
error("could not load module '", policy_module, "' for "
|
|
|
|
"label '", policy_label, "'");
|
|
|
|
throw Failed();
|
|
|
|
}
|
2013-08-10 03:44:55 +02:00
|
|
|
|
2017-01-30 11:07:48 +01:00
|
|
|
/* wait some time before querying the subjects */
|
|
|
|
timer.msleep(3000);
|
2013-08-10 03:44:55 +02:00
|
|
|
|
2017-01-30 11:07:48 +01:00
|
|
|
Trace::Subject_id subjects[32];
|
|
|
|
size_t num_subjects = trace.subjects(subjects, 32);
|
2013-08-10 03:44:55 +02:00
|
|
|
|
2017-01-30 11:07:48 +01:00
|
|
|
log(num_subjects, " tracing subjects present");
|
2013-08-10 03:44:55 +02:00
|
|
|
|
2017-01-30 11:07:48 +01:00
|
|
|
auto print_info = [this] (Trace::Subject_id id, Trace::Subject_info info) {
|
2013-08-10 03:44:55 +02:00
|
|
|
|
2017-01-30 11:07:48 +01:00
|
|
|
log("ID:", id.id, " "
|
|
|
|
"label:\"", info.session_label(), "\" "
|
|
|
|
"name:\"", info.thread_name(), "\" "
|
|
|
|
"state:", state_name(info.state()), " "
|
|
|
|
"policy:", info.policy_id().id, " "
|
2017-09-11 13:03:28 +02:00
|
|
|
"thread context time:", info.execution_time().thread_context, " "
|
|
|
|
"scheduling context time:", info.execution_time().scheduling_context, " ",
|
|
|
|
"priority:", info.execution_time().priority, " ",
|
|
|
|
"quantum:", info.execution_time().quantum);
|
2017-01-30 11:07:48 +01:00
|
|
|
};
|
2013-08-10 03:44:55 +02:00
|
|
|
|
2017-01-30 11:07:48 +01:00
|
|
|
for_each_subject(subjects, num_subjects, print_info);
|
2013-08-10 03:44:55 +02:00
|
|
|
|
2017-01-30 11:07:48 +01:00
|
|
|
/* enable tracing for test-thread */
|
|
|
|
auto enable_tracing = [this, &env] (Trace::Subject_id id,
|
|
|
|
Trace::Subject_info info) {
|
2013-08-10 03:44:55 +02:00
|
|
|
|
2017-01-30 11:07:48 +01:00
|
|
|
if ( info.session_label() != policy_label
|
|
|
|
|| info.thread_name() != "test-thread") {
|
|
|
|
return;
|
|
|
|
}
|
2013-08-10 03:44:55 +02:00
|
|
|
|
2017-01-30 11:07:48 +01:00
|
|
|
try {
|
|
|
|
log("enable tracing for "
|
|
|
|
"thread:'", info.thread_name().string(), "' with "
|
|
|
|
"policy:", policy_id.id);
|
2013-08-10 03:44:55 +02:00
|
|
|
|
2017-01-30 11:07:48 +01:00
|
|
|
trace.trace(id.id, policy_id, 16384U);
|
2013-08-10 03:44:55 +02:00
|
|
|
|
2017-01-30 11:07:48 +01:00
|
|
|
Dataspace_capability ds_cap = trace.buffer(id.id);
|
|
|
|
test_monitor.construct(env.rm(), id.id, ds_cap);
|
2013-08-10 03:44:55 +02:00
|
|
|
|
2017-01-30 11:07:48 +01:00
|
|
|
} catch (Trace::Source_is_dead) {
|
|
|
|
error("source is dead");
|
|
|
|
throw Failed();
|
2013-08-10 03:44:55 +02:00
|
|
|
}
|
2017-01-30 11:07:48 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
for_each_subject(subjects, num_subjects, enable_tracing);
|
|
|
|
|
|
|
|
/* give the test thread some time to run */
|
|
|
|
timer.msleep(3000);
|
|
|
|
|
|
|
|
for_each_subject(subjects, num_subjects, print_info);
|
|
|
|
|
|
|
|
/* read events from trace buffer */
|
|
|
|
if (test_monitor.constructed()) {
|
|
|
|
test_monitor->dump();
|
|
|
|
test_monitor.destruct();
|
2013-08-10 03:44:55 +02:00
|
|
|
}
|
2017-01-17 12:58:00 +01:00
|
|
|
|
2017-01-30 11:07:48 +01:00
|
|
|
log("passed Tracing test");
|
2013-08-10 03:44:55 +02:00
|
|
|
}
|
2017-01-17 12:58:00 +01:00
|
|
|
};
|
|
|
|
|
2017-01-30 11:07:48 +01:00
|
|
|
|
2017-01-17 12:58:00 +01:00
|
|
|
struct Main
|
|
|
|
{
|
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
|
|
|
Constructible<Test_out_of_metadata> test_1 { };
|
|
|
|
Constructible<Test_tracing> test_2 { };
|
2017-01-17 12:58:00 +01:00
|
|
|
|
|
|
|
Main(Env &env)
|
|
|
|
{
|
2017-05-11 15:36:47 +02:00
|
|
|
// test_1.construct(env);
|
|
|
|
// test_1.destruct();
|
2017-01-17 12:58:00 +01:00
|
|
|
test_2.construct(env);
|
|
|
|
test_2.destruct();
|
2017-01-30 11:07:48 +01:00
|
|
|
|
|
|
|
env.parent().exit(0);
|
2017-01-17 12:58:00 +01:00
|
|
|
}
|
|
|
|
};
|
2013-08-10 03:44:55 +02:00
|
|
|
|
|
|
|
|
2017-01-17 12:58:00 +01:00
|
|
|
void Component::construct(Env &env) { static Main main(env); }
|