16 #include "sw/device/lib/dif/dif_rv_core_ibex.h"
18 #include "sw/device/lib/testing/aes_testutils.h"
19 #include "sw/device/lib/testing/alert_handler_testutils.h"
20 #include "sw/device/lib/testing/entropy_src_testutils.h"
21 #include "sw/device/lib/testing/entropy_testutils.h"
22 #include "sw/device/lib/testing/keymgr_testutils.h"
23 #include "sw/device/lib/testing/otp_ctrl_testutils.h"
24 #include "sw/device/lib/testing/pwrmgr_testutils.h"
25 #include "sw/device/lib/testing/test_framework/check.h"
27 #include "sw/device/tests/otbn_randomness_impl.h"
29 #include "alert_handler_regs.h"
33 static dif_csrng_t csrng;
34 static dif_edn_t edn0;
35 static dif_edn_t edn1;
36 static dif_entropy_src_t entropy_src;
37 static dif_kmac_t kmac;
38 static dif_keymgr_t kmgr;
39 static dif_otbn_t otbn;
40 static dif_otp_ctrl_t otp;
41 static dif_pwrmgr_t pwrmgr;
42 static dif_rv_core_ibex_t ibex;
43 static dif_alert_handler_t alert_handler;
44 static dif_rv_core_ibex_fpga_info_t fpga_info;
50 OTTF_DEFINE_TEST_CONFIG();
57 static void aes_test(
const dif_aes_t *aes) {
67 .reseed_on_key_change =
false,
68 .ctrl_aux_lock =
false,
90 static void otp_ctrl_test(
const dif_otp_ctrl_t *otp) {
102 .check_timeout = 100000,
103 .integrity_period_mask = 0x4,
104 .consistency_period_mask = 0x3ffffff,
107 CHECK_STATUS_OK(otp_ctrl_testutils_wait_for_dai(otp));
114 static void keymgr_test(
const dif_keymgr_t *kmgr) {
118 static bool tested =
false;
129 CHECK_STATUS_OK(keymgr_testutils_check_state(kmgr, expected_stage_before));
131 CHECK_STATUS_OK(keymgr_testutils_wait_for_operation_done(kmgr));
132 CHECK_STATUS_OK(keymgr_testutils_check_state(kmgr, expected_stage_after));
140 static void ibex_test(
const dif_rv_core_ibex_t *ibex) {
142 for (
size_t i = 0; i < 4; i++) {
144 CHECK_DIF_OK(dif_rv_core_ibex_read_rnd_data(ibex, &rnd));
151 static void alert_handler_configure(
const dif_alert_handler_t *alert_handler) {
155 kDifAlertHandlerLocalAlertAlertPingFail};
161 .duration_cycles = 2000}};
165 .accumulator_threshold = 0,
166 .irq_deadline_cycles = 10000,
167 .escalation_phases = esc_phases,
168 .escalation_phases_len =
ARRAYSIZE(esc_phases),
175 kDifAlertHandlerClassB};
178 .alert_classes = NULL,
180 .local_alerts = loc_alerts,
181 .local_alert_classes = loc_alert_classes,
182 .local_alerts_len =
ARRAYSIZE(loc_alerts),
184 .class_configs = class_configs,
188 CHECK_STATUS_OK(alert_handler_testutils_configure_all(alert_handler, config,
195 static void alert_handler_test(
const dif_pwrmgr_t *pwrmgr) {
198 dif_pwrmgr_alert_t alert = kDifPwrmgrAlertFatalFault;
199 CHECK_DIF_OK(dif_pwrmgr_alert_force(pwrmgr, alert));
202 void test_initialize(
void) {
203 CHECK_DIF_OK(dif_entropy_src_init(
205 CHECK_DIF_OK(dif_csrng_init(
211 CHECK_DIF_OK(dif_rv_core_ibex_init(
213 CHECK_DIF_OK(dif_pwrmgr_init(
215 CHECK_DIF_OK(dif_keymgr_init(
219 CHECK_DIF_OK(dif_otp_ctrl_init(
225 CHECK_DIF_OK(dif_alert_handler_init(
231 CHECK_DIF_OK(dif_rv_core_ibex_read_fpga_info(&ibex, &fpga_info));
232 uint32_t loop = (fpga_info != 0) ? kFpgaLoop : 1;
234 for (
size_t i = 0; i < loop; ++i) {
235 LOG_INFO(
"Entropy src test %d/%d", i, loop);
236 alert_handler_test(&pwrmgr);
238 otbn_randomness_test_start(&otbn, 0);
246 CHECK(otbn_randomness_test_end(&otbn,
false));
247 CHECK_STATUS_OK(entropy_testutils_error_check(&csrng, &edn0, &edn1));
259 CHECK_STATUS_OK(keymgr_testutils_init_nvm_then_reset());
262 alert_handler_configure(&alert_handler);
263 CHECK_STATUS_OK(entropy_testutils_auto_mode_init());
266 CHECK_STATUS_OK(entropy_src_testutils_wait_for_state(
267 &entropy_src, kDifEntropySrcMainFsmStateContHTRunning));
269 return status_ok(execute_test());