Skip to content

Commit

Permalink
Merge pull request #2050 from lf-lang/cpp-assemble-fix
Browse files Browse the repository at this point in the history
Fixed bug in the C++ reaction dependency analysis
  • Loading branch information
cmnrd authored Oct 10, 2023
2 parents 529a217 + 08bbc0e commit 7af2e84
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/src/main/resources/lib/cpp/reactor-cpp
34 changes: 34 additions & 0 deletions test/Cpp/src/ReactionOrder.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
target Cpp

reactor Src {
output out: unsigned

reaction(startup) -> out {=
out.set(42);
=}
}

reactor Sink {
input in: unsigned

reaction(startup) in {=
if (!in.is_present()) {
reactor::log::Error() << "Received no value";
exit(1);
}
if(*in.get() != 42) {
reactor::log::Error() << "Received an unexpected value";
exit(1);
}
=}

reaction(shutdown) {=
reactor::log::Info() << "Success!";
=}
}

main reactor ReactionOrder {
src = new Src()
sink = new Sink()
src.out -> sink.in
}
52 changes: 52 additions & 0 deletions test/Cpp/src/enclave/EnclaveCommunicationHierarchy.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
target Cpp {
timeout: 1 s,
workers: 1
}

reactor Src {
timer t(0, 100 ms)
output out: int
state counter: int = 0

reaction(t) -> out {=
out.set(counter++);
=}
}

reactor Sink {
input in: int
state received: bool = false

reaction(in) {=
received = true;
auto value = *in.get();
reactor::log::Info() << "Received " << value;
auto expected = 100ms * value;
if (get_elapsed_logical_time() != expected) {
reactor::log::Error() << "Expecded value at " << expected << " but received it at " << get_elapsed_logical_time();
exit(1);
}
=}

reaction(shutdown) {=
if(!received) {
reactor::log::Error() << "Nothing received.";
exit(1);
}
=}
}

reactor WrappedSink {
input in: int
sinkinner = new Sink()
in -> sinkinner.in
}

main reactor {
@enclave
src = new Src()
@enclave
sink = new WrappedSink()

src.out -> sink.in
}
52 changes: 52 additions & 0 deletions test/Cpp/src/enclave/EnclaveCommunicationPhysicalHierarchy.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
target Cpp {
timeout: 1 s,
workers: 1
}

reactor Src {
timer t(0, 100 ms)
output out: int
state counter: int = 0

reaction(t) -> out {=
out.set(counter++);
=}
}

reactor Sink {
input in: int
state received: bool = false

reaction(in) {=
received = true;
auto value = *in.get();
reactor::log::Info() << "Received " << value << " at " << get_elapsed_logical_time();
auto expected = 100ms * value;
if (get_elapsed_logical_time() < expected) {
reactor::log::Error() << "Expecded value not before " << expected;
exit(1);
}
=}

reaction(shutdown) {=
if(!received) {
reactor::log::Error() << "Nothing received.";
exit(1);
}
=}
}

reactor WrappedSrc {
output out: int
@enclave
src = new Src()
src.out ~> out
}

main reactor {
src = new WrappedSrc()
@enclave
sink = new Sink()

src.out -> sink.in
}
14 changes: 14 additions & 0 deletions test/Cpp/src/enclave/EnclaveReactionOrder.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
target Cpp

import Src, Sink from "../ReactionOrder.lf"

reactor ReactionOrder {
src = new Src()
sink = new Sink()
src.out -> sink.in
}

main reactor {
@enclave
test = new ReactionOrder()
}

0 comments on commit 7af2e84

Please sign in to comment.