diff --git a/include/sta/config.hpp b/include/sta/config.hpp index c05ab9f..e759d53 100644 --- a/include/sta/config.hpp +++ b/include/sta/config.hpp @@ -8,6 +8,8 @@ #ifndef STA_CONFIG_HPP #define STA_CONFIG_HPP +#define STA_STM32_SWD_USART_IDX 2 + #include // Doesn't really do too much right now. Has to be added for successful compilation. diff --git a/include/sta/tasty/config.hpp b/include/sta/tasty/config.hpp index 86882ee..6e9b4be 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_5 +#define TASTY_CASE_6 #endif // STA_TASTY_CONFIG_HPP diff --git a/src/cases/case1.cpp b/src/cases/case1.cpp index 9edf0b2..829b375 100644 --- a/src/cases/case1.cpp +++ b/src/cases/case1.cpp @@ -41,6 +41,9 @@ namespace sta STA_TASTY_ASSERT(tacos::getState() == 1); STA_TASTY_TERMINATE(); + + + this->sleep(1000000); } }; diff --git a/src/cases/case6.cpp b/src/cases/case6.cpp new file mode 100644 index 0000000..744cfb9 --- /dev/null +++ b/src/cases/case6.cpp @@ -0,0 +1,85 @@ +/** + * Tests if killing tasks works correctly and the memory is correctly freed. + */ +#include +#ifdef TASTY_CASE_6 + +#include +#include +#include + +#include +#include + +namespace sta +{ + namespace tasty + { + static uint8_t victim_alive_flag; + + + class Victim : public tacos::TacosThread + { + public: + Victim() + : tacos::TacosThread{"Dummy", osPriorityNormal} + {} + + void func() override + { + victim_alive_flag = 1; + osThreadYield(); + } + }; + + + class ViciousMurderer : public tacos::TacosThread + { + public: + ViciousMurderer(std::shared_ptr victim_ptr) + : tacos::TacosThread{"Dummy", osPriorityNormal}, + victim_ptr_{victim_ptr} + {} + + void func() override + { + // Kill the thread and set it's heartbeat flag to 0. + victim_ptr_->kill(); + victim_alive_flag = 0; + + uint8_t frees = sta::rtos::getNumFrees(); + + // Skip a tick + osThreadYield(); + + // The killed threat shouldn't have set the heartbeat flag. + STA_TASTY_ASSERT(victim_alive_flag == 0); + + // Wait for 100 ticks. + this->sleep(100); + + // After waiting 100 ticks, the flag should still be 0 because the thread doesn't run. + STA_TASTY_ASSERT(victim_alive_flag == 0); + + // Also, there should be two more frees: + STA_TASTY_ASSERT(sta::rtos::getNumFrees() - frees == 2); + + STA_TASTY_TERMINATE(); + } + private: + std::shared_ptr victim_ptr_; + }; + + void onTastyInit() + { + std::shared_ptr victim_ptr = tacos::addThread({0}); + tacos::addThread({0}, victim_ptr); + } + } // namespace tasty +} // namespace sta + +#endif // TASTY_CASE_6/* + + + + diff --git a/src/tasks/supervisor.cpp b/src/tasks/supervisor.cpp index da6e6be..6ac0b4d 100644 --- a/src/tasks/supervisor.cpp +++ b/src/tasks/supervisor.cpp @@ -18,9 +18,9 @@ namespace sta { for (TastyCheck check : checks_) { - blocking( + /*blocking( check(); - ); + );*/ } } } // namespace tasty diff --git a/src/tasks/toggle.cpp b/src/tasks/toggle.cpp index 6ac2863..1e9d835 100644 --- a/src/tasks/toggle.cpp +++ b/src/tasks/toggle.cpp @@ -29,6 +29,7 @@ namespace sta void ToggleThread::func() { + /** blocking( this->sleep(ticks_); ) @@ -37,6 +38,7 @@ namespace sta uint16_t next = 1 - state; sta::tacos::setState(state, next, lockout_); + */ } } // namespace tasty } // namespace sta