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

Removal of the use of non-API global variables in tests #1696

Merged
merged 10 commits into from
Apr 15, 2023
2 changes: 1 addition & 1 deletion org.lflang/src/lib/py/reactor-c-py
7 changes: 4 additions & 3 deletions test/C/src/Alignment.lf
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,18 @@ reactor Destination {
state last_invoked: tag_t = {= NEVER_TAG_INITIALIZER =}

reaction(ok, in) {=
tag_t current_tag = lf_tag();
if (ok->is_present && in->is_present) {
lf_print("Destination: Input %d is prime at tag (%lld, %d).",
in->value,
current_tag.time - start_time, current_tag.microstep
current_tag.time - lf_time_start(), current_tag.microstep
);
}
if (lf_tag_compare(current_tag, self->last_invoked) <= 0) {
lf_print_error_and_exit("Invoked at tag (%lld, %d), "
"but previously invoked at tag (%lld, %d).",
current_tag.time - start_time, current_tag.microstep,
self->last_invoked.time - start_time, self->last_invoked.microstep
current_tag.time - lf_time_start(), current_tag.microstep,
self->last_invoked.time - lf_time_start(), self->last_invoked.microstep
);
}
self->last_invoked = current_tag;
Expand Down
1 change: 0 additions & 1 deletion test/C/src/DelayString.lf
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ reactor DelayString2(delay: time = 100 msec) {

reactor Test {
input in: string
state start_time: time = 0

reaction(in) {=
printf("Received: %s.\n", in->value);
Expand Down
2 changes: 1 addition & 1 deletion test/C/src/RequestStop.lf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ target C

main reactor {
reaction(shutdown) {=
tag_t current_time = lf_tag();
tag_t current_tag = lf_tag();
lf_print("Shutdown invoked at tag (%lld, %d). Calling lf_request_stop(), which should have no effect.",
current_tag.time - lf_time_start(), current_tag.microstep
);
Expand Down
10 changes: 5 additions & 5 deletions test/C/src/Starvation.lf
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ reactor SuperDenseSender(number_of_iterations: int = 10) {

reaction(shutdown) {=
tag_t current_tag = lf_tag();
if (current_tag.time == start_time
if (current_tag.time == lf_time_start()
&& current_tag.microstep == self->number_of_iterations + 1) {
printf("SUCCESS: Sender successfully detected starvation.\n");
} else {
fprintf(stderr, "ERROR: Failed to properly enforce starvation at sender. "
"Shutting down at tag (%lld, %u).\n",
current_tag.time - start_time,
current_tag.time - lf_time_start(),
current_tag.microstep);
exit(1);
}
Expand All @@ -41,19 +41,19 @@ reactor SuperDenseReceiver(number_of_iterations: int = 10) {
tag_t current_tag = lf_tag();
printf("Received %d at tag (%lld, %u).\n",
in->value,
current_tag.time - start_time,
current_tag.time - lf_time_start(),
current_tag.microstep);
=}

reaction(shutdown) {=
tag_t current_tag = lf_tag();
if (current_tag.time == start_time
if (current_tag.time == lf_time_start()
&& current_tag.microstep == self->number_of_iterations + 1) {
printf("SUCCESS: Receiver successfully detected starvation.\n");
} else {
fprintf(stderr, "ERROR: Failed to properly enforce starvation at receiver. "
"Shutting down at tag (%lld, %u).\n",
current_tag.time - start_time,
current_tag.time - lf_time_start(),
current_tag.microstep);
exit(1);
}
Expand Down
1 change: 1 addition & 0 deletions test/C/src/Timeout.lf
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ reactor Consumer {
=}

reaction(shutdown) {=
tag_t current_tag = lf_tag();
printf("Shutdown invoked at tag (%lld, %u).\n", current_tag.time - lf_time_start(), current_tag.microstep);
if (lf_tag_compare(current_tag,
(tag_t) { .time = MSEC(11) + lf_time_start(), .microstep = 0}) == 0 &&
Expand Down
1 change: 1 addition & 0 deletions test/C/src/TimeoutZero.lf
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ reactor Consumer {
=}

reaction(shutdown) {=
tag_t current_tag = lf_tag();
printf("Shutdown invoked at tag (%lld, %u).\n", current_tag.time - lf_time_start(), current_tag.microstep);
if (lf_tag_compare(current_tag,
(tag_t) { .time = MSEC(0) + lf_time_start(), .microstep = 0}) == 0 &&
Expand Down
10 changes: 5 additions & 5 deletions test/C/src/concurrent/StarvationThreaded.lf
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ reactor SuperDenseSender(number_of_iterations: int = 10) {

reaction(shutdown) {=
tag_t current_tag = lf_tag();
if (current_tag.time == start_time
if (current_tag.time == lf_time_start()
&& current_tag.microstep == self->number_of_iterations + 1) {
printf("SUCCESS: Sender successfully detected starvation.\n");
} else {
fprintf(stderr, "ERROR: Failed to properly enforce starvation at sender. "
"Shutting down at tag (%lld, %u).\n",
current_tag.time - start_time,
current_tag.time - lf_time_start(),
current_tag.microstep);
exit(1);
}
Expand All @@ -42,19 +42,19 @@ reactor SuperDenseReceiver(number_of_iterations: int = 10) {
tag_t current_tag = lf_tag();
printf("Received %d at tag (%lld, %u).\n",
in->value,
current_tag.time - start_time,
current_tag.time - lf_time_start(),
current_tag.microstep);
=}

reaction(shutdown) {=
tag_t current_tag = lf_tag();
if (current_tag.time == start_time
if (current_tag.time == lf_time_start()
&& current_tag.microstep == self->number_of_iterations + 1) {
printf("SUCCESS: Receiver successfully detected starvation.\n");
} else {
fprintf(stderr, "ERROR: Failed to properly enforce starvation at receiver. "
"Shutting down at tag (%lld, %u).\n",
current_tag.time - start_time,
current_tag.time - lf_time_start(),
current_tag.microstep);
exit(1);
}
Expand Down
3 changes: 2 additions & 1 deletion test/C/src/concurrent/TimeoutThreaded.lf
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ reactor Consumer {
=}

reaction(shutdown) {=
tag_t current_tag = lf_tag();
printf("Shutdown invoked at tag (%lld, %u).\n", current_tag.time - lf_time_start(), current_tag.microstep);
if (lf_tag_compare(current_tag,
(tag_t) { .time = MSEC(11) + lf_time_start(), .microstep = 0}) == 0 &&
self->success == true) {
printf("SUCCESS: successfully enforced timeout.\n");
} else {
fprintf(stderr,"ERROR: Shutdown invoked at tag (%llu, %d). Failed to enforce timeout.\n",
current_tag.time - start_time, current_tag.microstep);
current_tag.time - lf_time_start(), current_tag.microstep);
exit(1);
}
=}
Expand Down
5 changes: 3 additions & 2 deletions test/C/src/concurrent/TimeoutZeroThreaded.lf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ reactor Consumer {
if (lf_tag_compare(current_tag,
(tag_t) { .time = MSEC(0) + lf_time_start(), .microstep = 0}) > 0) {
fprintf(stderr,"ERROR: Tag (%lld, %d) received. Failed to enforce timeout.\n",
current_tag.time - start_time, current_tag.microstep);
current_tag.time - lf_time_start(), current_tag.microstep);
exit(1);
} else if (lf_tag_compare(current_tag,
(tag_t) { .time = MSEC(0) + lf_time_start(), .microstep = 0}) == 0) {
Expand All @@ -28,14 +28,15 @@ reactor Consumer {
=}

reaction(shutdown) {=
tag_t current_tag = lf_tag();
printf("Shutdown invoked at tag (%lld, %u).\n", current_tag.time - lf_time_start(), current_tag.microstep);
if (lf_tag_compare(current_tag,
(tag_t) { .time = MSEC(0) + lf_time_start(), .microstep = 0}) == 0 &&
self->success == true) {
printf("SUCCESS: successfully enforced timeout.\n");
} else {
fprintf(stderr,"ERROR: Shutdown invoked at tag (%llu, %d). Failed to enforce timeout.\n",
current_tag.time - start_time, current_tag.microstep);
current_tag.time - lf_time_start(), current_tag.microstep);
exit(1);
}
=}
Expand Down
2 changes: 1 addition & 1 deletion test/C/src/federated/DecentralizedP2PUnbalancedTimeout.lf
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ reactor Destination {
tag_t current_tag = lf_tag();
if (x->value != self->s) {
lf_print_error_and_exit("At tag (%lld, %u) expected %d and got %d.",
current_tag.time - start_time, current_tag.microstep, self->s, x->value
current_tag.time - lf_time_start(), current_tag.microstep, self->s, x->value
);
}
self->s++;
Expand Down
2 changes: 1 addition & 1 deletion test/C/src/federated/DistributedCountDecentralizedLate.lf
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ reactor Print {
=} STP(0) {=
tag_t current_tag = lf_tag();
printf("At tag (%lld, %u), message has violated the STP offset by (%lld, %u).\n",
current_tag.time - start_time, current_tag.microstep,
current_tag.time - lf_time_start(), current_tag.microstep,
current_tag.time - in->intended_tag.time,
current_tag.microstep - in->intended_tag.microstep);
self->success_stp_violation++;
Expand Down
2 changes: 1 addition & 1 deletion test/C/src/federated/DistributedNetworkOrder.lf
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ reactor Receiver {

reaction(in) {=
tag_t current_tag = lf_tag();
if (current_tag.time == (start_time + MSEC(10))) {
if (current_tag.time == (lf_time_start() + MSEC(10))) {
if (current_tag.microstep == 0 && in->value == 1) {
self->success++;
} else if (current_tag.microstep == 1 && in->value == 2) {
Expand Down
9 changes: 6 additions & 3 deletions test/C/src/federated/LoopDistributedDouble.lf
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,25 @@ reactor Looper(incr: int = 1, delay: time = 0 msec) {
=}

reaction(in) {=
tag_t current_tag = lf_tag();
lf_print("Received %d at logical time (%lld, %d).",
in->value,
current_tag.time - start_time, current_tag.microstep
current_tag.time - lf_time_start(), current_tag.microstep
);
=}

reaction(in2) {=
tag_t current_tag = lf_tag();
lf_print("Received %d on in2 at logical time (%lld, %d).",
in2->value,
current_tag.time - start_time, current_tag.microstep
current_tag.time - lf_time_start(), current_tag.microstep
);
=}

reaction(t) {=
tag_t current_tag = lf_tag();
lf_print("Timer triggered at logical time (%lld, %d).",
current_tag.time - start_time, current_tag.microstep
current_tag.time - lf_time_start(), current_tag.microstep
);
=}

Expand Down
1 change: 0 additions & 1 deletion test/C/src/federated/PhysicalSTP.lf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ reactor Print(STP_offset_param: time = 0) {
reaction(in) {=
interval_t elapsed_time = lf_time_logical_elapsed();
lf_print("At time %lld, received %d", elapsed_time, in->value);
// lf_print("Physical time of arrival is %lld.", in->physical_time_of_arrival - start_time);
if (in->value != self->c) {
lf_print_error_and_exit("Expected to receive %d.", self->c);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ reactor Receiver {

reaction(in) {=
tag_t current_tag = lf_tag();
if (current_tag.time == (start_time + MSEC(10))) {
if (current_tag.time == (lf_time_start() + MSEC(10))) {
if (current_tag.microstep == 0 && in->value == 1) {
self->success++;
} else if (current_tag.microstep == 1 && in->value == 2) {
Expand Down