Skip to content

Commit 86e0ed5

Browse files
Merge branch 'main' of github01.hclpnp.com:Modeling/rtistic-pub-doc
2 parents 3fb647b + 912c0a8 commit 86e0ed5

37 files changed

Lines changed: 2501 additions & 3 deletions

art-comp-test/port_multiplicity.code-workspace

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,21 @@
22
{
33
"path": "TestUtils"
44
},
5+
{
6+
"path": "tests/multiplicity1"
7+
},
8+
{
9+
"path": "tests/multiplicity2"
10+
},
511
{
612
"path": "tests/port_multiplicity_01"
713
},
814
{
915
"path": "tests/port_multiplicity_02"
1016
},
17+
{
18+
"path": "tests/port_multiplicity_03"
19+
},
1120
{
1221
"path": "tests/threads"
1322
}

art-comp-test/tests/art_0039/testcase.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ ac_output match5d: connector|Pinger|3 connections|46:13
1919
ac_output match5e: connector|Pinger|4 connections|48:13
2020
ac_output match6: WARNING[0039]|45:19|4 connections|px|only 3 connections
2121
ac_output match6a: connector|Pinger|4 connections|46:21
22-
ac_output match7: WARNING[0039]|47:19|5 connections|px|only 4 connections
22+
ac_output match7: WARNING[0039]|47:19|5 connections|px2|only 4 connections
2323
ac_output match7a: connector|Pinger|5 connections|48:22
2424
---
2525
Test validation rule `ART_0039_portPartMultiplicityMismatch`.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
[[rt::decl]]
2+
`
3+
#include <ostream>
4+
5+
struct [[rt::auto_descriptor]] MyType {
6+
int x = 0;
7+
int y = 0;
8+
};
9+
10+
std::ostream& operator<< ( std::ostream& out, const MyType& mt);
11+
`
12+
[[rt::impl]]
13+
`
14+
std::ostream& operator<< ( std::ostream& out, const MyType& mt)
15+
{
16+
out << "[" << mt.x << "," << mt.y << "]";
17+
return out;
18+
}
19+
`
20+
21+
capsule Top {
22+
[[rt::header_preface]]
23+
`
24+
#include "logging.art.h"
25+
`
26+
[[rt::impl_preface]]
27+
`
28+
#include <sstream>
29+
#include "testlib.art.h"
30+
`
31+
[[rt::decl]]
32+
`
33+
int x = 14;
34+
RTString s = "Hello!";
35+
MyType mt;
36+
`
37+
/* Ports */
38+
behavior port log : Log;
39+
behavior port frame : Frame;
40+
41+
/* Parts */
42+
/* Connectors */
43+
/* State Machine */
44+
statemachine {
45+
state State;
46+
initial -> State
47+
`
48+
// Default logging of data
49+
log.log(x);
50+
log.log(s);
51+
log.log(&mt, &RTType_MyType);
52+
53+
// Custom logging of data
54+
std::stringstream ss;
55+
ss << x << " " << s.Contents << " " << mt;
56+
log.log(ss.str().c_str());
57+
PASS();
58+
`;
59+
};
60+
};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
int 14
2+
Hello!
3+
MyType{x 0,y 0}
4+
14 Hello! [0,0]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
group: cpp_code_generation
3+
allow_stderr_printouts: true
4+
stderr_comparison: contains
5+
---
6+
Capsules can use a log port for logging messages to stderr in a thread-safe manner.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
let tc = TCF.define(TCF.CPP_TRANSFORM);
2+
tc.topCapsule = 'Top';
3+
tc.prerequisites = ["../../TestUtils/testlib.tcjs"];
4+
tc.targetFolder = 'logging_target';
5+
6+
/*
7+
tc.compileArguments = '$(DEBUG_TAG)';
8+
tc.linkArguments = '/DEBUG';
9+
tc.targetConfiguration = "WinT.x64-VisualC++-17.0";
10+
tc.targetRTSLocation = 'C:/git/rsarte-target-rts/rsa_rt/C++/TargetRTS';
11+
*/
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
protocol Prot {
2+
out m(`int`);
3+
};
4+
5+
capsule A {
6+
service behavior port p1~ : Prot;
7+
service behavior port p2 : Prot;
8+
statemachine {
9+
state WaitingForM;
10+
initial -> WaitingForM `
11+
printf("[%s:A] starting\n", this->getName());
12+
`;
13+
m: WaitingForM -> WaitingForM on p1.m
14+
`
15+
const char * myName = this->getName();
16+
int toSend;
17+
if (myName[1] == '1')
18+
toSend = 1;
19+
else if (myName[1] == '2')
20+
toSend = 2;
21+
else toSend = 3;
22+
23+
printf("[%s:A] received m(%d) on p1, sending m(%d) on port p2\n", myName, *rtdata, toSend);
24+
p2.m(toSend).send();
25+
`;
26+
};
27+
};
28+
29+
capsule B {
30+
[[rt::decl]]
31+
`
32+
public:
33+
int count = 0;
34+
int pIndexes = 0;
35+
`
36+
service behavior port p1 : Prot[3];
37+
service behavior port p2~ : Prot[3];
38+
statemachine {
39+
state State1;
40+
initial -> State1 `
41+
printf("[%s:B] starting\n", this->getName());
42+
printf("[%s:B] sending m(42) on port p1\n", this->getName());
43+
p1.m(42).send();
44+
`;
45+
m: State1 -> State1 on p2.m `
46+
printf("[%s:B] received m(%d) on port p2[%d]\n", this->getName(), *rtdata, msg->sapIndex0());
47+
48+
count += *rtdata;
49+
pIndexes += msg->sapIndex0();
50+
if (count == 1 + 2 + 3) {
51+
ASSERT(pIndexes == 0 + 1 + 2, "Sum of port indexes does not match 0 + 1 + 2");
52+
PASS();
53+
}
54+
`;
55+
};
56+
};
57+
58+
capsule Top {
59+
part a1 : A;
60+
part a2 : A;
61+
part a3 : A;
62+
part b : B;
63+
connect b.p1 with a1.p1;
64+
connect b.p1 with a2.p1;
65+
connect b.p1 with a3.p1;
66+
connect a1.p2 with b.p2;
67+
connect a2.p2 with b.p2;
68+
connect a3.p2 with b.p2;
69+
statemachine {
70+
state State1;
71+
initial -> State1;
72+
};
73+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
group: cpp_code_generation
3+
---
4+
This sample model is contributed by Queen's University [here](https://research.cs.queensu.ca/home/dingel/cisc844_F23/sampleModels/sampleModels.html).
5+
6+
Test port replication.
7+
8+
Part `b : B` sends message `m(42)` on port `p1` which has multiplicity `3` and is connected to three `A` parts.
9+
The message is replicated 3 times and is delivered to all `A` parts which send 3 messages back.
10+
In part `b : B` we are checking that all 3 messages are delivered from different port `p2` indexes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
let tc = TCF.define(TCF.CPP_TRANSFORM);
2+
tc.topCapsule = 'Top';
3+
tc.targetProject = 'multiplicity1_target';
4+
tc.prerequisites = [
5+
'../../TestUtils/testlib.tcjs'
6+
];
7+
tc.commonPreface = `
8+
#include "testlib.art.h"
9+
#include <stdio.h>
10+
`;
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
protocol Prot {
2+
out m();
3+
};
4+
5+
capsule A {
6+
service behavior port inA~ : Prot;
7+
service behavior port outA : Prot;
8+
statemachine {
9+
state State1;
10+
initial -> State1 `
11+
printf("Instance of capsule A with index %d started\n", this->getIndex());
12+
`;
13+
m: State1 -> State1 on inA.m
14+
`
15+
printf("Instance of A with index %d: received m at port inA[%d]\n", this->getIndex(), msg->sapIndex0());
16+
ASSERT(this->getIndex() == 2, "Expect message m to be received only in instance with index 2");
17+
printf("Instance of A with index %d: sending m back to outA\n", this->getIndex());
18+
outA.m().send();
19+
`;
20+
};
21+
};
22+
23+
capsule B {
24+
service behavior port inB~ : Prot[3];
25+
service behavior port outB : Prot[3];
26+
behavior port timer : Timing;
27+
statemachine {
28+
state State1, State2, FAIL;
29+
state PASS {
30+
entry `PASS();`;
31+
};
32+
initial -> State1 `
33+
printf("B: sending m on outB[2]\n");
34+
outB.m().sendAt(2);
35+
`;
36+
m: State1 -> State2 on inB.m `
37+
printf("Instance of B with index %d: receiving m at port inB[%d]\n", this->getIndex(), msg->sapIndex0());
38+
ASSERT(msg->sapIndex0() == 2, "Expect reply only from one capsule instance connected on port 2");
39+
timer.informIn(RTTimespec(1,0));
40+
`;
41+
timeout: State2 -> PASS on timer.timeout;
42+
m2: State2 -> FAIL on inB.m `
43+
FAIL("Expect only one m to be received");
44+
`;
45+
};
46+
};
47+
48+
capsule Top {
49+
part a : A[3];
50+
part b : B;
51+
connect b.outB with a.inA;
52+
connect a.outA with b.inB;
53+
statemachine {
54+
state State1;
55+
initial -> State1;
56+
};
57+
};

0 commit comments

Comments
 (0)