Skip to content

Commit

Permalink
Recover parts of original federated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chanijjani committed Feb 14, 2024
1 parent 023c54d commit fc0ec90
Show file tree
Hide file tree
Showing 22 changed files with 585 additions and 0 deletions.
46 changes: 46 additions & 0 deletions test/RustRti/src/federated/Absent.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
target C {
tracing: true,
timeout: 100 ms
}

reactor Sender {
output out1: int
output out2: int
timer t(0, 20 ms)
state c: int = 1

reaction(t) -> out1, out2 {=
if (self->c % 2 != 0) {
lf_set(out1, self->c);
} else {
lf_set(out2, self->c);
}
self->c++;
=}
}

reactor Receiver {
input in1: int
input in2: int

reaction(in1) {=
lf_print("Received %d on in1", in1->value);
if (in1->value % 2 == 0) {
lf_print_error_and_exit("********* Expected an odd integer!");
}
=}

reaction(in2) {=
lf_print("Received %d on in2", in2->value);
if (in2->value % 2 != 0) {
lf_print_error_and_exit("********* Expected an even integer!");
}
=}
}

federated reactor(d: time = 1 ms) {
s = new Sender()
r = new Receiver()
s.out1 -> r.in1
s.out2 -> r.in2
}
33 changes: 33 additions & 0 deletions test/RustRti/src/federated/BroadcastFeedback.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/** This tests an output that is broadcast back to a multiport input of a bank. */
target C {
timeout: 1 sec,
build-type: RelWithDebInfo
}

reactor SenderAndReceiver {
output out: int
input[2] in: int
state received: bool = false

reaction(startup) -> out {=
lf_set(out, 42);
=}

reaction(in) {=
if (in[0]->is_present && in[1]->is_present && in[0]->value == 42 && in[1]->value == 42) {
lf_print("SUCCESS");
self->received = true;
}
=}

reaction(shutdown) {=
if (!self->received == true) {
lf_print_error_and_exit("Failed to receive broadcast");
}
=}
}

federated reactor {
s = new[2] SenderAndReceiver()
(s.out)+ -> s.in
}
40 changes: 40 additions & 0 deletions test/RustRti/src/federated/BroadcastFeedbackWithHierarchy.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/** This tests an output that is broadcast back to a multiport input of a bank. */
target C {
timeout: 1 sec
}

reactor SenderAndReceiver {
output out: int
input[2] in: int
state received: bool = false

r = new Receiver()
in -> r.in

reaction(startup) -> out {=
lf_set(out, 42);
=}
}

reactor Receiver {
input[2] in: int
state received: bool = false

reaction(in) {=
if (in[0]->is_present && in[1]->is_present && in[0]->value == 42 && in[1]->value == 42) {
lf_print("SUCCESS");
self->received = true;
}
=}

reaction(shutdown) {=
if (!self->received == true) {
lf_print_error_and_exit("Failed to receive broadcast");
}
=}
}

federated reactor {
s = new[2] SenderAndReceiver()
(s.out)+ -> s.in
}
20 changes: 20 additions & 0 deletions test/RustRti/src/federated/ChainWithDelay.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Demonstration that monotonic NET hypothesis is invalid.
*
* @author Edward A. Lee
*/
target C {
timeout: 3 msec
}

import Count from "../lib/Count.lf"
import InternalDelay from "../lib/InternalDelay.lf"
import TestCount from "../lib/TestCount.lf"

federated reactor {
c = new Count(period = 1 msec)
i = new InternalDelay(delay = 500 usec)
t = new TestCount(num_inputs=3)
c.out -> i.in
i.out -> t.in
}
72 changes: 72 additions & 0 deletions test/RustRti/src/federated/CycleDetection.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* Check whether the internally generated network and control reactions introduce a cycle or not.
* The failure for this test is not being compiled.
* @author Edward A. Lee
*/
target C {
logging: DEBUG,
tracing: true
}

reactor CAReplica {
input local_update: int
input remote_update: int
input query: int

state balance: int = 0

output response: int

reaction(local_update, remote_update) {=
if (local_update->is_present) {
self->balance += local_update->value;
}
if (remote_update->is_present) {
self->balance += remote_update->value;
}
=}

reaction(query) -> response {=
lf_set(response, self->balance);
=}
}

reactor UserInput(send_stop: bool = true) {
input balance: int
output deposit: int

reaction(startup) -> deposit {=
lf_set(deposit, 100);
=}

reaction(balance) {=
if (balance->value != 200) {
lf_print_error_and_exit("Did not receive the expected balance. Expected: 200. Got: %d.", balance->value);
}
lf_print("Balance: %d", balance->value);
if (balance->value == 200) {
lf_print("Test passed!");
} else {
lf_print_error_and_exit("Expect balance of 200.");
}
if (self->send_stop) lf_request_stop();
=}

reaction(shutdown) {=
lf_print("Shutdown reaction invoked.");
=}
}

federated reactor {
u1 = new UserInput()
r1 = new CAReplica()
u2 = new UserInput()
r2 = new CAReplica()
(u1.deposit)+ -> r1.query, r1.local_update
r1.response -> u1.balance
u1.deposit -> r2.remote_update

(u2.deposit)+ -> r2.query, r2.local_update
r2.response -> u2.balance
u2.deposit -> r1.remote_update
}
24 changes: 24 additions & 0 deletions test/RustRti/src/federated/DistributedBank.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Check bank of federates.
target C {
timeout: 1 sec,
coordination: centralized
}

reactor Node(bank_index: int = 0) {
timer t(0, 100 msec)
state count: int = 0

reaction(t) {=
lf_print("Hello world %d.", self->count++);
=}

reaction(shutdown) {=
if (self->count == 0) {
lf_print_error_and_exit("Timer reactions did not execute.");
}
=}
}

federated reactor DistributedBank {
n = new[2] Node()
}
33 changes: 33 additions & 0 deletions test/RustRti/src/federated/DistributedBankToMultiport.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Check multiport to bank connections between federates.
target C {
timeout: 3 sec
}

import Count from "../lib/Count.lf"

reactor Destination {
input[2] in: int
state count: int = 1

reaction(in) {=
for (int i = 0; i < in_width; i++) {
lf_print("Received %d.", in[i]->value);
if (self->count != in[i]->value) {
lf_print_error_and_exit("Expected %d.", self->count);
}
}
self->count++;
=}

reaction(shutdown) {=
if (self->count == 0) {
lf_print_error_and_exit("No data received.");
}
=}
}

federated reactor {
s = new[2] Count()
d = new Destination()
s.out -> d.in
}
41 changes: 41 additions & 0 deletions test/RustRti/src/federated/DistributedCount.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Test a particularly simple form of a distributed deterministic system where a federation that
* receives timestamped messages has only those messages as triggers. Therefore, no additional
* coordination of the advancement of time (HLA or Ptides) is needed.
* @author Edward A. Lee
*/
target C {
timeout: 5 sec,
coordination: centralized
}

import Count from "../lib/Count.lf"

reactor Print {
input in: int
state c: int = 1

reaction(in) {=
interval_t elapsed_time = lf_time_logical_elapsed();
lf_print("At time " PRINTF_TIME ", received %d", elapsed_time, in->value);
if (in->value != self->c) {
lf_print_error_and_exit("Expected to receive %d.", self->c);
}
if (elapsed_time != MSEC(200) + SEC(1) * (self->c - 1) ) {
lf_print_error_and_exit("Expected received time to be " PRINTF_TIME ".", MSEC(200) * self->c);
}
self->c++;
=}

reaction(shutdown) {=
if (self->c != 6) {
lf_print_error_and_exit("Expected to receive 5 items.");
}
=}
}

federated reactor DistributedCount(offset: time = 200 msec) {
c = new Count()
p = new Print()
c.out -> p.in after offset
}
28 changes: 28 additions & 0 deletions test/RustRti/src/federated/PingPongDistributed.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Basic benchmark from the Savina benchmark suite that is intended to measure message-passing
* overhead.
*
* This version is distributed, communicating using logical connections over sockets.
*
* See [Benchmarks wiki page](https://github.com/icyphy/lingua-franca/wiki/Benchmarks).
*
* This is based on https://www.scala-lang.org/old/node/54 See
* https://shamsimam.github.io/papers/2014-agere-savina.pdf.
*
* This is a distributed version, where Ping and Pong run in separate programs and can be run on
* different machines.
*
* There is no parallelism in this application, so it does not benefit from being being distributed.
*
* @author Edward A. Lee
*/
target C

import Ping, Pong from "PingPongDistributedPhysical.lf"

federated reactor(count: int = 10) {
ping = new Ping(count=count)
pong = new Pong(expected=count)
ping.send -> pong.receive
pong.send -> ping.receive
}
11 changes: 11 additions & 0 deletions test/RustRti/src/lib/Count.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
target C

reactor Count(offset: time = 0, period: time = 1 sec) {
state count: int = 1
output out: int
timer t(offset, period)

reaction(t) -> out {=
lf_set(out, self->count++);
=}
}
12 changes: 12 additions & 0 deletions test/RustRti/src/lib/FileLevelPreamble.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/** Test for ensuring that file-level preambles are inherited when a file is imported. */
target C

preamble {=
#define FOO 2
=}

reactor FileLevelPreamble {
reaction(startup) {=
printf("FOO: %d\n", FOO);
=}
}
1 change: 1 addition & 0 deletions test/RustRti/src/lib/FileReader.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello World
21 changes: 21 additions & 0 deletions test/RustRti/src/lib/GenDelay.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
target C

preamble {=
typedef int message_t;
=}

reactor Source {
output out: message_t

reaction(startup) -> out {=
lf_set(out, 42);
=}
}

reactor Sink {
input in: message_t

reaction(in) {=
lf_print("Received %d at time %lld", in->value, lf_time_logical_elapsed());
=}
}
Loading

0 comments on commit fc0ec90

Please sign in to comment.