-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2128 from lf-lang/last-time
Fix minimum spacing of actions and reference to freed event
- Loading branch information
Showing
8 changed files
with
141 additions
and
6 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
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
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
Submodule reactor-c
updated
34 files
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,45 @@ | ||
// Test for https://github.com/lf-lang/reactor-c/issues/145 | ||
// This tests the defer policy, which is the default. | ||
target C { | ||
timeout: 1 s | ||
} | ||
|
||
main reactor { | ||
timer t(0, 100 ms) | ||
logical action a(1 ms, 300 ms): int | ||
state c: int = 0 | ||
state c2: int = 0 // For expected values. | ||
state last: time = 0 | ||
|
||
reaction(startup) {= | ||
// Unfortunately, a time state variable cannot be initialized with NEVER. | ||
// So we do that here. | ||
self->last = NEVER; | ||
=} | ||
|
||
reaction(t) -> a {= | ||
tag_t now = lf_tag(); | ||
instant_t start = lf_time_start(); | ||
lf_print("(Timer) Current: " PRINTF_TIME ", Scheduled: " PRINTF_TIME ", Count: %d", | ||
now.time - start, now.time + MSEC(1) - start, self->c | ||
); | ||
lf_schedule_int(a, 0, self->c++); | ||
=} | ||
|
||
reaction(a) {= | ||
tag_t now = lf_tag(); | ||
instant_t start = lf_time_start(); | ||
lf_print("(Action) Current: " PRINTF_TIME ", Microstep: %d, Count: %d", | ||
now.time - start, now.microstep, a->value | ||
); | ||
// Check min_spacing. | ||
if (now.time < self->last + MSEC(300)) { | ||
lf_print_error_and_exit("Minimum spacing of 300ms was violated."); | ||
} | ||
// The value should be equal to the current state c before incrementing. | ||
if (a->value != self->c2++) { | ||
lf_print_error_and_exit("Expected value %d", self->c2 - 1); | ||
} | ||
self->last = now.time; | ||
=} | ||
} |
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 @@ | ||
// Test for https://github.com/lf-lang/reactor-c/issues/145 | ||
// This tests the drop policy. | ||
target C { | ||
timeout: 1 s | ||
} | ||
|
||
main reactor { | ||
timer t(0, 100 ms) | ||
logical action a(1 ms, 300 ms, "drop"): int | ||
state c: int = 0 | ||
state last: time = 0 | ||
|
||
reaction(startup) {= | ||
// Unfortunately, a time state variable cannot be initialized with NEVER. | ||
// So we do that here. | ||
self->last = NEVER; | ||
=} | ||
|
||
reaction(t) -> a {= | ||
tag_t now = lf_tag(); | ||
instant_t start = lf_time_start(); | ||
lf_print("(Timer) Current: " PRINTF_TIME ", Scheduled: " PRINTF_TIME ", Count: %d", | ||
now.time - start, now.time + MSEC(1) - start, self->c | ||
); | ||
lf_schedule_int(a, 0, self->c++); | ||
=} | ||
|
||
reaction(a) {= | ||
tag_t now = lf_tag(); | ||
instant_t start = lf_time_start(); | ||
lf_print("(Action) Current: " PRINTF_TIME ", Microstep: %d, Count: %d", | ||
now.time - start, now.microstep, a->value | ||
); | ||
// Check min_spacing. | ||
if (now.time < self->last + MSEC(300)) { | ||
lf_print_error_and_exit("Minimum spacing of 300ms was violated."); | ||
} | ||
// The value should be equal to the current state c before incrementing. | ||
if (a->value != self->c - 1) { | ||
lf_print_error_and_exit("Expected value %d", self->c - 1); | ||
} | ||
self->last = now.time; | ||
=} | ||
} |
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 @@ | ||
// Test for https://github.com/lf-lang/reactor-c/issues/145 | ||
// This tests the replace policy. | ||
target C { | ||
timeout: 1 s | ||
} | ||
|
||
main reactor { | ||
timer t(0, 100 ms) | ||
logical action a(1 ms, 300 ms, "replace"): int | ||
state c: int = 0 | ||
state last: time = 0 | ||
|
||
reaction(startup) {= | ||
// Unfortunately, a time state variable cannot be initialized with NEVER. | ||
// So we do that here. | ||
self->last = NEVER; | ||
=} | ||
|
||
reaction(t) -> a {= | ||
tag_t now = lf_tag(); | ||
instant_t start = lf_time_start(); | ||
lf_print("(Timer) Current: " PRINTF_TIME ", Scheduled: " PRINTF_TIME ", Count: %d", | ||
now.time - start, now.time + MSEC(1) - start, self->c | ||
); | ||
lf_schedule_int(a, 0, self->c++); | ||
=} | ||
|
||
reaction(a) {= | ||
tag_t now = lf_tag(); | ||
instant_t start = lf_time_start(); | ||
lf_print("(Action) Current: " PRINTF_TIME ", Microstep: %d, Count: %d", | ||
now.time - start, now.microstep, a->value | ||
); | ||
// Check min_spacing. | ||
if (now.time < self->last + MSEC(300)) { | ||
lf_print_error_and_exit("Minimum spacing of 300ms was violated."); | ||
} | ||
// The value should be equal to the current state c before incrementing. | ||
if (a->value != self->c - 1) { | ||
lf_print_error_and_exit("Expected value %d", self->c - 1); | ||
} | ||
self->last = now.time; | ||
=} | ||
} |
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