[otbn] Add instruction count check in dif_otbn_smoketest.c OTBN smoke test now checks if the instruction counter matches the expected value after executing test_barrett384 and test_err_test. Signed-off-by: Vladimir Rozic <vrozic@lowrisc.org>
diff --git a/sw/device/tests/dif/dif_otbn_smoketest.c b/sw/device/tests/dif/dif_otbn_smoketest.c index 7ec647b..28238cf 100644 --- a/sw/device/tests/dif/dif_otbn_smoketest.c +++ b/sw/device/tests/dif/dif_otbn_smoketest.c
@@ -57,6 +57,17 @@ } /** + * Gets the OTBN instruction count, checks that it matches expectations. + */ +static void check_otbn_insn_cnt(otbn_t *otbn_ctx, uint32_t expected_insn_cnt) { + uint32_t insn_cnt; + CHECK(dif_otbn_get_insn_cnt(&otbn_ctx->dif, &insn_cnt) == kDifOtbnOk); + CHECK(insn_cnt == expected_insn_cnt, + "Expected to execute %d instructions, but got %d.", expected_insn_cnt, + insn_cnt); +} + +/** * Run a 384-bit Barrett Multiplication on OTBN and check its result. * * This test is not aiming to exhaustively test the Barrett multiplication @@ -124,6 +135,8 @@ "Unexpected result c at byte %d: 0x%x (actual) != 0x%x (expected)", i, c[i], c_expected[i]); } + + check_otbn_insn_cnt(otbn_ctx, 161); } /** @@ -143,6 +156,8 @@ CHECK(otbn_busy_wait_for_done(otbn_ctx) == kOtbnExecutionFailed); check_otbn_err_bits(otbn_ctx, kDifOtbnErrBitsBadDataAddr); + + check_otbn_insn_cnt(otbn_ctx, 1); } bool test_main() {