|
39 | 39 | *************************************************************************/
|
40 | 40 | #include "common_types.h"
|
41 | 41 | #include "cfe_es_api_typedefs.h"
|
| 42 | +#include "utassert.h" |
| 43 | +#include "cfe_error.h" |
42 | 44 |
|
43 | 45 | /************************************************************************
|
44 | 46 | ** Type Definitions
|
45 | 47 | *************************************************************************/
|
46 | 48 |
|
47 | 49 | typedef void (*CFE_Assert_StatusCallback_t)(uint8 MessageType, const char *Prefix, const char *OutputMessage);
|
48 | 50 |
|
| 51 | +/************************************************************************* |
| 52 | +** CFE-specific assertion macros |
| 53 | +** (similar to macros in the CFE coverage test) |
| 54 | +*************************************************************************/ |
| 55 | + |
| 56 | +/*****************************************************************************/ |
| 57 | +/** |
| 58 | +** \brief Checks the successful execution of a setup function. |
| 59 | +** |
| 60 | +** \par Description |
| 61 | +** Many tests require a number of steps of setup to configure CFE such |
| 62 | +** that the actual test can be performed. Failure of any setup steps |
| 63 | +** result in a text message and the test being considered failed. |
| 64 | +** |
| 65 | +** \par Assumptions, External Events, and Notes: |
| 66 | +** To keep logs clean, this only generates a log message if it fails |
| 67 | +** |
| 68 | +******************************************************************************/ |
| 69 | +#define CFE_UtAssert_SETUP(FN) CFE_UtAssert_SuccessCheck(FN, true, UTASSERT_CASETYPE_TSF, __FILE__, __LINE__, #FN) |
| 70 | + |
| 71 | +/*****************************************************************************/ |
| 72 | +/** |
| 73 | +** \brief Asserts the nominal execution of the function being tested. |
| 74 | +** |
| 75 | +** \par Description |
| 76 | +** The core of each unit test is the execution of the function being tested. |
| 77 | +** This function and macro should be used to test the nominal execution of the |
| 78 | +** function; the expectation is that it will return CFE_SUCCESS or an |
| 79 | +** unspecified positive value. |
| 80 | +** |
| 81 | +** \par Assumptions, External Events, and Notes: |
| 82 | +** None |
| 83 | +** |
| 84 | +******************************************************************************/ |
| 85 | +#define CFE_UtAssert_SUCCESS(FN) CFE_UtAssert_SuccessCheck(FN, true, UTASSERT_CASETYPE_FAILURE, __FILE__, __LINE__, #FN) |
| 86 | + |
| 87 | +/*****************************************************************************/ |
| 88 | +/** |
| 89 | +** \brief Asserts the off-nominal execution of the function being tested. |
| 90 | +** |
| 91 | +** \par Description |
| 92 | +** The core of each unit test is the execution of the function being tested. |
| 93 | +** This function and macro should be used to test the generic off-nominal execution |
| 94 | +** of the function; the expectation is that it will return an unspecified negative |
| 95 | +** value. |
| 96 | +** |
| 97 | +** \par Assumptions, External Events, and Notes: |
| 98 | +** This should be used in cases where a specific error for a particular condition |
| 99 | +** is not known/documented. Whenever a specific error is indicated by the documentation, |
| 100 | +** tests should check for that error instead of using this. |
| 101 | +** |
| 102 | +******************************************************************************/ |
| 103 | +#define CFE_UtAssert_NOT_SUCCESS(FN) \ |
| 104 | + CFE_UtAssert_SuccessCheck(FN, false, UTASSERT_CASETYPE_FAILURE, __FILE__, __LINE__, #FN) |
| 105 | + |
| 106 | +/*****************************************************************************/ |
| 107 | +/** |
| 108 | +** \brief Checks the successful execution of a teardown function. |
| 109 | +** |
| 110 | +** \par Description |
| 111 | +** Many tests require a number of steps of setup to configure CFE such that the actual test |
| 112 | +** can be performed, and undoing that configuration is the role of the teardown steps. Failure |
| 113 | +** of any teardown steps result in a text message and the test being considered failed. |
| 114 | +** |
| 115 | +** \par Assumptions, External Events, and Notes: |
| 116 | +** To keep logs clean, this only generates a log message if it fails |
| 117 | +** |
| 118 | +******************************************************************************/ |
| 119 | +#define CFE_UtAssert_TEARDOWN(FN) CFE_UtAssert_SuccessCheck(FN, true, UTASSERT_CASETYPE_TTF, __FILE__, __LINE__, #FN) |
| 120 | + |
| 121 | +/*****************************************************************************/ |
| 122 | +/** |
| 123 | +** \brief Macro to check CFE resource ID for equality |
| 124 | +** |
| 125 | +** \par Description |
| 126 | +** A macro that checks two resource ID values for equality. |
| 127 | +** |
| 128 | +** \par Assumptions, External Events, and Notes: |
| 129 | +** The generic #UtAssert_UINT32_EQ check should not be used, as ID values |
| 130 | +** and integers may not be interchangable with strict type checking. |
| 131 | +** |
| 132 | +******************************************************************************/ |
| 133 | +#define CFE_UtAssert_RESOURCEID_EQ(id1, id2) \ |
| 134 | + UtAssert_GenericUnsignedCompare(CFE_RESOURCEID_TO_ULONG(id1), UtAssert_Compare_EQ, CFE_RESOURCEID_TO_ULONG(id2), \ |
| 135 | + UtAssert_Radix_HEX, __FILE__, __LINE__, "Resource ID Check: ", #id1, #id2) |
| 136 | + |
| 137 | +/*****************************************************************************/ |
| 138 | +/** |
| 139 | +** \brief Check if a Resource ID is Undefined |
| 140 | +** |
| 141 | +** \par Description |
| 142 | +** A macro that checks if resource ID value is undefined. |
| 143 | +** |
| 144 | +** \par Assumptions, External Events, and Notes: |
| 145 | +** This utilizes the "TEST_DEFINED" macro provided by the resourceid module, as the |
| 146 | +** set of undefined IDs is more than the single value of CFE_RESOURCEID_UNDEFINED. |
| 147 | +** |
| 148 | +******************************************************************************/ |
| 149 | +#define CFE_UtAssert_RESOURCEID_UNDEFINED(id) \ |
| 150 | + UtAssert_True(!CFE_RESOURCEID_TEST_DEFINED(id), "%s (0x%lx) not defined", #id, CFE_RESOURCEID_TO_ULONG(id)) |
| 151 | + |
| 152 | +/*****************************************************************************/ |
| 153 | +/** |
| 154 | +** \brief Macro to check CFE memory size/offset for equality |
| 155 | +** |
| 156 | +** \par Description |
| 157 | +** A macro that checks two memory offset/size values for equality. |
| 158 | +** |
| 159 | +** \par Assumptions, External Events, and Notes: |
| 160 | +** This is a simple unsigned comparison which logs the values as hexadecimal |
| 161 | +** |
| 162 | +******************************************************************************/ |
| 163 | +#define CFE_UtAssert_MEMOFFSET_EQ(off1, off2) \ |
| 164 | + UtAssert_GenericUnsignedCompare(off1, UtAssert_Compare_EQ, off2, UtAssert_Radix_HEX, __FILE__, __LINE__, \ |
| 165 | + "Offset Check: ", #off1, #off2) |
| 166 | + |
| 167 | +/*****************************************************************************/ |
| 168 | +/** |
| 169 | +** \brief Macro to check CFE message ID for equality |
| 170 | +** |
| 171 | +** \par Description |
| 172 | +** A macro that checks two message ID values for equality. |
| 173 | +** |
| 174 | +** \par Assumptions, External Events, and Notes: |
| 175 | +** The generic #UtAssert_UINT32_EQ check should not be used, as CFE_SB_MsgId_t values |
| 176 | +** and integers may not be interchangable with strict type checking. |
| 177 | +** |
| 178 | +******************************************************************************/ |
| 179 | +#define CFE_UtAssert_MSGID_EQ(mid1, mid2) \ |
| 180 | + UtAssert_GenericUnsignedCompare(CFE_SB_MsgIdToValue(mid1), UtAssert_Compare_EQ, CFE_SB_MsgIdToValue(mid2), \ |
| 181 | + UtAssert_Radix_HEX, __FILE__, __LINE__, "MsgId Check: ", #mid1, #mid2) |
| 182 | + |
49 | 183 | /*************************************************************************
|
50 | 184 | ** Exported Functions
|
51 | 185 | *************************************************************************/
|
@@ -145,4 +279,29 @@ int32 CFE_Assert_OpenLogFile(const char *Filename);
|
145 | 279 | */
|
146 | 280 | void CFE_Assert_CloseLogFile(void);
|
147 | 281 |
|
| 282 | +/*****************************************************************************/ |
| 283 | +/** |
| 284 | +** \brief Helper function for nominal CFE calls |
| 285 | +** |
| 286 | +** \par Description |
| 287 | +** This helper function wraps the normal UtAssert function, intended for verifying |
| 288 | +** CFE API calls that are expected to return successfully (#CFE_SUCCESS typically). |
| 289 | +** |
| 290 | +** This can also be used to confirm setup and teardown operations by passing the CaseType |
| 291 | +** parameter appropriately (UTASSERT_CASETYPE_TSF or UTASSERT_CASETYPE_TTF, respectively). |
| 292 | +** |
| 293 | +** \par Assumptions, External Events, and Notes: |
| 294 | +** When used for setup (TSF) or teardown (TTF) then the test case is only logged to |
| 295 | +** the output if it fails. This is to keep logs more concise, by not including |
| 296 | +** test cases that are not related to the main focus of the code under test. |
| 297 | +** |
| 298 | +** Note this will accept any non-negative value as logical "success", so it |
| 299 | +** also works with functions that return a size or other non-error status. |
| 300 | +** |
| 301 | +** \returns Test pass status, returns true if status was successful, false if it failed. |
| 302 | +** |
| 303 | +******************************************************************************/ |
| 304 | +bool CFE_UtAssert_SuccessCheck(CFE_Status_t Status, bool ExpectSuccess, UtAssert_CaseType_t CaseType, const char *File, |
| 305 | + uint32 Line, const char *Text); |
| 306 | + |
148 | 307 | #endif /* CFE_ASSERT_H */
|
0 commit comments