Software APIs
alert_handler_entropy_test.c
1 // Copyright lowRISC contributors (OpenTitan project).
2 // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3 // SPDX-License-Identifier: Apache-2.0
4 
8 #include "sw/device/lib/runtime/irq.h"
10 #include "sw/device/lib/testing/alert_handler_testutils.h"
11 #include "sw/device/lib/testing/test_framework/FreeRTOSConfig.h"
12 #include "sw/device/lib/testing/test_framework/check.h"
14 
15 #include "alert_handler_regs.h" // Generated.
17 
18 /*
19  In SV test, force the alert_handler's wait_cyc_mask_i input to shorten the
20  ping request intervals. In C test, configure alert_handler to enable all
21  alerts and local alerts. Then in SV test, wait until all alerts are pinged and
22  check no alerts or local alert errors.
23 */
24 
25 OTTF_DEFINE_TEST_CONFIG();
26 
27 static dif_alert_handler_t alert_handler;
28 
29 static void alert_handler_config(void) {
30  dif_alert_handler_alert_t alerts[ALERT_HANDLER_PARAM_N_ALERTS];
31  dif_alert_handler_class_t alert_classes[ALERT_HANDLER_PARAM_N_ALERTS];
32 
33  // Enable all incoming alerts and configure them to classa.
34  // This alert should never fire because we do not expect any incoming alerts.
35  for (dif_alert_handler_alert_t i = 0; i < ALERT_HANDLER_PARAM_N_ALERTS; ++i) {
36  alerts[i] = i;
37  alert_classes[i] = kDifAlertHandlerClassA;
38  }
39 
40  // Enable all local alerts and configure them to classb.
41  dif_alert_handler_alert_t loc_alerts[ALERT_HANDLER_PARAM_N_LOC_ALERT];
42  dif_alert_handler_class_t loc_alert_classes[ALERT_HANDLER_PARAM_N_LOC_ALERT];
43  for (dif_alert_handler_alert_t i = 0; i < ALERT_HANDLER_PARAM_N_LOC_ALERT;
44  ++i) {
45  loc_alerts[i] = i;
46  loc_alert_classes[i] = kDifAlertHandlerClassB;
47  }
48 
51  .signal = 0,
52  .duration_cycles = 2000}};
53 
54  dif_alert_handler_class_config_t class_config = {
56  .accumulator_threshold = 0,
57  .irq_deadline_cycles = 10000,
58  .escalation_phases = esc_phases,
59  .escalation_phases_len = ARRAYSIZE(esc_phases),
60  .crashdump_escalation_phase = kDifAlertHandlerClassStatePhase1,
61  };
62 
63  dif_alert_handler_class_config_t class_configs[] = {class_config,
64  class_config};
65 
66  dif_alert_handler_class_t classes[] = {kDifAlertHandlerClassA,
67  kDifAlertHandlerClassB};
69  .alerts = alerts,
70  .alert_classes = alert_classes,
71  .alerts_len = ARRAYSIZE(alerts),
72  .local_alerts = loc_alerts,
73  .local_alert_classes = loc_alert_classes,
74  .local_alerts_len = ARRAYSIZE(loc_alerts),
75  .classes = classes,
76  .class_configs = class_configs,
77  .classes_len = ARRAYSIZE(class_configs),
78  .ping_timeout = 1000,
79  };
80 
81  CHECK_STATUS_OK(alert_handler_testutils_configure_all(&alert_handler, config,
83 }
84 
85 bool test_main(void) {
86  CHECK_DIF_OK(dif_alert_handler_init(
88  &alert_handler));
89 
90  alert_handler_config();
91  return true;
92 }