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.
Showing
2 changed files
with
80 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,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 | ||
} |
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,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 | ||
} |