Two more test cases for the watchdog

This commit is contained in:
dario 2024-02-07 18:51:25 +01:00
parent 90cc3dba58
commit fadd08665d
3 changed files with 195 additions and 2 deletions

118
src/cases/case10.cpp Normal file
View File

@ -0,0 +1,118 @@
/*
* case10.cpp
*
* Created on: Feb 7, 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 <sta/tasty/config.hpp>
#ifdef TASTY_CASE_10
#include <sta/tacos.hpp>
#include <sta/tasty/utils.hpp>
#include <sta/tacos/watchdog.hpp>
#include <sta/rtos/signal.hpp>
namespace sta
{
namespace tasty
{
RtosSignal * signal;
class ThreadA : public tacos::TacosThread
{
public:
ThreadA()
: tacos::TacosThread{"A", osPriorityNormal}
{
}
void pointless_expensive_computation()
{
uint32_t ticks = osKernelGetSysTimerCount();
uint32_t freq = osKernelGetSysTimerCount();
uint64_t dummyCounter = 0;
while (osKernelGetSysTimerCount() <= ticks + 2 * freq)
{
dummyCounter++;
}
}
void func() override
{
this->sleep(3000);
signal->notify();
// This should notify the watchdog that this thread should be monitored.
blocking(
pointless_expensive_computation();
)
signal->notify();
pointless_expensive_computation();
}
};
std::shared_ptr<ThreadA> thread_A;
class Observer : public tacos::TacosThread
{
public:
Observer()
: tacos::TacosThread{"Observer", osPriorityNormal}
{
}
void func() override
{
uint16_t restarts = tacos::Watchdog::instance()->getNumRestarts();
// Wait for thread A to finish sleeping.
blocking(
signal->wait();
)
// Thread A shouldn't have been restarted because sleep() sets the thread's status to WAITING.
STA_TASTY_ASSERT(tacos::Watchdog::instance()->getNumRestarts() == restarts);
blocking(
signal->wait();
)
// Thread A shouldn't have been restarted because the computationally expensive computation was wrapped in blocking()
STA_TASTY_ASSERT(tacos::Watchdog::instance()->getNumRestarts() == restarts);
this->sleep(2500);
STA_TASTY_ASSERT(tacos::Watchdog::instance()->getNumRestarts() == restarts + 1);
STA_TASTY_TERMINATE();
}
};
void onTastyInit()
{
signal = new RtosSignal(2);
thread_A = tacos::addThread<ThreadA>({0});
tacos::addThread<Observer>({0, 1});
}
} // namespace tasty
}
#endif // TASTY_CASE_10

77
src/cases/case11.cpp Normal file
View File

@ -0,0 +1,77 @@
/*
* case10.cpp
*
* Created on: Feb 7, 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 <sta/tasty/config.hpp>
#ifdef TASTY_CASE_11
#include <sta/tacos.hpp>
#include <sta/tasty/utils.hpp>
#include <sta/tacos/watchdog.hpp>
#include <sta/rtos/signal.hpp>
namespace sta
{
namespace tasty
{
class ThreadA : public tacos::TacosThread
{
public:
ThreadA()
: tacos::TacosThread{"A", osPriorityNormal}
{
}
void init() override
{
// Tells the watchdog to ignore this thread.
watchdogIgnore();
}
void func() override
{
// 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(2000);
// The watchdog shouldn't have restarted thread A.
STA_TASTY_ASSERT(tacos::Watchdog::instance()->getNumRestarts() == 0);
STA_TASTY_TERMINATE();
}
};
void onTastyInit()
{
tacos::addThread<ThreadA>({0});
tacos::addThread<Observer>({0, 1});
}
} // namespace tasty
}
#endif // TASTY_CASE_11

View File

@ -13,8 +13,6 @@
#include <sta/tacos.hpp>
#include <sta/tasty/utils.hpp>
#include <sta/tacos/watchdog.hpp>
#include <sta/rtos/mutex.hpp>
#include <sta/rtos/debug/heap_stats.hpp>
namespace sta