From 1b3b567ce257d5eb1d6675ea16cc2795b06aeffb Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Fri, 28 Jun 2024 15:29:25 -0700 Subject: [PATCH] Added test for reactor-c modes-with-microsteps --- core/src/main/resources/lib/c/reactor-c | 2 +- test/C/src/modal_models/ModesWithWatchdog.lf | 46 ++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 test/C/src/modal_models/ModesWithWatchdog.lf diff --git a/core/src/main/resources/lib/c/reactor-c b/core/src/main/resources/lib/c/reactor-c index 587a8f9498..33e7c20ddb 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 587a8f9498b69bc82f404e432f881d7bb0bcf383 +Subproject commit 33e7c20ddb052e9370e66b32a8232dd8195d6bb7 diff --git a/test/C/src/modal_models/ModesWithWatchdog.lf b/test/C/src/modal_models/ModesWithWatchdog.lf new file mode 100644 index 0000000000..8cec971ff5 --- /dev/null +++ b/test/C/src/modal_models/ModesWithWatchdog.lf @@ -0,0 +1,46 @@ +/** + * When in the Primary mode, the watchdog is sure to trigger, causing the reaction to watcher + * to be executed one microstep later. Previously, after a mode transition, the microstep was + * hardwired to 1, which caused a fatal error after the mode transition when the runtime tried + * to advance to microstep 1 and found that it was already at microstep 1. This program tests + * that this is fixed. Success is simply running to completion without error. + */ +target C { + keepalive: true, + timeout: 1 s +} + +reactor Arbitrator(timeout: time = 100 ms) { + input in1: double + input in2: double + + watchdog watcher(timeout) {= lf_print("watchdog timeout."); =} + + initial mode Primary { + reaction(in1) -> watcher {= + lf_watchdog_start(watcher, 0); + =} + + reaction(watcher) -> reset(Backup) {= + lf_print("watchdog reaction."); + lf_set_mode(Backup); + =} + } + + mode Backup { + reaction(in2) -> watcher {= + lf_watchdog_start(watcher, 0); + =} + } +} + +main reactor { + timer t(0, 100 ms) + + ar = new Arbitrator() + + reaction(t) -> ar.in1, ar.in2 {= + lf_set(ar.in1, 0.0); + lf_set(ar.in2, 0.0); + =} +}