diff --git a/repos/base/include/trace_session/client.h b/repos/base/include/trace_session/client.h index b8882e7003..9a1a95ec0d 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;