First proof of concept for automatic testing

This commit is contained in:
dario 2024-01-09 00:19:28 +01:00
parent d8b4258b20
commit 9dc48e1271
7 changed files with 77 additions and 12 deletions

View File

@ -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

64
run.py Normal file
View File

@ -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'))

View File

@ -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
#endif // TASTY_CASE_1

View File

@ -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
#endif // TASTY_CASE_2

View File

@ -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
#endif // TASTY_CASE_3

View File

@ -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
#endif // TASTY_CASE_4

View File

@ -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
#endif // TASTY_CASE_5