Skip to content

Commit

Permalink
added command line arg for max map size
Browse files Browse the repository at this point in the history
  • Loading branch information
cracked-machine committed Feb 5, 2024
1 parent 2850506 commit 5dc21c0
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 29 deletions.
10 changes: 5 additions & 5 deletions doc/example/report.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
![memory map diagram](report.png)
|name|origin|size|remaining|collisions
|:-|:-|:-|:-|:-|
|<span style='color:darkolivegreen'>kernel</span>|0x10|0x50|-0x10|{'rootfs': '0x50'}|
|<span style='color:darkviolet'>uboot</span>|0xD0|0x50|-0x10|{'uboot-scr': '0x110'}|
|<span style='color:slategrey'>rootfs</span>|0x50|0x30|0x10|{'kernel': '0x50'}|
|<span style='color:mediumaquamarine'>dtb</span>|0x90|0x30|0x10|{}|
|<span style='color:mediumslateblue'>uboot-scr</span>|0x110|0x30|0x2a8|{'uboot': '0x110'}|
|<span style='color:dimgrey'>kernel</span>|0x10|0x50|-0x10|{'rootfs': '0x50'}|
|<span style='color:aquamarine'>uboot</span>|0xD0|0x50|-0x10|{'uboot-scr': '0x110'}|
|<span style='color:darkolivegreen'>rootfs</span>|0x50|0x30|0x10|{'kernel': '0x50'}|
|<span style='color:slategray'>dtb</span>|0x90|0x30|0x10|{}|
|<span style='color:darkturquoise'>uboot-scr</span>|0x110|0x30|0x50|{'uboot': '0x110'}|
Binary file modified doc/example/report.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 6 additions & 3 deletions mm/diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
@typeguard.typechecked
class MemoryMap:

height = 1000
height = 400
"""height of the diagram image"""
width = 400
"""width of the diagram image"""
Expand All @@ -37,7 +37,6 @@ def __init__(self):
self._region_list = None
"""List of region objects"""

logging.debug("")
# create a list of region objects populated with input data
self._region_list = self._process_input()

Expand Down Expand Up @@ -145,10 +144,14 @@ def _process_input(self) -> List[mm.types.Region]:
self.parser = argparse.ArgumentParser()
self.parser.add_argument("regions", help='command line input for regions should be tuples of name, origin and size.',
nargs="*")
self.parser.add_argument("-o", "--out", help='path to the markdown output report file. Defaults to "out/report.md"',
self.parser.add_argument("-o", "--out", help='path to the markdown output report file. Default: "out/report.md"',
default="out/report.md")
self.parser.add_argument("-l", "--limit", help="The maximum memory address for the diagram. Default: 400", default=400, type=int)
self.args = self.parser.parse_args()

if self.args.limit:
MemoryMap.height = self.args.limit

if len(sys.argv) == 1:
self.parser.error("must pass in data points")
if len(self.args.regions) % 3:
Expand Down
28 changes: 15 additions & 13 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
[![Build](https://github.com/cracked-machine/mmdiagram/actions/workflows/python-app.yml/badge.svg)](https://github.com/cracked-machine/mmdiagram/actions/workflows/python-app.yml)
[![Codecov](https://img.shields.io/codecov/c/github/cracked-machine/mmdiagram)](https://app.codecov.io/gh/cracked-machine/mmdiagram)

### Setup
Tool for mapping of regions in memory, specifcally for visualising and troubleshooting region overlap/collision.

Run `sudo make init` to install python deps and linux packages.
![](doc/example/report.png)

As well as the `png` format diagram image, a `markdown` report is also created:
- inline image of the diagram
- collision data table

An example can be found in [doc/example/report.md](doc/example/report.md)

### Usage:

```
usage: generator.py [-h] [-o OUT] [regions ...]
usage: mm.diagram [-h] [-o OUT] [-l LIMIT] [regions ...]
positional arguments:
regions command line input for regions should be tuples of name, origin and size.
regions command line input for regions should be tuples of name, origin and size.
options:
-h, --help show this help message and exit
-o OUT, --out OUT path to the markdown output report file. Defaults to "out/report.md"
-h, --help show this help message and exit
-o OUT, --out OUT path to the markdown output report file. Default: "out/report.md"
-l LIMIT, --limit LIMIT
The maximum memory address for the diagram. Default: 400
```

- Generate five regions called `kernel`, `rootfs`, `dtb`, `uboot` and `uboot-scr` where four of the five regions intersect/collide. The default report output path is used.
- Generate five regions called `kernel`, `rootfs`, `dtb`, `uboot` and `uboot-scr` where four of the five regions intersect/collide. The default report output path is used. Diagram output is shown at the top of the page.

```
python3 -m mm.diagram kernel 0x10 0x50 rootfs 0x50 0x30 dtb 0x90 0x30 uboot 0xD0 0x50 uboot-scr 0x110 0x30
```

![](doc/example/report.png)

### Output

As well as the `png` format diagram image, a markdown report is also created:
- inline image of the diagram
- collision data table

An example can be found in [doc/example/report.md](doc/example/report.md)
24 changes: 18 additions & 6 deletions tests/test_distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ def test_distance_three_regions_same_size_no_collisions():
'0x90',
'0x30',
"-o",
f"/tmp/pytest/{__name__}.md"],
f"/tmp/pytest/{__name__}.md",
"-l",
"1000"],
mm.diagram.MemoryMap.height, 1000):

d = mm.diagram.MemoryMap()
Expand Down Expand Up @@ -52,7 +54,9 @@ def test_distance_three_regions_touching_no_collisions():
'0x70',
'0x30',
"-o",
f"/tmp/pytest/{__name__}.md"],
f"/tmp/pytest/{__name__}.md",
"-l",
"1000"],
mm.diagram.MemoryMap.height, 1000):

d = mm.diagram.MemoryMap()
Expand Down Expand Up @@ -84,7 +88,9 @@ def test_distance_three_regions_diff_size_no_collisions():
'0x90',
'0x30',
"-o",
f"/tmp/pytest/{__name__}.md"],
f"/tmp/pytest/{__name__}.md",
"-l",
"1000"],
mm.diagram.MemoryMap.height, 1000):
d = mm.diagram.MemoryMap()
for region in d._region_list:
Expand Down Expand Up @@ -116,7 +122,9 @@ def test_distance_three_regions_bottom_collision():
'0x90',
'0x30',
"-o",
f"/tmp/pytest/{__name__}.md"],
f"/tmp/pytest/{__name__}.md",
"-l",
"1000"],
mm.diagram.MemoryMap.height, 1000):
d = mm.diagram.MemoryMap()
for region in d._region_list:
Expand Down Expand Up @@ -148,7 +156,9 @@ def test_distance_three_regions_bottom_middle_collision():
'0x90',
'0x30',
"-o",
f"/tmp/pytest/{__name__}.md"],
f"/tmp/pytest/{__name__}.md",
"-l",
"1000"],
mm.diagram.MemoryMap.height, 1000):
d = mm.diagram.MemoryMap()
for region in d._region_list:
Expand Down Expand Up @@ -186,7 +196,9 @@ def test_distance_five_regions_bottom_top_collision():
'0x110',
'0x30',
"-o",
f"/tmp/pytest/{__name__}.md"],
f"/tmp/pytest/{__name__}.md",
"-l",
"1000"],
mm.diagram.MemoryMap.height, 1000):
d = mm.diagram.MemoryMap()
for region in d._region_list:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_generate_doc_example():
'0x30',
"-o",
"doc/example/report.md"],
mm.diagram.MemoryMap.height, 1000):
):
d = mm.diagram.MemoryMap()
for region in d._region_list:
if region.name == "kernel":
Expand All @@ -45,4 +45,4 @@ def test_generate_doc_example():
if region.name == "uboot-scr":
assert region._origin == "0x110"
assert region._size == "0x30"
assert region.remain == "0x2a8"
assert region.remain == "0x50"

0 comments on commit 5dc21c0

Please sign in to comment.