|
4 | 4 | from unittest.mock import MagicMock, patch, call |
5 | 5 | import sys |
6 | 6 | import os |
| 7 | +import tempfile |
7 | 8 |
|
8 | 9 | sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "util")) |
9 | 10 |
|
@@ -320,6 +321,81 @@ def test_allow_empty_regex_no_match_still_errors(self): |
320 | 321 |
|
321 | 322 | self.assertEqual(errors, 1) |
322 | 323 |
|
| 324 | + def test_auto_memories_cell_may_be_empty(self): |
| 325 | + """A macro AUTO_MEMORIES generated has no GDS; it is not an error.""" |
| 326 | + generated = make_mock_cell( |
| 327 | + "tage_entry_sram", cell_index=1, is_empty=True, parent_cells=1 |
| 328 | + ) |
| 329 | + other = make_mock_cell("other_cell", cell_index=2, is_empty=True) |
| 330 | + |
| 331 | + top = make_mock_cell("test_design", cell_index=0) |
| 332 | + |
| 333 | + pya_mod, main_layout, _, _ = make_mock_pya( |
| 334 | + cells_before_read=[], |
| 335 | + cells_after_read=[top], |
| 336 | + top_only_cells=[generated, other], |
| 337 | + ) |
| 338 | + main_layout.cell.return_value = top |
| 339 | + |
| 340 | + errors = def2stream.merge_gds( |
| 341 | + pya_mod=pya_mod, |
| 342 | + tech_file="/tmp/test.lyt", |
| 343 | + layer_map="", |
| 344 | + in_def="/tmp/test.def", |
| 345 | + design_name="test_design", |
| 346 | + in_files="", |
| 347 | + seal_file="", |
| 348 | + out_file="/tmp/out.gds", |
| 349 | + allow_empty_cells=frozenset(["tage_entry_sram"]), |
| 350 | + ) |
| 351 | + |
| 352 | + self.assertEqual(errors, 1) |
| 353 | + |
| 354 | + |
| 355 | +class TestAutoMemoriesCells(unittest.TestCase): |
| 356 | + def test_off_reads_nothing(self): |
| 357 | + self.assertEqual( |
| 358 | + def2stream.auto_memories_cells({"RESULTS_DIR": "/nonexistent"}), |
| 359 | + frozenset(), |
| 360 | + ) |
| 361 | + |
| 362 | + def test_names_from_blackboxes_txt(self): |
| 363 | + with tempfile.TemporaryDirectory() as results: |
| 364 | + os.mkdir(os.path.join(results, "memories")) |
| 365 | + with open(os.path.join(results, "memories", "blackboxes.txt"), "w") as f: |
| 366 | + # a name per line, optionally followed by more columns |
| 367 | + f.write("tage_entry_sram\nmbtb_entry_sram 491.400000\n\n") |
| 368 | + self.assertEqual( |
| 369 | + def2stream.auto_memories_cells( |
| 370 | + {"AUTO_MEMORIES": "1", "RESULTS_DIR": results} |
| 371 | + ), |
| 372 | + frozenset(["tage_entry_sram", "mbtb_entry_sram"]), |
| 373 | + ) |
| 374 | + |
| 375 | + def test_missing_list_is_an_error(self): |
| 376 | + # the flow always writes it; a missing list is a broken flow, not |
| 377 | + # a design without generated macros |
| 378 | + with tempfile.TemporaryDirectory() as results: |
| 379 | + with self.assertRaisesRegex(RuntimeError, "blackboxes.txt is missing"): |
| 380 | + def2stream.auto_memories_cells( |
| 381 | + {"AUTO_MEMORIES": "1", "RESULTS_DIR": results} |
| 382 | + ) |
| 383 | + |
| 384 | + def test_missing_results_dir_is_an_error(self): |
| 385 | + with self.assertRaisesRegex(RuntimeError, "RESULTS_DIR is not set"): |
| 386 | + def2stream.auto_memories_cells({"AUTO_MEMORIES": "1"}) |
| 387 | + |
| 388 | + def test_empty_list_allows_nothing(self): |
| 389 | + with tempfile.TemporaryDirectory() as results: |
| 390 | + os.mkdir(os.path.join(results, "memories")) |
| 391 | + open(os.path.join(results, "memories", "blackboxes.txt"), "w").close() |
| 392 | + self.assertEqual( |
| 393 | + def2stream.auto_memories_cells( |
| 394 | + {"AUTO_MEMORIES": "1", "RESULTS_DIR": results} |
| 395 | + ), |
| 396 | + frozenset(), |
| 397 | + ) |
| 398 | + |
323 | 399 |
|
324 | 400 | class TestOrphanCells(unittest.TestCase): |
325 | 401 | def test_orphan_cell_is_error(self): |
|
0 commit comments