diff --git a/include/sta/config.hpp b/include/sta/config.hpp index e759d53..e9db13c 100644 --- a/include/sta/config.hpp +++ b/include/sta/config.hpp @@ -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 +#define STA_TACOS_WATCHDOG_ENABLED #define STA_TACOS_WATCHDOG_FREQUENCY 1000 #define STA_TACOS_NUM_STATES 8 diff --git a/include/sta/tasty/utils.hpp b/include/sta/tasty/utils.hpp index 64cb9fd..fd59d3c 100644 --- a/include/sta/tasty/utils.hpp +++ b/include/sta/tasty/utils.hpp @@ -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 \ No newline at end of file +#endif // STA_TASTY_UTILS_HPP diff --git a/run.py b/run.py index d72bdf8..d78c20d 100644 --- a/run.py +++ b/run.py @@ -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() diff --git a/src/cases/case1.cpp b/src/cases/case1.cpp index 9edf0b2..3ac3b79 100644 --- a/src/cases/case1.cpp +++ b/src/cases/case1.cpp @@ -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(); diff --git a/src/cases/case2.cpp b/src/cases/case2.cpp index b55b088..00008b2 100644 --- a/src/cases/case2.cpp +++ b/src/cases/case2.cpp @@ -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); diff --git a/src/cases/case3.cpp b/src/cases/case3.cpp index 8fcd392..5cfcfac 100644 --- a/src/cases/case3.cpp +++ b/src/cases/case3.cpp @@ -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(); diff --git a/src/cases/case4.cpp b/src/cases/case4.cpp index 9305e5c..4c2059a 100644 --- a/src/cases/case4.cpp +++ b/src/cases/case4.cpp @@ -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); diff --git a/src/cases/case5.cpp b/src/cases/case5.cpp index 1df1372..2c28ae1 100644 --- a/src/cases/case5.cpp +++ b/src/cases/case5.cpp @@ -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); diff --git a/src/cases/case6.cpp b/src/cases/case6.cpp index 744cfb9..aa79595 100644 --- a/src/cases/case6.cpp +++ b/src/cases/case6.cpp @@ -72,6 +72,8 @@ namespace sta void onTastyInit() { + STA_TASTY_INIT(); + std::shared_ptr victim_ptr = tacos::addThread({0}); tacos::addThread({0}, victim_ptr); } diff --git a/src/cases/case7.cpp b/src/cases/case7.cpp index 5f9b70e..42a1964 100644 --- a/src/cases/case7.cpp +++ b/src/cases/case7.cpp @@ -75,6 +75,8 @@ namespace sta void onTastyInit() { + STA_TASTY_INIT(); + tacos::addThread({0}); tacos::addThread({0}); } diff --git a/src/cases/case8.cpp b/src/cases/case8.cpp index 7c7e643..cf0cf7c 100644 --- a/src/cases/case8.cpp +++ b/src/cases/case8.cpp @@ -82,6 +82,8 @@ namespace sta void onTastyInit() { + STA_TASTY_INIT(); + mutexA = new RtosMutex("MutA"); mutexB = new RtosMutex("MutB"); diff --git a/src/cases/case9.cpp b/src/cases/case9.cpp index 6c23e87..1117f50 100644 --- a/src/cases/case9.cpp +++ b/src/cases/case9.cpp @@ -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({0}); thread_B = tacos::addThread({1}); tacos::addThread({0, 1}); diff --git a/src/startup.cpp b/src/startup.cpp index 5452f27..98e49c8 100644 --- a/src/startup.cpp +++ b/src/startup.cpp @@ -16,14 +16,12 @@ namespace sta { STA_WEAK void onTastyInit() - { - - } + {} } namespace tacos { - void onManagerInit() + void startup() { tasty::onTastyInit(); } diff --git a/src/utils.cpp b/src/utils.cpp index 01010af..94efeb9 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -3,11 +3,17 @@ #ifdef STA_DEBUGGING_ENABLED #include +#include 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);