|
3 | 3 | from typing import List, Dict, Any
|
4 | 4 | import sys
|
5 | 5 | from pathlib import Path
|
| 6 | +from abc import ABCMeta, abstractmethod |
6 | 7 |
|
7 | 8 | import pytest
|
8 | 9 |
|
@@ -69,6 +70,141 @@ def test_tool_format(lib, filt) -> List[str]:
|
69 | 70 | "drink {0}/orange".format(tech_dir)
|
70 | 71 | ]
|
71 | 72 |
|
| 73 | + def test_timing_lib_with_preference_filter(self, tmp_path, request) -> None: |
| 74 | + """ |
| 75 | + Test that the library preference filter works as expected. |
| 76 | + """ |
| 77 | + import hammer.config as hammer_config |
| 78 | + |
| 79 | + tech_dir_base = str(tmp_path) |
| 80 | + tech_name = request.function.__name__ # create unique technology folders for each test |
| 81 | + tech_dir = HammerToolTestHelpers.create_tech_dir(tech_dir_base, tech_name) |
| 82 | + tech_json_filename = os.path.join(tech_dir, f"{tech_name}.tech.json") |
| 83 | + tech_json = { |
| 84 | + "name": f"{tech_name}", |
| 85 | + "libraries": [ |
| 86 | + { |
| 87 | + "ecsm_liberty_file": "eggs.ecsm", |
| 88 | + "ccs_liberty_file": "eggs.ccs", |
| 89 | + "nldm_liberty_file": "eggs.nldm" |
| 90 | + }, |
| 91 | + { |
| 92 | + "ccs_liberty_file": "custard.ccs", |
| 93 | + "nldm_liberty_file": "custard.nldm" |
| 94 | + }, |
| 95 | + { |
| 96 | + "nldm_liberty_file": "noodles.nldm" |
| 97 | + }, |
| 98 | + { |
| 99 | + "ecsm_liberty_file": "eggplant.ecsm" |
| 100 | + }, |
| 101 | + { |
| 102 | + "ccs_liberty_file": "cookies.ccs" |
| 103 | + } |
| 104 | + ] |
| 105 | + |
| 106 | + } |
| 107 | + with open(tech_json_filename, "w") as f: |
| 108 | + f.write(json.dumps(tech_json, cls=HammerJSONEncoder, indent=4)) |
| 109 | + (Path(tech_dir) / "eggs.ecsm").write_text("eggs ecsm") |
| 110 | + (Path(tech_dir) / "eggs.ccs").write_text("eggs ccs") |
| 111 | + (Path(tech_dir) / "eggs.nldm").write_text("eggs nldm") |
| 112 | + (Path(tech_dir) / "custard.ccs").write_text("custard ccs") |
| 113 | + (Path(tech_dir) / "custard.nldm").write_text("custard nldm") |
| 114 | + (Path(tech_dir) / "noodles.nldm").write_text("noodles nldm") |
| 115 | + (Path(tech_dir) / "eggplant.ecsm").write_text("eggplant ecsm") |
| 116 | + (Path(tech_dir) / "cookies.ccs").write_text("cookies ccs") |
| 117 | + |
| 118 | + sys.path.append(tech_dir_base) |
| 119 | + tech = self.get_tech(hammer_tech.HammerTechnology.load_from_module(tech_name)) |
| 120 | + tech.cache_dir = tech_dir |
| 121 | + |
| 122 | + logger = HammerVLSILogging.context("") |
| 123 | + logger.logging_class.clear_callbacks() |
| 124 | + tech.logger = logger |
| 125 | + |
| 126 | + class Tool(hammer_vlsi.DummyHammerTool, metaclass=ABCMeta): |
| 127 | + |
| 128 | + def __init__(self, removal=False): |
| 129 | + self.geek = "GeekforGeeks" |
| 130 | + |
| 131 | + |
| 132 | + lib_outputs = [] # type: List[str] |
| 133 | + @property |
| 134 | + def steps(self) -> List[hammer_vlsi.HammerToolStep]: |
| 135 | + return self.make_steps_from_methods([ |
| 136 | + self.step_one, |
| 137 | + self.step_two, |
| 138 | + self.step_three |
| 139 | + ]) |
| 140 | + |
| 141 | + # Test default NLDM preference. |
| 142 | + def step_one(self) -> bool: |
| 143 | + Tool.lib_outputs = tech.read_libs([hammer_tech.filters.get_timing_lib_with_preference()], |
| 144 | + hammer_tech.HammerTechnologyUtils.to_plain_item, |
| 145 | + must_exist=False) |
| 146 | + return True |
| 147 | + |
| 148 | + # Test lower case key input. |
| 149 | + def step_two(self) -> bool: |
| 150 | + Tool.lib_outputs = tech.read_libs([hammer_tech.filters.get_timing_lib_with_preference("ecsm")], |
| 151 | + hammer_tech.HammerTechnologyUtils.to_plain_item, |
| 152 | + must_exist=False) |
| 153 | + return True |
| 154 | + |
| 155 | + def step_three(self) -> bool: |
| 156 | + Tool.lib_outputs = tech.read_libs([hammer_tech.filters.get_timing_lib_with_preference("CCS")], |
| 157 | + hammer_tech.HammerTechnologyUtils.to_plain_item, |
| 158 | + must_exist=False) |
| 159 | + return True |
| 160 | + |
| 161 | + test = Tool() |
| 162 | + test.logger = HammerVLSILogging.context("") |
| 163 | + test.run_dir = str(tmp_path / "rundir") |
| 164 | + test.technology = tech |
| 165 | + test.set_database(hammer_config.HammerDatabase()) |
| 166 | + tech.set_database(hammer_config.HammerDatabase()) |
| 167 | + |
| 168 | + # Test the default case: |
| 169 | + test.run(hook_actions=[ |
| 170 | + hammer_vlsi.HammerTool.make_removal_hook("step_two"), |
| 171 | + hammer_vlsi.HammerTool.make_removal_hook("step_three")]) |
| 172 | + |
| 173 | + assert set(Tool.lib_outputs) == { |
| 174 | + "{0}/eggs.nldm".format(tech_dir), |
| 175 | + "{0}/custard.nldm".format(tech_dir), |
| 176 | + "{0}/noodles.nldm".format(tech_dir), |
| 177 | + "{0}/eggplant.ecsm".format(tech_dir), |
| 178 | + "{0}/cookies.ccs".format(tech_dir) |
| 179 | + } |
| 180 | + |
| 181 | + # Test the lower case input key and non-default ECSM preference. |
| 182 | + test.run(hook_actions=[ |
| 183 | + hammer_vlsi.HammerTool.make_removal_hook("step_one"), |
| 184 | + hammer_vlsi.HammerTool.make_removal_hook("step_three")]) |
| 185 | + |
| 186 | + assert set(Tool.lib_outputs) == { |
| 187 | + "{0}/eggs.ecsm".format(tech_dir), |
| 188 | + "{0}/custard.nldm".format(tech_dir), |
| 189 | + "{0}/noodles.nldm".format(tech_dir), |
| 190 | + "{0}/eggplant.ecsm".format(tech_dir), |
| 191 | + "{0}/cookies.ccs".format(tech_dir) |
| 192 | + } |
| 193 | + |
| 194 | + # Test the non-default CCS preference. |
| 195 | + test.run(hook_actions=[ |
| 196 | + hammer_vlsi.HammerTool.make_removal_hook("step_one"), |
| 197 | + hammer_vlsi.HammerTool.make_removal_hook("step_two")]) |
| 198 | + |
| 199 | + assert set(Tool.lib_outputs) == { |
| 200 | + "{0}/eggs.ccs".format(tech_dir), |
| 201 | + "{0}/custard.ccs".format(tech_dir), |
| 202 | + "{0}/noodles.nldm".format(tech_dir), |
| 203 | + "{0}/eggplant.ecsm".format(tech_dir), |
| 204 | + "{0}/cookies.ccs".format(tech_dir) |
| 205 | + } |
| 206 | + |
| 207 | + |
72 | 208 | def test_timing_lib_ecsm_filter(self, tmp_path, request) -> None:
|
73 | 209 | """
|
74 | 210 | Test that the ECSM-first filter works as expected.
|
|
0 commit comments