forked from lf-lang/lingua-franca
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Recover parts of original federated tests
- Loading branch information
1 parent
023c54d
commit fc0ec90
Showing
22 changed files
with
585 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
40
test/RustRti/src/federated/BroadcastFeedbackWithHierarchy.lf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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++); | ||
=} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
=} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hello World |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
=} | ||
} |
Oops, something went wrong.