fault_injection_async25_paper/test-circuit/simlib.act
2025-02-03 00:47:06 +01:00

89 lines
No EOL
3 KiB
Text

template<pint D_WIDTH, OUT_CHANNELS, N; pint DATA[N]; pbool LOOP; pint SOURCE_ID; pbool LOG>
defproc source_sequence_multi (chan!(int<D_WIDTH>) O[OUT_CHANNELS])
{
int i;
int<D_WIDTH> buf;
chp {
*[
i := 0;
*[ i < N ->
// select the right data element
[([]k:N: i=k -> buf := DATA[k])];
// and send it to every channel
(, j : OUT_CHANNELS :
O[j]!buf;
// if logging was enabled, log the send
[ LOG ->
log ("Source ", SOURCE_ID, " (Channel ", j, "): Sent value ", buf, "%x (0x", buf, ")")
[] else ->
skip
]
);
i := i + 1
]
<- LOOP ];
log ("Source ", SOURCE_ID, ": Sequence ended.")
}
}
template <pint IN_D_WIDTH, OUT_D_WIDTH, IN_CHANNELS, OUT_CHANNELS, SB_ID; pbool VERBOSE_TESTING>
defproc lockstep (chan?(int<IN_D_WIDTH>) IN[IN_CHANNELS]; chan?(int<OUT_D_WIDTH>) OUT_M[OUT_CHANNELS], OUT_D[OUT_CHANNELS])
{
int<IN_D_WIDTH> input[IN_CHANNELS];
int<OUT_D_WIDTH> output_m[OUT_CHANNELS], output_d[OUT_CHANNELS];
bool not_failed;
int num;
chp {
num := 0;
*[
// receive the data
(, i : IN_CHANNELS : IN[i]?input[i]),
(, i : OUT_CHANNELS : (OUT_M[i]?output_m[i]; log("Model response received, channel ", i))),
(, j : OUT_CHANNELS : (OUT_D[j]?output_d[j]; log("DUT response received, channel ", j)));
// check the results
not_failed+;
(; i : OUT_CHANNELS : [not_failed -> not_failed := output_m[i] = output_d[i] [] else -> skip]);
// print the output
[ not_failed -> (
// only print successful tests if verbose testing is enabled
[ VERBOSE_TESTING -> (
log_st ("");
log_p ("Scoreboard ", SB_ID, ": TEST SUCCESS (", num, "); inputs {");
(; i : IN_CHANNELS : log_p (i, ": ", input[i], "%x (0x", input[i], "); "));
log_p ("}, outputs {");
(; i : OUT_CHANNELS : log_p (i, ": ", output_d[i], "%x (0x", output_d[i], "); "));
log_p ("}");
log_nl ("")
)
[] else -> (
skip
)]
)
[] else -> (
log_st ("");
log_p ("Scoreboard ", SB_ID, ": TEST FAILED (", num, "); inputs {");
(; i : IN_CHANNELS : log_p (i, ": ", input[i], "%x (0x", input[i], "); "));
log_p ("}, outputs {");
(; i : OUT_CHANNELS : log_p (i, ": expected ", output_m[i], "%x (0x", output_m[i], "), got ", output_d[i], "%x (0x", output_d[i], "); "));
log_p ("}");
log_nl ("")
)];
num := num + 1
]
}
}