Guillermo Maturana | 037bfc2 | 2021-10-05 10:13:58 -0700 | [diff] [blame] | 1 | // Copyright lowRISC contributors. |
| 2 | // Licensed under the Apache License, Version 2.0, see LICENSE for details. |
| 3 | // SPDX-License-Identifier: Apache-2.0 |
| 4 | |
| 5 | #ifndef OPENTITAN_SW_DEVICE_LIB_TESTING_RSTMGR_TESTUTILS_H_ |
| 6 | #define OPENTITAN_SW_DEVICE_LIB_TESTING_RSTMGR_TESTUTILS_H_ |
| 7 | |
| 8 | #include <stdint.h> |
| 9 | |
| 10 | #include "sw/device/lib/dif/dif_rstmgr.h" |
| 11 | |
| 12 | /** |
| 13 | * Determines if the reset_info matches info. |
| 14 | * |
| 15 | * @param rstmgr A reset manager handle. |
| 16 | * @param info A bit mask of reset reasons. |
Guillermo Maturana | 475a6e1 | 2021-10-27 12:31:39 -0700 | [diff] [blame] | 17 | * |
| 18 | * @return True if the reset_info CSR matches info. |
Guillermo Maturana | 037bfc2 | 2021-10-05 10:13:58 -0700 | [diff] [blame] | 19 | */ |
Guillermo Maturana | 475a6e1 | 2021-10-27 12:31:39 -0700 | [diff] [blame] | 20 | bool rstmgr_testutils_is_reset_info(const dif_rstmgr_t *rstmgr, |
Guillermo Maturana | 037bfc2 | 2021-10-05 10:13:58 -0700 | [diff] [blame] | 21 | dif_rstmgr_reset_info_bitfield_t info); |
| 22 | |
Guillermo Maturana | 475a6e1 | 2021-10-27 12:31:39 -0700 | [diff] [blame] | 23 | /** |
Silvestrs Timofejevs | d53bbba | 2021-11-30 17:13:04 +0000 | [diff] [blame^] | 24 | * Determines if the reset info contains any of the reasons in `info`. |
| 25 | * |
| 26 | * @param rstmgr A reset manager handle. |
| 27 | * @param info A bit mask of reset reasons. |
| 28 | * |
| 29 | * @return True if the reset info contains any of the reasons in `info`. |
| 30 | */ |
| 31 | bool rstmgr_testutils_reset_info_any(const dif_rstmgr_t *rstmgr, |
| 32 | dif_rstmgr_reset_info_bitfield_t info); |
| 33 | |
| 34 | /** |
Guillermo Maturana | 475a6e1 | 2021-10-27 12:31:39 -0700 | [diff] [blame] | 35 | * Compares the given alert dump against the device's. |
| 36 | * |
| 37 | * If the dump array is null or its size is zero this check succeeds. It is |
| 38 | * possible to compare less words than the device captures, but it is an error |
| 39 | * to try to compare more. |
| 40 | * |
| 41 | * @param rstmgr A reset manager handle. |
| 42 | * @param expected_alert_dump An array holding the expected alert dump. |
| 43 | * @param dump_size The size of the expected_alert_dump array. |
Guillermo Maturana | 475a6e1 | 2021-10-27 12:31:39 -0700 | [diff] [blame] | 44 | */ |
Timothy Trippel | 1b73f80 | 2021-11-01 23:16:50 +0000 | [diff] [blame] | 45 | void rstmgr_testutils_compare_alert_info( |
Guillermo Maturana | 475a6e1 | 2021-10-27 12:31:39 -0700 | [diff] [blame] | 46 | const dif_rstmgr_t *rstmgr, |
| 47 | dif_rstmgr_alert_info_dump_segment_t *expected_alert_dump, |
| 48 | size_t dump_size); |
| 49 | |
| 50 | /** |
| 51 | * Compares the given cpu dump against the device's. |
| 52 | * |
| 53 | * If the dump array is null or its size is zero this check succeeds. It is |
| 54 | * possible to compare less words than the device captures, but it is an error |
| 55 | * to try to compare more. |
| 56 | * |
| 57 | * @param rstmgr A reset manager handle. |
| 58 | * @param expected_cpu_dump An array holding the expected cpu dump. |
| 59 | * @param dump_size The size of the expected_cpu_dump array. |
Guillermo Maturana | 475a6e1 | 2021-10-27 12:31:39 -0700 | [diff] [blame] | 60 | */ |
Timothy Trippel | 1b73f80 | 2021-11-01 23:16:50 +0000 | [diff] [blame] | 61 | void rstmgr_testutils_compare_cpu_info( |
Guillermo Maturana | 475a6e1 | 2021-10-27 12:31:39 -0700 | [diff] [blame] | 62 | const dif_rstmgr_t *rstmgr, |
| 63 | dif_rstmgr_cpu_info_dump_segment_t *expected_cpu_dump, size_t dump_size); |
| 64 | |
| 65 | /** |
| 66 | * Prepares the rstmgr for a reset scenario. |
| 67 | * |
| 68 | * @param rstmgr A reset manager handle. |
| 69 | */ |
| 70 | void rstmgr_testutils_pre_reset(const dif_rstmgr_t *rstmgr); |
| 71 | |
| 72 | /** |
| 73 | * Checks state after a reset. |
| 74 | * |
| 75 | * This will cause a failure if any of the checks fail. If either of the dump |
| 76 | * arrays is null or its size is zero the corresponding comparison will be |
| 77 | * skipped. |
| 78 | * |
| 79 | * @param rstmgr A reset manager handle. |
| 80 | * @param expected_reset_info The expected contents of the reset_info CSR. |
| 81 | * @param expected_alert_dump An array with the expected contents of the |
| 82 | * alert_info CSR. |
| 83 | * @param alert_dump_size The size of the expected_alert_dump array. |
| 84 | * @param expected_cpu_dump An array with the expected contents of the cpu_info |
| 85 | * CSR. |
| 86 | * @param cpu_dump_size The size of the expected_cpu_dump array. |
| 87 | */ |
| 88 | void rstmgr_testutils_post_reset( |
| 89 | const dif_rstmgr_t *rstmgr, |
| 90 | dif_rstmgr_reset_info_bitfield_t expected_reset_info, |
| 91 | dif_rstmgr_alert_info_dump_segment_t *expected_alert_dump, |
| 92 | size_t alert_dump_size, |
| 93 | dif_rstmgr_cpu_info_dump_segment_t *expected_cpu_dump, |
| 94 | size_t cpu_dump_size); |
| 95 | |
Guillermo Maturana | 037bfc2 | 2021-10-05 10:13:58 -0700 | [diff] [blame] | 96 | #endif // OPENTITAN_SW_DEVICE_LIB_TESTING_RSTMGR_TESTUTILS_H_ |