unity_config.h 12 KB

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