unity_config.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /* =========================================================================
  2. Unity - A Test Framework for C
  3. ThrowTheSwitch.org
  4. Copyright (c) 2007-24 Mike Karlesky, Mark VanderVoord, & Greg Williams
  5. SPDX-License-Identifier: MIT
  6. ========================================================================= */
  7. /* Unity Configuration
  8. * As of May 11th, 2016 at ThrowTheSwitch/Unity commit 837c529
  9. * Update: December 29th, 2016
  10. * See Also: Unity/docs/UnityConfigurationGuide.pdf
  11. *
  12. * Unity is designed to run on almost anything that is targeted by a C compiler.
  13. * It would be awesome if this could be done with zero configuration. While
  14. * there are some targets that come close to this dream, it is sadly not
  15. * universal. It is likely that you are going to need at least a couple of the
  16. * configuration options described in this document.
  17. *
  18. * All of Unity's configuration options are `#defines`. Most of these are simple
  19. * definitions. A couple are macros with arguments. They live inside the
  20. * unity_internals.h header file. We don't necessarily recommend opening that
  21. * file unless you really need to. That file is proof that a cross-platform
  22. * library is challenging to build. From a more positive perspective, it is also
  23. * proof that a great deal of complexity can be centralized primarily to one
  24. * place in order to provide a more consistent and simple experience elsewhere.
  25. *
  26. * Using These Options
  27. * It doesn't matter if you're using a target-specific compiler and a simulator
  28. * or a native compiler. In either case, you've got a couple choices for
  29. * configuring these options:
  30. *
  31. * 1. Because these options are specified via C defines, you can pass most of
  32. * these options to your compiler through command line compiler flags. Even
  33. * if you're using an embedded target that forces you to use their
  34. * overbearing IDE for all configuration, there will be a place somewhere in
  35. * your project to configure defines for your compiler.
  36. * 2. You can create a custom `unity_config.h` configuration file (present in
  37. * your toolchain's search paths). In this file, you will list definitions
  38. * and macros specific to your target. All you must do is define
  39. * `UNITY_INCLUDE_CONFIG_H` and Unity will rely on `unity_config.h` for any
  40. * further definitions it may need.
  41. */
  42. #ifndef UNITY_CONFIG_H
  43. #define UNITY_CONFIG_H
  44. /* ************************* AUTOMATIC INTEGER TYPES ***************************
  45. * C's concept of an integer varies from target to target. The C Standard has
  46. * rules about the `int` matching the register size of the target
  47. * microprocessor. It has rules about the `int` and how its size relates to
  48. * other integer types. An `int` on one target might be 16 bits while on another
  49. * target it might be 64. There are more specific types in compilers compliant
  50. * with C99 or later, but that's certainly not every compiler you are likely to
  51. * encounter. Therefore, Unity has a number of features for helping to adjust
  52. * itself to match your required integer sizes. It starts off by trying to do it
  53. * automatically.
  54. **************************************************************************** */
  55. /* The first attempt to guess your types is to check `limits.h`. Some compilers
  56. * that don't support `stdint.h` could include `limits.h`. If you don't
  57. * want Unity to check this file, define this to make it skip the inclusion.
  58. * Unity looks at UINT_MAX & ULONG_MAX, which were available since C89.
  59. */
  60. /* #define UNITY_EXCLUDE_LIMITS_H */
  61. /* The second thing that Unity does to guess your types is check `stdint.h`.
  62. * This file defines `UINTPTR_MAX`, since C99, that Unity can make use of to
  63. * learn about your system. It's possible you don't want it to do this or it's
  64. * possible that your system doesn't support `stdint.h`. If that's the case,
  65. * you're going to want to define this. That way, Unity will know to skip the
  66. * inclusion of this file and you won't be left with a compiler error.
  67. */
  68. /* #define UNITY_EXCLUDE_STDINT_H */
  69. /* ********************** MANUAL INTEGER TYPE DEFINITION ***********************
  70. * If you've disabled all of the automatic options above, you're going to have
  71. * to do the configuration yourself. There are just a handful of defines that
  72. * you are going to specify if you don't like the defaults.
  73. **************************************************************************** */
  74. /* Define this to be the number of bits an `int` takes up on your system. The
  75. * default, if not auto-detected, is 32 bits.
  76. *
  77. * Example:
  78. */
  79. /* #define UNITY_INT_WIDTH 16 */
  80. /* Define this to be the number of bits a `long` takes up on your system. The
  81. * default, if not autodetected, is 32 bits. This is used to figure out what
  82. * kind of 64-bit support your system can handle. Does it need to specify a
  83. * `long` or a `long long` to get a 64-bit value. On 16-bit systems, this option
  84. * is going to be ignored.
  85. *
  86. * Example:
  87. */
  88. /* #define UNITY_LONG_WIDTH 16 */
  89. /* Define this to be the number of bits a pointer takes up on your system. The
  90. * default, if not autodetected, is 32-bits. If you're getting ugly compiler
  91. * warnings about casting from pointers, this is the one to look at.
  92. *
  93. * Example:
  94. */
  95. /* #define UNITY_POINTER_WIDTH 64 */
  96. /* Unity will automatically include 64-bit support if it auto-detects it, or if
  97. * your `int`, `long`, or pointer widths are greater than 32-bits. Define this
  98. * to enable 64-bit support if none of the other options already did it for you.
  99. * There can be a significant size and speed impact to enabling 64-bit support
  100. * on small targets, so don't define it if you don't need it.
  101. */
  102. /* #define UNITY_INCLUDE_64 */
  103. /* it is UNITY_SUPPORT_64 *not* UNITY_INCLUDE_64 */
  104. #define UNITY_SUPPORT_64
  105. /* *************************** FLOATING POINT TYPES ****************************
  106. * In the embedded world, it's not uncommon for targets to have no support for
  107. * floating point operations at all or to have support that is limited to only
  108. * single precision. We are able to guess integer sizes on the fly because
  109. * integers are always available in at least one size. Floating point, on the
  110. * other hand, is sometimes not available at all. Trying to include `float.h` on
  111. * these platforms would result in an error. This leaves manual configuration as
  112. * the only option.
  113. **************************************************************************** */
  114. /* By default, Unity guesses that you will want single precision floating point
  115. * support, but not double precision. It's easy to change either of these using
  116. * the include and exclude options here. You may include neither, just float,
  117. * or both, as suits your needs.
  118. */
  119. /* #define UNITY_EXCLUDE_FLOAT */
  120. /* #define UNITY_INCLUDE_DOUBLE */
  121. /* #define UNITY_EXCLUDE_DOUBLE */
  122. #define UNITY_INCLUDE_FLOAT
  123. #define UNITY_INCLUDE_DOUBLE
  124. /* For features that are enabled, the following floating point options also
  125. * become available.
  126. */
  127. /* Unity aims for as small of a footprint as possible and avoids most standard
  128. * library calls (some embedded platforms don't have a standard library!).
  129. * Because of this, its routines for printing integer values are minimalist and
  130. * hand-coded. To keep Unity universal, though, we eventually chose to develop
  131. * our own floating point print routines. Still, the display of floating point
  132. * values during a failure are optional. By default, Unity will print the
  133. * actual results of floating point assertion failures. So a failed assertion
  134. * will produce a message like "Expected 4.0 Was 4.25". If you would like less
  135. * verbose failure messages for floating point assertions, use this option to
  136. * give a failure message `"Values Not Within Delta"` and trim the binary size.
  137. */
  138. /* #define UNITY_EXCLUDE_FLOAT_PRINT */
  139. /* If enabled, Unity assumes you want your `FLOAT` asserts to compare standard C
  140. * floats. If your compiler supports a specialty floating point type, you can
  141. * always override this behavior by using this definition.
  142. *
  143. * Example:
  144. */
  145. /* #define UNITY_FLOAT_TYPE float16_t */
  146. /* If enabled, Unity assumes you want your `DOUBLE` asserts to compare standard
  147. * C doubles. If you would like to change this, you can specify something else
  148. * by using this option. For example, defining `UNITY_DOUBLE_TYPE` to `long
  149. * double` could enable gargantuan floating point types on your 64-bit processor
  150. * instead of the standard `double`.
  151. *
  152. * Example:
  153. */
  154. /* #define UNITY_DOUBLE_TYPE long double */
  155. /* If you look up `UNITY_ASSERT_EQUAL_FLOAT` and `UNITY_ASSERT_EQUAL_DOUBLE` as
  156. * documented in the Unity Assertion Guide, you will learn that they are not
  157. * really asserting that two values are equal but rather that two values are
  158. * "close enough" to equal. "Close enough" is controlled by these precision
  159. * configuration options. If you are working with 32-bit floats and/or 64-bit
  160. * doubles (the normal on most processors), you should have no need to change
  161. * these options. They are both set to give you approximately 1 significant bit
  162. * in either direction. The float precision is 0.00001 while the double is
  163. * 10^-12. For further details on how this works, see the appendix of the Unity
  164. * Assertion Guide.
  165. *
  166. * Example:
  167. */
  168. /* #define UNITY_FLOAT_PRECISION 0.001f */
  169. /* #define UNITY_DOUBLE_PRECISION 0.001f */
  170. /* *************************** MISCELLANEOUS ***********************************
  171. * Miscellaneous configuration options for Unity
  172. **************************************************************************** */
  173. /* Unity uses the stddef.h header included in the C standard library for the
  174. * "NULL" macro. Define this in order to disable the include of stddef.h. If you
  175. * do this, you have to make sure to provide your own "NULL" definition.
  176. */
  177. /* #define UNITY_EXCLUDE_STDDEF_H */
  178. /* Define this to enable the unity formatted print macro:
  179. * "TEST_PRINTF"
  180. */
  181. /* #define UNITY_INCLUDE_PRINT_FORMATTED */
  182. /* *************************** TOOLSET CUSTOMIZATION ***************************
  183. * In addition to the options listed above, there are a number of other options
  184. * which will come in handy to customize Unity's behavior for your specific
  185. * toolchain. It is possible that you may not need to touch any of these but
  186. * certain platforms, particularly those running in simulators, may need to jump
  187. * through extra hoops to operate properly. These macros will help in those
  188. * situations.
  189. **************************************************************************** */
  190. /* By default, Unity prints its results to `stdout` as it runs. This works
  191. * perfectly fine in most situations where you are using a native compiler for
  192. * testing. It works on some simulators as well so long as they have `stdout`
  193. * routed back to the command line. There are times, however, where the
  194. * simulator will lack support for dumping results or you will want to route
  195. * results elsewhere for other reasons. In these cases, you should define the
  196. * `UNITY_OUTPUT_CHAR` macro. This macro accepts a single character at a time
  197. * (as an `int`, since this is the parameter type of the standard C `putchar`
  198. * function most commonly used). You may replace this with whatever function
  199. * call you like.
  200. *
  201. * Example:
  202. * Say you are forced to run your test suite on an embedded processor with no
  203. * `stdout` option. You decide to route your test result output to a custom
  204. * serial `RS232_putc()` function you wrote like thus:
  205. */
  206. /* #define UNITY_OUTPUT_CHAR(a) RS232_putc(a) */
  207. /* #define UNITY_OUTPUT_CHAR_HEADER_DECLARATION RS232_putc(int) */
  208. /* #define UNITY_OUTPUT_FLUSH() RS232_flush() */
  209. /* #define UNITY_OUTPUT_FLUSH_HEADER_DECLARATION RS232_flush(void) */
  210. /* #define UNITY_OUTPUT_START() RS232_config(115200,1,8,0) */
  211. /* #define UNITY_OUTPUT_COMPLETE() RS232_close() */
  212. /* Some compilers require a custom attribute to be assigned to pointers, like
  213. * `near` or `far`. In these cases, you can give Unity a safe default for these
  214. * by defining this option with the attribute you would like.
  215. *
  216. * Example:
  217. */
  218. /* #define UNITY_PTR_ATTRIBUTE __attribute__((far)) */
  219. /* #define UNITY_PTR_ATTRIBUTE near */
  220. /* Print execution time of each test when executed in verbose mode
  221. *
  222. * Example:
  223. *
  224. * TEST - PASS (10 ms)
  225. */
  226. /* #define UNITY_INCLUDE_EXEC_TIME */
  227. #endif /* UNITY_CONFIG_H */