From 18abbab2db12cecafc0439814fba2cf2ffa424a1 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Fri, 1 Sep 2023 10:54:08 -0400 Subject: [PATCH 1/3] Test lf_set_array --- test/C/src/ArraySet.lf | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 test/C/src/ArraySet.lf diff --git a/test/C/src/ArraySet.lf b/test/C/src/ArraySet.lf new file mode 100644 index 0000000000..c35bbb9750 --- /dev/null +++ b/test/C/src/ArraySet.lf @@ -0,0 +1,38 @@ +target C + +reactor Source { + output out: int[] + + reaction(startup) -> out {= + // Dynamically allocate an output array of length 3. + int* array = (int*)malloc(3 * sizeof(int)); + // Populate the array. + array[0] = 0; + array[1] = 1; + array[2] = 2; + // Set the output, specifying the array length. + lf_set_array(out, array, 3); + =} +} + +reactor Print { + input in: int[] + + reaction(in) {= + printf("Received: ["); + for (int i = 0; i < in->length; i++) { + if (i > 0) printf(", "); + printf("%d", in->value[i]); + if (in->value[i] != i) { + lf_print_error_and_exit("Expected %d.", i); + } + } + printf("]\n"); + =} +} + +main reactor { + s = new Source() + p = new Print() + s.out -> p.in +} From 8119a55a6c06fdf4470e8acae8838c2b66b58d4e Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Fri, 1 Sep 2023 11:24:41 -0400 Subject: [PATCH 2/3] Added test of persistent input to match docs --- test/C/src/PersistentInputs.lf | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 test/C/src/PersistentInputs.lf diff --git a/test/C/src/PersistentInputs.lf b/test/C/src/PersistentInputs.lf new file mode 100644 index 0000000000..55aa74540d --- /dev/null +++ b/test/C/src/PersistentInputs.lf @@ -0,0 +1,33 @@ +target C { + timeout: 400 ms, + fast: true +} +reactor Source { + output out: int + timer t(100 ms, 200 ms) + state count: int = 1 + reaction(t) -> out {= + lf_set(out, self->count++); + =} +} +reactor Sink { + input in: int + timer t(0, 100 ms) + // For testing, emulate the count variable of Source. + state count: int = 0 + timer t2(100 ms, 200 ms) + reaction(t2) {= + self->count++; + =} + reaction(t) in {= + printf("Value of the input is %d at time %lld\n", in->value, lf_time_logical_elapsed()); + if (in->value != self->count) { + lf_print_error_and_exit("Expected %d.", self->count); + } + =} +} +main reactor { + source = new Source() + sink = new Sink() + source.out -> sink.in +} \ No newline at end of file From 5ee6fec21557ccc2303a2d458091085ca5370f4d Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Fri, 1 Sep 2023 12:32:37 -0400 Subject: [PATCH 3/3] Formated --- test/C/src/PersistentInputs.lf | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/test/C/src/PersistentInputs.lf b/test/C/src/PersistentInputs.lf index 55aa74540d..8ff14e41b2 100644 --- a/test/C/src/PersistentInputs.lf +++ b/test/C/src/PersistentInputs.lf @@ -2,23 +2,23 @@ target C { timeout: 400 ms, fast: true } + reactor Source { output out: int timer t(100 ms, 200 ms) state count: int = 1 - reaction(t) -> out {= - lf_set(out, self->count++); - =} + + reaction(t) -> out {= lf_set(out, self->count++); =} } + reactor Sink { input in: int timer t(0, 100 ms) - // For testing, emulate the count variable of Source. - state count: int = 0 + state count: int = 0 // For testing, emulate the count variable of Source. timer t2(100 ms, 200 ms) - reaction(t2) {= - self->count++; - =} + + reaction(t2) {= self->count++; =} + reaction(t) in {= printf("Value of the input is %d at time %lld\n", in->value, lf_time_logical_elapsed()); if (in->value != self->count) { @@ -26,8 +26,9 @@ reactor Sink { } =} } + main reactor { source = new Source() sink = new Sink() source.out -> sink.in -} \ No newline at end of file +}