Added first test case for watchdog

This commit is contained in:
dario 2024-01-24 21:42:33 +01:00
parent 28f88b1ead
commit 529e2f6224
3 changed files with 84 additions and 4 deletions

View File

@ -2,6 +2,6 @@
#ifndef STA_TASTY_CONFIG_HPP
#define STA_TASTY_CONFIG_HPP
#define TASTY_CASE_6
#define TASTY_CASE_7
#endif // STA_TASTY_CONFIG_HPP

View File

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

83
src/cases/case7.cpp Normal file
View File

@ -0,0 +1,83 @@
/*
* case7.cpp
*
* Created on: Jan 24, 2024
* Author: Dario
*/
#include <sta/tasty/config.hpp>
#ifdef TASTY_CASE_7
#include <sta/tacos.hpp>
#include <sta/tasty/utils.hpp>
#include <sta/tacos/watchdog.hpp>
namespace sta
{
namespace tasty
{
static uint8_t alive_flag = 0;
class Dummy : public tacos::TacosThread
{
public:
Dummy()
: tacos::TacosThread{"Dummy", osPriorityNormal}
{
}
void init() override
{
alive_flag = 1;
}
void func() override
{
this->sleep(100);
// Thread is stuck in infinite loop
while (true)
{
osThreadYield();
}
}
};
class Observer : public tacos::TacosThread
{
public:
Observer()
: tacos::TacosThread{"Observer", osPriorityNormal}
{
}
void func() override
{
this->sleep(10);
STA_TASTY_ASSERT(alive_flag == 1);
this->sleep(110);
alive_flag = 0;
// After at most 1000 ticks, the watchdog should have revived the thread.
this->sleep(2000);
STA_TASTY_ASSERT(alive_flag == 1);
STA_TASTY_ASSERT(tacos::Watchdog::instance()->getNumRestarts() == 1);
STA_TASTY_TERMINATE();
}
};
void onTastyInit()
{
tacos::addThread<Dummy>({0});
tacos::addThread<Observer>({0});
}
} // namespace tasty
}
#endif // TASTY_CASE_7