mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/Tasty.git
synced 2025-06-12 03:25:58 +00:00
Added test case for thread killing
This commit is contained in:
parent
8e5bf802b0
commit
28f88b1ead
@ -8,6 +8,8 @@
|
|||||||
#ifndef STA_CONFIG_HPP
|
#ifndef STA_CONFIG_HPP
|
||||||
#define STA_CONFIG_HPP
|
#define STA_CONFIG_HPP
|
||||||
|
|
||||||
|
#define STA_STM32_SWD_USART_IDX 2
|
||||||
|
|
||||||
#include <sta/devices/stm32/mcu/STM32F411xE.hpp>
|
#include <sta/devices/stm32/mcu/STM32F411xE.hpp>
|
||||||
|
|
||||||
// Doesn't really do too much right now. Has to be added for successful compilation.
|
// Doesn't really do too much right now. Has to be added for successful compilation.
|
||||||
|
@ -2,6 +2,6 @@
|
|||||||
#ifndef STA_TASTY_CONFIG_HPP
|
#ifndef STA_TASTY_CONFIG_HPP
|
||||||
#define STA_TASTY_CONFIG_HPP
|
#define STA_TASTY_CONFIG_HPP
|
||||||
|
|
||||||
#define TASTY_CASE_5
|
#define TASTY_CASE_6
|
||||||
|
|
||||||
#endif // STA_TASTY_CONFIG_HPP
|
#endif // STA_TASTY_CONFIG_HPP
|
||||||
|
@ -41,6 +41,9 @@ namespace sta
|
|||||||
STA_TASTY_ASSERT(tacos::getState() == 1);
|
STA_TASTY_ASSERT(tacos::getState() == 1);
|
||||||
|
|
||||||
STA_TASTY_TERMINATE();
|
STA_TASTY_TERMINATE();
|
||||||
|
|
||||||
|
|
||||||
|
this->sleep(1000000);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
85
src/cases/case6.cpp
Normal file
85
src/cases/case6.cpp
Normal 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/*
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -18,9 +18,9 @@ namespace sta
|
|||||||
{
|
{
|
||||||
for (TastyCheck check : checks_)
|
for (TastyCheck check : checks_)
|
||||||
{
|
{
|
||||||
blocking(
|
/*blocking(
|
||||||
check();
|
check();
|
||||||
);
|
);*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace tasty
|
} // namespace tasty
|
||||||
|
@ -29,6 +29,7 @@ namespace sta
|
|||||||
|
|
||||||
void ToggleThread::func()
|
void ToggleThread::func()
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
blocking(
|
blocking(
|
||||||
this->sleep(ticks_);
|
this->sleep(ticks_);
|
||||||
)
|
)
|
||||||
@ -37,6 +38,7 @@ namespace sta
|
|||||||
uint16_t next = 1 - state;
|
uint16_t next = 1 - state;
|
||||||
|
|
||||||
sta::tacos::setState(state, next, lockout_);
|
sta::tacos::setState(state, next, lockout_);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
} // namespace tasty
|
} // namespace tasty
|
||||||
} // namespace sta
|
} // namespace sta
|
||||||
|
Loading…
x
Reference in New Issue
Block a user