Add RTE SWC dummy files and data types to rte_dummy
Change-Id: I2d29bafbf8d2d67b3aff55de486fbef5f2755845
This commit is contained in:
@@ -939,7 +939,7 @@ def build(
|
||||
if rte_dummy:
|
||||
LOG.info("******************************************************")
|
||||
LOG.info("Generating RTE dummy files")
|
||||
zc_rte = RteDummy(build_cfg, zc_nvm)
|
||||
zc_rte = RteDummy(build_cfg, zc_nvm, composition_yaml.cal_class_info["tl"])
|
||||
zc_rte.generate_rte_dummy()
|
||||
|
||||
if code_generation_config["generateCalibrationInterfaceFiles"]:
|
||||
|
@@ -17,71 +17,96 @@ from pathlib import Path
|
||||
class RteDummy(ProblemLogger):
|
||||
"""A class for RTE dummy file generation."""
|
||||
|
||||
def __init__(self, build_cfg, nvm_def):
|
||||
def __init__(self, build_cfg, nvm_def, calib_data):
|
||||
"""Init.
|
||||
|
||||
Args:
|
||||
build_cfg (BuildProjConfig): Object with build configuration settings.
|
||||
nvm_def (ZCNVMDef): Object with NVM definition information.
|
||||
calib_data (dict): Dictionary containing calibration data for a ZoneController project.
|
||||
"""
|
||||
super().__init__()
|
||||
self.build_cfg = build_cfg
|
||||
self.nvm_def = nvm_def
|
||||
self.header_file_name = "Rte_Type"
|
||||
self.calibration_variables = calib_data.get("class_info", {})
|
||||
self.swc_header_file_name = f"Rte_{self.build_cfg.get_composition_config('softwareComponentName')}"
|
||||
self.type_header_file_name = "Rte_Type"
|
||||
self.source_file_name = "Rte_Dummy"
|
||||
|
||||
def _get_header_header(self):
|
||||
"""Get header for the RTE dummy header."""
|
||||
def _get_common_header(self):
|
||||
"""Get common header for the RTE dummy files."""
|
||||
return (
|
||||
"/*\n"
|
||||
" * This file is generated by the Powertrain Build System.\n"
|
||||
" * It defines RTE dummy types and/or functions.\n"
|
||||
" * Do not modify this file manually.\n"
|
||||
" */\n"
|
||||
)
|
||||
|
||||
def _get_swc_header_content(self):
|
||||
"""Get content for the SWC RTE dummy header."""
|
||||
return (
|
||||
f"{self._get_common_header()}"
|
||||
f"#ifndef {self.swc_header_file_name.upper()}_H\n"
|
||||
f"#define {self.swc_header_file_name.upper()}_H\n\n"
|
||||
f'#include "{self.type_header_file_name}.h"\n'
|
||||
f"#endif /* {self.swc_header_file_name.upper()}_H */\n"
|
||||
)
|
||||
|
||||
def _get_type_header_header(self):
|
||||
"""Get header for the RTE type dummy header."""
|
||||
include_nvm_header = ""
|
||||
if not self.build_cfg.get_code_generation_config("useRteNvmStructs"):
|
||||
nvm_defs = self.build_cfg.get_nvm_defs()
|
||||
nvm_file_name = nvm_defs["fileName"]
|
||||
include_nvm_header = f'#include "{nvm_file_name}.h"\n'
|
||||
return (
|
||||
"/*\n"
|
||||
" * This file is generated by the Powertrain Build System.\n"
|
||||
" * It defines RTE dummy types.\n"
|
||||
" * Do not modify this file manually.\n"
|
||||
" */\n"
|
||||
f"#ifndef {self.header_file_name.upper()}_H\n"
|
||||
f"#define {self.header_file_name.upper()}_H\n\n"
|
||||
f"{self._get_common_header()}"
|
||||
f"#ifndef {self.type_header_file_name.upper()}_H\n"
|
||||
f"#define {self.type_header_file_name.upper()}_H\n\n"
|
||||
'#include "tl_basetypes.h"\n'
|
||||
f"{include_nvm_header}\n"
|
||||
"#define FALSE 0U\n"
|
||||
"#define TRUE 1U\n\n"
|
||||
"#define TRUE 1U\n"
|
||||
)
|
||||
|
||||
def _get_header_footer(self):
|
||||
"""Get footer for the RTE dummy header."""
|
||||
return f"\n#endif /* {self.header_file_name.upper()}_H */\n"
|
||||
def _get_type_header_footer(self):
|
||||
"""Get footer for the RTE type dummy header."""
|
||||
return f"\n#endif /* {self.type_header_file_name.upper()}_H */\n"
|
||||
|
||||
def _get_source_header(self):
|
||||
"""Get header for the RTE dummy source."""
|
||||
return (
|
||||
"/*\n"
|
||||
" * This file is generated by the Powertrain Build System.\n"
|
||||
" * It defines RTE dummy functions.\n"
|
||||
" * Do not modify this file manually.\n"
|
||||
" */\n"
|
||||
f'#include "{self.header_file_name}.h"\n\n'
|
||||
f"{self._get_common_header()}"
|
||||
f'#include "{self.swc_header_file_name}.h"\n\n'
|
||||
)
|
||||
|
||||
def _get_typedef_dummy(self):
|
||||
"""Get typedef dummy code."""
|
||||
typedefs = []
|
||||
|
||||
function_name = self.build_cfg.get_composition_config("compositionName")
|
||||
if function_name is None:
|
||||
function_name = self.build_cfg.get_composition_config("softwareComponentName")
|
||||
if self.build_cfg.get_code_generation_config("generateRteCheckpointIds"):
|
||||
typedefs.append(f"typedef UInt8 {function_name}FctList;\n")
|
||||
|
||||
# MAPs get typedef:ed to structs and need special data type mapping in calibration.py
|
||||
for signal_name, signal_data in self.calibration_variables.items():
|
||||
if isinstance(signal_data["width"], list):
|
||||
if signal_name.startswith("m") and signal_name[-2:] not in ["_r", "_c"]:
|
||||
typedefs.append(f"typedef {signal_data['type']} {signal_data['autosar_type']};\n")
|
||||
typedefs.append("\n")
|
||||
|
||||
return "".join(typedefs)
|
||||
|
||||
def _get_nvm_header_dummy(self):
|
||||
"""Get NVM dummy header code."""
|
||||
typedefs = []
|
||||
struct_defines = []
|
||||
function_declarations = []
|
||||
include_name = self.build_cfg.get_composition_config("softwareComponentName")
|
||||
function_name = self.build_cfg.get_composition_config("compositionName")
|
||||
if function_name is None:
|
||||
function_name = include_name
|
||||
prefix = self.build_cfg.get_scheduler_prefix()
|
||||
use_rte_nvm_structs = self.build_cfg.get_code_generation_config("useRteNvmStructs")
|
||||
|
||||
if self.build_cfg.get_code_generation_config("generateRteCheckpointIds"):
|
||||
typedefs.append(f"typedef UInt8 {function_name}FctList;")
|
||||
typedefs.append("")
|
||||
|
||||
for memory_area in self.nvm_def._nvm_memory_areas:
|
||||
nvm_name = f"{prefix}{memory_area}"
|
||||
struct_name = f"dt_{nvm_name}" if use_rte_nvm_structs else f"struct {nvm_name}"
|
||||
@@ -113,9 +138,40 @@ class RteDummy(ProblemLogger):
|
||||
)
|
||||
struct_defines.append(f"}} {struct_name};\n")
|
||||
|
||||
return "\n".join(typedefs + struct_defines + function_declarations)
|
||||
return "\n".join(struct_defines + function_declarations)
|
||||
|
||||
def _generate_nvm_source_dummy(self):
|
||||
def _get_calibration_source_dummy(self):
|
||||
"""Get calibration source dummy code."""
|
||||
if not self.calibration_variables:
|
||||
return ""
|
||||
|
||||
lines_to_write = []
|
||||
swc_name = self.build_cfg.get_composition_config("softwareComponentName")
|
||||
for signal_name, signal_data in self.calibration_variables.items():
|
||||
if isinstance(signal_data["width"], list):
|
||||
# MAPs get typedef:ed to structs and need special data type mapping in calibration.py
|
||||
if signal_name.startswith("m") and signal_name[-2:] not in ["_r", "_c"]:
|
||||
return_type = f'const {signal_data["autosar_type"]}*'
|
||||
return_string = (
|
||||
f"const {signal_data['autosar_type']} dummy; "
|
||||
f"{return_type} dummyPtr = &dummy; "
|
||||
"return dummyPtr;"
|
||||
)
|
||||
else:
|
||||
return_type = f'const {signal_data["type"]}*'
|
||||
return_string = (
|
||||
f"{signal_data['type']} dummy; "
|
||||
f"{return_type} dummyPtr = &dummy; "
|
||||
"return dummyPtr;"
|
||||
)
|
||||
else:
|
||||
return_type = f'{signal_data["type"]}'
|
||||
return_string = f"return ({return_type})0;"
|
||||
lines_to_write.append(f"{return_type} Rte_CData_{swc_name}_{signal_name}(void) {{ {return_string} }}")
|
||||
lines_to_write.append("")
|
||||
return "\n".join(lines_to_write)
|
||||
|
||||
def _get_nvm_source_dummy(self):
|
||||
"""Generate NVM source dummy code."""
|
||||
lines_to_write = []
|
||||
prefix = self.build_cfg.get_scheduler_prefix()
|
||||
@@ -123,7 +179,8 @@ class RteDummy(ProblemLogger):
|
||||
for memory_area in self.nvm_def._nvm_memory_areas:
|
||||
nvm_name = f"{prefix}{memory_area}"
|
||||
struct_name = f"dt_{nvm_name}" if use_rte_nvm_structs else f"struct {nvm_name}"
|
||||
lines_to_write.append(f"{struct_name} *Rte_Pim_{nvm_name}(void) {{ return ({struct_name} *)0; }}")
|
||||
return_string = f"{struct_name} dummy; {struct_name}* dummyPtr = &dummy; return dummyPtr;"
|
||||
lines_to_write.append(f"{struct_name} *Rte_Pim_{nvm_name}(void) {{ {return_string} }}")
|
||||
lines_to_write.append(f"void Rte_Read_{nvm_name.upper()}_{nvm_name.upper()}({struct_name} *block) {{}}")
|
||||
lines_to_write.append(f"void Rte_Write_{nvm_name.upper()}_{nvm_name.upper()}({struct_name} *block) {{}}")
|
||||
lines_to_write.append("")
|
||||
@@ -132,12 +189,17 @@ class RteDummy(ProblemLogger):
|
||||
def generate_rte_dummy(self):
|
||||
"""Generate RTE dummy files."""
|
||||
src_code_dest_dir = self.build_cfg.get_src_code_dst_dir()
|
||||
header_file = Path(src_code_dest_dir, self.header_file_name + ".h")
|
||||
swc_header_file = Path(src_code_dest_dir, self.swc_header_file_name + ".h")
|
||||
type_header_file = Path(src_code_dest_dir, self.type_header_file_name + ".h")
|
||||
source_file = Path(src_code_dest_dir, self.source_file_name + ".c")
|
||||
with header_file.open(mode="w", encoding="utf-8") as header_fh:
|
||||
header_fh.write(self._get_header_header())
|
||||
header_fh.write(self._get_nvm_header_dummy())
|
||||
header_fh.write(self._get_header_footer())
|
||||
with swc_header_file.open(mode="w", encoding="utf-8") as swc_header_fh:
|
||||
swc_header_fh.write(self._get_swc_header_content())
|
||||
with type_header_file.open(mode="w", encoding="utf-8") as type_header_fh:
|
||||
type_header_fh.write(self._get_type_header_header())
|
||||
type_header_fh.write(self._get_typedef_dummy())
|
||||
type_header_fh.write(self._get_nvm_header_dummy())
|
||||
type_header_fh.write(self._get_type_header_footer())
|
||||
with source_file.open(mode="w", encoding="utf-8") as source_fh:
|
||||
source_fh.write(self._get_source_header())
|
||||
source_fh.write(self._generate_nvm_source_dummy())
|
||||
source_fh.write(self._get_nvm_source_dummy())
|
||||
source_fh.write(self._get_calibration_source_dummy())
|
||||
|
143
test_data/powertrain_build/test_rte_dummy/rte_dummy.py
Normal file
143
test_data/powertrain_build/test_rte_dummy/rte_dummy.py
Normal file
@@ -0,0 +1,143 @@
|
||||
# Copyright 2024 Volvo Car Corporation
|
||||
# Licensed under Apache 2.0.
|
||||
|
||||
"""Unit test data for powertrain_build.rte_dummy."""
|
||||
|
||||
expected_swc_content = (
|
||||
"/*\n"
|
||||
" * This file is generated by the Powertrain Build System.\n"
|
||||
" * It defines RTE dummy types and/or functions.\n"
|
||||
" * Do not modify this file manually.\n"
|
||||
" */\n"
|
||||
"#ifndef RTE_TESTNAME_SC_H\n"
|
||||
"#define RTE_TESTNAME_SC_H\n\n"
|
||||
"#include \"Rte_Type.h\""
|
||||
"\n#endif /* RTE_TESTNAME_SC_H */\n"
|
||||
)
|
||||
|
||||
expected_type_header_header = (
|
||||
"/*\n"
|
||||
" * This file is generated by the Powertrain Build System.\n"
|
||||
" * It defines RTE dummy types and/or functions.\n"
|
||||
" * Do not modify this file manually.\n"
|
||||
" */\n"
|
||||
"#ifndef RTE_TYPE_H\n"
|
||||
"#define RTE_TYPE_H\n\n"
|
||||
"#include \"tl_basetypes.h\"\n"
|
||||
"#include \"vcc_nvm_struct.h\"\n"
|
||||
"\n"
|
||||
"#define FALSE 0U\n"
|
||||
"#define TRUE 1U\n"
|
||||
)
|
||||
|
||||
expected_rte_structs_type_header_header = (
|
||||
"/*\n"
|
||||
" * This file is generated by the Powertrain Build System.\n"
|
||||
" * It defines RTE dummy types and/or functions.\n"
|
||||
" * Do not modify this file manually.\n"
|
||||
" */\n"
|
||||
"#ifndef RTE_TYPE_H\n"
|
||||
"#define RTE_TYPE_H\n\n"
|
||||
"#include \"tl_basetypes.h\"\n"
|
||||
"\n"
|
||||
"#define FALSE 0U\n"
|
||||
"#define TRUE 1U\n"
|
||||
)
|
||||
|
||||
expected_typedefs = "\n"
|
||||
|
||||
expected_rte_structs_typedefs = (
|
||||
"typedef UInt8 testNameFctList;\n"
|
||||
"\n"
|
||||
)
|
||||
|
||||
expected_rte_structs_and_calibration_typedefs = (
|
||||
"typedef UInt8 testNameFctList;\n"
|
||||
"typedef UInt16 dt_mVcSignalOne;\n"
|
||||
"\n"
|
||||
)
|
||||
|
||||
expected_type_header_content = (
|
||||
"struct DUMMY_NVM_LIST_8 *Rte_Pim_DUMMY_NVM_LIST_8(void);\n"
|
||||
"void Rte_Read_DUMMY_NVM_LIST_8_DUMMY_NVM_LIST_8(struct DUMMY_NVM_LIST_8 *block);\n"
|
||||
"void Rte_Write_DUMMY_NVM_LIST_8_DUMMY_NVM_LIST_8(struct DUMMY_NVM_LIST_8 *block);\n"
|
||||
"struct DUMMY_NVM_LIST_16 *Rte_Pim_DUMMY_NVM_LIST_16(void);\n"
|
||||
"void Rte_Read_DUMMY_NVM_LIST_16_DUMMY_NVM_LIST_16(struct DUMMY_NVM_LIST_16 *block);\n"
|
||||
"void Rte_Write_DUMMY_NVM_LIST_16_DUMMY_NVM_LIST_16(struct DUMMY_NVM_LIST_16 *block);"
|
||||
)
|
||||
|
||||
expected_rte_structs_type_header_content = (
|
||||
"typedef struct\n"
|
||||
"{\n"
|
||||
" UInt8 e_dummy;\n"
|
||||
" UInt8 unused[1];\n"
|
||||
"} dt_DUMMY_NVM_LIST_8;\n\n"
|
||||
"typedef struct\n"
|
||||
"{\n"
|
||||
" UInt16 e_dummy2;\n"
|
||||
" UInt16 unused[1];\n"
|
||||
"} dt_DUMMY_NVM_LIST_16;\n"
|
||||
"\n"
|
||||
"dt_DUMMY_NVM_LIST_8 *Rte_Pim_DUMMY_NVM_LIST_8(void);\n"
|
||||
"void Rte_Read_DUMMY_NVM_LIST_8_DUMMY_NVM_LIST_8(dt_DUMMY_NVM_LIST_8 *block);\n"
|
||||
"void Rte_Write_DUMMY_NVM_LIST_8_DUMMY_NVM_LIST_8(dt_DUMMY_NVM_LIST_8 *block);\n"
|
||||
"dt_DUMMY_NVM_LIST_16 *Rte_Pim_DUMMY_NVM_LIST_16(void);\n"
|
||||
"void Rte_Read_DUMMY_NVM_LIST_16_DUMMY_NVM_LIST_16(dt_DUMMY_NVM_LIST_16 *block);\n"
|
||||
"void Rte_Write_DUMMY_NVM_LIST_16_DUMMY_NVM_LIST_16(dt_DUMMY_NVM_LIST_16 *block);"
|
||||
)
|
||||
|
||||
expected_type_header_footer = "\n#endif /* RTE_TYPE_H */\n"
|
||||
|
||||
expected_source_header = (
|
||||
"/*\n"
|
||||
" * This file is generated by the Powertrain Build System.\n"
|
||||
" * It defines RTE dummy types and/or functions.\n"
|
||||
" * Do not modify this file manually.\n"
|
||||
" */\n"
|
||||
"#include \"Rte_testName_SC.h\"\n\n"
|
||||
)
|
||||
|
||||
expected_nvm_source_content = (
|
||||
"struct DUMMY_NVM_LIST_8 *Rte_Pim_DUMMY_NVM_LIST_8(void) { "
|
||||
"struct DUMMY_NVM_LIST_8 dummy; "
|
||||
"struct DUMMY_NVM_LIST_8* dummyPtr = &dummy; "
|
||||
"return dummyPtr; "
|
||||
"}\n"
|
||||
"void Rte_Read_DUMMY_NVM_LIST_8_DUMMY_NVM_LIST_8(struct DUMMY_NVM_LIST_8 *block) {}\n"
|
||||
"void Rte_Write_DUMMY_NVM_LIST_8_DUMMY_NVM_LIST_8(struct DUMMY_NVM_LIST_8 *block) {}\n"
|
||||
"struct DUMMY_NVM_LIST_16 *Rte_Pim_DUMMY_NVM_LIST_16(void) { "
|
||||
"struct DUMMY_NVM_LIST_16 dummy; "
|
||||
"struct DUMMY_NVM_LIST_16* dummyPtr = &dummy; "
|
||||
"return dummyPtr; "
|
||||
"}\n"
|
||||
"void Rte_Read_DUMMY_NVM_LIST_16_DUMMY_NVM_LIST_16(struct DUMMY_NVM_LIST_16 *block) {}\n"
|
||||
"void Rte_Write_DUMMY_NVM_LIST_16_DUMMY_NVM_LIST_16(struct DUMMY_NVM_LIST_16 *block) {}\n"
|
||||
)
|
||||
|
||||
expected_rte_structs_nvm_source_content = (
|
||||
"dt_DUMMY_NVM_LIST_8 *Rte_Pim_DUMMY_NVM_LIST_8(void) { "
|
||||
"dt_DUMMY_NVM_LIST_8 dummy; "
|
||||
"dt_DUMMY_NVM_LIST_8* dummyPtr = &dummy; "
|
||||
"return dummyPtr; "
|
||||
"}\n"
|
||||
"void Rte_Read_DUMMY_NVM_LIST_8_DUMMY_NVM_LIST_8(dt_DUMMY_NVM_LIST_8 *block) {}\n"
|
||||
"void Rte_Write_DUMMY_NVM_LIST_8_DUMMY_NVM_LIST_8(dt_DUMMY_NVM_LIST_8 *block) {}\n"
|
||||
"dt_DUMMY_NVM_LIST_16 *Rte_Pim_DUMMY_NVM_LIST_16(void) { "
|
||||
"dt_DUMMY_NVM_LIST_16 dummy; "
|
||||
"dt_DUMMY_NVM_LIST_16* dummyPtr = &dummy; "
|
||||
"return dummyPtr; "
|
||||
"}\n"
|
||||
"void Rte_Read_DUMMY_NVM_LIST_16_DUMMY_NVM_LIST_16(dt_DUMMY_NVM_LIST_16 *block) {}\n"
|
||||
"void Rte_Write_DUMMY_NVM_LIST_16_DUMMY_NVM_LIST_16(dt_DUMMY_NVM_LIST_16 *block) {}\n"
|
||||
)
|
||||
|
||||
expected_calibration_source_content = ""
|
||||
|
||||
expected_calibration_calibration_source_content = (
|
||||
"const dt_mVcSignalOne* Rte_CData_testName_SC_mVcSignalOne(void) { "
|
||||
"const dt_mVcSignalOne dummy; "
|
||||
"const dt_mVcSignalOne* dummyPtr = &dummy; "
|
||||
"return dummyPtr; "
|
||||
"}\n"
|
||||
"UInt16 Rte_CData_testName_SC_sVcSignalTwo(void) { return (UInt16)0; }\n"
|
||||
)
|
@@ -8,6 +8,7 @@ from pathlib import Path
|
||||
from unittest.mock import MagicMock, patch, mock_open
|
||||
|
||||
from powertrain_build.rte_dummy import RteDummy
|
||||
from test_data.powertrain_build.test_rte_dummy import rte_dummy
|
||||
|
||||
|
||||
def mock_get_composition_config(key):
|
||||
@@ -65,7 +66,7 @@ class TestRteDummy(unittest.TestCase):
|
||||
]
|
||||
}
|
||||
]
|
||||
self.rte_dummy = RteDummy(self.build_cfg, self.nvm_def)
|
||||
self.rte_dummy = RteDummy(self.build_cfg, self.nvm_def, {})
|
||||
|
||||
def test_generate_rte_dummy(self):
|
||||
"""Test RteDummy.generate_rte_dummy()."""
|
||||
@@ -75,111 +76,69 @@ class TestRteDummy(unittest.TestCase):
|
||||
with patch.object(Path, "open", m_open, create=True):
|
||||
self.rte_dummy.generate_rte_dummy()
|
||||
expected = [
|
||||
( # header header
|
||||
"/*\n"
|
||||
" * This file is generated by the Powertrain Build System.\n"
|
||||
" * It defines RTE dummy types.\n"
|
||||
" * Do not modify this file manually.\n"
|
||||
" */\n"
|
||||
"#ifndef RTE_TYPE_H\n"
|
||||
"#define RTE_TYPE_H\n\n"
|
||||
"#include \"tl_basetypes.h\"\n"
|
||||
"#include \"vcc_nvm_struct.h\"\n\n"
|
||||
"#define FALSE 0U\n"
|
||||
"#define TRUE 1U\n\n"
|
||||
),
|
||||
( # header content
|
||||
"\n"
|
||||
"struct DUMMY_NVM_LIST_8 *Rte_Pim_DUMMY_NVM_LIST_8(void);\n"
|
||||
"void Rte_Read_DUMMY_NVM_LIST_8_DUMMY_NVM_LIST_8(struct DUMMY_NVM_LIST_8 *block);\n"
|
||||
"void Rte_Write_DUMMY_NVM_LIST_8_DUMMY_NVM_LIST_8(struct DUMMY_NVM_LIST_8 *block);\n"
|
||||
"struct DUMMY_NVM_LIST_16 *Rte_Pim_DUMMY_NVM_LIST_16(void);\n"
|
||||
"void Rte_Read_DUMMY_NVM_LIST_16_DUMMY_NVM_LIST_16(struct DUMMY_NVM_LIST_16 *block);\n"
|
||||
"void Rte_Write_DUMMY_NVM_LIST_16_DUMMY_NVM_LIST_16(struct DUMMY_NVM_LIST_16 *block);"
|
||||
),
|
||||
( # header footer
|
||||
"\n#endif /* RTE_TYPE_H */\n"
|
||||
),
|
||||
( # source header
|
||||
"/*\n"
|
||||
" * This file is generated by the Powertrain Build System.\n"
|
||||
" * It defines RTE dummy functions.\n"
|
||||
" * Do not modify this file manually.\n"
|
||||
" */\n"
|
||||
"#include \"Rte_Type.h\"\n\n"
|
||||
),
|
||||
( # source content
|
||||
"struct DUMMY_NVM_LIST_8 *Rte_Pim_DUMMY_NVM_LIST_8(void) { return (struct DUMMY_NVM_LIST_8 *)0; }\n"
|
||||
"void Rte_Read_DUMMY_NVM_LIST_8_DUMMY_NVM_LIST_8(struct DUMMY_NVM_LIST_8 *block) {}\n"
|
||||
"void Rte_Write_DUMMY_NVM_LIST_8_DUMMY_NVM_LIST_8(struct DUMMY_NVM_LIST_8 *block) {}\n"
|
||||
"struct DUMMY_NVM_LIST_16 *Rte_Pim_DUMMY_NVM_LIST_16(void) { return (struct DUMMY_NVM_LIST_16 *)0; }\n"
|
||||
"void Rte_Read_DUMMY_NVM_LIST_16_DUMMY_NVM_LIST_16(struct DUMMY_NVM_LIST_16 *block) {}\n"
|
||||
"void Rte_Write_DUMMY_NVM_LIST_16_DUMMY_NVM_LIST_16(struct DUMMY_NVM_LIST_16 *block) {}\n"
|
||||
)
|
||||
rte_dummy.expected_swc_content,
|
||||
rte_dummy.expected_type_header_header,
|
||||
rte_dummy.expected_typedefs,
|
||||
rte_dummy.expected_type_header_content,
|
||||
rte_dummy.expected_type_header_footer,
|
||||
rte_dummy.expected_source_header,
|
||||
rte_dummy.expected_nvm_source_content,
|
||||
rte_dummy.expected_calibration_source_content,
|
||||
]
|
||||
self.assertListEqual(result, expected)
|
||||
|
||||
def test_generate_rte_dummy_rte_structs(self):
|
||||
"""Test RteDummy.generate_rte_dummy()."""
|
||||
self.build_cfg.get_code_generation_config.return_value = True
|
||||
self.rte_dummy = RteDummy(self.build_cfg, self.nvm_def)
|
||||
self.rte_dummy = RteDummy(self.build_cfg, self.nvm_def, {})
|
||||
result = []
|
||||
m_open = mock_open()
|
||||
m_open.return_value.write = result.append
|
||||
with patch.object(Path, "open", m_open, create=True):
|
||||
self.rte_dummy.generate_rte_dummy()
|
||||
expected = [
|
||||
( # header header
|
||||
"/*\n"
|
||||
" * This file is generated by the Powertrain Build System.\n"
|
||||
" * It defines RTE dummy types.\n"
|
||||
" * Do not modify this file manually.\n"
|
||||
" */\n"
|
||||
"#ifndef RTE_TYPE_H\n"
|
||||
"#define RTE_TYPE_H\n\n"
|
||||
"#include \"tl_basetypes.h\"\n"
|
||||
"\n"
|
||||
"#define FALSE 0U\n"
|
||||
"#define TRUE 1U\n\n"
|
||||
),
|
||||
( # header content
|
||||
"typedef UInt8 testNameFctList;\n"
|
||||
"\n"
|
||||
"typedef struct\n"
|
||||
"{\n"
|
||||
" UInt8 e_dummy;\n"
|
||||
" UInt8 unused[1];\n"
|
||||
"} dt_DUMMY_NVM_LIST_8;\n\n"
|
||||
"typedef struct\n"
|
||||
"{\n"
|
||||
" UInt16 e_dummy2;\n"
|
||||
" UInt16 unused[1];\n"
|
||||
"} dt_DUMMY_NVM_LIST_16;\n\n"
|
||||
"dt_DUMMY_NVM_LIST_8 *Rte_Pim_DUMMY_NVM_LIST_8(void);\n"
|
||||
"void Rte_Read_DUMMY_NVM_LIST_8_DUMMY_NVM_LIST_8(dt_DUMMY_NVM_LIST_8 *block);\n"
|
||||
"void Rte_Write_DUMMY_NVM_LIST_8_DUMMY_NVM_LIST_8(dt_DUMMY_NVM_LIST_8 *block);\n"
|
||||
"dt_DUMMY_NVM_LIST_16 *Rte_Pim_DUMMY_NVM_LIST_16(void);\n"
|
||||
"void Rte_Read_DUMMY_NVM_LIST_16_DUMMY_NVM_LIST_16(dt_DUMMY_NVM_LIST_16 *block);\n"
|
||||
"void Rte_Write_DUMMY_NVM_LIST_16_DUMMY_NVM_LIST_16(dt_DUMMY_NVM_LIST_16 *block);"
|
||||
),
|
||||
( # header footer
|
||||
"\n#endif /* RTE_TYPE_H */\n"
|
||||
),
|
||||
( # source header
|
||||
"/*\n"
|
||||
" * This file is generated by the Powertrain Build System.\n"
|
||||
" * It defines RTE dummy functions.\n"
|
||||
" * Do not modify this file manually.\n"
|
||||
" */\n"
|
||||
"#include \"Rte_Type.h\"\n\n"
|
||||
),
|
||||
( # source content
|
||||
"dt_DUMMY_NVM_LIST_8 *Rte_Pim_DUMMY_NVM_LIST_8(void) { return (dt_DUMMY_NVM_LIST_8 *)0; }\n"
|
||||
"void Rte_Read_DUMMY_NVM_LIST_8_DUMMY_NVM_LIST_8(dt_DUMMY_NVM_LIST_8 *block) {}\n"
|
||||
"void Rte_Write_DUMMY_NVM_LIST_8_DUMMY_NVM_LIST_8(dt_DUMMY_NVM_LIST_8 *block) {}\n"
|
||||
"dt_DUMMY_NVM_LIST_16 *Rte_Pim_DUMMY_NVM_LIST_16(void) { return (dt_DUMMY_NVM_LIST_16 *)0; }\n"
|
||||
"void Rte_Read_DUMMY_NVM_LIST_16_DUMMY_NVM_LIST_16(dt_DUMMY_NVM_LIST_16 *block) {}\n"
|
||||
"void Rte_Write_DUMMY_NVM_LIST_16_DUMMY_NVM_LIST_16(dt_DUMMY_NVM_LIST_16 *block) {}\n"
|
||||
)
|
||||
rte_dummy.expected_swc_content,
|
||||
rte_dummy.expected_rte_structs_type_header_header,
|
||||
rte_dummy.expected_rte_structs_typedefs,
|
||||
rte_dummy.expected_rte_structs_type_header_content,
|
||||
rte_dummy.expected_type_header_footer,
|
||||
rte_dummy.expected_source_header,
|
||||
rte_dummy.expected_rte_structs_nvm_source_content,
|
||||
rte_dummy.expected_calibration_source_content,
|
||||
]
|
||||
self.assertListEqual(result, expected)
|
||||
|
||||
def test_generate_rte_dummy_rte_structs_and_calibration(self):
|
||||
"""Test RteDummy.generate_rte_dummy()."""
|
||||
self.build_cfg.get_code_generation_config.return_value = True
|
||||
calibration_data = {
|
||||
"class_info": {
|
||||
"mVcSignalOne": {
|
||||
"width": [2, 2],
|
||||
"type": "UInt16",
|
||||
"autosar_type": "dt_mVcSignalOne",
|
||||
},
|
||||
"sVcSignalTwo": {
|
||||
"width": 1,
|
||||
"type": "UInt16",
|
||||
"autosar_type": "UInt16",
|
||||
},
|
||||
}
|
||||
}
|
||||
self.rte_dummy = RteDummy(self.build_cfg, self.nvm_def, calibration_data)
|
||||
result = []
|
||||
m_open = mock_open()
|
||||
m_open.return_value.write = result.append
|
||||
with patch.object(Path, "open", m_open, create=True):
|
||||
self.rte_dummy.generate_rte_dummy()
|
||||
expected = [
|
||||
rte_dummy.expected_swc_content,
|
||||
rte_dummy.expected_rte_structs_type_header_header,
|
||||
rte_dummy.expected_rte_structs_and_calibration_typedefs,
|
||||
rte_dummy.expected_rte_structs_type_header_content,
|
||||
rte_dummy.expected_type_header_footer,
|
||||
rte_dummy.expected_source_header,
|
||||
rte_dummy.expected_rte_structs_nvm_source_content,
|
||||
rte_dummy.expected_calibration_calibration_source_content
|
||||
]
|
||||
self.assertListEqual(result, expected)
|
||||
|
Reference in New Issue
Block a user