Ronald Cron | b6d6d4c | 2020-06-03 10:11:18 +0200 | [diff] [blame] | 1 | /** |
| 2 | * \file helpers.h |
| 3 | * |
| 4 | * \brief This file contains the prototypes of helper functions for the |
| 5 | * purpose of testing. |
| 6 | */ |
| 7 | |
Bence Szépkúti | 8697465 | 2020-06-15 11:59:37 +0200 | [diff] [blame] | 8 | /* |
Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 9 | * Copyright The Mbed TLS Contributors |
Dave Rodgman | 16799db | 2023-11-02 19:47:20 +0000 | [diff] [blame] | 10 | * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
Ronald Cron | b6d6d4c | 2020-06-03 10:11:18 +0200 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #ifndef TEST_HELPERS_H |
| 14 | #define TEST_HELPERS_H |
| 15 | |
Mateusz Starzyk | b198272 | 2021-05-27 14:46:48 +0200 | [diff] [blame] | 16 | /* Most fields of publicly available structs are private and are wrapped with |
| 17 | * MBEDTLS_PRIVATE macro. This define allows tests to access the private fields |
| 18 | * directly (without using the MBEDTLS_PRIVATE wrapper). */ |
Mateusz Starzyk | 2c09c9b | 2021-05-14 22:20:10 +0200 | [diff] [blame] | 19 | #define MBEDTLS_ALLOW_PRIVATE_ACCESS |
| 20 | |
Bence Szépkúti | c662b36 | 2021-05-27 11:25:03 +0200 | [diff] [blame] | 21 | #include "mbedtls/build_info.h" |
Ronald Cron | b6d6d4c | 2020-06-03 10:11:18 +0200 | [diff] [blame] | 22 | |
Gilles Peskine | fa8ec26 | 2023-11-22 17:55:43 +0100 | [diff] [blame] | 23 | #if defined(__SANITIZE_ADDRESS__) /* gcc -fsanitize=address */ |
| 24 | # define MBEDTLS_TEST_HAVE_ASAN |
| 25 | #endif |
| 26 | #if defined(__has_feature) |
| 27 | # if __has_feature(address_sanitizer) /* clang -fsanitize=address */ |
| 28 | # define MBEDTLS_TEST_HAVE_ASAN |
| 29 | # endif |
| 30 | # if __has_feature(memory_sanitizer) /* clang -fsanitize=memory */ |
| 31 | # define MBEDTLS_TEST_HAVE_MSAN |
| 32 | # endif |
| 33 | # if __has_feature(thread_sanitizer) /* clang -fsanitize=thread */ |
| 34 | # define MBEDTLS_TEST_HAVE_TSAN |
| 35 | # endif |
| 36 | #endif |
| 37 | |
Gilles Peskine | 2a4c598 | 2021-01-29 21:18:09 +0100 | [diff] [blame] | 38 | #if defined(MBEDTLS_THREADING_C) && defined(MBEDTLS_THREADING_PTHREAD) && \ |
| 39 | defined(MBEDTLS_TEST_HOOKS) |
| 40 | #define MBEDTLS_TEST_MUTEX_USAGE |
| 41 | #endif |
| 42 | |
Ronald Cron | f40529d | 2020-06-09 16:27:37 +0200 | [diff] [blame] | 43 | #include "mbedtls/platform.h" |
Ronald Cron | f40529d | 2020-06-09 16:27:37 +0200 | [diff] [blame] | 44 | |
| 45 | #include <stddef.h> |
| 46 | #include <stdint.h> |
| 47 | |
Gilles Peskine | ebc49e5 | 2021-06-11 14:13:53 +0200 | [diff] [blame] | 48 | #if defined(MBEDTLS_BIGNUM_C) |
| 49 | #include "mbedtls/bignum.h" |
| 50 | #endif |
| 51 | |
Gilles Peskine | 571576f | 2022-09-20 21:37:56 +0200 | [diff] [blame] | 52 | /** The type of test case arguments that contain binary data. */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 53 | typedef struct data_tag { |
| 54 | uint8_t *x; |
Gilles Peskine | 571576f | 2022-09-20 21:37:56 +0200 | [diff] [blame] | 55 | uint32_t len; |
| 56 | } data_t; |
| 57 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 58 | typedef enum { |
Chris Jones | e60e2ae | 2021-01-20 17:51:47 +0000 | [diff] [blame] | 59 | MBEDTLS_TEST_RESULT_SUCCESS = 0, |
| 60 | MBEDTLS_TEST_RESULT_FAILED, |
| 61 | MBEDTLS_TEST_RESULT_SKIPPED |
| 62 | } mbedtls_test_result_t; |
Chris Jones | 9634bb1 | 2021-01-20 15:56:42 +0000 | [diff] [blame] | 63 | |
Paul Elliott | 5c498f3 | 2023-10-31 16:38:56 +0000 | [diff] [blame] | 64 | #define MBEDTLS_TEST_LINE_LENGTH 76 |
| 65 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 66 | typedef struct { |
Chris Jones | e60e2ae | 2021-01-20 17:51:47 +0000 | [diff] [blame] | 67 | mbedtls_test_result_t result; |
Chris Jones | 9634bb1 | 2021-01-20 15:56:42 +0000 | [diff] [blame] | 68 | const char *test; |
| 69 | const char *filename; |
| 70 | int line_no; |
| 71 | unsigned long step; |
Paul Elliott | 5c498f3 | 2023-10-31 16:38:56 +0000 | [diff] [blame] | 72 | char line1[MBEDTLS_TEST_LINE_LENGTH]; |
| 73 | char line2[MBEDTLS_TEST_LINE_LENGTH]; |
Gilles Peskine | 2a4c598 | 2021-01-29 21:18:09 +0100 | [diff] [blame] | 74 | #if defined(MBEDTLS_TEST_MUTEX_USAGE) |
| 75 | const char *mutex_usage_error; |
| 76 | #endif |
Paul Elliott | c7a1e99 | 2023-11-03 18:44:57 +0000 | [diff] [blame^] | 77 | #if defined(MBEDTLS_BIGNUM_C) |
| 78 | unsigned case_uses_negative_0; |
| 79 | #endif |
Chris Jones | 9634bb1 | 2021-01-20 15:56:42 +0000 | [diff] [blame] | 80 | } |
Chris Jones | e60e2ae | 2021-01-20 17:51:47 +0000 | [diff] [blame] | 81 | mbedtls_test_info_t; |
Paul Elliott | 4580d4d | 2023-10-27 18:41:02 +0100 | [diff] [blame] | 82 | |
| 83 | /** |
| 84 | * \brief Get the current test result status |
| 85 | * |
| 86 | * \return The current test result status |
| 87 | */ |
| 88 | mbedtls_test_result_t mbedtls_test_get_result(void); |
| 89 | |
| 90 | /** |
| 91 | * \brief Get the current test name/description |
| 92 | * |
| 93 | * \return The current test name/description |
| 94 | */ |
| 95 | const char *mbedtls_test_get_test(void); |
| 96 | |
| 97 | /** |
| 98 | * \brief Get the current test filename |
| 99 | * |
| 100 | * \return The current test filename |
| 101 | */ |
| 102 | const char *mbedtls_get_test_filename(void); |
| 103 | |
| 104 | /** |
| 105 | * \brief Get the current test file line number (for failure / skip) |
| 106 | * |
| 107 | * \return The current test file line number (for failure / skip) |
| 108 | */ |
| 109 | int mbedtls_test_get_line_no(void); |
| 110 | |
| 111 | /** |
| 112 | * \brief Increment the current test step. |
| 113 | */ |
| 114 | void mbedtls_test_increment_step(void); |
| 115 | |
| 116 | /** |
| 117 | * \brief Get the current test step |
| 118 | * |
| 119 | * \return The current test step |
| 120 | */ |
| 121 | unsigned long mbedtls_test_get_step(void); |
| 122 | |
| 123 | /** |
| 124 | * \brief Get the current test line buffer 1 |
| 125 | * |
| 126 | * \return The current test line buffer 1 |
| 127 | */ |
| 128 | const char *mbedtls_test_get_line1(void); |
| 129 | |
| 130 | /** |
| 131 | * \brief Get the current test line buffer 2 |
| 132 | * |
| 133 | * \return The current test line buffer 2 |
| 134 | */ |
| 135 | const char *mbedtls_test_get_line2(void); |
| 136 | |
| 137 | #if defined(MBEDTLS_TEST_MUTEX_USAGE) |
| 138 | /** |
| 139 | * \brief Get the current mutex usage error message |
| 140 | * |
| 141 | * \return The current mutex error message (may be NULL if no error) |
| 142 | */ |
| 143 | const char *mbedtls_test_get_mutex_usage_error(void); |
| 144 | |
| 145 | /** |
| 146 | * \brief Set the current mutex usage error message |
| 147 | * |
| 148 | * \note This will only set the mutex error message if one has not |
| 149 | * already been set, or if we are clearing the message (msg is |
| 150 | * NULL) |
| 151 | * |
| 152 | * \param msg Error message to set (can be NULL to clear) |
| 153 | */ |
| 154 | void mbedtls_test_set_mutex_usage_error(const char *msg); |
| 155 | #endif |
| 156 | |
Paul Elliott | c7a1e99 | 2023-11-03 18:44:57 +0000 | [diff] [blame^] | 157 | #if defined(MBEDTLS_BIGNUM_C) |
| 158 | |
| 159 | /** |
| 160 | * \brief Get whether the current test is a bignum test that uses |
| 161 | * negative zero. |
| 162 | * |
| 163 | * \return non zero if the current test uses bignum negative zero. |
| 164 | */ |
| 165 | unsigned mbedtls_test_get_case_uses_negative_0(void); |
| 166 | |
| 167 | /** |
| 168 | * \brief Indicate that the current test uses bignum negative zero. |
| 169 | * |
| 170 | * \note This function is called if the current test case had an |
| 171 | * input parsed with mbedtls_test_read_mpi() that is a negative |
| 172 | * 0 (`"-"`, `"-0"`, `"-00"`, etc., constructing a result with |
| 173 | * the sign bit set to -1 and the value being all-limbs-0, |
| 174 | * which is not a valid representation in #mbedtls_mpi but is |
| 175 | * tested for robustness). * |
| 176 | */ |
| 177 | void mbedtls_test_increment_case_uses_negative_0(void); |
| 178 | #endif |
Chris Jones | 9634bb1 | 2021-01-20 15:56:42 +0000 | [diff] [blame] | 179 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 180 | int mbedtls_test_platform_setup(void); |
| 181 | void mbedtls_test_platform_teardown(void); |
Ronald Cron | f40529d | 2020-06-09 16:27:37 +0200 | [diff] [blame] | 182 | |
Ronald Cron | a0c2539 | 2020-06-18 10:10:46 +0200 | [diff] [blame] | 183 | /** |
Chris Jones | 39ddb0a | 2021-02-03 16:15:00 +0000 | [diff] [blame] | 184 | * \brief Record the current test case as a failure. |
Chris Jones | 567e0ad | 2021-02-03 12:07:01 +0000 | [diff] [blame] | 185 | * |
Chris Jones | 39ddb0a | 2021-02-03 16:15:00 +0000 | [diff] [blame] | 186 | * This function can be called directly however it is usually |
| 187 | * called via macros such as TEST_ASSERT, TEST_EQUAL, |
| 188 | * PSA_ASSERT, etc... |
| 189 | * |
| 190 | * \note If the test case was already marked as failed, calling |
| 191 | * `mbedtls_test_fail( )` again will not overwrite any |
| 192 | * previous information about the failure. |
| 193 | * |
| 194 | * \param test Description of the failure or assertion that failed. This |
| 195 | * MUST be a string literal. |
Chris Jones | 567e0ad | 2021-02-03 12:07:01 +0000 | [diff] [blame] | 196 | * \param line_no Line number where the failure originated. |
| 197 | * \param filename Filename where the failure originated. |
| 198 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 199 | void mbedtls_test_fail(const char *test, int line_no, const char *filename); |
Chris Jones | 567e0ad | 2021-02-03 12:07:01 +0000 | [diff] [blame] | 200 | |
| 201 | /** |
Chris Jones | 39ddb0a | 2021-02-03 16:15:00 +0000 | [diff] [blame] | 202 | * \brief Record the current test case as skipped. |
Chris Jones | 567e0ad | 2021-02-03 12:07:01 +0000 | [diff] [blame] | 203 | * |
Chris Jones | 39ddb0a | 2021-02-03 16:15:00 +0000 | [diff] [blame] | 204 | * This function can be called directly however it is usually |
| 205 | * called via the TEST_ASSUME macro. |
| 206 | * |
| 207 | * \param test Description of the assumption that caused the test case to |
| 208 | * be skipped. This MUST be a string literal. |
| 209 | * \param line_no Line number where the test case was skipped. |
| 210 | * \param filename Filename where the test case was skipped. |
Chris Jones | 567e0ad | 2021-02-03 12:07:01 +0000 | [diff] [blame] | 211 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 212 | void mbedtls_test_skip(const char *test, int line_no, const char *filename); |
Chris Jones | 9634bb1 | 2021-01-20 15:56:42 +0000 | [diff] [blame] | 213 | |
Chris Jones | 567e0ad | 2021-02-03 12:07:01 +0000 | [diff] [blame] | 214 | /** |
| 215 | * \brief Set the test step number for failure reports. |
Chris Jones | 9634bb1 | 2021-01-20 15:56:42 +0000 | [diff] [blame] | 216 | * |
Chris Jones | 39ddb0a | 2021-02-03 16:15:00 +0000 | [diff] [blame] | 217 | * Call this function to display "step NNN" in addition to the |
Chris Jones | 567e0ad | 2021-02-03 12:07:01 +0000 | [diff] [blame] | 218 | * line number and file name if a test fails. Typically the "step |
| 219 | * number" is the index of a for loop but it can be whatever you |
| 220 | * want. |
Chris Jones | 9634bb1 | 2021-01-20 15:56:42 +0000 | [diff] [blame] | 221 | * |
| 222 | * \param step The step number to report. |
| 223 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 224 | void mbedtls_test_set_step(unsigned long step); |
Chris Jones | 9634bb1 | 2021-01-20 15:56:42 +0000 | [diff] [blame] | 225 | |
Chris Jones | 567e0ad | 2021-02-03 12:07:01 +0000 | [diff] [blame] | 226 | /** |
| 227 | * \brief Reset mbedtls_test_info to a ready/starting state. |
Chris Jones | 567e0ad | 2021-02-03 12:07:01 +0000 | [diff] [blame] | 228 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 229 | void mbedtls_test_info_reset(void); |
Chris Jones | 9634bb1 | 2021-01-20 15:56:42 +0000 | [diff] [blame] | 230 | |
Ronald Cron | a0c2539 | 2020-06-18 10:10:46 +0200 | [diff] [blame] | 231 | /** |
Gilles Peskine | 89615ee | 2021-04-29 20:28:54 +0200 | [diff] [blame] | 232 | * \brief Record the current test case as a failure if two integers |
| 233 | * have a different value. |
| 234 | * |
| 235 | * This function is usually called via the macro |
| 236 | * #TEST_EQUAL. |
| 237 | * |
| 238 | * \param test Description of the failure or assertion that failed. This |
| 239 | * MUST be a string literal. This normally has the form |
| 240 | * "EXPR1 == EXPR2" where EXPR1 has the value \p value1 |
| 241 | * and EXPR2 has the value \p value2. |
| 242 | * \param line_no Line number where the failure originated. |
| 243 | * \param filename Filename where the failure originated. |
| 244 | * \param value1 The first value to compare. |
| 245 | * \param value2 The second value to compare. |
| 246 | * |
| 247 | * \return \c 1 if the values are equal, otherwise \c 0. |
| 248 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 249 | int mbedtls_test_equal(const char *test, int line_no, const char *filename, |
| 250 | unsigned long long value1, unsigned long long value2); |
Gilles Peskine | 89615ee | 2021-04-29 20:28:54 +0200 | [diff] [blame] | 251 | |
| 252 | /** |
Gilles Peskine | d146542 | 2022-04-13 23:59:52 +0200 | [diff] [blame] | 253 | * \brief Record the current test case as a failure based |
| 254 | * on comparing two unsigned integers. |
| 255 | * |
| 256 | * This function is usually called via the macro |
| 257 | * #TEST_LE_U. |
| 258 | * |
| 259 | * \param test Description of the failure or assertion that failed. This |
| 260 | * MUST be a string literal. This normally has the form |
| 261 | * "EXPR1 <= EXPR2" where EXPR1 has the value \p value1 |
| 262 | * and EXPR2 has the value \p value2. |
| 263 | * \param line_no Line number where the failure originated. |
| 264 | * \param filename Filename where the failure originated. |
| 265 | * \param value1 The first value to compare. |
| 266 | * \param value2 The second value to compare. |
| 267 | * |
| 268 | * \return \c 1 if \p value1 <= \p value2, otherwise \c 0. |
| 269 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 270 | int mbedtls_test_le_u(const char *test, int line_no, const char *filename, |
| 271 | unsigned long long value1, unsigned long long value2); |
Gilles Peskine | d146542 | 2022-04-13 23:59:52 +0200 | [diff] [blame] | 272 | |
| 273 | /** |
| 274 | * \brief Record the current test case as a failure based |
| 275 | * on comparing two signed integers. |
| 276 | * |
| 277 | * This function is usually called via the macro |
| 278 | * #TEST_LE_S. |
| 279 | * |
| 280 | * \param test Description of the failure or assertion that failed. This |
| 281 | * MUST be a string literal. This normally has the form |
| 282 | * "EXPR1 <= EXPR2" where EXPR1 has the value \p value1 |
| 283 | * and EXPR2 has the value \p value2. |
| 284 | * \param line_no Line number where the failure originated. |
| 285 | * \param filename Filename where the failure originated. |
| 286 | * \param value1 The first value to compare. |
| 287 | * \param value2 The second value to compare. |
| 288 | * |
| 289 | * \return \c 1 if \p value1 <= \p value2, otherwise \c 0. |
| 290 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 291 | int mbedtls_test_le_s(const char *test, int line_no, const char *filename, |
| 292 | long long value1, long long value2); |
Gilles Peskine | d146542 | 2022-04-13 23:59:52 +0200 | [diff] [blame] | 293 | |
| 294 | /** |
Ronald Cron | ab500cb | 2020-07-01 17:09:10 +0200 | [diff] [blame] | 295 | * \brief This function decodes the hexadecimal representation of |
| 296 | * data. |
Ronald Cron | a0c2539 | 2020-06-18 10:10:46 +0200 | [diff] [blame] | 297 | * |
| 298 | * \note The output buffer can be the same as the input buffer. For |
| 299 | * any other overlapping of the input and output buffers, the |
| 300 | * behavior is undefined. |
| 301 | * |
| 302 | * \param obuf Output buffer. |
| 303 | * \param obufmax Size in number of bytes of \p obuf. |
| 304 | * \param ibuf Input buffer. |
| 305 | * \param len The number of unsigned char written in \p obuf. This must |
| 306 | * not be \c NULL. |
| 307 | * |
| 308 | * \return \c 0 on success. |
| 309 | * \return \c -1 if the output buffer is too small or the input string |
Ronald Cron | ab500cb | 2020-07-01 17:09:10 +0200 | [diff] [blame] | 310 | * is not a valid hexadecimal representation. |
Ronald Cron | a0c2539 | 2020-06-18 10:10:46 +0200 | [diff] [blame] | 311 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 312 | int mbedtls_test_unhexify(unsigned char *obuf, size_t obufmax, |
| 313 | const char *ibuf, size_t *len); |
Ronald Cron | a0c2539 | 2020-06-18 10:10:46 +0200 | [diff] [blame] | 314 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 315 | void mbedtls_test_hexify(unsigned char *obuf, |
| 316 | const unsigned char *ibuf, |
| 317 | int len); |
Ronald Cron | f40529d | 2020-06-09 16:27:37 +0200 | [diff] [blame] | 318 | |
| 319 | /** |
Gilles Peskine | 881447d | 2022-12-08 15:24:52 +0100 | [diff] [blame] | 320 | * \brief Convert hexadecimal digit to an integer. |
| 321 | * |
| 322 | * \param c The digit to convert (`'0'` to `'9'`, `'A'` to `'F'` or |
| 323 | * `'a'` to `'f'`). |
| 324 | * \param[out] uc On success, the value of the digit (0 to 15). |
| 325 | * |
| 326 | * \return 0 on success, -1 if \p c is not a hexadecimal digit. |
| 327 | */ |
| 328 | int mbedtls_test_ascii2uc(const char c, unsigned char *uc); |
| 329 | |
| 330 | /** |
Ronald Cron | f40529d | 2020-06-09 16:27:37 +0200 | [diff] [blame] | 331 | * Allocate and zeroize a buffer. |
| 332 | * |
| 333 | * If the size if zero, a pointer to a zeroized 1-byte buffer is returned. |
| 334 | * |
| 335 | * For convenience, dies if allocation fails. |
| 336 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 337 | unsigned char *mbedtls_test_zero_alloc(size_t len); |
Ronald Cron | f40529d | 2020-06-09 16:27:37 +0200 | [diff] [blame] | 338 | |
| 339 | /** |
| 340 | * Allocate and fill a buffer from hex data. |
| 341 | * |
| 342 | * The buffer is sized exactly as needed. This allows to detect buffer |
| 343 | * overruns (including overreads) when running the test suite under valgrind. |
| 344 | * |
| 345 | * If the size if zero, a pointer to a zeroized 1-byte buffer is returned. |
| 346 | * |
| 347 | * For convenience, dies if allocation fails. |
| 348 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 349 | unsigned char *mbedtls_test_unhexify_alloc(const char *ibuf, size_t *olen); |
Ronald Cron | f40529d | 2020-06-09 16:27:37 +0200 | [diff] [blame] | 350 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 351 | int mbedtls_test_hexcmp(uint8_t *a, uint8_t *b, |
| 352 | uint32_t a_len, uint32_t b_len); |
Ronald Cron | f40529d | 2020-06-09 16:27:37 +0200 | [diff] [blame] | 353 | |
Gilles Peskine | 1dc19ff | 2021-02-08 20:59:39 +0100 | [diff] [blame] | 354 | #if defined(MBEDTLS_PSA_CRYPTO_C) && defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) |
Gilles Peskine | 1af872d | 2021-01-20 20:02:01 +0100 | [diff] [blame] | 355 | #include "test/fake_external_rng_for_test.h" |
| 356 | #endif |
| 357 | |
Gilles Peskine | 2a4c598 | 2021-01-29 21:18:09 +0100 | [diff] [blame] | 358 | #if defined(MBEDTLS_TEST_MUTEX_USAGE) |
Paul Elliott | f25d831 | 2023-11-23 18:49:43 +0000 | [diff] [blame] | 359 | /** |
| 360 | * Activate the mutex usage verification framework. See threading_helpers.c for |
| 361 | * information. |
| 362 | * */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 363 | void mbedtls_test_mutex_usage_init(void); |
Gilles Peskine | 2a4c598 | 2021-01-29 21:18:09 +0100 | [diff] [blame] | 364 | |
Paul Elliott | f25d831 | 2023-11-23 18:49:43 +0000 | [diff] [blame] | 365 | /** |
| 366 | * Deactivate the mutex usage verification framework. See threading_helpers.c |
| 367 | * for information. |
| 368 | */ |
| 369 | void mbedtls_test_mutex_usage_end(void); |
| 370 | |
Gilles Peskine | 2a4c598 | 2021-01-29 21:18:09 +0100 | [diff] [blame] | 371 | /** Call this function after executing a test case to check for mutex usage |
| 372 | * errors. */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 373 | void mbedtls_test_mutex_usage_check(void); |
Gilles Peskine | 1061ec6 | 2021-01-29 21:17:11 +0100 | [diff] [blame] | 374 | #endif /* MBEDTLS_TEST_MUTEX_USAGE */ |
| 375 | |
Chris Jones | 96ae73b | 2021-01-08 17:04:59 +0000 | [diff] [blame] | 376 | #if defined(MBEDTLS_TEST_HOOKS) |
| 377 | /** |
Chris Jones | 3f613c1 | 2021-03-31 09:34:22 +0100 | [diff] [blame] | 378 | * \brief Check that only a pure high-level error code is being combined with |
| 379 | * a pure low-level error code as otherwise the resultant error code |
Chris Jones | 5e8805a | 2021-01-12 15:21:57 +0000 | [diff] [blame] | 380 | * would be corrupted. |
Chris Jones | 3f613c1 | 2021-03-31 09:34:22 +0100 | [diff] [blame] | 381 | * |
| 382 | * \note Both high-level and low-level error codes cannot be greater than |
| 383 | * zero however can be zero. If one error code is zero then the |
| 384 | * other error code is returned even if both codes are zero. |
| 385 | * |
| 386 | * \note If the check fails, fail the test currently being run. |
Chris Jones | 96ae73b | 2021-01-08 17:04:59 +0000 | [diff] [blame] | 387 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 388 | void mbedtls_test_err_add_check(int high, int low, |
| 389 | const char *file, int line); |
Chris Jones | 96ae73b | 2021-01-08 17:04:59 +0000 | [diff] [blame] | 390 | #endif |
| 391 | |
Ronald Cron | b6d6d4c | 2020-06-03 10:11:18 +0200 | [diff] [blame] | 392 | #endif /* TEST_HELPERS_H */ |