Skip to content
Snippets Groups Projects
Commit 1d284ff3 authored by Mikael Henriksson's avatar Mikael Henriksson :runner:
Browse files

Add proper testing to ProcessCollection

parent 2a20d18b
No related branches found
No related tags found
1 merge request!188Process
Pipeline #89724 passed
...@@ -65,7 +65,12 @@ def draw_exclusion_graph_coloring( ...@@ -65,7 +65,12 @@ def draw_exclusion_graph_coloring(
else: else:
node_color_dict = {k: color_list[v] for k, v in color_dict.items()} node_color_dict = {k: color_list[v] for k, v in color_dict.items()}
node_color_list = [node_color_dict[node] for node in exclusion_graph] node_color_list = [node_color_dict[node] for node in exclusion_graph]
nx.draw_networkx(exclusion_graph, node_color=node_color_list, ax=ax) nx.draw_networkx(
exclusion_graph,
node_color=node_color_list,
ax=ax,
pos=nx.spring_layout(exclusion_graph, seed=1),
)
class ProcessCollection: class ProcessCollection:
...@@ -79,7 +84,7 @@ class ProcessCollection: ...@@ -79,7 +84,7 @@ class ProcessCollection:
def __init__(self, collection: Optional[Set[Process]] = None): def __init__(self, collection: Optional[Set[Process]] = None):
if collection is None: if collection is None:
self._collection = set[Process]() self._collection: Set[Process] = set()
else: else:
self._collection = collection self._collection = collection
...@@ -182,7 +187,6 @@ class ProcessCollection: ...@@ -182,7 +187,6 @@ class ProcessCollection:
va="center", va="center",
) )
_ax.grid(True) _ax.grid(True)
_ax.set_title(f'Schedule time: {schedule_time}')
_ax.xaxis.set_major_locator(MaxNLocator(integer=True)) _ax.xaxis.set_major_locator(MaxNLocator(integer=True))
_ax.yaxis.set_major_locator(MaxNLocator(integer=True)) _ax.yaxis.set_major_locator(MaxNLocator(integer=True))
......
test/baseline/test_draw_process_collection.png

10.1 KiB

...@@ -2,6 +2,7 @@ import os ...@@ -2,6 +2,7 @@ import os
from distutils import dir_util from distutils import dir_util
from test.fixtures.operation_tree import * from test.fixtures.operation_tree import *
from test.fixtures.port import * from test.fixtures.port import *
from test.fixtures.resources import *
from test.fixtures.schedule import * from test.fixtures.schedule import *
from test.fixtures.signal import signal, signals from test.fixtures.signal import signal, signals
from test.fixtures.signal_flow_graph import * from test.fixtures.signal_flow_graph import *
......
import pytest
from b_asic.process import PlainMemoryVariable
from b_asic.resources import ProcessCollection
@pytest.fixture()
def simple_collection():
NO_PORT = 0
return ProcessCollection(
{
PlainMemoryVariable(4, NO_PORT, {NO_PORT: 2}),
PlainMemoryVariable(2, NO_PORT, {NO_PORT: 6}),
PlainMemoryVariable(3, NO_PORT, {NO_PORT: 5}),
PlainMemoryVariable(6, NO_PORT, {NO_PORT: 2}),
PlainMemoryVariable(0, NO_PORT, {NO_PORT: 3}),
PlainMemoryVariable(0, NO_PORT, {NO_PORT: 2}),
PlainMemoryVariable(0, NO_PORT, {NO_PORT: 6}),
}
)
@pytest.fixture()
def collection():
NO_PORT = 0
return ProcessCollection(
{
PlainMemoryVariable(4, NO_PORT, {NO_PORT: 2}),
PlainMemoryVariable(2, NO_PORT, {NO_PORT: 6}),
PlainMemoryVariable(3, NO_PORT, {NO_PORT: 5}),
PlainMemoryVariable(6, NO_PORT, {NO_PORT: 2}),
PlainMemoryVariable(0, NO_PORT, {NO_PORT: 3}),
PlainMemoryVariable(0, NO_PORT, {NO_PORT: 2}),
PlainMemoryVariable(0, NO_PORT, {NO_PORT: 6}),
}
)
from time import sleep
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import networkx as nx import networkx as nx
import pytest import pytest
...@@ -7,79 +5,25 @@ import pytest ...@@ -7,79 +5,25 @@ import pytest
from b_asic.process import PlainMemoryVariable from b_asic.process import PlainMemoryVariable
from b_asic.resources import ProcessCollection, draw_exclusion_graph_coloring from b_asic.resources import ProcessCollection, draw_exclusion_graph_coloring
NO_PORT = 0
#
# Tests to run
#
def test_run():
# TestProcessCollectionPlainMemoryVariable().test_draw_proces_collection()
TestProcessCollectionPlainMemoryVariable().test_split_memory_variable()
class TestProcessCollectionPlainMemoryVariable: class TestProcessCollectionPlainMemoryVariable:
def __init__(self) -> None: @pytest.mark.mpl_image_compare(style='mpl20')
self.collection = ProcessCollection( def test_draw_process_collection(self, simple_collection):
{ fig, ax = plt.subplots()
PlainMemoryVariable(4, NO_PORT, {NO_PORT: 2}), simple_collection.draw_lifetime_chart(ax=ax)
PlainMemoryVariable(2, NO_PORT, {NO_PORT: 6}), return fig
PlainMemoryVariable(3, NO_PORT, {NO_PORT: 5}),
PlainMemoryVariable(6, NO_PORT, {NO_PORT: 2}),
PlainMemoryVariable(0, NO_PORT, {NO_PORT: 3}),
PlainMemoryVariable(0, NO_PORT, {NO_PORT: 2}),
PlainMemoryVariable(0, NO_PORT, {NO_PORT: 6}),
}
)
def test_draw_proces_collection(self): def test_draw_proces_collection(self, simple_collection):
_, ax = plt.subplots(1, 2) _, ax = plt.subplots(1, 2)
self.collection.draw_lifetime_chart(schedule_time=8, ax=ax[0]) simple_collection.draw_lifetime_chart(schedule_time=8, ax=ax[0])
exclusion_graph = self.collection.create_exclusion_graph_from_overlap() exclusion_graph = (
simple_collection.create_exclusion_graph_from_overlap()
)
color_dict = nx.coloring.greedy_color(exclusion_graph) color_dict = nx.coloring.greedy_color(exclusion_graph)
draw_exclusion_graph_coloring(exclusion_graph, color_dict, ax=ax[1]) draw_exclusion_graph_coloring(exclusion_graph, color_dict, ax=ax[1])
plt.show()
def test_split_memory_variable(self): def test_split_memory_variable(self, simple_collection):
collection_split = self.collection.split( collection_split = simple_collection.split(
read_ports=1, write_ports=1, total_ports=2 read_ports=1, write_ports=1, total_ports=2
) )
_, ax = plt.subplots(1, len(collection_split) + 1) assert len(collection_split) == 3
# print(f'Length: {len(ax)}')
# assert(False)
self.collection.draw_lifetime_chart(ax=ax[0])
ax[0].set_title("Original")
for idx, collection in enumerate(collection_split):
collection.draw_lifetime_chart(ax=ax[idx + 1])
plt.show()
# def test_draw_process_collection():
# collection = ProcessCollection({
# PlainMemoryVariable(4, NO_PORT, {NO_PORT: 2}),
# PlainMemoryVariable(2, NO_PORT, {NO_PORT: 6}),
# PlainMemoryVariable(3, NO_PORT, {NO_PORT: 5}),
# PlainMemoryVariable(6, NO_PORT, {NO_PORT: 2}),
# PlainMemoryVariable(0, NO_PORT, {NO_PORT: 3}),
# PlainMemoryVariable(0, NO_PORT, {NO_PORT: 2}),
# PlainMemoryVariable(0, NO_PORT, {NO_PORT: 6}),
# })
# _, ax = plt.subplots(1, 2)
# collection.draw_lifetime_chart(schedule_time=8, ax=ax[0])
# exclusion_graph = collection.create_exclusion_graph_from_overlap()
# color_dict = nx.greedy_color(exclusion_graph)
# draw_exclusion_graph_coloring(exclusion_graph, color_dict, ax=ax[1])
# plt.show()
#
# def test_memory_split():
# @pytest.mark.mpl_image_compare(remove_text=True, style='mpl20')
# def test_create_exclusion_graph_overlap():
# collection = ProcessCollection({
# PlainMemoryVariable(4, NO_PORT, {NO_PORT: 2}),
# PlainMemoryVariable(2, NO_PORT, {NO_PORT: 6}),
# })
# exclusion_graph = collection.create_exclusion_graph_overlap()
# nx.draw(exclusion_graph)
# plt.show()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment