Limit max string length in log session for okl4

This commit also adds a test to test-log.
This commit is contained in:
Christian Helmuth
2017-10-06 16:50:01 +02:00
parent 487162a53d
commit 0da420c104
3 changed files with 30 additions and 3 deletions

View File

@ -1,5 +1,5 @@
/*
* \brief Testing 'log()' with negative integer
* \brief Testing 'Genode::log()' and LOG session
* \author Christian Prochaska
* \date 2012-04-20
*
@ -14,6 +14,7 @@
#include <base/component.h>
#include <base/log.h>
#include <log_session/connection.h>
void Component::construct(Genode::Env &env)
@ -33,5 +34,26 @@ void Component::construct(Genode::Env &env)
String<32> hex(Hex(3));
log("String(Hex(3)): ", hex);
log("Very long messages:");
static char buf[2*Log_session::MAX_STRING_LEN];
/* test writing of message with length = MAX_STRING_LEN with LOG connection */
for (char &c : buf) c = '.';
buf[0] = '1'; /* begin of line */
buf[Log_session::MAX_STRING_LEN - 2] = '2'; /* last visible */
buf[Log_session::MAX_STRING_LEN - 1] = '\0'; /* end of line */
Log_connection log_connection { env, "log" };
log_connection.write(buf);
/* test splitting of message with length > MAX_STRING_LEN with 'Genode::log()' */
for (char &c : buf) c = '.';
buf[0] = '3'; /* begin of first line */
buf[Log_session::MAX_STRING_LEN - 2] = '4'; /* last visible before flushed */
buf[Log_session::MAX_STRING_LEN - 1] = '5'; /* first after flush */
buf[2*Log_session::MAX_STRING_LEN - 3] = '6'; /* last visible before flushed */
buf[2*Log_session::MAX_STRING_LEN - 2] = '\0'; /* end of second line */
log(Cstring(buf));
log("Test done.");
}