Updated test cases to work for TACOS rework

This commit is contained in:
dario 2025-01-17 17:39:33 +01:00
parent b6c929d316
commit 5feca7778f
14 changed files with 64 additions and 33 deletions

View File

@ -19,12 +19,10 @@
#define STA_ASSERT_FORCE
#define STA_DEBUGGING_ENABLED
// Settings for the rtos-utils
#define STA_RTOS_SYSTEM_EVENTS_ENABLE
// Use the default configs for TACOS
#include <sta/tacos/configs/default.hpp>
#define STA_TACOS_WATCHDOG_ENABLED
#define STA_TACOS_WATCHDOG_FREQUENCY 1000
#define STA_TACOS_NUM_STATES 8

View File

@ -10,6 +10,11 @@ namespace sta
{
namespace tasty
{
/**
* @brief Initialize Tasty for the test case.
*
*/
void test_init();
/**
* @brief Print a test result via serial.
*
@ -28,6 +33,12 @@ namespace sta
} // namespace sta
/**
* @brief Initialize Tasty for the test case.
*
*/
#define STA_TASTY_INIT() ( (void)( sta::tasty::test_init() ) )
/**
* @brief Assert statement for automatic testing using tasty. Sends the test result to the host via serial.
*
@ -43,4 +54,4 @@ namespace sta
#endif // STA_DEBUGGING_ENABLED
#endif // STA_TASTY_UTILS_HPP
#endif // STA_TASTY_UTILS_HPP

2
run.py
View File

@ -45,7 +45,7 @@ for case in os.listdir(path):
# Store the results for each file and line combination in a dict.
results = dict()
with serial.Serial('COM4', baudrate=115200) as ser:
with serial.Serial('COM5', baudrate=115200) as ser:
while True:
try:
output = ser.readline().decode()

View File

@ -22,22 +22,24 @@ namespace sta
void func() override
{
STA_TASTY_INIT();
STA_TASTY_ASSERT(tacos::getState() == 0);
// Transitioning from 0 to 1 should work correclty.
tacos::setState(0, 1);
// Transitioning from 0 to 1 should work correctly.
tacos::requestState(0, 1);
STA_TASTY_ASSERT(tacos::getState() == 1);
// Transitioning from 0 to 5 should fail because we are in state 1.
tacos::setState(0, 5);
tacos::requestState(0, 5);
STA_TASTY_ASSERT(tacos::getState() == 1);
// Transitioning from 7 to 0 should fail aswell
tacos::setState(7, 0);
tacos::requestState(7, 0);
STA_TASTY_ASSERT(tacos::getState() == 1);
// Transitioning from 4 to 5 should also fail.
tacos::setState(5, 4);
tacos::requestState(5, 4);
STA_TASTY_ASSERT(tacos::getState() == 1);
STA_TASTY_TERMINATE();

View File

@ -22,6 +22,8 @@ namespace sta
void func() override
{
STA_TASTY_INIT();
STA_TASTY_ASSERT(tacos::getState() == 0);
// Schedule a state transition in 100 ticks.
@ -35,7 +37,7 @@ namespace sta
// ... and still not
STA_TASTY_ASSERT(tacos::getState() == 0);
this->sleep(48);
this->sleep(40);
// ... and still not
STA_TASTY_ASSERT(tacos::getState() == 0);

View File

@ -22,34 +22,36 @@ namespace sta
void func() override
{
STA_TASTY_INIT();
STA_TASTY_ASSERT(tacos::getState() == 0);
// Trigger a state transition with lockout of 100 ticks.
tacos::setState(0, 1, 100);
tacos::requestState(0, 1, 100);
// The state transition should have been executed correctly.
STA_TASTY_ASSERT(tacos::getState() == 1);
// This state transition should get blocked.
tacos::setState(1, 3);
tacos::requestState(1, 3);
STA_TASTY_ASSERT(tacos::getState() == 1);
this->sleep(50);
// This state transition should get blocked.
tacos::setState(1, 4);
tacos::requestState(1, 4);
STA_TASTY_ASSERT(tacos::getState() == 1);
this->sleep(48);
this->sleep(44);
// This state transition should get blocked.
tacos::setState(1, 2);
STA_TASTY_ASSERT(tacos::getState() == 0);
tacos::requestState(1, 2);
STA_TASTY_ASSERT(tacos::getState() == 1);
this->sleep(3);
this->sleep(10);
// This state transition should get executed correctly.
tacos::setState(1, 7);
tacos::requestState(1, 7);
STA_TASTY_ASSERT(tacos::getState() == 7);
STA_TASTY_TERMINATE();

View File

@ -22,10 +22,12 @@ namespace sta
void func() override
{
STA_TASTY_INIT();
STA_TASTY_ASSERT(tacos::getState() == 0);
// Trigger a state transition with lockout of 100 ticks.
tacos::setState(0, 1, 100);
tacos::requestState(0, 1, 100);
// Schedule a state transition to be executed after 50 ticks.
tacos::setStateTimed(1, 2, 50);
@ -33,16 +35,16 @@ namespace sta
// This should have no effect.
STA_TASTY_ASSERT(tacos::getState() == 1);
// Wait for 50 ticks.
this->sleep(50);
// Wait for 60 ticks.
this->sleep(60);
// The state transition should have been blocked by the lockout timer
STA_TASTY_ASSERT(tacos::getState() == 1);
// Schedule a state transition to be executed in 51 ticks.
tacos::setStateTimed(1, 2, 51);
// Schedule a state transition to be executed in 41 ticks.
tacos::setStateTimed(1, 2, 41);
this->sleep(51);
this->sleep(50);
// This state transition should get through.
STA_TASTY_ASSERT(tacos::getState() == 2);

View File

@ -22,6 +22,8 @@ namespace sta
void func() override
{
STA_TASTY_INIT();
STA_TASTY_ASSERT(tacos::getState() == 0);
// Schedule a state transition in 50 ticks.
@ -30,7 +32,7 @@ namespace sta
this->sleep(10);
// Force a state transition now. This should override the timed transition.
tacos::setState(0, 2);
tacos::requestState(0, 2);
STA_TASTY_ASSERT(tacos::getState() == 2);
this->sleep(41);

View File

@ -72,6 +72,8 @@ namespace sta
void onTastyInit()
{
STA_TASTY_INIT();
std::shared_ptr<Victim> victim_ptr = tacos::addThread<Victim>({0});
tacos::addThread<ViciousMurderer>({0}, victim_ptr);
}

View File

@ -75,6 +75,8 @@ namespace sta
void onTastyInit()
{
STA_TASTY_INIT();
tacos::addThread<Dummy>({0});
tacos::addThread<Observer>({0});
}

View File

@ -82,6 +82,8 @@ namespace sta
void onTastyInit()
{
STA_TASTY_INIT();
mutexA = new RtosMutex("MutA");
mutexB = new RtosMutex("MutB");

View File

@ -73,7 +73,7 @@ namespace sta
this->sleep(20);
tacos::setState(0, 1);
tacos::requestState(0, 1);
this->sleep(5);
@ -82,7 +82,7 @@ namespace sta
STA_TASTY_ASSERT(thread_A->getStatus() == tacos::ThreadStatus::STOPPED);
STA_TASTY_ASSERT(sta::rtos::getNumAllocs() == mallocs + 2);
tacos::setState(1, 0);
tacos::requestState(1, 0);
this->sleep(5);
@ -91,7 +91,7 @@ namespace sta
STA_TASTY_ASSERT(thread_B->getStatus() == tacos::ThreadStatus::STOPPED);
STA_TASTY_ASSERT(sta::rtos::getNumAllocs() == mallocs + 2);
tacos::setState(0, 1);
tacos::requestState(0, 1);
STA_TASTY_ASSERT(!thread_A->isRunning());
STA_TASTY_ASSERT(thread_B->isRunning());
@ -104,6 +104,8 @@ namespace sta
void onTastyInit()
{
STA_TASTY_INIT();
thread_A = tacos::addThread<ThreadA>({0});
thread_B = tacos::addThread<ThreadB>({1});
tacos::addThread<Observer>({0, 1});

View File

@ -16,14 +16,12 @@ namespace sta
{
STA_WEAK
void onTastyInit()
{
}
{}
}
namespace tacos
{
void onManagerInit()
void startup()
{
tasty::onTastyInit();
}

View File

@ -3,11 +3,17 @@
#ifdef STA_DEBUGGING_ENABLED
#include <sta/debug/debug.hpp>
#include <sta/devices/stm32/delay.hpp>
namespace sta
{
namespace tasty
{
void test_init()
{
sta::delayMs(10);
}
void test_case(const char * file, uint32_t line, bool rslt)
{
STA_DEBUG_PRINTF("[%s|%d|%d]", file, line, rslt);