Added new test case testing for memory leaks and correct thread starting

This commit is contained in:
dario 2024-02-07 17:03:45 +01:00
parent 529e2f6224
commit ccfc354c8f
6 changed files with 222 additions and 4 deletions

View File

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

View File

@ -1,5 +1,7 @@
/**
*
* Timed state transitions can be overwritten by timed state transitions with later deadline.
*
* TODO: Implement the correct requirement.
*/
#include <sta/tasty/config.hpp>
#ifdef TASTY_CASE_5
@ -13,8 +15,6 @@ namespace sta
{
class DummyThread : public tacos::TacosThread
{
private:
/* data */
public:
DummyThread()
: tacos::TacosThread{"Dummy", osPriorityNormal}

View File

@ -5,6 +5,9 @@
* Author: Dario
*/
/**
* A thread gets stuck in an infinite loop and the watchdog restarts it.
*/
#include <sta/tasty/config.hpp>
#ifdef TASTY_CASE_7

97
src/cases/case8.cpp Normal file
View File

@ -0,0 +1,97 @@
/*
* case8.cpp
*
* Created on: Jan 24, 2024
* Author: Dario
*/
/**
* A thread gets stuck in an infinite loop and the watchdog restarts it.
*/
#include <sta/tasty/config.hpp>
#ifdef TASTY_CASE_8
#include <sta/tacos.hpp>
#include <sta/tasty/utils.hpp>
#include <sta/tacos/watchdog.hpp>
#include <sta/rtos/mutex.hpp>
namespace sta
{
namespace tasty
{
static RtosMutex * mutexA;
static RtosMutex * mutexB;
class ThreadA : public tacos::TacosThread
{
public:
ThreadA()
: tacos::TacosThread{"A", osPriorityNormal}
{
}
void func() override
{
mutexA->acquire();
this->sleep(10);
mutexB->acquire();
}
};
class ThreadB : public tacos::TacosThread
{
public:
ThreadB()
: tacos::TacosThread{"B", osPriorityNormal}
{
}
void func() override
{
mutexB->acquire();
this->sleep(10);
mutexA->acquire();
}
};
class Observer : public tacos::TacosThread
{
public:
Observer()
: tacos::TacosThread{"Observer", osPriorityNormal}
{
}
void func() override
{
this->sleep(2000);
STA_TASTY_ASSERT(tacos::Watchdog::instance()->getNumRestarts() == 2);
STA_TASTY_TERMINATE();
}
};
void onTastyInit()
{
mutexA = new RtosMutex("MutA");
mutexB = new RtosMutex("MutB");
tacos::addThread<ThreadA>({0});
tacos::addThread<ThreadB>({0});
tacos::addThread<Observer>({0});
}
} // namespace tasty
}
#endif // TASTY_CASE_8

116
src/cases/case9.cpp Normal file
View File

@ -0,0 +1,116 @@
/*
* case8.cpp
*
* Created on: Jan 24, 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_9
#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
{
namespace tasty
{
class ThreadA : public tacos::TacosThread
{
public:
ThreadA()
: tacos::TacosThread{"A", osPriorityNormal}
{
}
void func() override
{
osThreadYield();
}
};
class ThreadB : public tacos::TacosThread
{
public:
ThreadB()
: tacos::TacosThread{"B", osPriorityNormal}
{
}
void func() override
{
osThreadYield();
}
};
std::shared_ptr<ThreadA> thread_A;
std::shared_ptr<ThreadB> thread_B;
class Observer : public tacos::TacosThread
{
public:
Observer()
: tacos::TacosThread{"Observer", osPriorityNormal}
{
}
void func() override
{
size_t mallocs = sta::rtos::getNumAllocs();
STA_TASTY_ASSERT(thread_A->isRunning());
STA_TASTY_ASSERT(!thread_B->isRunning());
STA_TASTY_ASSERT(thread_B->getStatus() == tacos::ThreadStatus::STOPPED);
this->sleep(20);
tacos::setState(0, 1);
this->sleep(5);
STA_TASTY_ASSERT(!thread_A->isRunning());
STA_TASTY_ASSERT(thread_B->isRunning());
STA_TASTY_ASSERT(thread_A->getStatus() == tacos::ThreadStatus::STOPPED);
STA_TASTY_ASSERT(sta::rtos::getNumAllocs() == mallocs + 2);
tacos::setState(1, 0);
this->sleep(5);
STA_TASTY_ASSERT(thread_A->isRunning());
STA_TASTY_ASSERT(!thread_B->isRunning());
STA_TASTY_ASSERT(thread_B->getStatus() == tacos::ThreadStatus::STOPPED);
STA_TASTY_ASSERT(sta::rtos::getNumAllocs() == mallocs + 2);
tacos::setState(0, 1);
STA_TASTY_ASSERT(!thread_A->isRunning());
STA_TASTY_ASSERT(thread_B->isRunning());
STA_TASTY_ASSERT(thread_A->getStatus() == tacos::ThreadStatus::STOPPED);
STA_TASTY_ASSERT(sta::rtos::getNumAllocs() == mallocs + 2);
STA_TASTY_TERMINATE();
}
};
void onTastyInit()
{
thread_A = tacos::addThread<ThreadA>({0});
thread_B = tacos::addThread<ThreadB>({1});
tacos::addThread<Observer>({0, 1});
}
} // namespace tasty
}
#endif // TASTY_CASE_9

View File

@ -16,6 +16,8 @@ namespace sta
void test_terminate()
{
STA_DEBUG_PRINTLN("[T]");
while (true) {}
}
} // namespace tasty
} // namespace sta