unity_config.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. #define UNITY_EXCLUDE_LIMITS_H
  56. /* The second thing that Unity does to guess your types is check `stdint.h`.
  57. * This file defines `UINTPTR_MAX`, since C99, that Unity can make use of to
  58. * learn about your system. It's possible you don't want it to do this or it's
  59. * possible that your system doesn't support `stdint.h`. If that's the case,
  60. * you're going to want to define this. That way, Unity will know to skip the
  61. * inclusion of this file and you won't be left with a compiler error.
  62. */
  63. /* #define UNITY_EXCLUDE_STDINT_H */
  64. #undef UNITY_EXCLUDE_STDINT_H
  65. /* ********************** MANUAL INTEGER TYPE DEFINITION ***********************
  66. * If you've disabled all of the automatic options above, you're going to have
  67. * to do the configuration yourself. There are just a handful of defines that
  68. * you are going to specify if you don't like the defaults.
  69. **************************************************************************** */
  70. /* Define this to be the number of bits an `int` takes up on your system. The
  71. * default, if not auto-detected, is 32 bits.
  72. *
  73. * Example:
  74. */
  75. /* #define UNITY_INT_WIDTH 16 */
  76. #define UNITY_INT_WIDTH 32
  77. /* Define this to be the number of bits a `long` takes up on your system. The
  78. * default, if not autodetected, is 32 bits. This is used to figure out what
  79. * kind of 64-bit support your system can handle. Does it need to specify a
  80. * `long` or a `long long` to get a 64-bit value. On 16-bit systems, this option
  81. * is going to be ignored.
  82. *
  83. * Example:
  84. */
  85. /* #define UNITY_LONG_WIDTH 16 */
  86. #define UNITY_LONG_WIDTH 32
  87. /* Define this to be the number of bits a pointer takes up on your system. The
  88. * default, if not autodetected, is 32-bits. If you're getting ugly compiler
  89. * warnings about casting from pointers, this is the one to look at.
  90. *
  91. * Example:
  92. */
  93. /* #define UNITY_POINTER_WIDTH 64 */
  94. #define UNITY_POINTER_WIDTH 32
  95. /* Unity will automatically include 64-bit support if it auto-detects it, or if
  96. * your `int`, `long`, or pointer widths are greater than 32-bits. Define this
  97. * to enable 64-bit support if none of the other options already did it for you.
  98. * There can be a significant size and speed impact to enabling 64-bit support
  99. * on small targets, so don't define it if you don't need it.
  100. */
  101. /* #define UNITY_INCLUDE_64 */
  102. #define UNITY_INCLUDE_64
  103. #define UNITY_SUPPORT_64
  104. /* *************************** FLOATING POINT TYPES ****************************
  105. * In the embedded world, it's not uncommon for targets to have no support for
  106. * floating point operations at all or to have support that is limited to only
  107. * single precision. We are able to guess integer sizes on the fly because
  108. * integers are always available in at least one size. Floating point, on the
  109. * other hand, is sometimes not available at all. Trying to include `float.h` on
  110. * these platforms would result in an error. This leaves manual configuration as
  111. * the only option.
  112. **************************************************************************** */
  113. /* By default, Unity guesses that you will want single precision floating point
  114. * support, but not double precision. It's easy to change either of these using
  115. * the include and exclude options here. You may include neither, just float,
  116. * or both, as suits your needs.
  117. */
  118. /* #define UNITY_EXCLUDE_FLOAT */
  119. /* #define UNITY_INCLUDE_DOUBLE */
  120. /* #define UNITY_EXCLUDE_DOUBLE */
  121. #undef UNITY_EXCLUDE_FLOAT
  122. #define UNITY_INCLUDE_DOUBLE
  123. #undef UNITY_EXCLUDE_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. #undef UNITY_EXCLUDE_FLOAT_PRINT
  140. /* If enabled, Unity assumes you want your `FLOAT` asserts to compare standard C
  141. * floats. If your compiler supports a specialty floating point type, you can
  142. * always override this behavior by using this definition.
  143. *
  144. * Example:
  145. */
  146. /* #define UNITY_FLOAT_TYPE float16_t */
  147. /* If enabled, Unity assumes you want your `DOUBLE` asserts to compare standard
  148. * C doubles. If you would like to change this, you can specify something else
  149. * by using this option. For example, defining `UNITY_DOUBLE_TYPE` to `long
  150. * double` could enable gargantuan floating point types on your 64-bit processor
  151. * instead of the standard `double`.
  152. *
  153. * Example:
  154. */
  155. /* #define UNITY_DOUBLE_TYPE long double */
  156. /* If you look up `UNITY_ASSERT_EQUAL_FLOAT` and `UNITY_ASSERT_EQUAL_DOUBLE` as
  157. * documented in the Unity Assertion Guide, you will learn that they are not
  158. * really asserting that two values are equal but rather that two values are
  159. * "close enough" to equal. "Close enough" is controlled by these precision
  160. * configuration options. If you are working with 32-bit floats and/or 64-bit
  161. * doubles (the normal on most processors), you should have no need to change
  162. * these options. They are both set to give you approximately 1 significant bit
  163. * in either direction. The float precision is 0.00001 while the double is
  164. * 10^-12. For further details on how this works, see the appendix of the Unity
  165. * Assertion Guide.
  166. *
  167. * Example:
  168. */
  169. /* #define UNITY_FLOAT_PRECISION 0.001f */
  170. /* #define UNITY_DOUBLE_PRECISION 0.001f */
  171. /* *************************** TOOLSET CUSTOMIZATION ***************************
  172. * In addition to the options listed above, there are a number of other options
  173. * which will come in handy to customize Unity's behavior for your specific
  174. * toolchain. It is possible that you may not need to touch any of these but
  175. * certain platforms, particularly those running in simulators, may need to jump
  176. * through extra hoops to operate properly. These macros will help in those
  177. * situations.
  178. **************************************************************************** */
  179. /* By default, Unity prints its results to `stdout` as it runs. This works
  180. * perfectly fine in most situations where you are using a native compiler for
  181. * testing. It works on some simulators as well so long as they have `stdout`
  182. * routed back to the command line. There are times, however, where the
  183. * simulator will lack support for dumping results or you will want to route
  184. * results elsewhere for other reasons. In these cases, you should define the
  185. * `UNITY_OUTPUT_CHAR` macro. This macro accepts a single character at a time
  186. * (as an `int`, since this is the parameter type of the standard C `putchar`
  187. * function most commonly used). You may replace this with whatever function
  188. * call you like.
  189. *
  190. * Example:
  191. * Say you are forced to run your test suite on an embedded processor with no
  192. * `stdout` option. You decide to route your test result output to a custom
  193. * serial `RS232_putc()` function you wrote like thus:
  194. */
  195. /* #define UNITY_OUTPUT_CHAR(a) RS232_putc(a) */
  196. /* #define UNITY_OUTPUT_CHAR_HEADER_DECLARATION RS232_putc(int) */
  197. /* #define UNITY_OUTPUT_FLUSH() RS232_flush() */
  198. /* #define UNITY_OUTPUT_FLUSH_HEADER_DECLARATION RS232_flush(void) */
  199. /* #define UNITY_OUTPUT_START() RS232_config(115200,1,8,0) */
  200. /* #define UNITY_OUTPUT_COMPLETE() RS232_close() */
  201. #define UNITY_OUTPUT_CHAR(a) UnityOutputChar(a)
  202. #define UNITY_OUTPUT_CHAR_HEADER_DECLARATION UnityOutputChar(int)
  203. #define UNITY_OUTPUT_FLUSH() UnityOutputFlush()
  204. #define UNITY_OUTPUT_FLUSH_HEADER_DECLARATION UnityOutputFlush(void)
  205. #define UNITY_OUTPUT_START() UnityOutputStart()
  206. #define UNITY_OUTPUT_COMPLETE() UnityOutputComplete()
  207. void UnityOutputChar(int);
  208. void UnityOutputFlush(void);
  209. void UnityOutputStart(void);
  210. void UnityOutputComplete(void);
  211. void UnityRunAllTests(void);
  212. /* For some targets, Unity can make the otherwise required `setUp()` and
  213. * `tearDown()` functions optional. This is a nice convenience for test writers
  214. * since `setUp` and `tearDown` don't often actually _do_ anything. If you're
  215. * using gcc or clang, this option is automatically defined for you. Other
  216. * compilers can also support this behavior, if they support a C feature called
  217. * weak functions. A weak function is a function that is compiled into your
  218. * executable _unless_ a non-weak version of the same function is defined
  219. * elsewhere. If a non-weak version is found, the weak version is ignored as if
  220. * it never existed. If your compiler supports this feature, you can let Unity
  221. * know by defining `UNITY_SUPPORT_WEAK` as the function attributes that would
  222. * need to be applied to identify a function as weak. If your compiler lacks
  223. * support for weak functions, you will always need to define `setUp` and
  224. * `tearDown` functions (though they can be and often will be just empty). The
  225. * most common options for this feature are:
  226. */
  227. /* #define UNITY_SUPPORT_WEAK weak */
  228. /* #define UNITY_SUPPORT_WEAK __attribute__((weak)) */
  229. /* #define UNITY_NO_WEAK */
  230. #define UNITY_SUPPORT_WEAK __attribute__((weak))
  231. /* Some compilers require a custom attribute to be assigned to pointers, like
  232. * `near` or `far`. In these cases, you can give Unity a safe default for these
  233. * by defining this option with the attribute you would like.
  234. *
  235. * Example:
  236. */
  237. /* #define UNITY_PTR_ATTRIBUTE __attribute__((far)) */
  238. /* #define UNITY_PTR_ATTRIBUTE near */
  239. #define UNITY_INTERNAL_HEAP_SIZE_BYTES (256 * 1024)
  240. #endif /* UNITY_CONFIG_H */