12 #include "sw/device/lib/runtime/irq.h"
14 #include "sw/device/lib/testing/pwrmgr_testutils.h"
15 #include "sw/device/lib/testing/rand_testutils.h"
16 #include "sw/device/lib/testing/ret_sram_testutils.h"
17 #include "sw/device/lib/testing/rstmgr_testutils.h"
18 #include "sw/device/lib/testing/test_framework/check.h"
22 #include "sensor_ctrl_regs.h"
24 OTTF_DEFINE_TEST_CONFIG();
39 static dif_rstmgr_t rstmgr;
40 static dif_sensor_ctrl_t sensor_ctrl;
41 static dif_alert_handler_t alert_handler;
46 static void clear_event(uint32_t idx,
dif_toggle_t fatal) {
69 bool fatal_cause =
false;
70 bool recov_cause =
false;
81 CHECK(fatal_cause & !recov_cause,
82 "Fatal alert not correctly observed in alert handler");
84 CHECK(recov_cause & !fatal_cause,
85 "Recov alert not correctly observed in alert handler");
104 static void test_event(uint32_t idx,
dif_toggle_t fatal) {
108 LOG_INFO(
"Testing alert %d masked off", idx);
122 CHECK(events == 0,
"Event is disabled, so we expect no recoverable faults");
124 CHECK(events == 0,
"Event is disabled, so we expect no fatal faults");
126 LOG_INFO(
"Testing alert %d %s masked on", idx, fatal ?
"fatal" :
"recov");
136 CHECK(((get_events(fatal) >> idx) & 0x1) == 1,
"Event %d not observed in AST",
140 CHECK(((get_events(!fatal) >> idx) & 0x1) == 0,
141 "Event %d observed in AST when it should not be", idx);
144 clear_event(idx, fatal);
147 check_alert_state(fatal);
156 kCounterEventIdx = 0,
158 kCounterNumTests = 0,
160 kNumTestsMax = SENSOR_CTRL_PARAM_NUM_ALERT_EVENTS >> 1,
163 static uint32_t get_next_event_to_test(
void) {
166 rand_testutils_reseed();
169 ret_sram_testutils_counter_get(kCounterEventIdx, &event_idx));
170 CHECK_STATUS_OK(ret_sram_testutils_counter_increment(kCounterEventIdx));
172 }
while (rand_testutils_gen32() <= UINT32_MAX >> 1 &&
173 event_idx < SENSOR_CTRL_PARAM_NUM_ALERT_EVENTS);
179 CHECK_DIF_OK(dif_sensor_ctrl_init(
184 CHECK_DIF_OK(dif_alert_handler_init(
188 CHECK_DIF_OK(dif_rstmgr_init(
201 rst_info = rstmgr_testutils_reason_get();
202 rstmgr_testutils_reason_clear();
204 ret_sram_testutils_init();
207 CHECK_STATUS_OK(ret_sram_testutils_counter_clear(kCounterEventIdx));
208 CHECK_STATUS_OK(ret_sram_testutils_counter_clear(kCounterNumTests));
215 CHECK_STATUS_OK(ret_sram_testutils_counter_get(kCounterNumTests, &value));
216 uint32_t event_idx = get_next_event_to_test();
217 if (event_idx == SENSOR_CTRL_PARAM_NUM_ALERT_EVENTS ||
218 value >= kNumTestsMax) {
222 LOG_INFO(
"Testing event %d", event_idx);
232 CHECK_STATUS_OK(ret_sram_testutils_counter_increment(kCounterNumTests));