Skip to content

Commit

Permalink
improved table image: colouring for fail/pass on collision data
Browse files Browse the repository at this point in the history
  • Loading branch information
cracked-machine committed Feb 11, 2024
1 parent 34a09af commit 64d620f
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 9 deletions.
6 changes: 3 additions & 3 deletions doc/example/tests.test_docs_collisions.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![memory map diagram](tests.test_docs_collisions.png)
|name|origin|size|remaining|collisions
|:-|:-|:-|:-|:-|
|<span style='color:cadetblue'>kernel</span>|0x10|0x60|-0x20|{'rootfs': '0x50'}|
|<span style='color:deepskyblue'>rootfs</span>|0x50|0x50|-0x10|{'kernel': '0x50', 'dtb': '0x90'}|
|<span style='color:royalblue'>dtb</span>|0x90|0x30|0x328|{'rootfs': '0x90'}|
|<span style='color:darkcyan'>kernel</span>|0x10|0x60|-0x20|{'rootfs': '0x50'}|
|<span style='color:mediumslateblue'>rootfs</span>|0x50|0x50|-0x10|{'kernel': '0x50', 'dtb': '0x90'}|
|<span style='color:lightseagreen'>dtb</span>|0x90|0x30|0x328|{'rootfs': '0x90'}|
Binary file modified doc/example/tests.test_docs_collisions_cropped.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/example/tests.test_docs_collisions_full.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/example/tests.test_docs_collisions_table.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions doc/example/tests.test_docs_normal.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![memory map diagram](tests.test_docs_normal.png)
|name|origin|size|remaining|collisions
|:-|:-|:-|:-|:-|
|<span style='color:lightskyblue'>kernel</span>|0x10|0x30|0x10|{}|
|<span style='color:maroon'>rootfs</span>|0x50|0x30|0x110|{}|
|<span style='color:slateblue'>dtb</span>|0x190|0x30|0x228|{}|
|<span style='color:midnightblue'>kernel</span>|0x10|0x30|0x10|{}|
|<span style='color:darkslategrey'>rootfs</span>|0x50|0x30|0x110|{}|
|<span style='color:lightseagreen'>dtb</span>|0x190|0x30|0x228|{}|
Binary file modified doc/example/tests.test_docs_normal_cropped.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/example/tests.test_docs_normal_full.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/example/tests.test_docs_normal_table.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion mm/diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ def _truncate_diagram(self, img_to_crop: PIL.Image.Image, memregion_list: List[m
img_main_cropped.save(pathlib.Path(self.args.out).parent / img_file_path)

def _create_markdown(self, region_list: List[mm.types.MemoryRegion]):
"""Create markdown doc containing the diagram image and text-base summary table"""
with open(self.args.out, "w") as f:
f.write(f"""![memory map diagram]({pathlib.Path(self.args.out).stem}.png)\n""")
f.write("|name|origin|size|remaining|collisions\n")
Expand All @@ -213,14 +214,17 @@ def _create_markdown(self, region_list: List[mm.types.MemoryRegion]):
f.write(f"{memregion}\n")

def _create_summary_table(self, region_list: List[mm.types.MemoryRegion]):
"""Create a png image of the summary table"""
table_data = []
for memregion in region_list:
table_data.append(memregion.get_data_as_list())

table: PIL.Image.Image = mm.types.Table().draw_table(
table=table_data,
header=["Name", "Origin", "Size", "Remains", "Collisions"],
font=PIL.ImageFont.load_default(self.table_text_size)
font=PIL.ImageFont.load_default(self.table_text_size),
stock=True,
colors={'red':'green','green':'red'}
)
tableimg_file_path = pathlib.Path(self.args.out).stem + "_table.png"
table.save(pathlib.Path(self.args.out).parent / tableimg_file_path)
Expand Down
8 changes: 6 additions & 2 deletions mm/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ def __str__(self):
+ str(self.remain) + "|"\
+ str(self.collisons) + "|"

def get_data_as_list(self):
return [str(self.name), str(self._origin), str(self._size), str(self.remain), str(self.collisons)]
def get_data_as_list(self) -> List:
"""Get selected instance attributes"""
if self.collisons:
return [str(self.name), str(self._origin), str(self._size), str(self.remain), "-" + str(self.collisons)]
else:
return [str(self.name), str(self._origin), str(self._size), str(self.remain), "+" + str(None)]

def _pick_available_colour(self):
# remove the picked colour from the list so it can't be picked again
Expand Down
Binary file modified out.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 64d620f

Please sign in to comment.