Skip to content

Commit

Permalink
Merge pull request #45 from MrKevinWeiss/pr/philiphelp
Browse files Browse the repository at this point in the history
Apply fixes and small improvements
  • Loading branch information
MrKevinWeiss authored Nov 3, 2022
2 parents 1c36556 + 5439bd2 commit 7cbe8a2
Show file tree
Hide file tree
Showing 15 changed files with 67 additions and 48 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 30 additions & 2 deletions examples/minimal/README.md
Original file line number Diff line number Diff line change
@@ -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
```
10 changes: 10 additions & 0 deletions examples/minimal/all_outputs.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion examples/minimal/c_files/mm_typedefs_map_1.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/minimal/c_files/mm_typedefs_type_1.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extern "C"

#include "mm_cc.h"

/* tyepdefs ***************************************************************/
/* tyepdefs ******************************************************************/
MM_PACKED_START
typedef union {
struct {
Expand Down
4 changes: 0 additions & 4 deletions examples/minimal/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,3 @@ files:
base_dir: "."

c_dir: c_files

csv_dir: /tmp/gen/csv_files

cfg_dir: /tmp/gen/config
19 changes: 0 additions & 19 deletions examples/philip/read_philip.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion memory_map_manager/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"')
Expand Down
12 changes: 9 additions & 3 deletions memory_map_manager/mmm_config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion memory_map_manager/templates/mm_typedefs_map.h.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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" -%}
2 changes: 1 addition & 1 deletion memory_map_manager/templates/mm_typedefs_type.h.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions test_requirements.txt
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions tests/_regtest_outputs/test_export.test_gen_minimal.out
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ extern "C"
#include "mm_cc.h"
#include "mm_typedefs_type_1.h"

/* tyepdefs ***************************************************************/
/* tyepdefs ******************************************************************/
MM_PACKED_START
typedef union {
struct {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_code_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
15 changes: 3 additions & 12 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7cbe8a2

Please sign in to comment.