Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests for lf_set_array and persistent inputs #1987

Merged
merged 3 commits into from
Sep 3, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions test/C/src/ArraySet.lf
Original file line number Diff line number Diff line change
@@ -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
}
33 changes: 33 additions & 0 deletions test/C/src/PersistentInputs.lf
Original file line number Diff line number Diff line change
@@ -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
}
Loading