From 978c30f383873d7d34f6e6852605b87fd0257be5 Mon Sep 17 00:00:00 2001 From: MrKevinWeiss Date: Thu, 3 Nov 2022 11:45:15 +0100 Subject: [PATCH 1/7] cleanup(examples): remove unused file --- examples/philip/read_philip.yaml | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 examples/philip/read_philip.yaml diff --git a/examples/philip/read_philip.yaml b/examples/philip/read_philip.yaml deleted file mode 100644 index e2e5839..0000000 --- a/examples/philip/read_philip.yaml +++ /dev/null @@ -1,19 +0,0 @@ ---- -files: - - adc.yaml - - dac.yaml - - gpio.yaml - - i2c.yaml - - map.yaml - - pwm.yaml - - rtc.yaml - - spi.yaml - - sys.yaml - - tmr.yaml - - uart.yaml - -c_dir: /home/weiss/wd/PHiLIP/FW/MMM - -csv_dir: /home/weiss/wd/PHiLIP/IF/philip_pal/philip_pal/mem_map - -config_dir: /home/weiss/wd/PHiLIP From 47515e1dff35dcbf5b176048349c97113543592e Mon Sep 17 00:00:00 2001 From: MrKevinWeiss Date: Thu, 3 Nov 2022 12:10:03 +0100 Subject: [PATCH 2/7] fix(examples/minimal): Only generate c_files Since the paths are linux specific and not used for the test we can just remove them. --- examples/minimal/main.yaml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/examples/minimal/main.yaml b/examples/minimal/main.yaml index 479c402..5371855 100644 --- a/examples/minimal/main.yaml +++ b/examples/minimal/main.yaml @@ -4,7 +4,3 @@ files: base_dir: "." c_dir: c_files - -csv_dir: /tmp/gen/csv_files - -cfg_dir: /tmp/gen/config From 084059624a151d7cd319420529066d583e204126 Mon Sep 17 00:00:00 2001 From: MrKevinWeiss Date: Thu, 3 Nov 2022 12:10:38 +0100 Subject: [PATCH 3/7] doc(examples/minimal): Add usage --- examples/minimal/README.md | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/examples/minimal/README.md b/examples/minimal/README.md index e8519c8..9868d42 100644 --- a/examples/minimal/README.md +++ b/examples/minimal/README.md @@ -1,2 +1,30 @@ -This example show the bare minimum data needed to run the generator. -It also includes the output of the map as well as C tests. +This is an example of the bare minimum map requirements. +It contains the map, the map c_file outputs, and a simple C program to ensure that the c_file outputs can be used. + +Note that the `CMake.txt` and `tests` have been manually created. +Also remember that the [schema](../../memory_map_manager/data/mm_map_cfg.json) states that unassigned default values of the maps will be 0. + +# Usage + +Regenerate the files with: +``` +mmm-gen +``` + +Build the binaries (assuming CMake is setup): +``` +cmake -S . -B build +cmake --build build/ +``` + +Test the binaries: +``` +cd build +ctest +cd .. +``` + +Verify the output manually: +``` +./build/tests/test_0 +``` From 21ea68ebd4227c851d6e4f58bb8ad80ae98a1335 Mon Sep 17 00:00:00 2001 From: MrKevinWeiss Date: Thu, 3 Nov 2022 12:11:52 +0100 Subject: [PATCH 4/7] chore: Fix typo --- memory_map_manager/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/memory_map_manager/__main__.py b/memory_map_manager/__main__.py index e3c7dda..60b37a2 100644 --- a/memory_map_manager/__main__.py +++ b/memory_map_manager/__main__.py @@ -42,7 +42,7 @@ def main(): parser.add_argument("--clean", "-C", action="store_true", help='clean the generated directories before ' - 'generation. be careful!') + 'generation. Be careful!') parser.add_argument('--loglevel', choices=log_levels, default='info', help='python logger log level, defaults to "info"') From 9fcc4b809a3e80a3eaaf1343c99d2d4ad1176699 Mon Sep 17 00:00:00 2001 From: MrKevinWeiss Date: Thu, 3 Nov 2022 12:24:03 +0100 Subject: [PATCH 5/7] doc: Recommend pipx or venv for install --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index b653dad..153e869 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,8 @@ offset and size. ## Installation +_As this is a "console application" one can use a `venv` or `pipx` instead of pip._ + Stable versions can be installed with: ``` pip install memory-map-manager From a36b77eb421d6bcb86ee838132708ee2fcc9f441 Mon Sep 17 00:00:00 2001 From: MrKevinWeiss Date: Thu, 3 Nov 2022 13:12:25 +0100 Subject: [PATCH 6/7] fix(tests): Fix broken cov and tests --- examples/minimal/all_outputs.yaml | 10 ++++++++++ examples/minimal/c_files/mm_typedefs_map_1.h | 2 +- examples/minimal/c_files/mm_typedefs_type_1.h | 2 +- memory_map_manager/templates/mm_typedefs_map.h.j2 | 2 +- .../templates/mm_typedefs_type.h.j2 | 2 +- test_requirements.txt | 5 +++++ .../test_export.test_gen_minimal.out | 4 ++-- tests/test_code_gen.py | 2 +- tox.ini | 15 +++------------ 9 files changed, 25 insertions(+), 19 deletions(-) create mode 100644 examples/minimal/all_outputs.yaml create mode 100644 test_requirements.txt diff --git a/examples/minimal/all_outputs.yaml b/examples/minimal/all_outputs.yaml new file mode 100644 index 0000000..479c402 --- /dev/null +++ b/examples/minimal/all_outputs.yaml @@ -0,0 +1,10 @@ +files: + - my_minimal_map.yaml + +base_dir: "." + +c_dir: c_files + +csv_dir: /tmp/gen/csv_files + +cfg_dir: /tmp/gen/config diff --git a/examples/minimal/c_files/mm_typedefs_map_1.h b/examples/minimal/c_files/mm_typedefs_map_1.h index 7f95f24..a0033eb 100644 --- a/examples/minimal/c_files/mm_typedefs_map_1.h +++ b/examples/minimal/c_files/mm_typedefs_map_1.h @@ -20,7 +20,7 @@ extern "C" #include "mm_cc.h" #include "mm_typedefs_type_1.h" -/* tyepdefs ***************************************************************/ +/* tyepdefs ******************************************************************/ typedef type_1 map_1; #ifdef __cplusplus diff --git a/examples/minimal/c_files/mm_typedefs_type_1.h b/examples/minimal/c_files/mm_typedefs_type_1.h index 7875f28..ae50f46 100644 --- a/examples/minimal/c_files/mm_typedefs_type_1.h +++ b/examples/minimal/c_files/mm_typedefs_type_1.h @@ -21,7 +21,7 @@ extern "C" #include "mm_cc.h" -/* tyepdefs ***************************************************************/ +/* tyepdefs ******************************************************************/ MM_PACKED_START typedef union { struct { diff --git a/memory_map_manager/templates/mm_typedefs_map.h.j2 b/memory_map_manager/templates/mm_typedefs_map.h.j2 index f31ba55..05fb479 100644 --- a/memory_map_manager/templates/mm_typedefs_map.h.j2 +++ b/memory_map_manager/templates/mm_typedefs_map.h.j2 @@ -10,7 +10,7 @@ #include "mm_typedefs_{{ dep }}.h" {%- endfor %} -/* tyepdefs {{ '*' * (line_width - 18) }}*/{{ "\n/** @brief " + typedef.description + " */" if typedef.description}} +/* tyepdefs {{ '*' * (line_width - 15) }}*/{{ "\n/** @brief " + typedef.description + " */" if typedef.description}} typedef {{ name }} {{ map_name }}; {% include "header_end.h.j2" -%} diff --git a/memory_map_manager/templates/mm_typedefs_type.h.j2 b/memory_map_manager/templates/mm_typedefs_type.h.j2 index bca784a..da7541c 100644 --- a/memory_map_manager/templates/mm_typedefs_type.h.j2 +++ b/memory_map_manager/templates/mm_typedefs_type.h.j2 @@ -14,7 +14,7 @@ #include "mm_typedefs_{{ dep }}.h" {%- endfor %} -/* tyepdefs {{ '*' * (line_width - 18) }}*/ +/* tyepdefs {{ '*' * (line_width - 15) }}*/ MM_PACKED_START{{ "\n/** @brief " + typedef.description + " */" if typedef.description}} typedef union { struct { diff --git a/test_requirements.txt b/test_requirements.txt new file mode 100644 index 0000000..2d7c25c --- /dev/null +++ b/test_requirements.txt @@ -0,0 +1,5 @@ +pytest==7.2.0 +pytest-cov==4.0.0 +py # Needed for broken pytest-regtest +pytest-regtest==1.5.0 +pytest-console-scripts==1.3.1 diff --git a/tests/_regtest_outputs/test_export.test_gen_minimal.out b/tests/_regtest_outputs/test_export.test_gen_minimal.out index 1329b58..700c036 100644 --- a/tests/_regtest_outputs/test_export.test_gen_minimal.out +++ b/tests/_regtest_outputs/test_export.test_gen_minimal.out @@ -162,7 +162,7 @@ extern "C" #include "mm_cc.h" #include "mm_typedefs_type_1.h" -/* tyepdefs ***************************************************************/ +/* tyepdefs ******************************************************************/ MM_PACKED_START typedef union { struct { @@ -200,7 +200,7 @@ extern "C" #include "mm_typedefs_type_1.h" #include "mm_typedefs_type_1.h" -/* tyepdefs ***************************************************************/ +/* tyepdefs ******************************************************************/ typedef type_1 map_1; #ifdef __cplusplus diff --git a/tests/test_code_gen.py b/tests/test_code_gen.py index 7e929d7..940fa7f 100644 --- a/tests/test_code_gen.py +++ b/tests/test_code_gen.py @@ -20,7 +20,7 @@ def test_cli_minimal(script_runner): ret = script_runner.run('mmm-gen', '-p', 'examples/minimal/main.yaml') assert ret.success assert 'SUCCESS' in ret.stdout - ret = script_runner.run('mmm-gen', '-p', 'examples/minimal/main.yaml') + ret = script_runner.run('mmm-gen', '-p', 'examples/minimal/all_outputs.yaml') assert ret.success assert 'SUCCESS' in ret.stdout ret = script_runner.run('mmm-gen', '-p', 'examples/minimal/main.yaml', '-C') diff --git a/tox.ini b/tox.ini index b674bd5..7a5a553 100644 --- a/tox.ini +++ b/tox.ini @@ -22,30 +22,21 @@ commands = [testenv:test] deps = - pytest - pytest-cov - pytest-regtest - pytest-console-scripts + -rtest_requirements.txt -rrequirements.txt commands = pytest [testenv:testmin] deps = - pytest - pytest-cov - pytest-regtest - pytest-console-scripts + -rtest_requirements.txt -rmin_requirements.txt commands = pytest [testenv:testmax] deps = - pytest - pytest-cov - pytest-regtest - pytest-console-scripts + -rtest_requirements.txt commands = pip install . --upgrade pytest From 5439bd26ac463a920461435a979f17e0deb3bd20 Mon Sep 17 00:00:00 2001 From: MrKevinWeiss Date: Thu, 3 Nov 2022 13:32:24 +0100 Subject: [PATCH 7/7] feat: Improve recursion error --- memory_map_manager/mmm_config_parser.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/memory_map_manager/mmm_config_parser.py b/memory_map_manager/mmm_config_parser.py index 6b28463..25af182 100644 --- a/memory_map_manager/mmm_config_parser.py +++ b/memory_map_manager/mmm_config_parser.py @@ -641,6 +641,7 @@ def _resolve_typedef_order(self, typedefs): known_types = list(self.PRIMARIES.keys()) kbfe = list(self._bfs.keys()) kbfe.extend(self._enums.keys()) + unresolved_types = [] while True: type_count = len(known_types) finished = True @@ -652,17 +653,22 @@ def _resolve_typedef_order(self, typedefs): r_type = ele.get('type', self.default_type) if r_type not in known_types and r_type not in kbfe: finished = False + unresolved_types.append(r_type) break else: known_types.append(td_name) + if td_name in unresolved_types: + unresolved_types.remove(td_name) if finished: break if type_count == len(known_types): - missing_deps = set(typedefs.keys()) - set(known_types) - raise RecursionError(f'Cannot resolve {missing_deps} types ' + unresolved_types = list(set(unresolved_types)) + missing_deps = list(set(typedefs.keys()) - set(known_types)) + raise RecursionError(f'Cannot resolve {missing_deps} typedefs ' 'due to missing definition/circular ' - 'dependency') + f'dependency/typo. {unresolved_types} ' + 'types are not resolved.') return [x for x in known_types if x not in self.PRIMARIES] def _calc_rtype(self, bit_total, r_type):