Skip to content

Commit 2ebdf09

Browse files
elena-volkova-hclGitHub Enterprise
authored andcommitted
RIC-1072: RIC-959: New test cases multiplicity1, multiplicity2, port_multiplicity_03 (#59)
* RIC-1072: New test case multiplicity1 * RIC-959: New test case port_multiplicity_03 * RIC-959: Add readme.md to port_multiplicity_03 * Removed extra comma * RIC-1072: Changed the order of connector definition * RIC-959: Added more checks for sap indexes * Minor updates * RIC-1072: Removed log port from capsules * RIC-1072: New ModelRT sample multiplicity2 * RIC-1072: New test case multiplicity2 * RIC-959: Updated testcase description * minor * Changed order * Remove image * RIC-1072: Added information about Queens to art test cases
1 parent f2d200e commit 2ebdf09

27 files changed

Lines changed: 2226 additions & 0 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
}
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+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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 and capsule instance replication.
7+
8+
Part `b : B` is connected to replicated part `a : A [3]` via `outB` and `inB` ports with multiplicity `3`.
9+
Part `b : B` sends message `m()` to a concrete instance connected on port with index `2`.
10+
Part `a` sends message back.
11+
In part `b : B` we are checking that a single message is received on port with index `2`.
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 = 'multiplicity2_target';
4+
tc.prerequisites = [
5+
'../../TestUtils/testlib.tcjs'
6+
];
7+
tc.commonPreface = `
8+
#include "testlib.art.h"
9+
#include <stdio.h>
10+
`;
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
protocol TestEvents {
2+
};
3+
4+
capsule A {
5+
service behavior notify port p: TestEvents;
6+
statemachine {
7+
state Created {
8+
rtBound: on p.rtBound
9+
`
10+
std::cout << "Bound port " << this->getName() << ".p[" << msg->sapIndex0() << "]\n";
11+
`;
12+
};
13+
initial -> Created
14+
`
15+
std::cout << "Created " << this->getName() << ":A\n";
16+
`;
17+
};
18+
19+
};
20+
21+
capsule Top {
22+
behavior notify port pb~ : TestEvents [4];
23+
behavior port frame : Frame;
24+
25+
part part1 : A;
26+
connect part1.p with pb;
27+
28+
part part2 : A;
29+
connect part2.p with pb;
30+
31+
optional part part3 : A [0..1];
32+
connect part3.p with pb;
33+
34+
optional part part4 : A [0..1];
35+
connect part4.p with pb;
36+
37+
statemachine {
38+
state S1, S2, S3, S4;
39+
state AllDone {
40+
entry `PASS();`;
41+
};
42+
43+
initial -> S1
44+
`
45+
std::cout << "Created " << this->getName() << ":Top\n";
46+
`;
47+
48+
t1: S1 -> S2 on pb.rtBound
49+
`
50+
std::cout << "Bound port " << this->getName() << ".pb[" << msg->sapIndex0() << "]\n";
51+
ASSERT(msg->sapIndex0() == 0, "Expect pb bound on index 0");
52+
`;
53+
incarnate_part3: S2 -> S3 on pb.rtBound
54+
`
55+
std::cout << "Bound port " << this->getName() << ".pb[" << msg->sapIndex0() << "]\n";
56+
ASSERT(msg->sapIndex0() == 1, "Expect pb bound on index 1");
57+
RTActorId id = frame.incarnate(part3);
58+
ASSERT(id.isValid(), "Incarnate in 'part3' failed");
59+
`;
60+
incarnate_part4: S3 -> S4 on pb.rtBound
61+
`
62+
std::cout << "Bound port " << this->getName() << ".pb[" << msg->sapIndex0() << "]\n";
63+
ASSERT(msg->sapIndex0() == 2, "Expect pb bound on index 2");
64+
RTActorId id = frame.incarnate(part4);
65+
ASSERT(id.isValid(), "Incarnate in 'part4' failed");
66+
`;
67+
pass: S4 -> AllDone on pb.rtBound
68+
`
69+
std::cout << "Bound port " << this->getName() << ".pb[" << msg->sapIndex0() << "]\n";
70+
ASSERT(msg->sapIndex0() == 3, "Expect pb bound on index 3");
71+
`;
72+
};
73+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
group: cpp_code_generation
3+
---
4+
Test replicated port binding to fixed and optional capsule parts by checking rtBound events.
5+
6+
There are 4 instances of capsule `A`, two of them are fixed, others are optional and created from `Top` statemachine.
7+
Port `pb` is defined with multiplicity `4` and is connected to all parts.
8+
Port `pb` is also defined as `notify` and it will get `rtBound` events when a new instance is connected.
9+
After all 4 instances of capsule `A` are properly bound, test case exits with PASS.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
let tc = TCF.define(TCF.CPP_TRANSFORM);
2+
tc.topCapsule = 'Top';
3+
tc.targetProject = 'port_multiplicity_03_target';
4+
tc.prerequisites = [
5+
'../../TestUtils/testlib.tcjs'
6+
];
7+
tc.commonPreface = `
8+
#include "testlib.art.h"
9+
`;

0 commit comments

Comments
 (0)