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

Latest commit

 

History

History
384 lines (332 loc) · 12.8 KB

SDL_test_fuzzer.h

File metadata and controls

384 lines (332 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
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
May 18, 2013
May 18, 2013
24
*
Nov 28, 2012
Nov 28, 2012
25
26
27
28
29
* Include file for SDL test framework.
*
* This code is a part of the SDL2_test library, not the main SDL library.
*/
May 18, 2013
May 18, 2013
30
/*
Nov 28, 2012
Nov 28, 2012
31
32
Data generators for fuzzing test data in a reproducible way.
May 18, 2013
May 18, 2013
33
Nov 28, 2012
Nov 28, 2012
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
*/
#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
extern "C" {
#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();
/**
May 18, 2013
May 18, 2013
132
* \returns random double in range [0.0 - 1.0[
Nov 28, 2012
Nov 28, 2012
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
*/
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
159
* RandomUint8BoundaryValue(0, 255, SDL_FALSE) returns 0 (error set)
Nov 28, 2012
Nov 28, 2012
160
161
162
*
* \param boundary1 Lower boundary limit
* \param boundary2 Upper boundary limit
Feb 13, 2013
Feb 13, 2013
163
* \param validDomain Should the generated boundary be valid (=within the bounds) or not?
Nov 28, 2012
Nov 28, 2012
164
*
Feb 13, 2013
Feb 13, 2013
165
* \returns Random boundary value for the given range and domain or 0 with error set
Nov 28, 2012
Nov 28, 2012
166
167
168
169
170
171
172
173
174
175
176
177
178
179
*/
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
180
* RandomUint16BoundaryValue(0, 0xFFFF, SDL_FALSE) returns 0 (error set)
Nov 28, 2012
Nov 28, 2012
181
182
183
*
* \param boundary1 Lower boundary limit
* \param boundary2 Upper boundary limit
Feb 13, 2013
Feb 13, 2013
184
* \param validDomain Should the generated boundary be valid (=within the bounds) or not?
Nov 28, 2012
Nov 28, 2012
185
*
Feb 13, 2013
Feb 13, 2013
186
* \returns Random boundary value for the given range and domain or 0 with error set
Nov 28, 2012
Nov 28, 2012
187
188
189
190
191
192
193
194
195
196
197
198
199
200
*/
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
201
* RandomUint32BoundaryValue(0, 0xFFFFFFFF, SDL_FALSE) returns 0 (with error set)
Nov 28, 2012
Nov 28, 2012
202
203
204
*
* \param boundary1 Lower boundary limit
* \param boundary2 Upper boundary limit
Feb 13, 2013
Feb 13, 2013
205
* \param validDomain Should the generated boundary be valid (=within the bounds) or not?
Nov 28, 2012
Nov 28, 2012
206
*
Feb 13, 2013
Feb 13, 2013
207
* \returns Random boundary value for the given range and domain or 0 with error set
Nov 28, 2012
Nov 28, 2012
208
209
210
211
212
213
214
215
216
217
218
219
220
221
*/
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
222
* RandomUint64BoundaryValue(0, 0xFFFFFFFFFFFFFFFF, SDL_FALSE) returns 0 (with error set)
Nov 28, 2012
Nov 28, 2012
223
224
225
*
* \param boundary1 Lower boundary limit
* \param boundary2 Upper boundary limit
Feb 13, 2013
Feb 13, 2013
226
* \param validDomain Should the generated boundary be valid (=within the bounds) or not?
Nov 28, 2012
Nov 28, 2012
227
*
Feb 13, 2013
Feb 13, 2013
228
* \returns Random boundary value for the given range and domain or 0 with error set
Nov 28, 2012
Nov 28, 2012
229
230
231
232
233
234
235
236
237
238
239
240
241
*/
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
242
243
* 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
244
245
246
*
* \param boundary1 Lower boundary limit
* \param boundary2 Upper boundary limit
Feb 13, 2013
Feb 13, 2013
247
* \param validDomain Should the generated boundary be valid (=within the bounds) or not?
Nov 28, 2012
Nov 28, 2012
248
*
Feb 13, 2013
Feb 13, 2013
249
* \returns Random boundary value for the given range and domain or SINT8_MIN with error set
Nov 28, 2012
Nov 28, 2012
250
251
252
253
254
255
256
257
258
259
260
261
262
263
*/
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
264
265
* 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
266
267
268
*
* \param boundary1 Lower boundary limit
* \param boundary2 Upper boundary limit
Feb 13, 2013
Feb 13, 2013
269
* \param validDomain Should the generated boundary be valid (=within the bounds) or not?
Nov 28, 2012
Nov 28, 2012
270
*
Feb 13, 2013
Feb 13, 2013
271
* \returns Random boundary value for the given range and domain or SINT16_MIN with error set
Nov 28, 2012
Nov 28, 2012
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
*/
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
290
* \param validDomain Should the generated boundary be valid (=within the bounds) or not?
Nov 28, 2012
Nov 28, 2012
291
*
Feb 13, 2013
Feb 13, 2013
292
* \returns Random boundary value for the given range and domain or SINT32_MIN with error set
Nov 28, 2012
Nov 28, 2012
293
294
295
296
297
298
299
300
301
302
303
304
305
306
*/
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
307
* RandomSint64BoundaryValue(SINT64_MIN, SINT64_MAX, SDL_FALSE) returns SINT64_MIN (== error value) and error set
Nov 28, 2012
Nov 28, 2012
308
309
310
*
* \param boundary1 Lower boundary limit
* \param boundary2 Upper boundary limit
Feb 13, 2013
Feb 13, 2013
311
* \param validDomain Should the generated boundary be valid (=within the bounds) or not?
Nov 28, 2012
Nov 28, 2012
312
*
Feb 13, 2013
Feb 13, 2013
313
* \returns Random boundary value for the given range and domain or SINT64_MIN with error set
Nov 28, 2012
Nov 28, 2012
314
315
316
317
318
319
320
321
322
323
*/
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
324
325
326
327
* \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
328
329
330
331
332
*/
Sint32 SDLTest_RandomIntegerInRange(Sint32 min, Sint32 max);
/**
Jan 13, 2013
Jan 13, 2013
333
* Generates random null-terminated string. The minimum length for
May 18, 2013
May 18, 2013
334
* the string is 1 character, maximum length for the string is 255
Jan 13, 2013
Jan 13, 2013
335
* characters and it can contain ASCII characters from 32 to 126.
Nov 28, 2012
Nov 28, 2012
336
337
338
*
* Note: Returned string needs to be deallocated.
*
Jan 13, 2013
Jan 13, 2013
339
* \returns Newly allocated random string; or NULL if length was invalid or string could not be allocated.
Nov 28, 2012
Nov 28, 2012
340
341
342
343
344
345
*/
char * SDLTest_RandomAsciiString();
/**
* Generates random null-terminated string. The maximum length for
Jan 13, 2013
Jan 13, 2013
346
347
* the string is defined by the maxLength parameter.
* String can contain ASCII characters from 32 to 126.
Nov 28, 2012
Nov 28, 2012
348
349
350
*
* Note: Returned string needs to be deallocated.
*
Jan 13, 2013
Jan 13, 2013
351
* \param maxLength The maximum length of the generated string.
Nov 28, 2012
Nov 28, 2012
352
*
May 18, 2013
May 18, 2013
353
* \returns Newly allocated random string; or NULL if maxLength was invalid or string could not be allocated.
Nov 28, 2012
Nov 28, 2012
354
355
356
*/
char * SDLTest_RandomAsciiStringWithMaximumLength(int maxLength);
Jan 13, 2013
Jan 13, 2013
357
358
359
360
361
362
363
364
365
366
367
368
369
370
/**
* 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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
/**
* Returns the invocation count for the fuzzer since last ...FuzzerInit.
*/
int SDLTest_GetFuzzerInvocationCount();
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#include "close_code.h"
#endif /* _SDL_test_fuzzer_h */
/* vi: set ts=4 sw=4 expandtab: */