From 9dc48e12710ccd1864d78e0f590e5cd49a3ba83f Mon Sep 17 00:00:00 2001 From: dario Date: Tue, 9 Jan 2024 00:19:28 +0100 Subject: [PATCH] First proof of concept for automatic testing --- include/sta/tasty/config.hpp | 5 +-- run.py | 64 ++++++++++++++++++++++++++++++++++++ src/cases/case1.cpp | 4 +-- src/cases/case2.cpp | 4 +-- src/cases/case3.cpp | 4 +-- src/cases/case4.cpp | 4 +-- src/cases/case5.cpp | 4 +-- 7 files changed, 77 insertions(+), 12 deletions(-) create mode 100644 run.py diff --git a/include/sta/tasty/config.hpp b/include/sta/tasty/config.hpp index 8bb9665..73432a9 100644 --- a/include/sta/tasty/config.hpp +++ b/include/sta/tasty/config.hpp @@ -1,6 +1,7 @@ + #ifndef STA_TASTY_CONFIG_HPP #define STA_TASTY_CONFIG_HPP -#define TASTY_CASE_5 +#define TASTY_CASE_7 -#endif // STA_TASTY_CONFIG_HPP +#endif // STA_TASTY_CONFIG_HPP diff --git a/run.py b/run.py new file mode 100644 index 0000000..3fe4de7 --- /dev/null +++ b/run.py @@ -0,0 +1,64 @@ +import serial +import subprocess +import os +import re +import sys + +from termcolor import colored + + +# Just the content we want to paste into the config.hpp file. +cfg_template = """ +#ifndef STA_TASTY_CONFIG_HPP +#define STA_TASTY_CONFIG_HPP + +#define TASTY_CASE_{} + +#endif // STA_TASTY_CONFIG_HPP +""" + +path = 'Tasty/src/cases/' + + +for case in os.listdir(path): + # Find the number of the test case. + match = re.match('case([0-9])+\.cpp', case) + number = match.group(1) + + with open('Tasty/include/sta/tasty/config.hpp', 'w') as f: + f.write(cfg_template.format(number)) + + # Build the new project and upload it to the STM32. + subprocess.call(f'Tasty/flash.bat {case}', stdout=sys.stdout) + + print(colored(f'Running case { number }...', 'blue')) + + # Store the results for each file and line combination in a dict. + results = dict() + + with serial.Serial('COM4', baudrate=115200) as ser: + while True: + try: + output = ser.readline().decode() + except: + continue + + # '[T]' is used to decode the end of a test case. + if '[T]' in output: + break + + # Try to extract the test results from the serial output. + match = re.match('\[(.*?)\|([0-9]+)\|(0|1)\]', output) + + if match is not None: + file, line, result = match.group(1), match.group(2), match.group(3) + + # Update the result for the file and line by logical ANDing it with the new result. + results[(file, line)] = results.get((file, line), True) and int(result) == 1 + + # Print the test results. + for (file, line), result in results.items(): + if result: + print(file + ', line ' + line + '\t' + colored('[PASSED]' , 'green')) + else: + print(file + ', line ' + line + '\t' + colored('[FAILED]' , 'red')) diff --git a/src/cases/case1.cpp b/src/cases/case1.cpp index 5b7d3f3..9edf0b2 100644 --- a/src/cases/case1.cpp +++ b/src/cases/case1.cpp @@ -11,7 +11,7 @@ namespace sta { namespace tasty { - class DummyThread + class DummyThread : public tacos::TacosThread { private: /* data */ @@ -51,4 +51,4 @@ namespace sta } // namespace tasty } // namespace sta -#endif // TASTY_CASE_1 \ No newline at end of file +#endif // TASTY_CASE_1 diff --git a/src/cases/case2.cpp b/src/cases/case2.cpp index 7054fa3..b55b088 100644 --- a/src/cases/case2.cpp +++ b/src/cases/case2.cpp @@ -11,7 +11,7 @@ namespace sta { namespace tasty { - class DummyThread + class DummyThread : public tacos::TacosThread { private: /* data */ @@ -56,4 +56,4 @@ namespace sta } // namespace tasty } // namespace sta -#endif // TASTY_CASE_2 \ No newline at end of file +#endif // TASTY_CASE_2 diff --git a/src/cases/case3.cpp b/src/cases/case3.cpp index d8df185..8fcd392 100644 --- a/src/cases/case3.cpp +++ b/src/cases/case3.cpp @@ -11,7 +11,7 @@ namespace sta { namespace tasty { - class DummyThread + class DummyThread : public tacos::TacosThread { private: /* data */ @@ -63,4 +63,4 @@ namespace sta } // namespace tasty } // namespace sta -#endif // TASTY_CASE_3 \ No newline at end of file +#endif // TASTY_CASE_3 diff --git a/src/cases/case4.cpp b/src/cases/case4.cpp index 83319b5..9305e5c 100644 --- a/src/cases/case4.cpp +++ b/src/cases/case4.cpp @@ -11,7 +11,7 @@ namespace sta { namespace tasty { - class DummyThread + class DummyThread : public tacos::TacosThread { private: /* data */ @@ -58,4 +58,4 @@ namespace sta } // namespace tasty } // namespace sta -#endif // TASTY_CASE_4 \ No newline at end of file +#endif // TASTY_CASE_4 diff --git a/src/cases/case5.cpp b/src/cases/case5.cpp index cbb65d7..76e3793 100644 --- a/src/cases/case5.cpp +++ b/src/cases/case5.cpp @@ -11,7 +11,7 @@ namespace sta { namespace tasty { - class DummyThread + class DummyThread : public tacos::TacosThread { private: /* data */ @@ -49,4 +49,4 @@ namespace sta } // namespace tasty } // namespace sta -#endif // TASTY_CASE_5 \ No newline at end of file +#endif // TASTY_CASE_5