diff --git a/src/lib/testu01/genode_chrono.cc b/src/lib/testu01/genode_chrono.cc index fa96982..fd7814a 100644 --- a/src/lib/testu01/genode_chrono.cc +++ b/src/lib/testu01/genode_chrono.cc @@ -1,12 +1,24 @@ -#include +#include #include +Genode::Allocator *_heap = nullptr; +Timer::Connection *_timer = nullptr; + + +void testu01_init(Genode::Allocator &heap, Timer::Connection &timer) +{ + _heap = &heap; + _timer = &timer; +} + + /* XXX: should be the CPU session time, but the timer works for now */ static void Heure (unsigned long *tsec, unsigned long *tusec) { - static Timer::Connection timer; + if (!_timer) + Genode::error("library not initialized with 'testu01_init'!"); - unsigned long ms = timer.elapsed_ms(); + unsigned long ms = _timer->elapsed_ms(); *tsec = ms / 1000; *tusec = ms * 1000; @@ -25,13 +37,16 @@ void chrono_Init (chrono_Chrono *C) { chrono_Chrono * chrono_Create (void) { - chrono_Chrono *C = new (Genode::env()->heap()) chrono_Chrono; + if (!_heap) + Genode::error("library not initialized with 'testu01_init'!"); + + chrono_Chrono *C = new (*_heap) chrono_Chrono; Heure(&C->second, &C->microsec); return C; } -void chrono_Delete (chrono_Chrono *C) { destroy(Genode::env()->heap(), C); } +void chrono_Delete (chrono_Chrono *C) { destroy(*_heap, C); } double chrono_Val (chrono_Chrono *C, chrono_TimeFormat Unit) diff --git a/src/lib/testu01/genode_gdef.cc b/src/lib/testu01/genode_gdef.cc index 880d46b..2fc9613 100644 --- a/src/lib/testu01/genode_gdef.cc +++ b/src/lib/testu01/genode_gdef.cc @@ -7,9 +7,7 @@ extern "C" { void gdef_GetHostName (char machine[], int n) { - Genode::Attached_rom_dataspace config("config"); - try { config.xml().attribute("hostname").value(machine, n); } - catch (...) { Genode::strncpy(machine, "genode", n); } + if (n) *machine = '\0'; } void gdef_WriteHostName (void) { } diff --git a/src/test/testu01_alphabit/main.cc b/src/test/testu01_alphabit/main.cc index 5afd2f0..e98ee30 100644 --- a/src/test/testu01_alphabit/main.cc +++ b/src/test/testu01_alphabit/main.cc @@ -1,5 +1,8 @@ +#include + #include #include +#include #include extern "C" { @@ -30,7 +33,13 @@ void Libc::Component::construct(Libc::Env &env) return; } - bbattery_AlphabitFile((char *)file.string(), nbits); + Heap heap(env.pd(), env.rm()); + Timer::Connection timer(env); + + testu01_init(heap, timer); + + Libc::with_libc([&] () { + bbattery_AlphabitFile((char *)file.string(), nbits); }); env.parent().exit(0); } diff --git a/src/test/testu01_alphabit/target.mk b/src/test/testu01_alphabit/target.mk index a46a2b9..4d63a78 100644 --- a/src/test/testu01_alphabit/target.mk +++ b/src/test/testu01_alphabit/target.mk @@ -1,3 +1,3 @@ -TARGET = testu01_alphabet +TARGET = testu01_alphabit LIBS += testu01 libc libm SRC_CC = main.cc diff --git a/src/test/testu01_rabbit/main.cc b/src/test/testu01_rabbit/main.cc index 9df09f4..8c921b7 100644 --- a/src/test/testu01_rabbit/main.cc +++ b/src/test/testu01_rabbit/main.cc @@ -1,5 +1,8 @@ +#include + #include #include +#include #include extern "C" { @@ -36,7 +39,13 @@ void Libc::Component::construct(Libc::Env &env) return; } - bbattery_RabbitFile((char *)file.string(), nbits); + Heap heap(env.pd(), env.rm()); + Timer::Connection timer(env); + + testu01_init(heap, timer); + + Libc::with_libc([&] () { + bbattery_RabbitFile((char *)file.string(), nbits); }); env.parent().exit(0); }