diff --git a/include/sta/tasty/config.hpp b/include/sta/tasty/config.hpp index 73432a9..9baa6f7 100644 --- a/include/sta/tasty/config.hpp +++ b/include/sta/tasty/config.hpp @@ -2,6 +2,6 @@ #ifndef STA_TASTY_CONFIG_HPP #define STA_TASTY_CONFIG_HPP -#define TASTY_CASE_7 +#define TASTY_CASE_9 #endif // STA_TASTY_CONFIG_HPP diff --git a/src/cases/case5.cpp b/src/cases/case5.cpp index 76e3793..1df1372 100644 --- a/src/cases/case5.cpp +++ b/src/cases/case5.cpp @@ -1,5 +1,7 @@ /** - * + * Timed state transitions can be overwritten by timed state transitions with later deadline. + * + * TODO: Implement the correct requirement. */ #include #ifdef TASTY_CASE_5 @@ -13,8 +15,6 @@ namespace sta { class DummyThread : public tacos::TacosThread { - private: - /* data */ public: DummyThread() : tacos::TacosThread{"Dummy", osPriorityNormal} diff --git a/src/cases/case7.cpp b/src/cases/case7.cpp index 3afe246..5f9b70e 100644 --- a/src/cases/case7.cpp +++ b/src/cases/case7.cpp @@ -5,6 +5,9 @@ * Author: Dario */ +/** + * A thread gets stuck in an infinite loop and the watchdog restarts it. + */ #include #ifdef TASTY_CASE_7 diff --git a/src/cases/case8.cpp b/src/cases/case8.cpp new file mode 100644 index 0000000..0127ffc --- /dev/null +++ b/src/cases/case8.cpp @@ -0,0 +1,97 @@ +/* + * case8.cpp + * + * Created on: Jan 24, 2024 + * Author: Dario + */ + +/** + * A thread gets stuck in an infinite loop and the watchdog restarts it. + */ +#include +#ifdef TASTY_CASE_8 + +#include +#include +#include +#include + +namespace sta +{ + namespace tasty + { + static RtosMutex * mutexA; + static RtosMutex * mutexB; + + class ThreadA : public tacos::TacosThread + { + public: + ThreadA() + : tacos::TacosThread{"A", osPriorityNormal} + { + + } + + void func() override + { + mutexA->acquire(); + + this->sleep(10); + + mutexB->acquire(); + } + }; + + class ThreadB : public tacos::TacosThread + { + public: + ThreadB() + : tacos::TacosThread{"B", osPriorityNormal} + { + + } + + void func() override + { + mutexB->acquire(); + + this->sleep(10); + + mutexA->acquire(); + } + }; + + class Observer : public tacos::TacosThread + { + public: + Observer() + : tacos::TacosThread{"Observer", osPriorityNormal} + { + + } + + void func() override + { + this->sleep(2000); + + STA_TASTY_ASSERT(tacos::Watchdog::instance()->getNumRestarts() == 2); + + STA_TASTY_TERMINATE(); + } + }; + + void onTastyInit() + { + mutexA = new RtosMutex("MutA"); + mutexB = new RtosMutex("MutB"); + + tacos::addThread({0}); + tacos::addThread({0}); + tacos::addThread({0}); + } + } // namespace tasty +} + +#endif // TASTY_CASE_8 + + diff --git a/src/cases/case9.cpp b/src/cases/case9.cpp new file mode 100644 index 0000000..88bd40e --- /dev/null +++ b/src/cases/case9.cpp @@ -0,0 +1,116 @@ +/* + * case8.cpp + * + * Created on: Jan 24, 2024 + * Author: Dario + */ + +/** + * Tests if threads are properly terminated and started because of state transitions. The thread status is updated accordingly and no memory leaks occur. + */ +#include +#ifdef TASTY_CASE_9 + +#include +#include +#include +#include +#include + +namespace sta +{ + namespace tasty + { + class ThreadA : public tacos::TacosThread + { + public: + ThreadA() + : tacos::TacosThread{"A", osPriorityNormal} + { + + } + + void func() override + { + osThreadYield(); + } + }; + + class ThreadB : public tacos::TacosThread + { + public: + ThreadB() + : tacos::TacosThread{"B", osPriorityNormal} + { + + } + + void func() override + { + osThreadYield(); + } + }; + + + std::shared_ptr thread_A; + std::shared_ptr thread_B; + + + class Observer : public tacos::TacosThread + { + public: + Observer() + : tacos::TacosThread{"Observer", osPriorityNormal} + { + + } + + void func() override + { + size_t mallocs = sta::rtos::getNumAllocs(); + + STA_TASTY_ASSERT(thread_A->isRunning()); + STA_TASTY_ASSERT(!thread_B->isRunning()); + STA_TASTY_ASSERT(thread_B->getStatus() == tacos::ThreadStatus::STOPPED); + + this->sleep(20); + + tacos::setState(0, 1); + + this->sleep(5); + + STA_TASTY_ASSERT(!thread_A->isRunning()); + STA_TASTY_ASSERT(thread_B->isRunning()); + STA_TASTY_ASSERT(thread_A->getStatus() == tacos::ThreadStatus::STOPPED); + STA_TASTY_ASSERT(sta::rtos::getNumAllocs() == mallocs + 2); + + tacos::setState(1, 0); + + this->sleep(5); + + STA_TASTY_ASSERT(thread_A->isRunning()); + STA_TASTY_ASSERT(!thread_B->isRunning()); + STA_TASTY_ASSERT(thread_B->getStatus() == tacos::ThreadStatus::STOPPED); + STA_TASTY_ASSERT(sta::rtos::getNumAllocs() == mallocs + 2); + + tacos::setState(0, 1); + + STA_TASTY_ASSERT(!thread_A->isRunning()); + STA_TASTY_ASSERT(thread_B->isRunning()); + STA_TASTY_ASSERT(thread_A->getStatus() == tacos::ThreadStatus::STOPPED); + STA_TASTY_ASSERT(sta::rtos::getNumAllocs() == mallocs + 2); + + STA_TASTY_TERMINATE(); + } + }; + + void onTastyInit() + { + thread_A = tacos::addThread({0}); + thread_B = tacos::addThread({1}); + tacos::addThread({0, 1}); + } + } // namespace tasty +} + +#endif // TASTY_CASE_9 diff --git a/src/utils.cpp b/src/utils.cpp index 6335b34..01010af 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -16,6 +16,8 @@ namespace sta void test_terminate() { STA_DEBUG_PRINTLN("[T]"); + + while (true) {} } } // namespace tasty } // namespace sta