From 5d678dba9edd6e45c5657b27a09b34592572ae6e Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Wed, 17 Jun 2015 13:25:51 +0200 Subject: [PATCH] core: throw Trace::Out_of_metadata in subjects() While importing trace sources as trace subjects into a TRACE session, the session quota might become depleted. The TRACE session already keeps track of the session quota via an allocator guard but the 'subjects' RPC function missed to handle the out-of-memory condition. This patch reflects the error condition as an 'Out_of_metadata' exception to the TRACE client. It also contains an extension of the trace test to exercise the corner case. --- repos/base/include/trace_session/client.h | 2 ++ .../include/trace_session/trace_session.h | 3 +- .../base/src/core/trace_session_component.cc | 11 ++++-- repos/os/src/test/trace/main.cc | 36 +++++++++++++++++++ 4 files changed, 49 insertions(+), 3 deletions(-) diff --git a/repos/base/include/trace_session/client.h b/repos/base/include/trace_session/client.h index b8882e700..9a1a95ec0 100644 --- a/repos/base/include/trace_session/client.h +++ b/repos/base/include/trace_session/client.h @@ -61,6 +61,8 @@ struct Genode::Trace::Session_client : Genode::Rpc_client #include #include +#include static char const *state_name(Genode::Trace::Subject_info::State state) { @@ -117,12 +118,47 @@ class Trace_buffer_monitor }; +static void test_out_of_metadata() +{ + printf("test Out_of_metadata exception of Trace::Session::subjects call\n"); + + /* + * 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 + * by the 'Out_of_metadata' exception. The test validates this + * error-handling procedure. + */ + + enum { MAX_SUBJECT_IDS = 16 }; + Genode::Trace::Subject_id subject_ids[MAX_SUBJECT_IDS]; + + Genode::Trace::Connection trace(sizeof(subject_ids) + 4096, sizeof(subject_ids), 0); + + try { + trace.subjects(subject_ids, MAX_SUBJECT_IDS); + + /* we should never arrive here */ + struct Unexpectedly_got_no_exception{}; + throw Unexpectedly_got_no_exception(); + + } catch (Trace::Out_of_metadata) { + printf("got Trace::Out_of_metadata exception as expected\n"); + } + + printf("passed Out_of_metadata test\n"); +} + + int main(int argc, char **argv) { using namespace Genode; printf("--- test-trace started ---\n"); + test_out_of_metadata(); + static Genode::Trace::Connection trace(1024*1024, 64*1024, 0); static Timer::Connection timer;