From a029cdf089bab30d9ebaf79d08c5398272ba364d Mon Sep 17 00:00:00 2001 From: Hokeun Kim Date: Sun, 27 Mar 2022 21:58:42 +0900 Subject: [PATCH 1/3] Update TypeScript's federated test, HelloDistributed.lf, to check received values (by following the HelloDistributed.lf test of C taarget). --- org.lflang/src/lib/ts/reactor-ts | 2 +- .../src/federated/HelloDistributed.lf | 79 +++++++++---------- 2 files changed, 39 insertions(+), 42 deletions(-) diff --git a/org.lflang/src/lib/ts/reactor-ts b/org.lflang/src/lib/ts/reactor-ts index 47830e13bf..4a61dcb656 160000 --- a/org.lflang/src/lib/ts/reactor-ts +++ b/org.lflang/src/lib/ts/reactor-ts @@ -1 +1 @@ -Subproject commit 47830e13bf2d32ed5012a51b720a4df54c9afcbe +Subproject commit 4a61dcb6567a8bd0b83076981b879be9c0ac56c9 diff --git a/test/TypeScript/src/federated/HelloDistributed.lf b/test/TypeScript/src/federated/HelloDistributed.lf index 78cd15f8d1..f12fff0b13 100644 --- a/test/TypeScript/src/federated/HelloDistributed.lf +++ b/test/TypeScript/src/federated/HelloDistributed.lf @@ -1,52 +1,49 @@ -/** - * A test-version of distributed HelloWorld in the example directory, - * example/TypeScript/src/DistributedHelloWorld/HelloWorld.lf - * This is to make sure that the federated execution for TypeScript target - * always works when there is a relevant change. - * - * @author Edward A. Lee - * @author Hokeun Kim +/** 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 + * @author Hokeun Kim */ -// TODO(hokeun): Add a check for the number of received messages to be exactly 2. target TypeScript { timeout: 2 secs }; -/** - * Reactor that generates a sequence of messages, one per second. - * The message will be a string consisting of a root string followed - * by a count. - * @param root The root string. - * @output message The message. - */ -reactor MessageGenerator(root:string("")) { - // Output type char* instead of string is used for dynamically - // allocated character arrays (as opposed to static constant strings). - output message:string; - state count:number(1); - // Send first message after 1 sec so that the startup reactions - // do not factor into the transport time measurement on the first message. - timer t(1 sec, 1 sec); - reaction(t) -> message {= - message = root + " " + count++; - console.log(`At time (elapsed) logical tag ${util.getElapsedLogicalTime()}, source sends message: ${message}`); +reactor Source { + output out:string; + reaction(startup) -> out {= + console.log("Sending 'Hello World!' message from source federate."); + out = "Hello World!"; + util.requestStop(); =} } -/** - * Reactor that prints the current tag and an incoming string. - * - * @input message The message. - */ -reactor PrintMessage { - input message:string; - reaction(message) {= - console.log(`PrintMessage: At (elapsed) logical time ${util.getElapsedLogicalTime()}, receiver receives: ${message}`); +reactor Destination { + input inp:string; + state received:boolean(false); + reaction(startup) {= + console.log("Destination started."); + =} + reaction(inp) {= + console.log(`At logical time ${util.getElapsedLogicalTime()}, destination received: $inp`); + if (inp !== "Hello World!") { + util.requestErrorStop("ERROR: Expected to receive 'Hello World!'"); + } + received = true; + =} + reaction(shutdown) {= + console.log("Shutdown invoked."); + if (!received) { + util.reportError("Destination did not receive the message."); + } =} } -federated reactor HelloDistributed { - source = new MessageGenerator(root = "Hello World"); - print = new PrintMessage(); - source.message -> print.message; -} \ No newline at end of file +federated reactor HelloDistributed at localhost { + reaction(startup) {= + console.log("Printing something in top-level federated reactor."); + =} + s = new Source(); // Reactor s is in federate Source + d = new Destination(); // Reactor d is in federate Destination + s.out -> d.inp; // This version preserves the timestamp. +} From b745cca087ea956f29233a1338839aff276297e7 Mon Sep 17 00:00:00 2001 From: Hokeun Kim Date: Sun, 27 Mar 2022 21:59:26 +0900 Subject: [PATCH 2/3] Add DistributedCount.lf test for federated execution of TypeScript. --- .../src/federated/DistributedCount.lf | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 test/TypeScript/src/federated/DistributedCount.lf diff --git a/test/TypeScript/src/federated/DistributedCount.lf b/test/TypeScript/src/federated/DistributedCount.lf new file mode 100644 index 0000000000..2a651ffce6 --- /dev/null +++ b/test/TypeScript/src/federated/DistributedCount.lf @@ -0,0 +1,50 @@ +/** 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 + * @author Hokeun Kim + */ + target TypeScript { + timeout: 5 sec +}; + +// TODO(hokeun): Replace the following reactor with import Count from "../lib/Count.lf"; +// once TypeScript serialization is implemented. +reactor Count(offset:time(0), period:time(1 sec)) { + output out:string; + timer t(offset, period); + state count:number(1); + reaction(t) -> out {= + out = String(count++); + =} +} + +reactor Print { + // TODO(hokeun): Change type of inp to number once + // once TypeScript serialization is implemented. + input inp:string; + state c:number(1); + reaction(inp) {= + const elapsedTime = util.getElapsedLogicalTime(); + console.log("At time " + elapsedTime + ", received " + inp); + if (inp !== String(c)) { + util.requestErrorStop("Expected to receive " + c + "."); + } + if (elapsedTime.isEqualTo(TimeValue.msec(200).add(TimeValue.sec(c - 1)))) { + util.requestErrorStop("Expected received time to be " + TimeValue.msec(200).add(TimeValue.sec(c - 1)) + "."); + } + c++; + =} + reaction(shutdown) {= + if (c != 6) { + util.reportError("Expected to receive 5 items."); + } + =} +} + +federated reactor DistributedCount(offset:time(200 msec)) { + c = new Count(); + p = new Print(); + c.out -> p.inp after offset; +} From 7e048703fda71631f3392dcc0fa6040a222e85ea Mon Sep 17 00:00:00 2001 From: Hokeun Kim Date: Thu, 31 Mar 2022 21:51:34 +0900 Subject: [PATCH 3/3] Update comments and reactor-ts version. --- org.lflang/src/lib/ts/reactor-ts | 2 +- test/TypeScript/src/federated/DistributedCount.lf | 3 ++- test/TypeScript/src/federated/HelloDistributed.lf | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/org.lflang/src/lib/ts/reactor-ts b/org.lflang/src/lib/ts/reactor-ts index 4a61dcb656..a0eb024cfe 160000 --- a/org.lflang/src/lib/ts/reactor-ts +++ b/org.lflang/src/lib/ts/reactor-ts @@ -1 +1 @@ -Subproject commit 4a61dcb6567a8bd0b83076981b879be9c0ac56c9 +Subproject commit a0eb024cfe944b073cebdb739e0e52735dde3e35 diff --git a/test/TypeScript/src/federated/DistributedCount.lf b/test/TypeScript/src/federated/DistributedCount.lf index 2a651ffce6..988b10b012 100644 --- a/test/TypeScript/src/federated/DistributedCount.lf +++ b/test/TypeScript/src/federated/DistributedCount.lf @@ -1,4 +1,5 @@ -/** Test a particularly simple form of a distributed deterministic system +/** + * 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. diff --git a/test/TypeScript/src/federated/HelloDistributed.lf b/test/TypeScript/src/federated/HelloDistributed.lf index f12fff0b13..61dcb84731 100644 --- a/test/TypeScript/src/federated/HelloDistributed.lf +++ b/test/TypeScript/src/federated/HelloDistributed.lf @@ -1,4 +1,5 @@ -/** Test a particularly simple form of a distributed deterministic system +/** + * 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.