🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

386 lines
13 KiB

  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /**
  19. * \file SDL_test_fuzzer.h
  20. *
  21. * Include file for SDL test framework.
  22. *
  23. * This code is a part of the SDL2_test library, not the main SDL library.
  24. */
  25. /*
  26. Data generators for fuzzing test data in a reproducible way.
  27. */
  28. #ifndef SDL_test_fuzzer_h_
  29. #define SDL_test_fuzzer_h_
  30. #include "begin_code.h"
  31. /* Set up for C function definitions, even when using C++ */
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35. /*
  36. Based on GSOC code by Markus Kauppila <markus.kauppila@gmail.com>
  37. */
  38. /**
  39. * \file
  40. * Note: The fuzzer implementation uses a static instance of random context
  41. * internally which makes it thread-UNsafe.
  42. */
  43. /**
  44. * Initializes the fuzzer for a test
  45. *
  46. * \param execKey Execution "Key" that initializes the random number generator uniquely for the test.
  47. *
  48. */
  49. void SDLTest_FuzzerInit(Uint64 execKey);
  50. /**
  51. * Returns a random Uint8
  52. *
  53. * \returns a generated integer
  54. */
  55. Uint8 SDLTest_RandomUint8(void);
  56. /**
  57. * Returns a random Sint8
  58. *
  59. * \returns a generated signed integer
  60. */
  61. Sint8 SDLTest_RandomSint8(void);
  62. /**
  63. * Returns a random Uint16
  64. *
  65. * \returns a generated integer
  66. */
  67. Uint16 SDLTest_RandomUint16(void);
  68. /**
  69. * Returns a random Sint16
  70. *
  71. * \returns a generated signed integer
  72. */
  73. Sint16 SDLTest_RandomSint16(void);
  74. /**
  75. * Returns a random integer
  76. *
  77. * \returns a generated integer
  78. */
  79. Sint32 SDLTest_RandomSint32(void);
  80. /**
  81. * Returns a random positive integer
  82. *
  83. * \returns a generated integer
  84. */
  85. Uint32 SDLTest_RandomUint32(void);
  86. /**
  87. * Returns random Uint64.
  88. *
  89. * \returns a generated integer
  90. */
  91. Uint64 SDLTest_RandomUint64(void);
  92. /**
  93. * Returns random Sint64.
  94. *
  95. * \returns a generated signed integer
  96. */
  97. Sint64 SDLTest_RandomSint64(void);
  98. /**
  99. * \returns a random float in range [0.0 - 1.0]
  100. */
  101. float SDLTest_RandomUnitFloat(void);
  102. /**
  103. * \returns a random double in range [0.0 - 1.0]
  104. */
  105. double SDLTest_RandomUnitDouble(void);
  106. /**
  107. * \returns a random float.
  108. *
  109. */
  110. float SDLTest_RandomFloat(void);
  111. /**
  112. * \returns a random double.
  113. *
  114. */
  115. double SDLTest_RandomDouble(void);
  116. /**
  117. * Returns a random boundary value for Uint8 within the given boundaries.
  118. * Boundaries are inclusive, see the usage examples below. If validDomain
  119. * is true, the function will only return valid boundaries, otherwise non-valid
  120. * boundaries are also possible.
  121. * If boundary1 > boundary2, the values are swapped
  122. *
  123. * Usage examples:
  124. * RandomUint8BoundaryValue(10, 20, SDL_TRUE) returns 10, 11, 19 or 20
  125. * RandomUint8BoundaryValue(1, 20, SDL_FALSE) returns 0 or 21
  126. * RandomUint8BoundaryValue(0, 99, SDL_FALSE) returns 100
  127. * RandomUint8BoundaryValue(0, 255, SDL_FALSE) returns 0 (error set)
  128. *
  129. * \param boundary1 Lower boundary limit
  130. * \param boundary2 Upper boundary limit
  131. * \param validDomain Should the generated boundary be valid (=within the bounds) or not?
  132. *
  133. * \returns a random boundary value for the given range and domain or 0 with error set
  134. */
  135. Uint8 SDLTest_RandomUint8BoundaryValue(Uint8 boundary1, Uint8 boundary2, SDL_bool validDomain);
  136. /**
  137. * Returns a random boundary value for Uint16 within the given boundaries.
  138. * Boundaries are inclusive, see the usage examples below. If validDomain
  139. * is true, the function will only return valid boundaries, otherwise non-valid
  140. * boundaries are also possible.
  141. * If boundary1 > boundary2, the values are swapped
  142. *
  143. * Usage examples:
  144. * RandomUint16BoundaryValue(10, 20, SDL_TRUE) returns 10, 11, 19 or 20
  145. * RandomUint16BoundaryValue(1, 20, SDL_FALSE) returns 0 or 21
  146. * RandomUint16BoundaryValue(0, 99, SDL_FALSE) returns 100
  147. * RandomUint16BoundaryValue(0, 0xFFFF, SDL_FALSE) returns 0 (error set)
  148. *
  149. * \param boundary1 Lower boundary limit
  150. * \param boundary2 Upper boundary limit
  151. * \param validDomain Should the generated boundary be valid (=within the bounds) or not?
  152. *
  153. * \returns a random boundary value for the given range and domain or 0 with error set
  154. */
  155. Uint16 SDLTest_RandomUint16BoundaryValue(Uint16 boundary1, Uint16 boundary2, SDL_bool validDomain);
  156. /**
  157. * Returns a random boundary value for Uint32 within the given boundaries.
  158. * Boundaries are inclusive, see the usage examples below. If validDomain
  159. * is true, the function will only return valid boundaries, otherwise non-valid
  160. * boundaries are also possible.
  161. * If boundary1 > boundary2, the values are swapped
  162. *
  163. * Usage examples:
  164. * RandomUint32BoundaryValue(10, 20, SDL_TRUE) returns 10, 11, 19 or 20
  165. * RandomUint32BoundaryValue(1, 20, SDL_FALSE) returns 0 or 21
  166. * RandomUint32BoundaryValue(0, 99, SDL_FALSE) returns 100
  167. * RandomUint32BoundaryValue(0, 0xFFFFFFFF, SDL_FALSE) returns 0 (with error set)
  168. *
  169. * \param boundary1 Lower boundary limit
  170. * \param boundary2 Upper boundary limit
  171. * \param validDomain Should the generated boundary be valid (=within the bounds) or not?
  172. *
  173. * \returns a random boundary value for the given range and domain or 0 with error set
  174. */
  175. Uint32 SDLTest_RandomUint32BoundaryValue(Uint32 boundary1, Uint32 boundary2, SDL_bool validDomain);
  176. /**
  177. * Returns a random boundary value for Uint64 within the given boundaries.
  178. * Boundaries are inclusive, see the usage examples below. If validDomain
  179. * is true, the function will only return valid boundaries, otherwise non-valid
  180. * boundaries are also possible.
  181. * If boundary1 > boundary2, the values are swapped
  182. *
  183. * Usage examples:
  184. * RandomUint64BoundaryValue(10, 20, SDL_TRUE) returns 10, 11, 19 or 20
  185. * RandomUint64BoundaryValue(1, 20, SDL_FALSE) returns 0 or 21
  186. * RandomUint64BoundaryValue(0, 99, SDL_FALSE) returns 100
  187. * RandomUint64BoundaryValue(0, 0xFFFFFFFFFFFFFFFF, SDL_FALSE) returns 0 (with error set)
  188. *
  189. * \param boundary1 Lower boundary limit
  190. * \param boundary2 Upper boundary limit
  191. * \param validDomain Should the generated boundary be valid (=within the bounds) or not?
  192. *
  193. * \returns a random boundary value for the given range and domain or 0 with error set
  194. */
  195. Uint64 SDLTest_RandomUint64BoundaryValue(Uint64 boundary1, Uint64 boundary2, SDL_bool validDomain);
  196. /**
  197. * Returns a random boundary value for Sint8 within the given boundaries.
  198. * Boundaries are inclusive, see the usage examples below. If validDomain
  199. * is true, the function will only return valid boundaries, otherwise non-valid
  200. * boundaries are also possible.
  201. * If boundary1 > boundary2, the values are swapped
  202. *
  203. * Usage examples:
  204. * RandomSint8BoundaryValue(-10, 20, SDL_TRUE) returns -11, -10, 19 or 20
  205. * RandomSint8BoundaryValue(-100, -10, SDL_FALSE) returns -101 or -9
  206. * RandomSint8BoundaryValue(SINT8_MIN, 99, SDL_FALSE) returns 100
  207. * RandomSint8BoundaryValue(SINT8_MIN, SINT8_MAX, SDL_FALSE) returns SINT8_MIN (== error value) with error set
  208. *
  209. * \param boundary1 Lower boundary limit
  210. * \param boundary2 Upper boundary limit
  211. * \param validDomain Should the generated boundary be valid (=within the bounds) or not?
  212. *
  213. * \returns a random boundary value for the given range and domain or SINT8_MIN with error set
  214. */
  215. Sint8 SDLTest_RandomSint8BoundaryValue(Sint8 boundary1, Sint8 boundary2, SDL_bool validDomain);
  216. /**
  217. * Returns a random boundary value for Sint16 within the given boundaries.
  218. * Boundaries are inclusive, see the usage examples below. If validDomain
  219. * is true, the function will only return valid boundaries, otherwise non-valid
  220. * boundaries are also possible.
  221. * If boundary1 > boundary2, the values are swapped
  222. *
  223. * Usage examples:
  224. * RandomSint16BoundaryValue(-10, 20, SDL_TRUE) returns -11, -10, 19 or 20
  225. * RandomSint16BoundaryValue(-100, -10, SDL_FALSE) returns -101 or -9
  226. * RandomSint16BoundaryValue(SINT16_MIN, 99, SDL_FALSE) returns 100
  227. * RandomSint16BoundaryValue(SINT16_MIN, SINT16_MAX, SDL_FALSE) returns SINT16_MIN (== error value) with error set
  228. *
  229. * \param boundary1 Lower boundary limit
  230. * \param boundary2 Upper boundary limit
  231. * \param validDomain Should the generated boundary be valid (=within the bounds) or not?
  232. *
  233. * \returns a random boundary value for the given range and domain or SINT16_MIN with error set
  234. */
  235. Sint16 SDLTest_RandomSint16BoundaryValue(Sint16 boundary1, Sint16 boundary2, SDL_bool validDomain);
  236. /**
  237. * Returns a random boundary value for Sint32 within the given boundaries.
  238. * Boundaries are inclusive, see the usage examples below. If validDomain
  239. * is true, the function will only return valid boundaries, otherwise non-valid
  240. * boundaries are also possible.
  241. * If boundary1 > boundary2, the values are swapped
  242. *
  243. * Usage examples:
  244. * RandomSint32BoundaryValue(-10, 20, SDL_TRUE) returns -11, -10, 19 or 20
  245. * RandomSint32BoundaryValue(-100, -10, SDL_FALSE) returns -101 or -9
  246. * RandomSint32BoundaryValue(SINT32_MIN, 99, SDL_FALSE) returns 100
  247. * RandomSint32BoundaryValue(SINT32_MIN, SINT32_MAX, SDL_FALSE) returns SINT32_MIN (== error value)
  248. *
  249. * \param boundary1 Lower boundary limit
  250. * \param boundary2 Upper boundary limit
  251. * \param validDomain Should the generated boundary be valid (=within the bounds) or not?
  252. *
  253. * \returns a random boundary value for the given range and domain or SINT32_MIN with error set
  254. */
  255. Sint32 SDLTest_RandomSint32BoundaryValue(Sint32 boundary1, Sint32 boundary2, SDL_bool validDomain);
  256. /**
  257. * Returns a random boundary value for Sint64 within the given boundaries.
  258. * Boundaries are inclusive, see the usage examples below. If validDomain
  259. * is true, the function will only return valid boundaries, otherwise non-valid
  260. * boundaries are also possible.
  261. * If boundary1 > boundary2, the values are swapped
  262. *
  263. * Usage examples:
  264. * RandomSint64BoundaryValue(-10, 20, SDL_TRUE) returns -11, -10, 19 or 20
  265. * RandomSint64BoundaryValue(-100, -10, SDL_FALSE) returns -101 or -9
  266. * RandomSint64BoundaryValue(SINT64_MIN, 99, SDL_FALSE) returns 100
  267. * RandomSint64BoundaryValue(SINT64_MIN, SINT64_MAX, SDL_FALSE) returns SINT64_MIN (== error value) and error set
  268. *
  269. * \param boundary1 Lower boundary limit
  270. * \param boundary2 Upper boundary limit
  271. * \param validDomain Should the generated boundary be valid (=within the bounds) or not?
  272. *
  273. * \returns a random boundary value for the given range and domain or SINT64_MIN with error set
  274. */
  275. Sint64 SDLTest_RandomSint64BoundaryValue(Sint64 boundary1, Sint64 boundary2, SDL_bool validDomain);
  276. /**
  277. * Returns integer in range [min, max] (inclusive).
  278. * Min and max values can be negative values.
  279. * If Max in smaller than min, then the values are swapped.
  280. * Min and max are the same value, that value will be returned.
  281. *
  282. * \param min Minimum inclusive value of returned random number
  283. * \param max Maximum inclusive value of returned random number
  284. *
  285. * \returns a generated random integer in range
  286. */
  287. Sint32 SDLTest_RandomIntegerInRange(Sint32 min, Sint32 max);
  288. /**
  289. * Generates random null-terminated string. The minimum length for
  290. * the string is 1 character, maximum length for the string is 255
  291. * characters and it can contain ASCII characters from 32 to 126.
  292. *
  293. * Note: Returned string needs to be deallocated.
  294. *
  295. * \returns a newly allocated random string; or NULL if length was invalid or string could not be allocated.
  296. */
  297. char * SDLTest_RandomAsciiString(void);
  298. /**
  299. * Generates random null-terminated string. The maximum length for
  300. * the string is defined by the maxLength parameter.
  301. * String can contain ASCII characters from 32 to 126.
  302. *
  303. * Note: Returned string needs to be deallocated.
  304. *
  305. * \param maxLength The maximum length of the generated string.
  306. *
  307. * \returns a newly allocated random string; or NULL if maxLength was invalid or string could not be allocated.
  308. */
  309. char * SDLTest_RandomAsciiStringWithMaximumLength(int maxLength);
  310. /**
  311. * Generates random null-terminated string. The length for
  312. * the string is defined by the size parameter.
  313. * String can contain ASCII characters from 32 to 126.
  314. *
  315. * Note: Returned string needs to be deallocated.
  316. *
  317. * \param size The length of the generated string
  318. *
  319. * \returns a newly allocated random string; or NULL if size was invalid or string could not be allocated.
  320. */
  321. char * SDLTest_RandomAsciiStringOfSize(int size);
  322. /**
  323. * Get the invocation count for the fuzzer since last ...FuzzerInit.
  324. *
  325. * \returns the invocation count.
  326. */
  327. int SDLTest_GetFuzzerInvocationCount(void);
  328. /* Ends C function definitions when using C++ */
  329. #ifdef __cplusplus
  330. }
  331. #endif
  332. #include "close_code.h"
  333. #endif /* SDL_test_fuzzer_h_ */
  334. /* vi: set ts=4 sw=4 expandtab: */