mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-19 21:57:55 +00:00
parent
2f7e421eed
commit
1d3ec6f0ae
@ -657,6 +657,43 @@ static void test_cxa_guards(Env &env)
|
||||
log("running '", __func__, "' done");
|
||||
}
|
||||
|
||||
|
||||
/*********************************************
|
||||
** Successive construction and destruction **
|
||||
*********************************************/
|
||||
|
||||
struct Create_destroy_helper : Thread
|
||||
{
|
||||
enum { STACK_SIZE = 0x2000 };
|
||||
|
||||
unsigned const result_value;
|
||||
unsigned volatile result { ~0U };
|
||||
|
||||
Create_destroy_helper(Env &env, unsigned result_value)
|
||||
: Thread(env, "create_destroy", STACK_SIZE),
|
||||
result_value(result_value)
|
||||
{ }
|
||||
|
||||
void entry()
|
||||
{
|
||||
result = result_value;
|
||||
}
|
||||
};
|
||||
|
||||
static void test_successive_create_destroy_threads(Env &env)
|
||||
{
|
||||
log("running '", __func__, "'");
|
||||
|
||||
for (unsigned i = 0; i < 500; i++) {
|
||||
Create_destroy_helper thread(env, i);
|
||||
thread.start();
|
||||
thread.join();
|
||||
if (thread.result != i)
|
||||
throw -30;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Component::construct(Env &env)
|
||||
{
|
||||
log("--- thread test started ---");
|
||||
@ -676,6 +713,7 @@ void Component::construct(Env &env)
|
||||
test_pause_resume(env);
|
||||
|
||||
test_create_as_many_threads(env);
|
||||
test_successive_create_destroy_threads(env);
|
||||
} catch (int error) {
|
||||
Genode::error("error ", error);
|
||||
throw;
|
||||
|
@ -1,35 +0,0 @@
|
||||
build "core init drivers/timer test/thread_join"
|
||||
|
||||
create_boot_directory
|
||||
|
||||
install_config {
|
||||
<config>
|
||||
<parent-provides>
|
||||
<service name="ROM"/>
|
||||
<service name="CPU"/>
|
||||
<service name="RM"/>
|
||||
<service name="PD"/>
|
||||
<service name="IRQ"/>
|
||||
<service name="IO_PORT"/>
|
||||
<service name="IO_MEM"/>
|
||||
<service name="LOG"/>
|
||||
</parent-provides>
|
||||
<default-route>
|
||||
<any-service> <parent/> <any-child/> </any-service>
|
||||
</default-route>
|
||||
<default caps="100"/>
|
||||
<start name="timer">
|
||||
<resource name="RAM" quantum="1M"/>
|
||||
<provides><service name="Timer"/></provides>
|
||||
</start>
|
||||
<start name="test-thread_join">
|
||||
<resource name="RAM" quantum="10M"/>
|
||||
</start>
|
||||
</config>
|
||||
}
|
||||
|
||||
build_boot_image "core ld.lib.so init timer test-thread_join"
|
||||
|
||||
append qemu_args "-nographic "
|
||||
|
||||
run_genode_until {.*--- Thread join test finished ---.*\n} 20
|
@ -1,73 +0,0 @@
|
||||
/*
|
||||
* \brief Test for the 'Thread::join()' function
|
||||
* \author Norman Feske
|
||||
* \date 2012-11-16
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2012-2017 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU Affero General Public License version 3.
|
||||
*/
|
||||
|
||||
/* Genode includes */
|
||||
#include <base/component.h>
|
||||
#include <base/thread.h>
|
||||
#include <timer_session/connection.h>
|
||||
|
||||
using namespace Genode;
|
||||
|
||||
|
||||
struct Worker : Thread
|
||||
{
|
||||
Timer::Session &timer;
|
||||
unsigned const result_value;
|
||||
unsigned volatile result;
|
||||
|
||||
void entry()
|
||||
{
|
||||
log("Worker thread is up");
|
||||
timer.msleep(250);
|
||||
|
||||
log("Worker is leaving the entry function with result=", result_value);
|
||||
result = result_value;
|
||||
}
|
||||
|
||||
Worker(Env &env, Timer::Session &timer, unsigned result_value)
|
||||
: Thread(env, "worker", 1024 * sizeof(addr_t)), timer(timer),
|
||||
result_value(result_value), result(~0)
|
||||
{
|
||||
Thread::start();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct Main
|
||||
{
|
||||
struct Worker_unfinished_after_join : Exception { };
|
||||
|
||||
Timer::Connection timer;
|
||||
|
||||
Main(Env &env) : timer(env)
|
||||
{
|
||||
log("--- Thread join test ---");
|
||||
for (unsigned i = 0; i < 10; i++) {
|
||||
|
||||
/*
|
||||
* A worker thread is created in each iteration. Just before
|
||||
* leaving the entry function, the worker assigns the result
|
||||
* to 'Worker::result' variable. By validating this value,
|
||||
* we determine whether the worker has finished or not.
|
||||
*/
|
||||
Worker worker(env, timer, i);
|
||||
worker.join();
|
||||
if (worker.result != i) {
|
||||
throw Worker_unfinished_after_join(); }
|
||||
}
|
||||
log("--- Thread join test finished ---");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
void Component::construct(Genode::Env &env) { static Main main(env); }
|
@ -1,3 +0,0 @@
|
||||
TARGET = test-thread_join
|
||||
SRC_CC = main.cc
|
||||
LIBS = base
|
@ -88,7 +88,6 @@ sub_rm
|
||||
synced_interface
|
||||
tar_rom
|
||||
thread
|
||||
thread_join
|
||||
timed_semaphore
|
||||
timeout
|
||||
timer
|
||||
|
Loading…
Reference in New Issue
Block a user