File size: 3,933 Bytes
784ee2c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env python3

import os
import sys
import unittest

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "utils")))
from class_process import Process
from test_utils import TestUtils


class MacroDimTest(unittest.TestCase):
    """Unit test for get_macro_dimensions method"""

    def setUp(self):
        """Sets up process object used by test methods"""

        self._process = Process(TestUtils.get_base_process_data())
        # delta for use when comparing floats
        self._delta = 0.01

    def test_macro_dim(self):
        """
        Tests basic macro dimension calculation based on three bank
        configurations
        """

        banks = [1, 2, 4]
        base_height = 663.552
        base_width = 5.054
        for num_banks in banks:
            sram_data = {
                "width": 39,
                "depth": 2048,
                "banks": num_banks,
            }
            width, height = self._process.get_macro_dimensions(
                sram_data["width"], sram_data["depth"], sram_data["banks"], 0
            )
            exp_height = base_height / num_banks
            exp_width = base_width * num_banks
            self.assertFalse(self._process.has_defined_bitcell_size())
            self.assertAlmostEqual(height, exp_height, delta=self._delta)
            self.assertAlmostEqual(width, exp_width, delta=self._delta)

    def test_macro_dim_add_height(self):
        """
        Tests basic macro dimension calculation based on three bank
        configurations
        """

        banks = [1, 2, 4]
        base_height = 663.552
        base_width = 5.054
        for num_banks in banks:
            sram_data = {
                "width": 39,
                "depth": 2048,
                "banks": num_banks,
                "additional_height": 10,
            }
            width, height = self._process.get_macro_dimensions(
                sram_data["width"],
                sram_data["depth"],
                sram_data["banks"],
                sram_data["additional_height"],
            )
            exp_height = (base_height / num_banks) + sram_data["additional_height"]
            exp_width = base_width * num_banks
            self.assertFalse(self._process.has_defined_bitcell_size())
            self.assertAlmostEqual(height, exp_height, delta=self._delta)
            self.assertAlmostEqual(width, exp_width, delta=self._delta)

    def test_macro_dim_invalid_banks(self):
        """Tests detection that an invalid bank value was given"""

        sram_data = {
            "width": 39,
            "depth": 2048,
            "banks": 8,
        }
        with self.assertRaises(Exception):
            width, height = self._process.get_macro_dimensions(
                sram_data["width"], sram_data["depth"], sram_data["banks"], 0
            )

    def test_macro_dim_bitcell_override(self):
        """Tests when bitcell dimensions are provided"""

        process_data = TestUtils.get_base_process_data().copy()
        process_data["bitcell_width_um"] = 123.0
        process_data["bitcell_height_um"] = 456.0
        process = Process(process_data)

        sram_data = {
            "width": 32,
            "depth": 256,
            "banks": 1,
        }
        exp_width = 4723.2
        exp_height = 140083.2
        width, height = process.get_macro_dimensions(
            sram_data["width"], sram_data["depth"], sram_data["banks"], 0
        )
        self.assertTrue(process.has_defined_bitcell_size())
        bitcell_width, bitcell_height = process.get_bitcell_dimensions()
        self.assertEqual(bitcell_width, process_data["bitcell_width_um"])
        self.assertEqual(bitcell_height, process_data["bitcell_height_um"])
        self.assertAlmostEqual(width, exp_width, delta=self._delta)
        self.assertAlmostEqual(height, exp_height, delta=self._delta)


if __name__ == "__main__":
    unittest.main()