Added test case for thread killing

This commit is contained in:
dario 2024-01-18 12:40:12 +01:00
parent 8e5bf802b0
commit 28f88b1ead
6 changed files with 95 additions and 3 deletions

View File

@ -8,6 +8,8 @@
#ifndef STA_CONFIG_HPP
#define STA_CONFIG_HPP
#define STA_STM32_SWD_USART_IDX 2
#include <sta/devices/stm32/mcu/STM32F411xE.hpp>
// Doesn't really do too much right now. Has to be added for successful compilation.

View File

@ -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

View File

@ -41,6 +41,9 @@ namespace sta
STA_TASTY_ASSERT(tacos::getState() == 1);
STA_TASTY_TERMINATE();
this->sleep(1000000);
}
};

85
src/cases/case6.cpp Normal file
View File

@ -0,0 +1,85 @@
/**
* Tests if killing tasks works correctly and the memory is correctly freed.
*/
#include <sta/tasty/config.hpp>
#ifdef TASTY_CASE_6
#include <memory>
#include <sta/tacos.hpp>
#include <sta/tasty/utils.hpp>
#include <sta/rtos/debug/heap_stats.hpp>
#include <sta/rtos/signal.hpp>
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> 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> victim_ptr_;
};
void onTastyInit()
{
std::shared_ptr<Victim> victim_ptr = tacos::addThread<Victim>({0});
tacos::addThread<ViciousMurderer>({0}, victim_ptr);
}
} // namespace tasty
} // namespace sta
#endif // TASTY_CASE_6/*

View File

@ -18,9 +18,9 @@ namespace sta
{
for (TastyCheck check : checks_)
{
blocking(
/*blocking(
check();
);
);*/
}
}
} // namespace tasty

View File

@ -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