[test] improve module tests (#3517)

Co-authored-by: Fabien-B <Fabien-B@github.com>.
This commit is contained in:
Fabien-B
2025-08-15 15:48:51 +02:00
committed by GitHub
parent 0008be8ec6
commit a05854c3b3
3 changed files with 36 additions and 4 deletions
+3
View File
@@ -34,5 +34,8 @@
<!-- Load DSDL generated files--> <!-- Load DSDL generated files-->
<include name="$(PAPARAZZI_HOME)/var/include/DSDLcode/include"/> <include name="$(PAPARAZZI_HOME)/var/include/DSDLcode/include"/>
<file name="uavcan.equipment.air_data.RawAirData.c" dir="$(PAPARAZZI_HOME)/var/include/DSDLcode/src"/> <file name="uavcan.equipment.air_data.RawAirData.c" dir="$(PAPARAZZI_HOME)/var/include/DSDLcode/src"/>
<test>
<include name="$(PAPARAZZI_HOME)/sw/ext/dronecan/libcanard"/>
</test>
</makefile> </makefile>
</module> </module>
@@ -0,0 +1,15 @@
#pragma once
#include <inttypes.h>
#include <canard.h>
struct uavcan_iface_t;
typedef struct {} uavcan_event;
typedef void (*uavcan_callback)(struct uavcan_iface_t *iface, CanardRxTransfer *transfer);
void uavcan_init(void);
void uavcan_bind(uint16_t data_type_id, uint64_t data_type_signature, uavcan_event *ev, uavcan_callback cb);
void uavcan_broadcast(struct uavcan_iface_t *iface, uint64_t data_type_signature, uint16_t data_type_id,
uint8_t priority, const void *payload, uint16_t payload_len);
+18 -4
View File
@@ -48,15 +48,15 @@ OTHER_PARAMS: List[str] = [
class Test: class Test:
def __init__(self, tst, files, files_arch, test_name, test_id): def __init__(self, tst, files, files_arch, includes, test_name, test_id):
self.configure_regex = re.compile(r"(\$\([a-zA-Z_][a-zA-Z_0-9]*\))") self.configure_regex = re.compile(r"(\$\([a-zA-Z_][a-zA-Z_0-9]*\))")
self.files = files # type: List[str] self.files = files # type: List[str]
self.files_arch = files_arch # type: List[str] self.files_arch = files_arch # type: List[str]
self.includes = includes # type: List[str]
self.firmware = None # type: Optional[str] self.firmware = None # type: Optional[str]
self.archs = [] # type: List[str] self.archs = [] # type: List[str]
self.defines = [] # type: List[Tuple[str,str, str]] self.defines = [] # type: List[Tuple[str,str, str]]
self.configures = {} # type: Dict[str:str] self.configures = {} # type: Dict[str:str]
self.includes = [] # type: List[str]
self.shells = [] # type: List[str] self.shells = [] # type: List[str]
self.test_name = test_name self.test_name = test_name
self.test_id = test_id self.test_id = test_id
@@ -108,6 +108,10 @@ class Test:
for m in re.findall(self.configure_regex, string): for m in re.findall(self.configure_regex, string):
if m[2:-1] in self.configures.keys(): if m[2:-1] in self.configures.keys():
string = string.replace(m, self.configures[m[2:-1]]) string = string.replace(m, self.configures[m[2:-1]])
else:
env_val = getenv(m[2:-1])
if env_val is not None:
string = string.replace(m, env_val)
return string return string
self.files = map(substitute, self.files) self.files = map(substitute, self.files)
self.files_arch = map(substitute, self.files_arch) self.files_arch = map(substitute, self.files_arch)
@@ -141,7 +145,8 @@ class Test:
for file in self.files: for file in self.files:
# build with the "test" arch. # build with the "test" arch.
arch_include = f"-I../../tests/modules/test_arch" arch_include = f"-I../../tests/modules/test_arch"
cmd_args = [gcc] + GCC_PARAMS + [file] + OTHER_PARAMS + module_id + defines + includes + [arch_include] + shells arch_modules_include = f"-I../../tests/modules/test_arch/modules"
cmd_args = [gcc] + GCC_PARAMS + [file] + OTHER_PARAMS + module_id + defines + includes + [arch_include, arch_modules_include] + shells
cmds.append(cmd_args) cmds.append(cmd_args)
for file in self.files_arch: for file in self.files_arch:
@@ -212,8 +217,9 @@ class Module:
for mkf in mod_elt.findall("makefile"): for mkf in mod_elt.findall("makefile"):
files = self.get_files(mkf) files = self.get_files(mkf)
files_arch = self.get_files_arch(mkf) files_arch = self.get_files_arch(mkf)
includes = self.get_includes(mkf)
for i, tst in enumerate(mkf.findall("test")): for i, tst in enumerate(mkf.findall("test")):
test = Test(tst, files, files_arch, f"{self.name}", i) test = Test(tst, files, files_arch, includes, f"{self.name}", i)
self.tests.append(test) self.tests.append(test)
def get_files(self, mkf): def get_files(self, mkf):
@@ -247,6 +253,14 @@ class Module:
files.append(file_path) files.append(file_path)
return files return files
def get_includes(self, mkf):
includes = []
for include in mkf.findall("include"):
name = include.attrib["name"]
includes.append(name)
return includes
def get_modules(): def get_modules():
files = os.listdir(PPRZ_HOME+"/conf/modules") files = os.listdir(PPRZ_HOME+"/conf/modules")