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 test::Test;
|
||||
using lib::Sync;
|
||||
using lib::RecursiveLock_Waitable;
|
||||
using lib::NonrecursiveLock_Waitable;
|
||||
using backend::Thread;
|
||||
|
||||
|
||||
|
|
@ -85,8 +85,8 @@ namespace test {
|
|||
* logic predicate notation.
|
||||
*/
|
||||
class MockSys
|
||||
: public lumiera::Subsys,
|
||||
public Sync<RecursiveLock_Waitable>
|
||||
: public lumiera::Subsys
|
||||
, public Sync<NonrecursiveLock_Waitable>
|
||||
{
|
||||
Literal id_;
|
||||
const string spec_;
|
||||
|
|
@ -97,7 +97,6 @@ namespace test {
|
|||
volatile bool termRequest_;
|
||||
int running_duration_;
|
||||
|
||||
|
||||
bool
|
||||
shouldStart (lumiera::Option&)
|
||||
{
|
||||
|
|
@ -113,14 +112,12 @@ namespace test {
|
|||
{
|
||||
REQUIRE (!(isUp_|started_|didRun_), "attempt to start %s twice!", cStr(*this));
|
||||
|
||||
Lock sync(this);
|
||||
string startSpec (extractID ("start",spec_));
|
||||
ASSERT (!isnil (startSpec));
|
||||
|
||||
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
|
||||
sync.wait(started_); // run-status handshake
|
||||
{
|
||||
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
|
||||
}
|
||||
else
|
||||
if ("fail"==startSpec) //----not starting, incorrectly reporting success
|
||||
|
|
@ -163,13 +160,10 @@ namespace test {
|
|||
string runSpec (extractID ("run",spec_));
|
||||
ASSERT (!isnil (runSpec));
|
||||
|
||||
{ // run-status handshake
|
||||
Lock sync(this);
|
||||
started_ = true;
|
||||
isUp_ = ("true"==runSpec || "throw"==runSpec);
|
||||
didRun_ = ("false"!=runSpec); // includes "fail" and "throw"
|
||||
sync.notify();
|
||||
}
|
||||
started_ = true;
|
||||
isUp_ = ("true"==runSpec || "throw"==runSpec);
|
||||
didRun_ = ("false"!=runSpec); // includes "fail" and "throw"
|
||||
lumiera_thread_sync ();
|
||||
|
||||
if (isUp_) //-------------actually enter running state for some time
|
||||
{
|
||||
|
|
@ -263,10 +257,10 @@ namespace test {
|
|||
{
|
||||
singleSubsys_complete_cycle();
|
||||
singleSubsys_start_failure();
|
||||
singleSubsys_emegency_exit();
|
||||
//singleSubsys_emegency_exit();
|
||||
|
||||
dependentSubsys_complete_cycle();
|
||||
dependentSubsys_start_failure();
|
||||
//dependentSubsys_complete_cycle();
|
||||
//dependentSubsys_start_failure();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -404,6 +398,14 @@ namespace test {
|
|||
ASSERT (!unit3.didRun());
|
||||
// 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