Skip to content

Commit

Permalink
[CORRECTIVE] Fix memory map and other memory related tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
hagantsa committed Nov 22, 2023
1 parent 72dfc59 commit 90b3048
Show file tree
Hide file tree
Showing 21 changed files with 233 additions and 161 deletions.
19 changes: 12 additions & 7 deletions IPXACTmodels/Component/validators/FieldValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,17 +282,22 @@ bool FieldValidator::hasValidReserved(QSharedPointer<Field> field) const
//-----------------------------------------------------------------------------
bool FieldValidator::hasValidBitWidth(QSharedPointer<Field> field) const
{
QString solvedValue = expressionParser_->parseExpression(field->getBitWidth());
if (field->getFieldDefinitionRef().isEmpty())
{
QString solvedValue = expressionParser_->parseExpression(field->getBitWidth());

bool changeOk = true;
quint64 intValue = solvedValue.toULongLong(&changeOk);
bool changeOk = true;
quint64 intValue = solvedValue.toULongLong(&changeOk);

if (changeOk && intValue > 0)
{
return true;
if (changeOk && intValue > 0)
{
return true;
}

return false;
}

return false;
return true;
}

//-----------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ void RegisterFileValidator::findErrorsInRegisterData(QVector<QString>& errors,
void RegisterFileValidator::findErrorsInAccessPolicies(QStringList& errors,
QSharedPointer<RegisterFile> selectedRegisterFile, QString const& context) const
{
QString registerFileContext = QStringLiteral("register ") + selectedRegisterFile->name() + QStringLiteral(" within ") + context;
QString registerFileContext = QStringLiteral("register file ") + selectedRegisterFile->name() + QStringLiteral(" within ") + context;

RegisterBaseValidator::findErrorsInAccessPolicies(errors, selectedRegisterFile, registerFileContext);
}
Expand Down
2 changes: 1 addition & 1 deletion editors/ComponentEditor/memoryMaps/memorymapsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ QVariant MemoryMapsModel::data(QModelIndex const& index, int role) const
{
return KactusColors::MANDATORY_FIELD;
}
else if (!index.parent().isValid() && index.column() == MemoryMapsColumns::REMAPSTATE_COLUMN)
else if (index.column() == MemoryMapsColumns::REMAPSTATE_COLUMN)
{
return KactusColors::DISABLED_FIELD;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/IPXACTmodels/Component/tst_AccessPolicyReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ void tst_AccessPolicyReader::readModeRefs()

QCOMPARE(accessPolicy->getModeReferences()->size(), 2);
QCOMPARE(accessPolicy->getModeReferences()->first()->getReference(), QString("normal"));
QCOMPARE(accessPolicy->getModeReferences()->first()->getPriority(), QString("0"));
QCOMPARE(accessPolicy->getModeReferences()->first()->getPriority(), 0);
QCOMPARE(accessPolicy->getModeReferences()->at(1)->getReference(), QString("test"));
QCOMPARE(accessPolicy->getModeReferences()->at(1)->getPriority(), QString("1"));
QCOMPARE(accessPolicy->getModeReferences()->at(1)->getPriority(), 1);
}

//-----------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions tests/IPXACTmodels/Component/tst_AccessPolicyWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ void tst_AccessPolicyWriter::cleanup()
void tst_AccessPolicyWriter::writeModeRefs()
{
QSharedPointer<ModeReference> modeRef1(new ModeReference());
modeRef1->setPriority("0");
modeRef1->setPriority(0);
modeRef1->setReference("testMode1");

QSharedPointer<ModeReference> modeRef2(new ModeReference());
modeRef2->setPriority("1");
modeRef2->setPriority(1);
modeRef2->setReference("testMode2");

accessPolicy_->getModeReferences()->append(modeRef1);
Expand Down
30 changes: 26 additions & 4 deletions tests/IPXACTmodels/Component/tst_AddressBlockValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <IPXACTmodels/Component/RegisterFile.h>
#include <IPXACTmodels/Component/Field.h>
#include <IPXACTmodels/Component/MemoryArray.h>
#include <IPXACTmodels/Component/Mode.h>
#include <IPXACTmodels/Component/Component.h>
#include <IPXACTmodels/common/Parameter.h>

#include <QtTest>
Expand Down Expand Up @@ -1067,13 +1069,22 @@ void tst_AddressBlockValidator::testAccessPolicies2022()
testBlock->setWidth("10");

QSharedPointer<ModeReference> modeRef1(new ModeReference());
modeRef1->setPriority("0");
modeRef1->setPriority(0);
modeRef1->setReference("ref");

QSharedPointer<ModeReference> modeRef2(new ModeReference());
modeRef2->setPriority("0");
modeRef2->setPriority(0);
modeRef2->setReference("ref1");

QSharedPointer<Mode> mode1(new Mode("ref"));
QSharedPointer<Mode> mode2(new Mode("ref1"));

QSharedPointer<Component> dummyComponent(new Component(VLNV("test", "vendor", "library", "component", "1.0"), Document::Revision::Std22));
dummyComponent->getModes()->append(mode1);
dummyComponent->getModes()->append(mode2);

validator->componentChange(dummyComponent);

QSharedPointer<AccessPolicy> accessPolicy1(new AccessPolicy());
QSharedPointer<AccessPolicy> accessPolicy2(new AccessPolicy());
accessPolicy1->getModeReferences()->append(modeRef1);
Expand All @@ -1088,6 +1099,7 @@ void tst_AddressBlockValidator::testAccessPolicies2022()
<< "One or more mode references in access policies of address block champloo within test contain duplicate priority values."
<< "One or more mode references in access policies of address block champloo within test contain duplicate mode reference values."
<< "In address block testBlock in test, multiple access policies are not allowed if one of them lacks a mode reference."
<< "Mode reference in access policies of address block champloo within test has invalid or empty reference value 'ref2'."
);

// Test duplicate mode reference priority.
Expand All @@ -1098,25 +1110,35 @@ void tst_AddressBlockValidator::testAccessPolicies2022()
// Test duplicate reference.
errors.clear();

modeRef2->setPriority("1");
modeRef2->setPriority(1);
modeRef2->setReference("ref");

validator->findErrorsIn(errors, testBlock, "8", "test");
QVERIFY(errors.contains(possibleErrors.at(1)));
QVERIFY(validator->hasValidAccessPolicies(testBlock) == false);

// Test valid.
// Test invalid (not found in component modes).
errors.clear();

modeRef2->setReference("ref2");

validator->findErrorsIn(errors, testBlock, "8", "test");
QVERIFY(errors.contains(possibleErrors.back()));

QVERIFY(validator->hasValidAccessPolicies(testBlock) == false);

// Finally test valid.
errors.clear();
modeRef2->setReference("ref1");

validator->findErrorsIn(errors, testBlock, "8", "test");
QVERIFY(std::none_of(possibleErrors.cbegin(), possibleErrors.cend(), [&errors](QString const& str)
{
return errors.contains(str);
}));

QVERIFY(validator->hasValidAccessPolicies(testBlock));

}

//-----------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions tests/IPXACTmodels/Component/tst_AddressBlockWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,10 +433,10 @@ void tst_AddressBlockWriter::writeAccessPolicies2022()
QSharedPointer<ModeReference> modeRef1(new ModeReference());
QSharedPointer<ModeReference> modeRef2(new ModeReference());

modeRef1->setPriority("1");
modeRef1->setPriority(1);
modeRef1->setReference("testMode");

modeRef2->setPriority("2");
modeRef2->setPriority(2);
modeRef2->setReference("testMode2");

testAccessPolicy1->getModeReferences()->append(modeRef1);
Expand Down
40 changes: 20 additions & 20 deletions tests/IPXACTmodels/Component/tst_AddressSpaceValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private slots:

bool errorIsNotFoundInErrorList(QString const& expectedError, QVector<QString> errorList);

QSharedPointer<AddressSpaceValidator> createValidator();
QSharedPointer<AddressSpaceValidator> createValidator(Document::Revision docRevision);
};

//-----------------------------------------------------------------------------
Expand All @@ -96,7 +96,7 @@ void tst_AddressSpaceValidator::testHasValidName()

QSharedPointer<AddressSpace> testSpace (new AddressSpace(name));

QSharedPointer<AddressSpaceValidator> validator = createValidator();
QSharedPointer<AddressSpaceValidator> validator = createValidator(Document::Revision::Std14);

QCOMPARE(validator->hasValidName(testSpace->name()), isValid);

Expand Down Expand Up @@ -139,7 +139,7 @@ void tst_AddressSpaceValidator::testHasValidIsPresent()
QSharedPointer<AddressSpace> testSpace (new AddressSpace("TestAddressBlock"));
testSpace->setIsPresent(isPresent);

QSharedPointer<AddressSpaceValidator> validator = createValidator();
QSharedPointer<AddressSpaceValidator> validator = createValidator(Document::Revision::Std14);

QCOMPARE(validator->hasValidIsPresent(testSpace->getIsPresent()), isValid);

Expand Down Expand Up @@ -184,7 +184,7 @@ void tst_AddressSpaceValidator::testHasValidRange()

QSharedPointer<AddressSpace> testSpace (new AddressSpace("testSpace", range, "0"));

QSharedPointer<AddressSpaceValidator> validator = createValidator();
QSharedPointer<AddressSpaceValidator> validator = createValidator(Document::Revision::Std14);

QCOMPARE(validator->hasValidRange(testSpace), isValid);

Expand Down Expand Up @@ -232,7 +232,7 @@ void tst_AddressSpaceValidator::testHasValidWidth()

QSharedPointer<AddressSpace> testSpace (new AddressSpace("testSpace", "10", width));

QSharedPointer<AddressSpaceValidator> validator = createValidator();
QSharedPointer<AddressSpaceValidator> validator = createValidator(Document::Revision::Std14);

QCOMPARE(validator->hasValidWidth(testSpace), isValid);

Expand Down Expand Up @@ -283,7 +283,7 @@ void tst_AddressSpaceValidator::testSegmentHasValidName()
QSharedPointer<AddressSpace> testSpace (new AddressSpace("testSpace", "100"));
testSpace->getSegments()->append(testSegment);

QSharedPointer<AddressSpaceValidator> validator = createValidator();
QSharedPointer<AddressSpaceValidator> validator = createValidator(Document::Revision::Std14);

QCOMPARE(validator->hasValidSegments(testSpace), isValid);

Expand Down Expand Up @@ -328,7 +328,7 @@ void tst_AddressSpaceValidator::testSegmentsHaveUniqueNames()
testSpace->getSegments()->append(segmentOne);
testSpace->getSegments()->append(segmentTwo);

QSharedPointer<AddressSpaceValidator> validator = createValidator();
QSharedPointer<AddressSpaceValidator> validator = createValidator(Document::Revision::Std14);

QCOMPARE(validator->hasValidSegments(testSpace), false);

Expand Down Expand Up @@ -360,7 +360,7 @@ void tst_AddressSpaceValidator::testSegmentHasValidIsPresent()
QSharedPointer<AddressSpace> testSpace (new AddressSpace("TestAddressBlock", "100"));
testSpace->getSegments()->append(testSegment);

QSharedPointer<AddressSpaceValidator> validator = createValidator();
QSharedPointer<AddressSpaceValidator> validator = createValidator(Document::Revision::Std14);
QCOMPARE(validator->hasValidSegments(testSpace), isValid);

if (!isValid)
Expand Down Expand Up @@ -412,7 +412,7 @@ void tst_AddressSpaceValidator::testSegmentHasValidAddressOffset()
testSpace->setRange("50000000000");
}

QSharedPointer<AddressSpaceValidator> validator = createValidator();
QSharedPointer<AddressSpaceValidator> validator = createValidator(Document::Revision::Std14);
QCOMPARE(validator->hasValidSegments(testSpace), isValid);

if (!isValid)
Expand Down Expand Up @@ -465,7 +465,7 @@ void tst_AddressSpaceValidator::testSegmentHasValidRange()
testSpace->setRange("50000000000");
}

QSharedPointer<AddressSpaceValidator> validator = createValidator();
QSharedPointer<AddressSpaceValidator> validator = createValidator(Document::Revision::Std14);
QCOMPARE(validator->hasValidSegments(testSpace), isValid);

if (!isValid)
Expand Down Expand Up @@ -515,7 +515,7 @@ void tst_AddressSpaceValidator::testSegmentIsContainedWithinAddressSpace()
QSharedPointer<AddressSpace> testSpace (new AddressSpace("Wanpan", spaceRange));
testSpace->getSegments()->append(testSegment);

QSharedPointer<AddressSpaceValidator> validator = createValidator();
QSharedPointer<AddressSpaceValidator> validator = createValidator(Document::Revision::Std14);
QCOMPARE(validator->hasValidSegments(testSpace), isValid);

if (!isValid)
Expand Down Expand Up @@ -576,7 +576,7 @@ void tst_AddressSpaceValidator::testOverlappingSegments()
testSpace->getSegments()->append(segmentOne);
testSpace->getSegments()->append(segmentTwo);

QSharedPointer<AddressSpaceValidator> validator = createValidator();
QSharedPointer<AddressSpaceValidator> validator = createValidator(Document::Revision::Std14);
QCOMPARE(validator->hasValidSegments(testSpace), isValid);

if (!isValid)
Expand Down Expand Up @@ -643,7 +643,7 @@ void tst_AddressSpaceValidator::testHasValidAddressUnitBits()
QSharedPointer<AddressSpace> testSpace (new AddressSpace("TestAddressBlock"));
testSpace->setAddressUnitBits(addressUnitBits);

QSharedPointer<AddressSpaceValidator> validator = createValidator();
QSharedPointer<AddressSpaceValidator> validator = createValidator(Document::Revision::Std14);
QCOMPARE(validator->hasValidAddressUnitBits(testSpace), isValid);

if (!isValid)
Expand Down Expand Up @@ -688,7 +688,7 @@ void tst_AddressSpaceValidator::testHasValidLocalMemoryMap()
QSharedPointer<AddressSpace> testSpace (new AddressSpace("testSpace"));
testSpace->setLocalMemoryMap(testLocalMap);

QSharedPointer<AddressSpaceValidator> validator = createValidator();
QSharedPointer<AddressSpaceValidator> validator = createValidator(Document::Revision::Std14);
QCOMPARE(validator->hasValidLocalMemoryMap(testSpace), false);

QVector<QString> foundErrors;
Expand Down Expand Up @@ -719,7 +719,7 @@ void tst_AddressSpaceValidator::testHasValidParameters()
QSharedPointer<AddressSpace> testSpace (new AddressSpace("testSpace"));
testSpace->getParameters()->append(testParameter);

QSharedPointer<AddressSpaceValidator> validator = createValidator();
QSharedPointer<AddressSpaceValidator> validator = createValidator(Document::Revision::Std14);
QCOMPARE(validator->hasValidParameters(testSpace), false);

QVector<QString> errorsFound;
Expand Down Expand Up @@ -774,21 +774,21 @@ bool tst_AddressSpaceValidator::errorIsNotFoundInErrorList(QString const& expect
//-----------------------------------------------------------------------------
// Function: tst_AddressSpaceValidator::createValidator()
//-----------------------------------------------------------------------------
QSharedPointer<AddressSpaceValidator> tst_AddressSpaceValidator::createValidator()
QSharedPointer<AddressSpaceValidator> tst_AddressSpaceValidator::createValidator(Document::Revision docRevision)
{
QSharedPointer<ExpressionParser> parser(new SystemVerilogExpressionParser());
QSharedPointer<ParameterValidator> parameterValidator(
new ParameterValidator(parser, QSharedPointer<QList<QSharedPointer<Choice> > >()));
new ParameterValidator(parser, QSharedPointer<QList<QSharedPointer<Choice> > >(), docRevision));
QSharedPointer<EnumeratedValueValidator> enumeratedValueValidator(new EnumeratedValueValidator(parser));
QSharedPointer<FieldValidator> fieldValidator(
new FieldValidator(parser, enumeratedValueValidator, parameterValidator));
QSharedPointer<RegisterValidator> registerValidator(
new RegisterValidator(parser, fieldValidator, parameterValidator));
QSharedPointer<RegisterFileValidator> registerFileValidator(new RegisterFileValidator(parser,
registerValidator, parameterValidator));
registerValidator, parameterValidator, docRevision));
QSharedPointer<AddressBlockValidator> addressBlockValidator(
new AddressBlockValidator(parser, registerValidator, registerFileValidator, parameterValidator));
QSharedPointer<SubspaceMapValidator> subspaceValidator(new SubspaceMapValidator(parser, parameterValidator));
new AddressBlockValidator(parser, registerValidator, registerFileValidator, parameterValidator, docRevision));
QSharedPointer<SubspaceMapValidator> subspaceValidator(new SubspaceMapValidator(parser, parameterValidator, docRevision));
QSharedPointer<MemoryMapBaseValidator> localMemoryMapValidator(
new MemoryMapBaseValidator(parser, addressBlockValidator, subspaceValidator));

Expand Down
4 changes: 2 additions & 2 deletions tests/IPXACTmodels/Component/tst_FieldAccessPolicyReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ void tst_FieldAccessPolicyReader::readModeRefs()

QCOMPARE(fieldAccessPolicy->getModeReferences()->size(), 2);
QCOMPARE(fieldAccessPolicy->getModeReferences()->first()->getReference(), QString("normal"));
QCOMPARE(fieldAccessPolicy->getModeReferences()->first()->getPriority(), QString("0"));
QCOMPARE(fieldAccessPolicy->getModeReferences()->first()->getPriority(), 0);
QCOMPARE(fieldAccessPolicy->getModeReferences()->at(1)->getReference(), QString("test"));
QCOMPARE(fieldAccessPolicy->getModeReferences()->at(1)->getPriority(), QString("1"));
QCOMPARE(fieldAccessPolicy->getModeReferences()->at(1)->getPriority(), 1);
}

//-----------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 90b3048

Please sign in to comment.