Skip to content

Commit

Permalink
Clean up test cases (#8334)
Browse files Browse the repository at this point in the history
- Enable some test cases that are now working, and delete some that are
  obsolete.
- Fix the sts model and enable the test case for it.
- Add check that models don't extend one of their enclosing scopes, and
  enable the RecursiveExtends2 test again.
  • Loading branch information
perost committed Dec 16, 2021
1 parent f66698d commit 16a0a9c
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 58 deletions.
22 changes: 20 additions & 2 deletions OMCompiler/Compiler/NFFrontEnd/NFInst.mo
Expand Up @@ -477,7 +477,7 @@ algorithm
// Look up the base class and expand it.
scope := InstNode.parent(ext);
base_nodes as (base_node :: _) := Lookup.lookupBaseClassName(base_path, scope, info);
checkExtendsLoop(base_node, base_path, info);
checkExtendsLoop(base_node, scope, base_path, info);
checkReplaceableBaseClass(base_nodes, base_path, info);
base_node := expand(base_node);

Expand All @@ -501,8 +501,11 @@ function checkExtendsLoop
"Gives an error if a base node is in the process of being expanded itself,
since that means we have an extends loop in the model."
input InstNode node;
input InstNode scope;
input Absyn.Path path;
input SourceInfo info;
protected
InstNode parent;
algorithm
() := match InstNode.getClass(node)
// expand begins by changing the class to an EXPANDED_CLASS, but keeps the
Expand All @@ -515,7 +518,22 @@ algorithm
then
fail();

else ();
else
algorithm
parent := scope;

while not InstNode.isTopScope(parent) loop
if InstNode.refEqual(parent, node) then
Error.addSourceMessage(Error.EXTENDS_LOOP,
{AbsynUtil.pathString(path)}, info);
fail();
end if;

parent := InstNode.parentScope(parent);
end while;
then
();

end match;
end checkExtendsLoop;

Expand Down
10 changes: 4 additions & 6 deletions testsuite/flattening/modelica/scodeinst/Makefile
Expand Up @@ -174,6 +174,7 @@ CevalRecord6.mo \
CevalRecord7.mo \
CevalRecordArray1.mo \
CevalRecordArray2.mo \
CevalRecordArray3.mo \
CevalRecordArray4.mo \
CevalRecordArray5.mo \
CevalRecordArray6.mo \
Expand Down Expand Up @@ -349,6 +350,7 @@ DuplicateElements5.mo \
DuplicateElements9.mo \
DuplicateElements10.mo \
DuplicateElementsValid1.mo \
DuplicateElementsValid2.mo \
DuplicateMod1.mo \
DuplicateMod2.mo \
DuplicateMod3.mo \
Expand Down Expand Up @@ -872,6 +874,7 @@ RecordExtends2.mo \
RecordUnknownDim1.mo \
RecursiveConstants1.mo \
RecursiveExtends1.mo \
RecursiveExtends2.mo \
RecursiveExtends3.mo \
RecursiveInst1.mo \
RecursiveInst2.mo \
Expand Down Expand Up @@ -1052,6 +1055,7 @@ WhenVariableMismatch2.mo \
WhenVariableMismatch3.mo \
Wild1.mo \
OCGTests.mos \
sts.mos \

# test that currently fail. Move up when fixed.
# Run make testfailing
Expand All @@ -1061,7 +1065,6 @@ CevalFuncRecord4.mo \
FinalParameter1.mo \
FinalParameter2.mo \
FinalParameter3.mo \
CevalRecordArray3.mo \
IfExpression6.mo \
IfExpression9.mo \
RedeclareConstant1.mo \
Expand All @@ -1071,9 +1074,7 @@ dim2.mo \
DuplicateElements6.mo \
DuplicateElements7.mo \
DuplicateElements8.mo \
DuplicateElementsValid2.mo \
DuplicateElementsCond1.mo \
cond3.mo \
conn12.mo \
conn13.mo \
conn14.mo \
Expand Down Expand Up @@ -1110,14 +1111,11 @@ InvalidConnectorType6.mo \
InvalidExpandableConnector1.mo \
InvalidVariability1.mo \
InvalidVariability2.mo \
loop4.mo \
PropagateRedeclareMod1.mo \
RecursiveExtends2.mo \
redeclare8.mo \
type4.mo \
type5.mo \
PackageConstant2.mo \
sts.mos \


# Dependency files that are not .mo .mos or Makefile
Expand Down
3 changes: 2 additions & 1 deletion testsuite/flattening/modelica/scodeinst/RecursiveExtends2.mo
Expand Up @@ -21,7 +21,8 @@ end RecursiveExtends2;

// Result:
// Error processing file: RecursiveExtends2.mo
// [flattening/modelica/scodeinst/RecursiveExtends2.mo:11:5-11:14:writable] Error: Extending A is not allowed, since it is an enclosing class.
// [flattening/modelica/scodeinst/RecursiveExtends2.mo:11:5-11:14:writable] Error: extends A causes an instantiation loop.
// [flattening/modelica/scodeinst/RecursiveExtends2.mo:19:3-19:14:writable] Error: Base class A.B not found in scope RecursiveExtends2.
//
// # Error encountered! Exiting...
// # Please check the error message and the flags.
Expand Down
18 changes: 0 additions & 18 deletions testsuite/flattening/modelica/scodeinst/cond3.mo

This file was deleted.

29 changes: 0 additions & 29 deletions testsuite/flattening/modelica/scodeinst/loop4.mo

This file was deleted.

2 changes: 1 addition & 1 deletion testsuite/flattening/modelica/scodeinst/sts.mo
Expand Up @@ -16,7 +16,7 @@ package ScalableTestSuite "A library of scalable Modelica test models"
parameter SIunits.RotationalDampingConstant DampCoeff "damping coefficient";
final parameter SIunits.RotationalSpringConstant SpringCoeff = E * J / l "spring coefficient";
parameter SIunits.PerUnit F "force component at y-axis";
Modelica.Mechanics.MultiBody.Joints.Revolute[N] revolute(each useAxisFlange = true, phi(each fixed = true), w(each fixed = true)) "N revolute joint";
Modelica.Mechanics.MultiBody.Joints.Revolute[N] revolute(each useAxisFlange = true, each phi(fixed = true), each w(fixed = true)) "N revolute joint";
Modelica.Mechanics.Rotational.Components.SpringDamper[N] springdamper(each c = SpringCoeff, each d = DampCoeff) "N spring damper to connect to N revolute";
Modelica.Mechanics.MultiBody.Parts.BodyBox bodybox1(length = l / 2, width = W, height = H, r = {l / 2, 0, 0}, density = D) "first bodybox connected to world";
Modelica.Mechanics.MultiBody.Parts.BodyBox bodyboxN(length = l / 2, width = W, height = H, r = {l / 2, 0, 0}, density = D) "last bodybox which is free end";
Expand Down
2 changes: 1 addition & 1 deletion testsuite/flattening/modelica/scodeinst/sts.mos
Expand Up @@ -15,6 +15,6 @@ checkModel(ScalableTestSuite.Mechanical.FlexibleBeam.ScaledExperiments.FlexibleB
// ""
// "Check of ScalableTestSuite.Mechanical.FlexibleBeam.ScaledExperiments.FlexibleBeamModelica_N_2 completed successfully.
// Class ScalableTestSuite.Mechanical.FlexibleBeam.ScaledExperiments.FlexibleBeamModelica_N_2 has 1637 equation(s) and 1637 variable(s).
// 1210 of these are trivial equation(s)."
// 1240 of these are trivial equation(s)."
// ""
// endResult

0 comments on commit 16a0a9c

Please sign in to comment.