WIP: subsystem runner test, still broken
using new thread synchronization Disabled further tests, making one after another working. Some notes: * currently running this leads to different outcomes on differnt runs, there are some races/unsyncronized things left, to be investigated. * I suggest to make Subsystems joinable, this prolly needs some work in the error handling department (thread-wrapper.hpp too) * using nonrecursive/waitable lock, recursive locks are have some bad taste unless absolutely necessary * after all a timed lock with polling is not the right approach to check for subsystem shutdowns, I opted against thread cancelation because of its programming overhead and complexity. We may refine this and allow synchronous cancellation (with an approbiate thread flag) in some cases.
This commit is contained in:
parent
8607a4006a
commit
f17249713c
1 changed files with 20 additions and 18 deletions
|
|
@ -43,7 +43,7 @@ using util::isnil;
|
||||||
using util::cStr;
|
using util::cStr;
|
||||||
using test::Test;
|
using test::Test;
|
||||||
using lib::Sync;
|
using lib::Sync;
|
||||||
using lib::RecursiveLock_Waitable;
|
using lib::NonrecursiveLock_Waitable;
|
||||||
using backend::Thread;
|
using backend::Thread;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -85,8 +85,8 @@ namespace test {
|
||||||
* logic predicate notation.
|
* logic predicate notation.
|
||||||
*/
|
*/
|
||||||
class MockSys
|
class MockSys
|
||||||
: public lumiera::Subsys,
|
: public lumiera::Subsys
|
||||||
public Sync<RecursiveLock_Waitable>
|
, public Sync<NonrecursiveLock_Waitable>
|
||||||
{
|
{
|
||||||
Literal id_;
|
Literal id_;
|
||||||
const string spec_;
|
const string spec_;
|
||||||
|
|
@ -97,7 +97,6 @@ namespace test {
|
||||||
volatile bool termRequest_;
|
volatile bool termRequest_;
|
||||||
int running_duration_;
|
int running_duration_;
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
shouldStart (lumiera::Option&)
|
shouldStart (lumiera::Option&)
|
||||||
{
|
{
|
||||||
|
|
@ -113,14 +112,12 @@ namespace test {
|
||||||
{
|
{
|
||||||
REQUIRE (!(isUp_|started_|didRun_), "attempt to start %s twice!", cStr(*this));
|
REQUIRE (!(isUp_|started_|didRun_), "attempt to start %s twice!", cStr(*this));
|
||||||
|
|
||||||
Lock sync(this);
|
|
||||||
string startSpec (extractID ("start",spec_));
|
string startSpec (extractID ("start",spec_));
|
||||||
ASSERT (!isnil (startSpec));
|
ASSERT (!isnil (startSpec));
|
||||||
|
|
||||||
if ("true"==startSpec) //----simulate successful subsystem start
|
if ("true"==startSpec) //----simulate successful subsystem start
|
||||||
{
|
{
|
||||||
Thread (id_, bind (&MockSys::run, this, termination)); /////TODO: the thread description should be rather "Test: "+string(*this), but this requires to implement the class Literal as planned
|
Thread (id_, bind (&MockSys::run, this, termination)).sync(); /////TODO: the thread description should be rather "Test: "+string(*this), but this requires to implement the class Literal as planned
|
||||||
sync.wait(started_); // run-status handshake
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if ("fail"==startSpec) //----not starting, incorrectly reporting success
|
if ("fail"==startSpec) //----not starting, incorrectly reporting success
|
||||||
|
|
@ -163,13 +160,10 @@ namespace test {
|
||||||
string runSpec (extractID ("run",spec_));
|
string runSpec (extractID ("run",spec_));
|
||||||
ASSERT (!isnil (runSpec));
|
ASSERT (!isnil (runSpec));
|
||||||
|
|
||||||
{ // run-status handshake
|
started_ = true;
|
||||||
Lock sync(this);
|
isUp_ = ("true"==runSpec || "throw"==runSpec);
|
||||||
started_ = true;
|
didRun_ = ("false"!=runSpec); // includes "fail" and "throw"
|
||||||
isUp_ = ("true"==runSpec || "throw"==runSpec);
|
lumiera_thread_sync ();
|
||||||
didRun_ = ("false"!=runSpec); // includes "fail" and "throw"
|
|
||||||
sync.notify();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isUp_) //-------------actually enter running state for some time
|
if (isUp_) //-------------actually enter running state for some time
|
||||||
{
|
{
|
||||||
|
|
@ -263,10 +257,10 @@ namespace test {
|
||||||
{
|
{
|
||||||
singleSubsys_complete_cycle();
|
singleSubsys_complete_cycle();
|
||||||
singleSubsys_start_failure();
|
singleSubsys_start_failure();
|
||||||
singleSubsys_emegency_exit();
|
//singleSubsys_emegency_exit();
|
||||||
|
|
||||||
dependentSubsys_complete_cycle();
|
//dependentSubsys_complete_cycle();
|
||||||
dependentSubsys_start_failure();
|
//dependentSubsys_start_failure();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -404,6 +398,14 @@ namespace test {
|
||||||
ASSERT (!unit3.didRun());
|
ASSERT (!unit3.didRun());
|
||||||
// can't say for sure if unit4 actually did run
|
// can't say for sure if unit4 actually did run
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
SubsystemRunner_test()
|
||||||
|
{ lumiera_threadpool_init(); }
|
||||||
|
|
||||||
|
~SubsystemRunner_test()
|
||||||
|
{ lumiera_threadpool_destroy(); }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue