diff --git a/repos/base/run/new_delete.run b/repos/base/run/new_delete.run
index acf198114b..3d7f6c8c7d 100644
--- a/repos/base/run/new_delete.run
+++ b/repos/base/run/new_delete.run
@@ -21,7 +21,7 @@ build_boot_image "core ld.lib.so init test-new_delete"
append qemu_args "-nographic -m 64"
-run_genode_until {child "test-new_delete" exited with exit value 0.*\n} 15
+run_genode_until "Test done.*\n" 15
grep_output {^\[init -> test-new_delete\]}
diff --git a/repos/base/run/rm_nested.run b/repos/base/run/rm_nested.run
index dc45f64927..88482df463 100644
--- a/repos/base/run/rm_nested.run
+++ b/repos/base/run/rm_nested.run
@@ -28,4 +28,4 @@ build_boot_image "core ld.lib.so init test-rm_nested"
append qemu_args "-nographic -m 64"
-run_genode_until {child "test-rm_nested" exited with exit value 0.*} 300
+run_genode_until ".*--- finished nested region map test ---.*\n" 300
diff --git a/repos/base/run/slab.run b/repos/base/run/slab.run
index bcc4d62ae0..5332fa7938 100644
--- a/repos/base/run/slab.run
+++ b/repos/base/run/slab.run
@@ -32,6 +32,6 @@ build_boot_image "core ld.lib.so init timer test-slab"
append qemu_args "-nographic -m 128"
-run_genode_until {child "test-slab" exited with exit value 0.*\n} 100
+run_genode_until "Test done.*\n" 100
puts "Test succeeded"
diff --git a/repos/base/src/test/fpu/main.cc b/repos/base/src/test/fpu/main.cc
index a323a8b2ad..a521bc40b2 100644
--- a/repos/base/src/test/fpu/main.cc
+++ b/repos/base/src/test/fpu/main.cc
@@ -12,39 +12,20 @@
*/
/* Genode includes */
-#include
-#include
+#include
+#include
#include
+#include
using namespace Genode;
-class Sync_signal_transmitter : public Signal_transmitter
+class Fpu_user : public Thread
{
private:
- Lock _lock;
-
- public:
-
- Sync_signal_transmitter(Signal_context_capability context = Signal_context_capability())
- :
- Signal_transmitter(context),
- _lock(Lock::UNLOCKED)
- { }
-
- void submit(unsigned cnt)
- {
- Lock::Guard guard(_lock);
- Signal_transmitter::submit(cnt);
- }
-};
-
-class Fpu_user : public Thread_deprecated<0x2000>
-{
- private:
-
- float _x;
- Sync_signal_transmitter * _st;
+ float _x;
+ Signal_transmitter _st;
+ Semaphore & _sem;
void _calc(float volatile & x, float volatile & y)
{
@@ -56,59 +37,50 @@ class Fpu_user : public Thread_deprecated<0x2000>
public:
- Fpu_user() : Thread_deprecated("fpu_user"), _x(0), _st(0) { }
-
- void start(float const x, Sync_signal_transmitter * const st)
- {
- _x = x;
- _st = st;
- Thread::start();
- }
+ Fpu_user(Env & env, float x, Signal_context_capability c, Semaphore &s)
+ : Thread(env, "fpu_user", sizeof(size_t)*2048), _x(x), _st(c), _sem(s) {
+ start(); }
void entry()
{
- Genode::log("FPU user started");
- bool submitted = false;
- while (1) {
- enum { TRIALS = 1000 };
- for (unsigned i = 0; i < TRIALS; i++) {
- float volatile a = _x + (float)i * ((float)1 / TRIALS);
- float volatile b = _x + (float)i * ((float)1 / TRIALS);
- float volatile c = _x;
- _calc(a, c);
- _calc(b, c);
- if (a != b) {
- Genode::error("calculation error");
- _st->submit(1);
- sleep_forever();
- }
- }
- if (!submitted) {
- _st->submit(1);
- submitted = true;
+ log("FPU user started");
+
+ enum { TRIALS = 1000 };
+ for (unsigned i = 0; i < TRIALS; i++) {
+ float volatile a = _x + (float)i * ((float)1 / TRIALS);
+ float volatile b = _x + (float)i * ((float)1 / TRIALS);
+ float volatile c = _x;
+ _calc(a, c);
+ _calc(b, c);
+ if (a != b) {
+ error("calculation error");
+ break;
}
}
+
+ _sem.up();
+ _st.submit();
}
};
-int main()
-{
- /* create ack signal */
- Signal_context sc;
- Signal_receiver sr;
- Signal_context_capability const scc = sr.manage(&sc);
- Sync_signal_transmitter st(scc);
- /* start pseudo-parallel FPU users */
+struct Main
+{
enum { FPU_USERS = 10 };
- Fpu_user fpu_users[FPU_USERS];
- for (unsigned i = 0; i < FPU_USERS; i++) {
- float const x = (i + 1) * 1.234;
- fpu_users[i].start(x, &st);
- }
- /* wait for an ack of every FPU user */
- for (unsigned i = 0; i < FPU_USERS;) { i += sr.wait_for_signal().num(); }
- log("test done");
- sleep_forever();
- return 0;
-}
+
+ Semaphore sem;
+ Env & env;
+ Heap heap { env.ram(), env.rm() };
+ Signal_handler handler { env.ep(), *this, &Main::handle };
+
+ Main(Env & env) : env(env) {
+ for (unsigned i = 0; i < FPU_USERS; i++)
+ new (heap) Fpu_user(env, (i + 1) * 1.234, handler, sem); }
+
+ void handle() {
+ if (sem.cnt() >= FPU_USERS) log("test done"); }
+};
+
+
+void Component::construct(Genode::Env & env) {
+ static Main main(env); }
diff --git a/repos/base/src/test/mp_server/main.cc b/repos/base/src/test/mp_server/main.cc
index ee456ef7fd..70288a8c18 100644
--- a/repos/base/src/test/mp_server/main.cc
+++ b/repos/base/src/test/mp_server/main.cc
@@ -13,13 +13,11 @@
*/
/* Genode includes */
+#include
+#include
#include
-#include
-#include
-#include
-
-#include
#include
+#include
namespace Test {
@@ -81,34 +79,35 @@ namespace Test {
/**
* Set up a server running on every CPU one Rpc_entrypoint
*/
-int main(int argc, char **argv)
+void Component::construct(Genode::Env & env)
{
using namespace Genode;
+ Heap heap(env.ram(), env.rm());
+
log("--- test-mp_server started ---");
- Affinity::Space cpus = env()->cpu_session()->affinity_space();
+ Affinity::Space cpus = env.cpu().affinity_space();
log("Detected ", cpus.width(), "x", cpus.height(), " CPU",
cpus.total() > 1 ? "s." : ".");
enum { STACK_SIZE = 2*1024*sizeof(long) };
- static Cap_connection cap;
- Rpc_entrypoint ** eps = new (env()->heap()) Rpc_entrypoint*[cpus.total()];
+ Rpc_entrypoint ** eps = new (heap) Rpc_entrypoint*[cpus.total()];
for (unsigned i = 0; i < cpus.total(); i++)
- eps[i] = new (env()->heap()) Rpc_entrypoint(&cap, STACK_SIZE, "rpc en",
- true, cpus.location_of_index(i));
+ eps[i] = new (heap) Rpc_entrypoint(&env.pd(), STACK_SIZE, "rpc en",
+ true, cpus.location_of_index(i));
/* XXX using the same object and putting it to different queues fails XXX */
- Test::Component * components = new (env()->heap()) Test::Component[cpus.total()];
+ Test::Component * components = new (heap) Test::Component[cpus.total()];
- Test::Capability * caps = new (env()->heap()) Test::Capability[cpus.total()];
+ Test::Capability * caps = new (heap) Test::Capability[cpus.total()];
for (unsigned i = 0; i < cpus.total(); i++)
caps[i] = eps[i]->manage(&components[i]);
- Test::Client ** clients = new (env()->heap()) Test::Client*[cpus.total()];
+ Test::Client ** clients = new (heap) Test::Client*[cpus.total()];
for (unsigned i = 0; i < cpus.total(); i++)
- clients[i] = new (env()->heap()) Test::Client(caps[i]);
+ clients[i] = new (heap) Test::Client(caps[i]);
/* Test: Invoke RPC entrypoint on different CPUs */
for (unsigned i = 0; i < cpus.total(); i++) {
@@ -132,6 +131,4 @@ int main(int argc, char **argv)
}
log("done");
-
- sleep_forever();
}
diff --git a/repos/base/src/test/new_delete/main.cc b/repos/base/src/test/new_delete/main.cc
index d0061a00ef..3f4c74122e 100644
--- a/repos/base/src/test/new_delete/main.cc
+++ b/repos/base/src/test/new_delete/main.cc
@@ -12,8 +12,9 @@
* under the terms of the GNU General Public License version 2.
*/
+#include
+#include
#include
-#include
using Genode::log;
using Genode::destroy;
@@ -40,29 +41,24 @@ struct E : C, D
struct Allocator : Genode::Allocator
{
- Genode::Allocator &heap = *Genode::env()->heap();
+ Genode::Heap heap;
+ Genode::Allocator & a { heap };
- Allocator() { }
+ Allocator(Genode::Env & env) : heap(env.ram(), env.rm()) { }
virtual ~Allocator() { }
- Genode::size_t consumed() const override
- {
- return heap.consumed();
- }
+ Genode::size_t consumed() const override {
+ return a.consumed(); }
- Genode::size_t overhead(Genode::size_t size) const override
- {
- return heap.overhead(size);
- }
+ Genode::size_t overhead(Genode::size_t size) const override {
+ return a.overhead(size); }
- bool need_size_for_free() const override
- {
- return heap.need_size_for_free();
- }
+ bool need_size_for_free() const override {
+ return a.need_size_for_free(); }
bool alloc(Genode::size_t size, void **p) override
{
- *p = heap.alloc(size);
+ *p = a.alloc(size);
log("Allocator::alloc()");
@@ -72,14 +68,14 @@ struct Allocator : Genode::Allocator
void free(void *p, Genode::size_t size) override
{
log("Allocator::free()");
- heap.free(p, size);
+ a.free(p, size);
}
};
-int main()
+void Component::construct(Genode::Env &env)
{
- Allocator a;
+ Allocator a(env);
/***********************
** Allocator pointer **
@@ -87,14 +83,14 @@ int main()
/* test successful allocation / successful construction */
{
- E *e = new (&a) E(false);
- destroy(&a, e);
+ E *e = new (a) E(false);
+ destroy(a, e);
}
/* test successful allocation / exception in construction */
try {
- E *e = new (&a) E(true);
- destroy(&a, e);
+ E *e = new (a) E(true);
+ destroy(a, e);
} catch (...) { log("exception caught"); }
/*************************
@@ -104,12 +100,14 @@ int main()
/* test successful allocation / successful construction */
{
E *e = new (a) E(false);
- destroy(&a, e);
+ destroy(a, e);
}
/* test successful allocation / exception in construction */
try {
E *e = new (a) E(true);
- destroy(&a, e);
+ destroy(a, e);
} catch (...) { log("exception caught"); }
+
+ log("Test done");
}
diff --git a/repos/base/src/test/rm_fault/main.cc b/repos/base/src/test/rm_fault/main.cc
index 560f7b29eb..81d13f4b54 100644
--- a/repos/base/src/test/rm_fault/main.cc
+++ b/repos/base/src/test/rm_fault/main.cc
@@ -228,7 +228,7 @@ void Component::construct(Env &env)
* Distinguish parent from child by requesting an service that is only
* available to the parent.
*/
- Rm_connection rm;
+ Rm_connection rm(env);
static Main_parent parent(env);
log("-- parent role started --");
}
diff --git a/repos/base/src/test/rm_nested/main.cc b/repos/base/src/test/rm_nested/main.cc
index 38b88ba208..2fda7cfeca 100644
--- a/repos/base/src/test/rm_nested/main.cc
+++ b/repos/base/src/test/rm_nested/main.cc
@@ -18,10 +18,7 @@
* under the terms of the GNU General Public License version 2.
*/
-#include
-#include
-#include
-#include
+#include
#include
#include
#include
@@ -38,22 +35,15 @@ enum {
/**
* Region-manager fault handler resolves faults by attaching new dataspaces
*/
-class Local_fault_handler : public Thread_deprecated<4096>
+class Local_fault_handler : public Entrypoint
{
private:
- Region_map &_region_map;
- Signal_receiver &_receiver;
+ Env & _env;
+ Region_map & _region_map;
+ Signal_handler _handler;
- public:
-
- Local_fault_handler(Region_map ®ion_map, Signal_receiver &receiver)
- :
- Thread_deprecated("local_fault_handler"),
- _region_map(region_map), _receiver(receiver)
- { }
-
- void handle_fault()
+ void _handle_fault()
{
Region_map::State state = _region_map.state();
@@ -64,45 +54,44 @@ class Local_fault_handler : public Thread_deprecated<4096>
", pf_addr=", Hex(state.addr, Hex::PREFIX));
log("allocate dataspace and attach it to sub region map");
- Dataspace_capability ds = env()->ram_session()->alloc(PAGE_SIZE);
+ Dataspace_capability ds = _env.ram().alloc(PAGE_SIZE);
_region_map.attach_at(ds, state.addr & ~(PAGE_SIZE - 1));
log("returning from handle_fault");
}
- void entry()
+ public:
+
+ Local_fault_handler(Genode::Env & env, Region_map ®ion_map)
+ : Entrypoint(env, sizeof(addr_t)*2048, "local_fault_handler"),
+ _env(env),
+ _region_map(region_map),
+ _handler(*this, *this, &Local_fault_handler::_handle_fault)
{
- while (true) {
- log("fault handler: waiting for fault signal");
- Signal signal = _receiver.wait_for_signal();
- log("received ", signal.num(), " fault signals");
- for (unsigned i = 0; i < signal.num(); i++)
- handle_fault();
- }
+ region_map.fault_handler(_handler);
+
+ log("fault handler: waiting for fault signal");
}
+
+ void dissolve() { Entrypoint::dissolve(_handler); }
};
-int main(int argc, char **argv)
+void Component::construct(Genode::Env & env)
{
log("--- nested region map test ---");
/*
* Initialize sub region map and set up a local fault handler for it.
*/
- static Rm_connection rm;
- static Region_map_client region_map(rm.create(MANAGED_SIZE));
- static Cap_connection cap;
- static Signal_receiver receiver;
- static Signal_context context;
- region_map.fault_handler(receiver.manage(&context));
- static Local_fault_handler fault_handler(region_map, receiver);
- fault_handler.start();
+ static Rm_connection rm(env);
+ static Region_map_client region_map(rm.create(MANAGED_SIZE));
+ static Local_fault_handler fault_handler(env, region_map);
/*
* Attach region map as dataspace to the local address space.
*/
- void *addr = env()->rm_session()->attach(region_map.dataspace());
+ void *addr = env.rm().attach(region_map.dataspace());
log("attached sub dataspace at local address ", addr);
Dataspace_client client(region_map.dataspace());
@@ -118,12 +107,11 @@ int main(int argc, char **argv)
managed[i] = 13;
}
- receiver.dissolve(&context);
+ fault_handler.dissolve();
log("test destruction of region_map");
Capability rcap = rm.create(4096);
rm.destroy(rcap);
log("--- finished nested region map test ---");
- return 0;
}
diff --git a/repos/base/src/test/segfault/main.cc b/repos/base/src/test/segfault/main.cc
index 97e719e4f3..c5ac25ea63 100644
--- a/repos/base/src/test/segfault/main.cc
+++ b/repos/base/src/test/segfault/main.cc
@@ -4,12 +4,12 @@
* \date 2012-11-01
*/
+#include
#include
-int main(int argc, char **argv)
+void Component::construct(Genode::Env &)
{
Genode::log("going to produce a segmentation fault...");
*((int *)0x44) = 0x55;
- return 0;
}
diff --git a/repos/base/src/test/slab/main.cc b/repos/base/src/test/slab/main.cc
index 95d3051c67..168312050f 100644
--- a/repos/base/src/test/slab/main.cc
+++ b/repos/base/src/test/slab/main.cc
@@ -12,7 +12,8 @@
* under the terms of the GNU General Public License version 2.
*/
-#include
+#include
+#include
#include
#include
#include
@@ -26,7 +27,8 @@ using Genode::error;
struct Array_of_slab_elements
{
- Genode::Slab &slab;
+ Genode::Slab & slab;
+ Genode::Allocator & alloc;
size_t const num_elem;
size_t const slab_size;
@@ -40,21 +42,14 @@ struct Array_of_slab_elements
struct Alloc_failed { };
- /**
- * Constructor
- *
- * \throw Alloc_failed
- */
- Array_of_slab_elements(Genode::Slab &slab, size_t num_elem, size_t slab_size)
- :
- slab(slab), num_elem(num_elem), slab_size(slab_size)
+ Array_of_slab_elements(Genode::Slab &slab, size_t num_elem, size_t slab_size,
+ Genode::Allocator & alloc)
+ : slab(slab), alloc(alloc), num_elem(num_elem), slab_size(slab_size),
+ elem((void**) alloc.alloc(_elem_array_size()))
{
- elem = (void **)Genode::env()->heap()->alloc(_elem_array_size());
-
log(" allocate ", num_elem, " elements");
for (size_t i = 0; i < num_elem; i++)
- if (!slab.alloc(slab_size, &elem[i]))
- throw Alloc_failed();
+ if (!slab.alloc(slab_size, &elem[i])) throw Alloc_failed();
}
~Array_of_slab_elements()
@@ -63,19 +58,21 @@ struct Array_of_slab_elements
for (size_t i = 0; i < num_elem; i++)
slab.free(elem[i], slab_size);
- Genode::env()->heap()->free(elem, _elem_array_size());
+ alloc.free(elem, _elem_array_size());
}
};
-int main(int argc, char **argv)
+void Component::construct(Genode::Env & env)
{
+ Genode::Heap heap(env.ram(), env.rm());
+
log("--- slab test ---");
- static Timer::Connection timer;
+ static Timer::Connection timer(env);
enum { SLAB_SIZE = 16, BLOCK_SIZE = 256 };
- static Genode::Allocator_guard alloc(Genode::env()->heap(), ~0UL);
+ static Genode::Allocator_guard alloc(&heap, ~0UL);
{
Genode::Slab slab(SLAB_SIZE, BLOCK_SIZE, nullptr, &alloc);
@@ -85,7 +82,7 @@ int main(int argc, char **argv)
"used quota: ", alloc.consumed(), " "
"time: ", timer.elapsed_ms(), " ms)");
- Array_of_slab_elements array(slab, i*100000, SLAB_SIZE);
+ Array_of_slab_elements array(slab, i*100000, SLAB_SIZE, heap);
log(" allocation completed (used quota: ", alloc.consumed(), ")");
}
@@ -100,7 +97,7 @@ int main(int argc, char **argv)
enum { HEAP_OVERHEAD = 36 };
if (alloc.consumed() > 2*(BLOCK_SIZE + HEAP_OVERHEAD)) {
error("slab failed to release empty slab blocks");
- return -1;
+ return;
}
}
@@ -108,8 +105,8 @@ int main(int argc, char **argv)
log("destructed slab (used quota: ", alloc.consumed(), ")");
if (alloc.consumed() > 0) {
error("slab failed to release all backing store");
- return -2;
+ return;
}
- return 0;
+ log("Test done");
}
diff --git a/repos/base/src/test/util_mmio/main.cc b/repos/base/src/test/util_mmio/main.cc
index f617cdb72b..f94165778d 100644
--- a/repos/base/src/test/util_mmio/main.cc
+++ b/repos/base/src/test/util_mmio/main.cc
@@ -12,8 +12,9 @@
*/
/* Genode includes */
-#include
+#include
#include
+#include
using namespace Genode;
@@ -186,8 +187,11 @@ int compare_mem(uint8_t * base1, uint8_t * base2, size_t size)
void error(unsigned line) { error("Test in line ", line, " failed"); }
-int main()
+void Component::construct(Genode::Env &)
{
+ using ::Cpu_state;
+
+
/************************************
** 'Genode::Mmio::Register' tests **
************************************/
@@ -465,6 +469,5 @@ int main()
}
log("Test done");
- return 0;
}
diff --git a/repos/base/src/test/weak_ptr/main.cc b/repos/base/src/test/weak_ptr/main.cc
index 5f29bce74c..f18ebebae6 100644
--- a/repos/base/src/test/weak_ptr/main.cc
+++ b/repos/base/src/test/weak_ptr/main.cc
@@ -12,8 +12,9 @@
*/
/* Genode includes */
+#include
#include
-#include
+#include
#include
#include
#include
@@ -35,7 +36,7 @@ void Genode::Weak_object_base::debug_info() const
}
-static int weak_ptr_valid;
+static bool weak_ptr_valid;
void Genode::Weak_ptr_base::debug_info() const
@@ -91,7 +92,7 @@ struct Object : Genode::Weak_object