From f17249713c0610da2b08a02206261676cf155ece Mon Sep 17 00:00:00 2001 From: Christian Thaeter Date: Thu, 21 Jan 2010 01:49:56 +0100 Subject: [PATCH] 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. --- tests/lib/subsystem-runner-test.cpp | 38 +++++++++++++++-------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/tests/lib/subsystem-runner-test.cpp b/tests/lib/subsystem-runner-test.cpp index e86e0af05..f5be9da3c 100644 --- a/tests/lib/subsystem-runner-test.cpp +++ b/tests/lib/subsystem-runner-test.cpp @@ -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 + : public lumiera::Subsys + , public Sync { 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(); } + };