Skip to content

Commit

Permalink
tests for ticket:5134
Browse files Browse the repository at this point in the history
  • Loading branch information
adrpo authored and OpenModelica-Hudson committed Sep 21, 2018
1 parent 4ad0cdf commit 4b2bcb8
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 6 deletions.
12 changes: 9 additions & 3 deletions flattening/modelica/records/External_C_RecordTest.c
Expand Up @@ -16,14 +16,20 @@ struct PLUS {
struct ADD right;
};

struct PLUS mk_plus_ext(struct ADD left, struct ADD right)
struct PLUS mk_plus_ext(struct ADD *left, struct ADD *right)
{
struct PLUS out;
out.left = left;
out.right = right;
out.left = *left;
out.right = *right;
return out;
}

void void_mk_plus_ext(struct PLUS* out, struct ADD *left, struct ADD *right)
{
out->left = *left;
out->right = *right;
}

struct EMPTY {
};

Expand Down
30 changes: 29 additions & 1 deletion flattening/modelica/records/NestedRecordTestConstructor.mos
Expand Up @@ -15,7 +15,12 @@ plus3:=RecordTest.mk_plus3(right,left);
res:=RecordTest.mk_plus4(1.0,2.0,3.0,4.0);
res:=RecordTest.MULT_PLUS(plus1,plus2,plus3);
setCommandLineOptions("-d=gen");
res:=RecordTest.mk_plus_ext(RecordTest.ADD(1.0,2.0),RecordTest.ADD(3.0,4.0));
"No explicit external call";
res := RecordTest.mk_plus_ext(RecordTest.ADD(1.0,2.0),RecordTest.ADD(3.0,4.0));
"Explicit external call, return value";
res_explicit := RecordTest.mk_plus_ext_explicit(RecordTest.ADD(1.0,2.0),RecordTest.ADD(3.0,4.0));
"Explicit external call, return by input argument reference";
res_by_ref := RecordTest.mk_plus_ext_by_reference(RecordTest.ADD(1.0,2.0),RecordTest.ADD(3.0,4.0));

// Result:
// true
Expand Down Expand Up @@ -100,6 +105,29 @@ res:=RecordTest.mk_plus_ext(RecordTest.ADD(1.0,2.0),RecordTest.ADD(3.0,4.0));
// end RecordTest.PLUS;
// end RecordTest.MULT_PLUS;
// true
// "No explicit external call"
// record RecordTest.PLUS
// left = record RecordTest.ADD
// a1 = 1.0,
// a2 = 2.0
// end RecordTest.ADD;,
// right = record RecordTest.ADD
// a1 = 3.0,
// a2 = 4.0
// end RecordTest.ADD;
// end RecordTest.PLUS;
// "Explicit external call, return value"
// record RecordTest.PLUS
// left = record RecordTest.ADD
// a1 = 1.0,
// a2 = 2.0
// end RecordTest.ADD;,
// right = record RecordTest.ADD
// a1 = 3.0,
// a2 = 4.0
// end RecordTest.ADD;
// end RecordTest.PLUS;
// "Explicit external call, return by input argument reference"
// record RecordTest.PLUS
// left = record RecordTest.ADD
// a1 = 1.0,
Expand Down
14 changes: 14 additions & 0 deletions flattening/modelica/records/RecordTest.mo
Expand Up @@ -90,6 +90,20 @@ function mk_plus_ext
external "C" annotation(Library="External_C_RecordTest.o");
end mk_plus_ext;

function mk_plus_ext_explicit
input ADD left;
input ADD right;
output PLUS out;
external "C" out = mk_plus_ext(left, right) annotation(Library="External_C_RecordTest.o");
end mk_plus_ext_explicit;

function mk_plus_ext_by_reference
input ADD left;
input ADD right;
output PLUS out;
external "C" void_mk_plus_ext(out, left, right) annotation(Library="External_C_RecordTest.o");
end mk_plus_ext_by_reference;

function eval_plus
input PLUS plus;
output Real out;
Expand Down
4 changes: 2 additions & 2 deletions simulation/modelica/records/Makefile
Expand Up @@ -3,8 +3,8 @@ TEST = ../../../rtest -v
TESTFILES = \
ATotal.mos \
InOutRecord.mos \
TestComplexSum1.mos

TestComplexSum1.mos \
Ticket5134.mos

# test that currently fail. Move up when fixed.
# Run make testfailing
Expand Down
23 changes: 23 additions & 0 deletions simulation/modelica/records/Ticket5134.mo
@@ -0,0 +1,23 @@
within ;
model RecordPassedToFunction
record R
Integer i=2;
end R;
parameter R r(i=3);
function f
input R r;
output Real y;
external "C" y = doSomething(r) annotation(Include="
struct CRecordType {
int i;
};
double doSomething(void* vp) {
struct CRecordType *rp = (struct CRecordType*) vp;
return rp->i;
}
");
end f;
Real y = f(r);
annotation (Icon(coordinateSystem(preserveAspectRatio=false)), Diagram(
coordinateSystem(preserveAspectRatio=false)));
end RecordPassedToFunction;
14 changes: 14 additions & 0 deletions simulation/modelica/records/Ticket5134.mos
@@ -0,0 +1,14 @@
// name: Ticket5134.mos
// keywords: record passed by reference!
// status: correct
// teardown_command: rm -rf RecordPassedToFunction* output.log

loadFile("Ticket5134.mo"); getErrorString();
buildModel(RecordPassedToFunction); getErrorString();

// Result:
// true
// ""
// {"RecordPassedToFunction","RecordPassedToFunction_init.xml"}
// ""
// endResult

0 comments on commit 4b2bcb8

Please sign in to comment.