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_begin_code.h>
38/* Set up for C function definitions, even when using C++ */
39#ifdef __cplusplus
40extern "C" {
41#endif
42
43
44/*
45 Based on GSOC code by Markus Kauppila <markus.kauppila@gmail.com>
46*/
47
48
49/**
50 * Note: The fuzzer implementation uses a static instance of random context
51 * internally which makes it thread-UNsafe.
52 */
53
54/**
55 * Initializes the fuzzer for a test
56 *
57 * \param execKey Execution "Key" that initializes the random number generator uniquely for the test.
58 *
59 */
61
62
63/**
64 * Returns a random Uint8
65 *
66 * \returns a generated integer
67 */
69
70/**
71 * Returns a random Sint8
72 *
73 * \returns a generated signed integer
74 */
76
77
78/**
79 * Returns a random Uint16
80 *
81 * \returns a generated integer
82 */
84
85/**
86 * Returns a random Sint16
87 *
88 * \returns a generated signed integer
89 */
91
92
93/**
94 * Returns a random integer
95 *
96 * \returns a generated integer
97 */
99
100
101/**
102 * Returns a random positive integer
103 *
104 * \returns a generated integer
105 */
107
108/**
109 * Returns random Uint64.
110 *
111 * \returns a generated integer
112 */
114
115
116/**
117 * Returns random Sint64.
118 *
119 * \returns a generated signed integer
120 */
122
123/**
124 * \returns a random float in range [0.0 - 1.0]
125 */
127
128/**
129 * \returns a random double in range [0.0 - 1.0]
130 */
132
133/**
134 * \returns a random float.
135 *
136 */
138
139/**
140 * \returns a random double.
141 *
142 */
144
145/**
146 * Returns a random boundary value for Uint8 within the given boundaries.
147 * Boundaries are inclusive, see the usage examples below. If validDomain
148 * is true, the function will only return valid boundaries, otherwise non-valid
149 * boundaries are also possible.
150 * If boundary1 > boundary2, the values are swapped
151 *
152 * Usage examples:
153 * RandomUint8BoundaryValue(10, 20, SDL_TRUE) returns 10, 11, 19 or 20
154 * RandomUint8BoundaryValue(1, 20, SDL_FALSE) returns 0 or 21
155 * RandomUint8BoundaryValue(0, 99, SDL_FALSE) returns 100
156 * RandomUint8BoundaryValue(0, 255, SDL_FALSE) returns 0 (error set)
157 *
158 * \param boundary1 Lower boundary limit
159 * \param boundary2 Upper boundary limit
160 * \param validDomain Should the generated boundary be valid (=within the bounds) or not?
161 *
162 * \returns a random boundary value for the given range and domain or 0 with error set
163 */
164Uint8 SDLTest_RandomUint8BoundaryValue(Uint8 boundary1, Uint8 boundary2, SDL_bool validDomain);
165
166/**
167 * Returns a random boundary value for Uint16 within the given boundaries.
168 * Boundaries are inclusive, see the usage examples below. If validDomain
169 * is true, the function will only return valid boundaries, otherwise non-valid
170 * boundaries are also possible.
171 * If boundary1 > boundary2, the values are swapped
172 *
173 * Usage examples:
174 * RandomUint16BoundaryValue(10, 20, SDL_TRUE) returns 10, 11, 19 or 20
175 * RandomUint16BoundaryValue(1, 20, SDL_FALSE) returns 0 or 21
176 * RandomUint16BoundaryValue(0, 99, SDL_FALSE) returns 100
177 * RandomUint16BoundaryValue(0, 0xFFFF, SDL_FALSE) returns 0 (error set)
178 *
179 * \param boundary1 Lower boundary limit
180 * \param boundary2 Upper boundary limit
181 * \param validDomain Should the generated boundary be valid (=within the bounds) or not?
182 *
183 * \returns a random boundary value for the given range and domain or 0 with error set
184 */
186
187/**
188 * Returns a random boundary value for Uint32 within the given boundaries.
189 * Boundaries are inclusive, see the usage examples below. If validDomain
190 * is true, the function will only return valid boundaries, otherwise non-valid
191 * boundaries are also possible.
192 * If boundary1 > boundary2, the values are swapped
193 *
194 * Usage examples:
195 * RandomUint32BoundaryValue(10, 20, SDL_TRUE) returns 10, 11, 19 or 20
196 * RandomUint32BoundaryValue(1, 20, SDL_FALSE) returns 0 or 21
197 * RandomUint32BoundaryValue(0, 99, SDL_FALSE) returns 100
198 * RandomUint32BoundaryValue(0, 0xFFFFFFFF, SDL_FALSE) returns 0 (with error set)
199 *
200 * \param boundary1 Lower boundary limit
201 * \param boundary2 Upper boundary limit
202 * \param validDomain Should the generated boundary be valid (=within the bounds) or not?
203 *
204 * \returns a random boundary value for the given range and domain or 0 with error set
205 */
207
208/**
209 * Returns a random boundary value for Uint64 within the given boundaries.
210 * Boundaries are inclusive, see the usage examples below. If validDomain
211 * is true, the function will only return valid boundaries, otherwise non-valid
212 * boundaries are also possible.
213 * If boundary1 > boundary2, the values are swapped
214 *
215 * Usage examples:
216 * RandomUint64BoundaryValue(10, 20, SDL_TRUE) returns 10, 11, 19 or 20
217 * RandomUint64BoundaryValue(1, 20, SDL_FALSE) returns 0 or 21
218 * RandomUint64BoundaryValue(0, 99, SDL_FALSE) returns 100
219 * RandomUint64BoundaryValue(0, 0xFFFFFFFFFFFFFFFF, SDL_FALSE) returns 0 (with error set)
220 *
221 * \param boundary1 Lower boundary limit
222 * \param boundary2 Upper boundary limit
223 * \param validDomain Should the generated boundary be valid (=within the bounds) or not?
224 *
225 * \returns a random boundary value for the given range and domain or 0 with error set
226 */
228
229/**
230 * Returns a random boundary value for Sint8 within the given boundaries.
231 * Boundaries are inclusive, see the usage examples below. If validDomain
232 * is true, the function will only return valid boundaries, otherwise non-valid
233 * boundaries are also possible.
234 * If boundary1 > boundary2, the values are swapped
235 *
236 * Usage examples:
237 * RandomSint8BoundaryValue(-10, 20, SDL_TRUE) returns -11, -10, 19 or 20
238 * RandomSint8BoundaryValue(-100, -10, SDL_FALSE) returns -101 or -9
239 * RandomSint8BoundaryValue(SINT8_MIN, 99, SDL_FALSE) returns 100
240 * RandomSint8BoundaryValue(SINT8_MIN, SINT8_MAX, SDL_FALSE) returns SINT8_MIN (== error value) with error set
241 *
242 * \param boundary1 Lower boundary limit
243 * \param boundary2 Upper boundary limit
244 * \param validDomain Should the generated boundary be valid (=within the bounds) or not?
245 *
246 * \returns a random boundary value for the given range and domain or SINT8_MIN with error set
247 */
248Sint8 SDLTest_RandomSint8BoundaryValue(Sint8 boundary1, Sint8 boundary2, SDL_bool validDomain);
249
250
251/**
252 * Returns a random boundary value for Sint16 within the given boundaries.
253 * Boundaries are inclusive, see the usage examples below. If validDomain
254 * is true, the function will only return valid boundaries, otherwise non-valid
255 * boundaries are also possible.
256 * If boundary1 > boundary2, the values are swapped
257 *
258 * Usage examples:
259 * RandomSint16BoundaryValue(-10, 20, SDL_TRUE) returns -11, -10, 19 or 20
260 * RandomSint16BoundaryValue(-100, -10, SDL_FALSE) returns -101 or -9
261 * RandomSint16BoundaryValue(SINT16_MIN, 99, SDL_FALSE) returns 100
262 * RandomSint16BoundaryValue(SINT16_MIN, SINT16_MAX, SDL_FALSE) returns SINT16_MIN (== error value) with error set
263 *
264 * \param boundary1 Lower boundary limit
265 * \param boundary2 Upper boundary limit
266 * \param validDomain Should the generated boundary be valid (=within the bounds) or not?
267 *
268 * \returns a random boundary value for the given range and domain or SINT16_MIN with error set
269 */
271
272/**
273 * Returns a random boundary value for Sint32 within the given boundaries.
274 * Boundaries are inclusive, see the usage examples below. If validDomain
275 * is true, the function will only return valid boundaries, otherwise non-valid
276 * boundaries are also possible.
277 * If boundary1 > boundary2, the values are swapped
278 *
279 * Usage examples:
280 * RandomSint32BoundaryValue(-10, 20, SDL_TRUE) returns -11, -10, 19 or 20
281 * RandomSint32BoundaryValue(-100, -10, SDL_FALSE) returns -101 or -9
282 * RandomSint32BoundaryValue(SINT32_MIN, 99, SDL_FALSE) returns 100
283 * RandomSint32BoundaryValue(SINT32_MIN, SINT32_MAX, SDL_FALSE) returns SINT32_MIN (== error value)
284 *
285 * \param boundary1 Lower boundary limit
286 * \param boundary2 Upper boundary limit
287 * \param validDomain Should the generated boundary be valid (=within the bounds) or not?
288 *
289 * \returns a random boundary value for the given range and domain or SINT32_MIN with error set
290 */
292
293/**
294 * Returns a random boundary value for Sint64 within the given boundaries.
295 * Boundaries are inclusive, see the usage examples below. If validDomain
296 * is true, the function will only return valid boundaries, otherwise non-valid
297 * boundaries are also possible.
298 * If boundary1 > boundary2, the values are swapped
299 *
300 * Usage examples:
301 * RandomSint64BoundaryValue(-10, 20, SDL_TRUE) returns -11, -10, 19 or 20
302 * RandomSint64BoundaryValue(-100, -10, SDL_FALSE) returns -101 or -9
303 * RandomSint64BoundaryValue(SINT64_MIN, 99, SDL_FALSE) returns 100
304 * RandomSint64BoundaryValue(SINT64_MIN, SINT64_MAX, SDL_FALSE) returns SINT64_MIN (== error value) and error set
305 *
306 * \param boundary1 Lower boundary limit
307 * \param boundary2 Upper boundary limit
308 * \param validDomain Should the generated boundary be valid (=within the bounds) or not?
309 *
310 * \returns a random boundary value for the given range and domain or SINT64_MIN with error set
311 */
313
314
315/**
316 * Returns integer in range [min, max] (inclusive).
317 * Min and max values can be negative values.
318 * If Max in smaller than min, then the values are swapped.
319 * Min and max are the same value, that value will be returned.
320 *
321 * \param min Minimum inclusive value of returned random number
322 * \param max Maximum inclusive value of returned random number
323 *
324 * \returns a generated random integer in range
325 */
327
328
329/**
330 * Generates random null-terminated string. The minimum length for
331 * the string is 1 character, maximum length for the string is 255
332 * characters and it can contain ASCII characters from 32 to 126.
333 *
334 * Note: Returned string needs to be deallocated.
335 *
336 * \returns a newly allocated random string; or NULL if length was invalid or string could not be allocated.
337 */
339
340
341/**
342 * Generates random null-terminated string. The maximum length for
343 * the string is defined by the maxLength parameter.
344 * String can contain ASCII characters from 32 to 126.
345 *
346 * Note: Returned string needs to be deallocated.
347 *
348 * \param maxLength The maximum length of the generated string.
349 *
350 * \returns a newly allocated random string; or NULL if maxLength was invalid or string could not be allocated.
351 */
353
354
355/**
356 * Generates random null-terminated string. The length for
357 * the string is defined by the size parameter.
358 * String can contain ASCII characters from 32 to 126.
359 *
360 * Note: Returned string needs to be deallocated.
361 *
362 * \param size The length of the generated string
363 *
364 * \returns a newly allocated random string; or NULL if size was invalid or string could not be allocated.
365 */
367
368/**
369 * Get the invocation count for the fuzzer since last ...FuzzerInit.
370 *
371 * \returns the invocation count.
372 */
374
375/* Ends C function definitions when using C++ */
376#ifdef __cplusplus
377}
378#endif
379#include <SDL3/SDL_close_code.h>
380
381#endif /* SDL_test_fuzzer_h_ */
uint8_t Uint8
Definition SDL_stdinc.h:229
int64_t Sint64
Definition SDL_stdinc.h:276
uint16_t Uint16
Definition SDL_stdinc.h:247
int8_t Sint8
Definition SDL_stdinc.h:220
int32_t Sint32
Definition SDL_stdinc.h:256
SDL_MALLOC size_t size
Definition SDL_stdinc.h:531
int SDL_bool
Definition SDL_stdinc.h:213
int16_t Sint16
Definition SDL_stdinc.h:238
uint64_t Uint64
Definition SDL_stdinc.h:287
uint32_t Uint32
Definition SDL_stdinc.h:265
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)