|
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 Asserts the nominal execution of the function being tested. |
| 59 | +** |
| 60 | +** \par Description |
| 61 | +** The core of each unit test is the execution of the function being tested. |
| 62 | +** This function and macro should be used to test the nominal execution of the |
| 63 | +** function; the expectation is that it will return CFE_SUCCESS or an |
| 64 | +** unspecified positive value. |
| 65 | +** |
| 66 | +** \par Assumptions, External Events, and Notes: |
| 67 | +** None |
| 68 | +** |
| 69 | +******************************************************************************/ |
| 70 | +#define CFE_UtAssert_STATUS_OK(FN) \ |
| 71 | + CFE_UtAssert_StatusCheck(FN, true, UTASSERT_CASETYPE_FAILURE, __FILE__, __LINE__, #FN) |
| 72 | + |
| 73 | +/*****************************************************************************/ |
| 74 | +/** |
| 75 | +** \brief Asserts the off-nominal execution of the function being tested. |
| 76 | +** |
| 77 | +** \par Description |
| 78 | +** The core of each unit test is the execution of the function being tested. |
| 79 | +** This function and macro should be used to test the generic off-nominal execution |
| 80 | +** of the function; the expectation is that it will return an unspecified negative |
| 81 | +** value. |
| 82 | +** |
| 83 | +** \par Assumptions, External Events, and Notes: |
| 84 | +** This should be used in cases where a specific error for a particular condition |
| 85 | +** is not known/documented. Whenever a specific error is indicated by the documentation, |
| 86 | +** tests should check for that error instead of using this. |
| 87 | +** |
| 88 | +******************************************************************************/ |
| 89 | +#define CFE_UtAssert_STATUS_ERROR(FN) \ |
| 90 | + CFE_UtAssert_StatusCheck(FN, false, UTASSERT_CASETYPE_FAILURE, __FILE__, __LINE__, #FN) |
| 91 | + |
| 92 | +/*****************************************************************************/ |
| 93 | +/** |
| 94 | +** \brief Macro to check CFE resource ID for equality |
| 95 | +** |
| 96 | +** \par Description |
| 97 | +** A macro that checks two resource ID values for equality. |
| 98 | +** |
| 99 | +** \par Assumptions, External Events, and Notes: |
| 100 | +** The generic #UtAssert_UINT32_EQ check should not be used, as ID values |
| 101 | +** and integers may not be interchangable with strict type checking. |
| 102 | +** |
| 103 | +******************************************************************************/ |
| 104 | +#define CFE_UtAssert_RESOURCEID_EQ(id1, id2) \ |
| 105 | + UtAssert_GenericUnsignedCompare(CFE_RESOURCEID_TO_ULONG(id1), UtAssert_Compare_EQ, CFE_RESOURCEID_TO_ULONG(id2), \ |
| 106 | + UtAssert_Radix_HEX, __FILE__, __LINE__, "Resource ID Check: ", #id1, #id2) |
| 107 | + |
| 108 | +/*****************************************************************************/ |
| 109 | +/** |
| 110 | +** \brief Check if a Resource ID is Undefined |
| 111 | +** |
| 112 | +** \par Description |
| 113 | +** A macro that checks if resource ID value is undefined. |
| 114 | +** |
| 115 | +** \par Assumptions, External Events, and Notes: |
| 116 | +** This utilizes the "TEST_DEFINED" macro provided by the resourceid module, as the |
| 117 | +** set of undefined IDs is more than the single value of CFE_RESOURCEID_UNDEFINED. |
| 118 | +** |
| 119 | +******************************************************************************/ |
| 120 | +#define CFE_UtAssert_RESOURCEID_UNDEFINED(id) \ |
| 121 | + UtAssert_True(!CFE_RESOURCEID_TEST_DEFINED(id), "%s (0x%lx) not defined", #id, CFE_RESOURCEID_TO_ULONG(id)) |
| 122 | + |
| 123 | +/*****************************************************************************/ |
| 124 | +/** |
| 125 | +** \brief Macro to check CFE memory size/offset for equality |
| 126 | +** |
| 127 | +** \par Description |
| 128 | +** A macro that checks two memory offset/size values for equality. |
| 129 | +** |
| 130 | +** \par Assumptions, External Events, and Notes: |
| 131 | +** This is a simple unsigned comparison which logs the values as hexadecimal |
| 132 | +** |
| 133 | +******************************************************************************/ |
| 134 | +#define CFE_UtAssert_MEMOFFSET_EQ(off1, off2) \ |
| 135 | + UtAssert_GenericUnsignedCompare(off1, UtAssert_Compare_EQ, off2, UtAssert_Radix_HEX, __FILE__, __LINE__, \ |
| 136 | + "Offset Check: ", #off1, #off2) |
| 137 | + |
| 138 | +/*****************************************************************************/ |
| 139 | +/** |
| 140 | +** \brief Macro to check CFE message ID for equality |
| 141 | +** |
| 142 | +** \par Description |
| 143 | +** A macro that checks two message ID values for equality. |
| 144 | +** |
| 145 | +** \par Assumptions, External Events, and Notes: |
| 146 | +** The generic #UtAssert_UINT32_EQ check should not be used, as CFE_SB_MsgId_t values |
| 147 | +** and integers may not be interchangable with strict type checking. |
| 148 | +** |
| 149 | +******************************************************************************/ |
| 150 | +#define CFE_UtAssert_MSGID_EQ(mid1, mid2) \ |
| 151 | + UtAssert_GenericUnsignedCompare(CFE_SB_MsgIdToValue(mid1), UtAssert_Compare_EQ, CFE_SB_MsgIdToValue(mid2), \ |
| 152 | + UtAssert_Radix_HEX, __FILE__, __LINE__, "MsgId Check: ", #mid1, #mid2) |
| 153 | + |
49 | 154 | /*************************************************************************
|
50 | 155 | ** Exported Functions
|
51 | 156 | *************************************************************************/
|
@@ -145,4 +250,30 @@ int32 CFE_Assert_OpenLogFile(const char *Filename);
|
145 | 250 | */
|
146 | 251 | void CFE_Assert_CloseLogFile(void);
|
147 | 252 |
|
| 253 | +/*****************************************************************************/ |
| 254 | +/** |
| 255 | +** \brief Helper function for nominal CFE calls |
| 256 | +** |
| 257 | +** \par Description |
| 258 | +** This helper function wraps the normal UtAssert function, intended for verifying |
| 259 | +** CFE API calls that are expected to return successfully. |
| 260 | +** |
| 261 | +** Note that this checks for a logical "success", which includes the specific #CFE_SUCCESS |
| 262 | +** status code, as well as all other status codes that represent a successful completion |
| 263 | +** of the function objectives (i.e. such as a nonzero size, from functions that return a |
| 264 | +** size). |
| 265 | +** |
| 266 | +** This can also be used to report with an alternative pass/fail marker by passing the CaseType |
| 267 | +** parameter appropriately. |
| 268 | +** |
| 269 | +** \par Assumptions, External Events, and Notes: |
| 270 | +** Note this will accept any non-negative value as logical "success", so it |
| 271 | +** also works with functions that return a size or other non-error status. |
| 272 | +** |
| 273 | +** \returns Test pass status, returns true if status was successful, false if it failed. |
| 274 | +** |
| 275 | +******************************************************************************/ |
| 276 | +bool CFE_UtAssert_StatusCheck(CFE_Status_t Status, bool ExpectSuccess, UtAssert_CaseType_t CaseType, const char *File, |
| 277 | + uint32 Line, const char *Text); |
| 278 | + |
148 | 279 | #endif /* CFE_ASSERT_H */
|
0 commit comments