Skip to content

Commit

Permalink
Add two more federated tests
Browse files Browse the repository at this point in the history
- MultipleSTP.lf and PhysicalSTP.lf
  • Loading branch information
chanijjani committed Mar 7, 2024
1 parent 222a49a commit 088869b
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
36 changes: 36 additions & 0 deletions test/RustRti/src/federated/MultipleSTP.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* This test checks for a bug that was triggered when two STP offsets happened to have equal values.
* The problem was that TimeValue did not override hashCode() even though it had implemented
* equals().
*/
target C {
timeout: 1 s,
coordination: decentralized
}

reactor Sensor(period: time = 500 ms) {
output y: int

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

reactor Print {
input x: int
input z: int

reaction(x) {=
lf_print("****** Received %d", x->value);
=} STP(20 ms) {= =}

reaction(z) {= =} STP(20 ms) {= =}
}

federated reactor {
s = new Sensor()
p = new Print()

s.y -> p.x
s.y -> p.z
}
44 changes: 44 additions & 0 deletions test/RustRti/src/federated/PhysicalSTP.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/** This is a test that detects STP violations according to the physical time of message arrival. */
target C {
timeout: 1900 msec,
coordination: decentralized
}

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

reactor Print(STP_offset_param: time = 0) {
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);
}
instant_t STP_discrepency = lf_time_logical() + self->STP_offset_param - in->physical_time_of_arrival;
if (STP_discrepency < 0) {
lf_print("The message has violated the STP offset by " PRINTF_TIME " in physical time.", -1 * STP_discrepency);
self->c++;
} else {
lf_print_error_and_exit("Message arrived " PRINTF_TIME " early.", STP_discrepency);
}
=} STP(STP_offset_param) {=
// This STP handler should never be invoked because the only source of event
// for Print is the Count reactor.
lf_print_error_and_exit("Logical STP violation was detected. Only physical STP violations are possible.");
=}

reaction(shutdown) {=
if (self->c != 3) {
lf_print_error_and_exit("Expected to receive 2 items but got %d.", self->c);
}
=}
}

federated reactor {
c = new Count(offset = 1 msec, period = 1 sec)
p = new Print(STP_offset_param = 1 usec)

c.out -> p.in
}

0 comments on commit 088869b

Please sign in to comment.