From e72d34e7ab0b850cc8707219a04adc8b8778ff3d Mon Sep 17 00:00:00 2001 From: xtof Date: Mon, 25 Mar 2024 11:42:37 +0100 Subject: [PATCH] more coverage --- src/snl/snl/kernel/SNLInstance.cpp | 16 ++++++++++----- src/snl/snl/kernel/SNLInstance.h | 2 +- test/snl/snl/kernel/SNLInstanceTest2.cpp | 5 +++++ test/snl/snl/kernel/SNLOccurrenceTest.cpp | 24 +++++++++++++++++++++-- 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/src/snl/snl/kernel/SNLInstance.cpp b/src/snl/snl/kernel/SNLInstance.cpp index bac345c2..be664429 100644 --- a/src/snl/snl/kernel/SNLInstance.cpp +++ b/src/snl/snl/kernel/SNLInstance.cpp @@ -336,16 +336,22 @@ bool SNLInstance::isLeaf() const { return getModel()->isLeaf(); } -SNLInstTerm* SNLInstance::getInstTerm(const SNLBitTerm* term) const { - if (term->getDesign() != getModel()) { +SNLInstTerm* SNLInstance::getInstTerm(const SNLBitTerm* bitTerm) const { + if (bitTerm == nullptr) { + std::string reason = "SNLInstance::getInsTerm error in " + + getName().getString() + " model: " + getModel()->getName().getString() + + " bitTerm arg is null"; + throw SNLException(reason); + } + if (bitTerm->getDesign() != getModel()) { std::string reason = "SNLInstance::getInsTerm incoherency: " + getName().getString() + " model: " + getModel()->getName().getString() - + " and " + term->getString() + " model: " + term->getDesign()->getName().getString() + + " and " + bitTerm->getString() + " model: " + bitTerm->getDesign()->getName().getString() + " should be the same"; throw SNLException(reason); } - assert(term->getFlatID() < instTerms_.size()); - return instTerms_[term->getFlatID()]; + assert(bitTerm->getFlatID() < instTerms_.size()); + return instTerms_[bitTerm->getFlatID()]; } NajaCollection SNLInstance::getInstTerms() const { diff --git a/src/snl/snl/kernel/SNLInstance.h b/src/snl/snl/kernel/SNLInstance.h index 8c2dc239..6f45e4bc 100644 --- a/src/snl/snl/kernel/SNLInstance.h +++ b/src/snl/snl/kernel/SNLInstance.h @@ -77,7 +77,7 @@ class SNLInstance final: public SNLDesignObject { NajaCollection getInstParameters() const; ///\return SNLInstTerm corresponding to the SNLBitTerm representative in this instance. - SNLInstTerm* getInstTerm(const SNLBitTerm* term) const; + SNLInstTerm* getInstTerm(const SNLBitTerm* bitTerm) const; ///\return the NajaCollection of all SNLInstTerm of this SNLInstance. NajaCollection getInstTerms() const; /** diff --git a/test/snl/snl/kernel/SNLInstanceTest2.cpp b/test/snl/snl/kernel/SNLInstanceTest2.cpp index 3832cc13..632effb0 100644 --- a/test/snl/snl/kernel/SNLInstanceTest2.cpp +++ b/test/snl/snl/kernel/SNLInstanceTest2.cpp @@ -65,4 +65,9 @@ TEST_F(SNLInstanceTest2, testInstTermRenameError) { auto ins = SNLInstance::create(design_, model_, SNLName("instance")); auto instTerm = ins->getInstTerm(a); EXPECT_THROW(instTerm->setName(SNLName("b")), SNLException); +} + +TEST_F(SNLInstanceTest2, testInstTermNullTerm) { + auto ins = SNLInstance::create(design_, model_, SNLName("instance")); + EXPECT_THROW(ins->getInstTerm(nullptr), SNLException); } \ No newline at end of file diff --git a/test/snl/snl/kernel/SNLOccurrenceTest.cpp b/test/snl/snl/kernel/SNLOccurrenceTest.cpp index dca2328a..2c35187f 100644 --- a/test/snl/snl/kernel/SNLOccurrenceTest.cpp +++ b/test/snl/snl/kernel/SNLOccurrenceTest.cpp @@ -13,6 +13,7 @@ using ::testing::ElementsAre; #include "SNLScalarNet.h" #include "SNLBitNetOccurrence.h" #include "SNLBitTermOccurrence.h" +#include "SNLInstTermOccurrence.h" #include "SNLEquipotential.h" #include "SNLException.h" using namespace naja::SNL; @@ -25,15 +26,17 @@ class SNLOccurrenceTest: public ::testing::Test { // |-> h1: i(i) // |-> h2: i(i) // |-> prim: i(i) + // |-> prim: i(o) (dangling) // simple test design with i term and net at each level - // connected to upper and lower level - // + // connected to upper and lower level. + // At bottom level prim:o is unconnected. auto universe = SNLUniverse::create(); auto db = SNLDB::create(universe); auto primitivesLib = SNLLibrary::create(db, SNLLibrary::Type::Primitives); auto designsLib = SNLLibrary::create(db); auto prim = SNLDesign::create(primitivesLib, SNLDesign::Type::Primitive, SNLName("PRIM")); auto primi = SNLScalarTerm::create(prim, SNLTerm::Direction::Input, SNLName("i")); + auto primo = SNLScalarTerm::create(prim, SNLTerm::Direction::Input, SNLName("o")); auto primiNet = SNLScalarNet::create(prim, SNLName("i")); primi->setNet(primiNet); auto top = SNLDesign::create(designsLib, SNLName("TOP")); @@ -142,6 +145,23 @@ TEST_F(SNLOccurrenceTest, testh1Level) { EXPECT_LT(h1iTermOccurrence, SNLBitNetOccurrence(h1Path, iTerm->getNet())); } +TEST_F(SNLOccurrenceTest, testh2Level) { + auto h0Path = SNLPath(h0Instance_); + auto h1Path = SNLPath(h0Path, h1Instance_); + auto h2Path = SNLPath(h1Path, h2Instance_); + ASSERT_EQ(3, h2Path.size()); + auto primI = primInstance_->getInstTerm(primInstance_->getModel()->getScalarTerm(SNLName("i"))); + auto primO = primInstance_->getInstTerm(primInstance_->getModel()->getScalarTerm(SNLName("o"))); + ASSERT_NE(nullptr, primI); + ASSERT_NE(nullptr, primO); + auto primITermOccurrence = SNLInstTermOccurrence(h2Path, primI); + auto primOTermOccurrence = SNLInstTermOccurrence(h2Path, primO); + ASSERT_TRUE(primITermOccurrence.isValid()); + ASSERT_TRUE(primOTermOccurrence.isValid()); + EXPECT_FALSE(primOTermOccurrence.getNetOccurrence().isValid()); + EXPECT_EQ(nullptr, primOTermOccurrence.getNet()); +} + TEST_F(SNLOccurrenceTest, testEquipotential0) { ASSERT_NE(h0Instance_, nullptr); auto top = h0Instance_->getDesign();