Skip to content
Snippets Groups Projects
test_resources.py 3.15 KiB
Newer Older
  • Learn to ignore specific revisions
  • Mikael Henriksson's avatar
    Mikael Henriksson committed
    import matplotlib.pyplot as plt
    import pytest
    
    
    from b_asic.process import PlainMemoryVariable
    
    from b_asic.research.interleaver import (
        generate_matrix_transposer,
        generate_random_interleaver,
    )
    
    from b_asic.resources import ProcessCollection, draw_exclusion_graph_coloring
    
    Mikael Henriksson's avatar
    Mikael Henriksson committed
    
    
    class TestProcessCollectionPlainMemoryVariable:
        @pytest.mark.mpl_image_compare(style='mpl20')
        def test_draw_process_collection(self, simple_collection):
            fig, ax = plt.subplots()
    
    Oscar Gustafsson's avatar
    Oscar Gustafsson committed
            simple_collection.plot(ax=ax, show_markers=False)
    
    Mikael Henriksson's avatar
    Mikael Henriksson committed
            return fig
    
    
        @pytest.mark.mpl_image_compare(style='mpl20')
        def test_draw_matrix_transposer_4(self):
            fig, ax = plt.subplots()
    
    Oscar Gustafsson's avatar
    Oscar Gustafsson committed
            generate_matrix_transposer(4).plot(ax=ax)
    
        def test_split_memory_variable(self, simple_collection: ProcessCollection):
            collection_split = simple_collection.split_ports(
                heuristic="graph_color", read_ports=1, write_ports=1, total_ports=2
            )
            assert len(collection_split) == 3
    
    
        @pytest.mark.mpl_image_compare(style='mpl20')
        def test_left_edge_cell_assignment(self, simple_collection: ProcessCollection):
            fig, ax = plt.subplots(1, 2)
            assignment = simple_collection.left_edge_cell_assignment()
    
                assignment[cell].plot(ax=ax[1], row=cell)
            simple_collection.plot(ax[0])
            return fig
    
    
        def test_cell_assignment_matrix_transposer(self):
            collection = generate_matrix_transposer(4, min_lifetime=5)
            assignment_left_edge = collection.left_edge_cell_assignment()
            assignment_graph_color = collection.graph_color_cell_assignment(
                coloring_strategy='saturation_largest_first'
            )
            assert len(assignment_left_edge.keys()) == 18
    
            assert len(assignment_graph_color) == 16
    
        def test_generate_vhdl(self):
            collection = generate_matrix_transposer(4, min_lifetime=5)
            assignment = collection.graph_color_cell_assignment()
            _, ax = plt.subplots()
            for cell, pc in enumerate(assignment):
                pc.plot(ax=ax, row=cell)
            # plt.show()
            collection.generate_memory_based_storage_vhdl(
                "/tmp/wow.vhdl",
                assignment=assignment,
                word_length=13,
                read_ports=1,
                write_ports=1,
                total_ports=2,
            )
    
        # Issue: #175
        def test_interleaver_issue175(self):
            with open('test/fixtures/interleaver-two-port-issue175.p', 'rb') as f:
                interleaver_collection: ProcessCollection = pickle.load(f)
                assert len(interleaver_collection.split_ports(total_ports=1)) == 2
    
    
        def test_generate_random_interleaver(self):
            for _ in range(10):
                for size in range(5, 20, 5):
    
                    collection = generate_random_interleaver(size)
                    assert len(collection.split_ports(read_ports=1, write_ports=1)) == 1
                    if any(var.execution_time for var in collection.collection):
                        assert len(collection.split_ports(total_ports=1)) == 2
    
    Oscar Gustafsson's avatar
    Oscar Gustafsson committed
    
        def test_len_process_collection(self, simple_collection: ProcessCollection):
            assert len(simple_collection) == 7