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