Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
388 lines (336 loc) · 12.8 KB

SDL_test_fuzzer.h

File metadata and controls

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