@@ -178,5 +178,58 @@ TEST_F(TestWriteReadDbHier, WriteReadOdb)
178178 ASSERT_NE (db2_mi1, nullptr );
179179}
180180
181+ // Construct hierarchical netlist with multiple blocks and write/read it back.
182+ // The hierarchical netlist should be read back successfully.
183+ TEST_F (TestWriteReadDbHier, WriteReadOdbMultiBlocks)
184+ {
185+ SetUpTmpPath (" WriteReadOdbMultiBlocks" );
186+ db_->setHierarchy (true );
187+
188+ // Create masters
189+ dbMaster* buf_master = db_->findMaster (" BUF_X1" );
190+ ASSERT_TRUE (buf_master);
191+
192+ // Create child block
193+ dbBlock* child_block = dbBlock::create (block_, " CHILD_BLOCK" );
194+ ASSERT_TRUE (child_block);
195+
196+ // Create module in child block
197+ dbModule* mod0 = dbModule::create (child_block, " MOD0" );
198+ ASSERT_TRUE (mod0);
199+
200+ dbModBTerm* mod0_a = dbModBTerm::create (mod0, " A" );
201+ ASSERT_TRUE (mod0_a);
202+
203+ // Create instance in child block
204+ dbInst* child_inst
205+ = dbInst::create (child_block, buf_master, " child_inst" , false , mod0);
206+ ASSERT_TRUE (child_inst);
207+
208+ // --------------------------------------------------------------
209+ // Write ODB and read back
210+ // --------------------------------------------------------------
211+ dbDatabase* db2 = writeReadDb ();
212+ ASSERT_TRUE (db2->hasHierarchy ());
213+ dbBlock* top_block2 = db2->getChip ()->getBlock ();
214+
215+ // Find child block
216+ dbBlock* child_block2 = top_block2->findChild (" CHILD_BLOCK" );
217+ ASSERT_NE (child_block2, nullptr );
218+
219+ // Find module in child block
220+ dbModule* mod0_2 = child_block2->findModule (" MOD0" );
221+ ASSERT_NE (mod0_2, nullptr );
222+
223+ // Verify ModBTerm hash is populated
224+ dbModBTerm* mod0_a_2 = mod0_2->findModBTerm (" A" );
225+ ASSERT_NE (mod0_a_2, nullptr );
226+ EXPECT_STREQ (mod0_a_2->getName (), " A" );
227+
228+ // Verify Inst hash is populated
229+ dbInst* child_inst_2 = child_block2->findInst (" child_inst" );
230+ ASSERT_NE (child_inst_2, nullptr );
231+ EXPECT_EQ (child_inst_2->getName (), " child_inst" );
232+ }
233+
181234} // namespace
182235} // namespace odb
0 commit comments