diff options
Diffstat (limited to 'tests/test-Tasks.cc')
-rw-r--r-- | tests/test-Tasks.cc | 47 |
1 files changed, 44 insertions, 3 deletions
diff --git a/tests/test-Tasks.cc b/tests/test-Tasks.cc index 272e61d..6bbb503 100644 --- a/tests/test-Tasks.cc +++ b/tests/test-Tasks.cc @@ -1,6 +1,7 @@ #include <Main.h> #include <Task.h> #include <TaskMan.h> +#include <StacklessTask.h> using namespace Balau; @@ -20,9 +21,42 @@ class TestTask : public Task { } }; +class TestOperation { + public: + TestOperation() : m_count(0), m_completed(false) { } + void Do() { + if (m_count++ == 0) { + m_timeout.set(0.2); + Task::operationYield(&m_timeout, Task::STACKLESS); + } + TAssert(m_timeout.gotSignal()); + m_completed = true; + } + bool completed() { return m_completed; } + private: + int m_count; + bool m_completed; + Events::Timeout m_timeout; +}; + +class TestStackless : public StacklessTask { + public: + virtual const char * getName() const { return "TestStackless"; } + private: + virtual void Do() { + StacklessBegin(); + m_operation = new TestOperation(); + StacklessOperation(m_operation->Do()); + TAssert(m_operation->completed()); + delete m_operation; + StacklessEnd(); + } + TestOperation * m_operation; +}; + static void yieldingFunction() { Events::Timeout timeout(0.2); - Task::yield(&timeout); + Task::operationYield(&timeout); TAssert(timeout.gotSignal()); } @@ -30,8 +64,15 @@ void MainTask::Do() { customPrinter = new CustomPrinter(); Printer::log(M_STATUS, "Test::Tasks running."); - Task * testTask = Balau::createTask(new TestTask()); - Events::TaskEvent taskEvt(testTask); + Events::TaskEvent taskEvt; + Task * testTask = TaskMan::registerTask(new TestTask(), &taskEvt); + waitFor(&taskEvt); + TAssert(!taskEvt.gotSignal()); + yield(); + TAssert(taskEvt.gotSignal()); + taskEvt.ack(); + + Task * testStackless = TaskMan::registerTask(new TestStackless(), &taskEvt); waitFor(&taskEvt); TAssert(!taskEvt.gotSignal()); yield(); |