Software APIs
rom_e2e_alert_config_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 
5 #include "sw/device/lib/testing/test_framework/check.h"
7 #include "sw/device/silicon_creator/lib/drivers/alert.h"
8 #include "sw/device/silicon_creator/lib/drivers/lifecycle.h"
9 #include "sw/device/silicon_creator/lib/drivers/otp.h"
10 
11 #include "otp_ctrl_regs.h"
12 
13 OTTF_DEFINE_TEST_CONFIG();
14 
15 /**
16  * Check that the alert_handler register CRC32 matches OTP value.
17  *
18  * The `OWNER_SW_CFG_ROM_ALERT_DIGEST_<LC_STATE>` OTP word should match the
19  * digest computed by XORing the CRC32 of the alert_handler registers with the
20  * current lifecycle state and kErrorOk, as done in
21  * `sw/device/silicon_creator/lib/shutdown.c:shutdown_init`.
22  */
23 static void alert_cfg_test(void) {
24  uint32_t digest = alert_config_crc32() ^ lifecycle_state_get() ^ kErrorOk;
25 
26  // `OTP_ALERT_DIGEST` in configured for each test to reference the digest for
27  // the current LC state.
28  CHECK(digest == otp_read32(OTP_ALERT_DIGEST));
29 }
30 
31 bool test_main(void) {
32  alert_cfg_test();
33  return true;
34 }