From eac43b80d65691f8d1bb56ac31c018df1c465d0a Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Fri, 2 Jan 2009 10:57:13 +0100 Subject: [PATCH] cover simple testcase of starting just one subsystem --- tests/40components.tests | 5 +++++ tests/lib/subsystem-runner-test.cpp | 30 +++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/tests/40components.tests b/tests/40components.tests index c9666cb21..2a1c8be8c 100644 --- a/tests/40components.tests +++ b/tests/40components.tests @@ -337,6 +337,11 @@ return: 0 END +TEST "Starting and stopping subsystems" SubsystemRunner_test < Testgroup=ALL diff --git a/tests/lib/subsystem-runner-test.cpp b/tests/lib/subsystem-runner-test.cpp index d53ba9865..50d000316 100644 --- a/tests/lib/subsystem-runner-test.cpp +++ b/tests/lib/subsystem-runner-test.cpp @@ -24,6 +24,7 @@ #include "lib/test/run.hpp" #include "common/subsys.hpp" #include "common/subsystem-runner.hpp" +#include "common/option.hpp" #include "include/symbol.hpp" #include "lib/thread-wrapper.hpp" @@ -59,6 +60,11 @@ namespace lumiera { * shutdown request every XX milliseconds */ const uint TICK_DURATION_ms = 5; + /** dummy options just to be ignored */ + util::Cmdline dummyArgs (""); + lumiera::Option dummyOpt (dummyArgs); + + /** * A simulated "Lumiera Subsystem". @@ -77,6 +83,7 @@ namespace lumiera { Literal spec_; bool isUp_; + bool didRun_; volatile bool termRequest_; int running_duration_; @@ -137,6 +144,7 @@ namespace lumiera { if ("false"!=runSpec) //----actually hold running state for some time { + didRun_ = true; running_duration_ = (rand() % MAX_RUNNING_TIME_ms); Lock wait_blocking (this, &MockSys::tick); @@ -175,6 +183,7 @@ namespace lumiera { : id_(id), spec_(spec), isUp_(false), + didRun_(false), termRequest_(false), running_duration_(0) { } @@ -185,7 +194,8 @@ namespace lumiera { friend inline ostream& operator<< (ostream& os, MockSys const& mosi) { return os << string(mosi); } - + + bool didRun () const { return didRun_; } }; @@ -217,9 +227,25 @@ namespace lumiera { virtual void run (Arg) { - + singleSubsys_complete_cycle(); } + + void + singleSubsys_complete_cycle() + { + MockSys unit ("one", "start(true), run(true)."); + SubsystemRunner runner(dummyOpt); + REQUIRE (!unit.isRunning()); + REQUIRE (!unit.didRun()); + + runner.maybeRun (unit); + bool emergency = runner.wait(); + + ASSERT (!emergency); + ASSERT (!unit.isRunning()); + ASSERT (unit.didRun()); + } };