-
Notifications
You must be signed in to change notification settings - Fork 936
odb: migrate swap_master test from Tcl to C++ #10732
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
maliberty
wants to merge
1
commit into
The-OpenROAD-Project:master
Choose a base branch
from
The-OpenROAD-Project-staging:test-swap-master-leaf-cpp
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| // SPDX-License-Identifier: BSD-3-Clause | ||
| // Copyright (c) 2026, The OpenROAD Authors | ||
|
|
||
| // Unit tests for dbInst::swapMaster(dbMaster*), the leaf-cell master swap. | ||
| // | ||
| // This replaces the integration test swap_master.tcl, which only printed | ||
| // the post-swap master name and diffed it against a golden log. Here we | ||
| // assert the documented contract directly: the return value, that the | ||
| // master actually changes, that existing iterm connections are preserved by | ||
| // MTerm name, and that an incompatible signature is rejected without | ||
| // mutating the instance. (Binding-level coverage of the swapMaster command | ||
| // remains in test_inst.tcl / test_inst.py.) | ||
| // | ||
| // NOTE: dbModInst::swapMaster(dbModule*) (the module-instance overload) is a | ||
| // different API covered by TestSwapMaster.cpp. | ||
|
|
||
| #include "gtest/gtest.h" | ||
| #include "helper.h" | ||
| #include "odb/db.h" | ||
|
|
||
| namespace odb { | ||
|
|
||
| namespace { | ||
|
|
||
| class SwapMasterLeafTest : public SimpleDbFixture | ||
| { | ||
| protected: | ||
| void SetUp() override | ||
| { | ||
| SimpleDbFixture::SetUp(); | ||
| // createSimpleDB() builds: | ||
| // and2 : MTerms a, b, o (2x1) | ||
| // or2 : MTerms a, b, o (2x1, same signature as and2) | ||
| // inv1 : MTerms ip0, op0 (1x1, different signature) | ||
| createSimpleDB(); | ||
| block_ = db_->getChip()->getBlock(); | ||
| lib_ = db_->findLib("lib1"); | ||
| } | ||
|
|
||
| dbBlock* block_ = nullptr; | ||
| dbLib* lib_ = nullptr; | ||
| }; | ||
|
|
||
| // Swapping to a master with an identical MTerm signature succeeds, changes the | ||
| // master, and preserves every iterm's net connection (remapped by MTerm name). | ||
| TEST_F(SwapMasterLeafTest, SwapToCompatibleMasterPreservesConnections) | ||
| { | ||
| dbMaster* and2 = lib_->findMaster("and2"); | ||
| dbMaster* or2 = lib_->findMaster("or2"); | ||
| ASSERT_NE(and2, nullptr); | ||
| ASSERT_NE(or2, nullptr); | ||
|
|
||
| dbInst* inst = dbInst::create(block_, and2, "i1"); | ||
| ASSERT_NE(inst, nullptr); | ||
| auto [na, nb, no] = makeNets<3>(block_, {"na", "nb", "no"}); | ||
| dbITerm* a = inst->findITerm("a"); | ||
| dbITerm* b = inst->findITerm("b"); | ||
| dbITerm* o = inst->findITerm("o"); | ||
| ASSERT_NE(a, nullptr); | ||
| ASSERT_NE(b, nullptr); | ||
| ASSERT_NE(o, nullptr); | ||
| a->connect(na); | ||
| b->connect(nb); | ||
| o->connect(no); | ||
|
|
||
| ASSERT_EQ(inst->getMaster(), and2); | ||
|
|
||
| const bool swapped = inst->swapMaster(or2); | ||
|
|
||
| EXPECT_TRUE(swapped); | ||
| EXPECT_EQ(inst->getMaster(), or2); | ||
| // Connections survive the swap, matched to the new master by MTerm name. | ||
| dbITerm* swapped_a = inst->findITerm("a"); | ||
| dbITerm* swapped_b = inst->findITerm("b"); | ||
| dbITerm* swapped_o = inst->findITerm("o"); | ||
| ASSERT_NE(swapped_a, nullptr); | ||
| ASSERT_NE(swapped_b, nullptr); | ||
| ASSERT_NE(swapped_o, nullptr); | ||
| EXPECT_EQ(swapped_a->getNet(), na); | ||
| EXPECT_EQ(swapped_b->getNet(), nb); | ||
| EXPECT_EQ(swapped_o->getNet(), no); | ||
| } | ||
|
|
||
| // Swapping to a master whose MTerm signature differs is rejected: swapMaster | ||
| // returns false and leaves the instance untouched. | ||
| TEST_F(SwapMasterLeafTest, SwapToIncompatibleMasterIsRejected) | ||
| { | ||
| dbMaster* and2 = lib_->findMaster("and2"); | ||
| dbMaster* inv1 = lib_->findMaster("inv1"); | ||
| ASSERT_NE(and2, nullptr); | ||
| ASSERT_NE(inv1, nullptr); | ||
|
|
||
| dbInst* inst = dbInst::create(block_, and2, "i1"); | ||
| ASSERT_NE(inst, nullptr); | ||
|
|
||
| const bool swapped = inst->swapMaster(inv1); | ||
|
|
||
| EXPECT_FALSE(swapped); | ||
| EXPECT_EQ(inst->getMaster(), and2); | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| } // namespace odb | ||
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.