SDL  2.0
SDL_test_fuzzer.c File Reference
#include "SDL_config.h"
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <float.h>
#include "SDL_test.h"
+ Include dependency graph for SDL_test_fuzzer.c:

Go to the source code of this file.

Functions

void SDLTest_FuzzerInit (Uint64 execKey)
 
int SDLTest_GetFuzzerInvocationCount ()
 
Uint8 SDLTest_RandomUint8 ()
 
Sint8 SDLTest_RandomSint8 ()
 
Uint16 SDLTest_RandomUint16 ()
 
Sint16 SDLTest_RandomSint16 ()
 
Sint32 SDLTest_RandomSint32 ()
 
Uint32 SDLTest_RandomUint32 ()
 
Uint64 SDLTest_RandomUint64 ()
 
Sint64 SDLTest_RandomSint64 ()
 
Sint32 SDLTest_RandomIntegerInRange (Sint32 pMin, Sint32 pMax)
 
static Uint64 SDLTest_GenerateUnsignedBoundaryValues (const Uint64 maxValue, Uint64 boundary1, Uint64 boundary2, SDL_bool validDomain)
 
Uint8 SDLTest_RandomUint8BoundaryValue (Uint8 boundary1, Uint8 boundary2, SDL_bool validDomain)
 
Uint16 SDLTest_RandomUint16BoundaryValue (Uint16 boundary1, Uint16 boundary2, SDL_bool validDomain)
 
Uint32 SDLTest_RandomUint32BoundaryValue (Uint32 boundary1, Uint32 boundary2, SDL_bool validDomain)
 
Uint64 SDLTest_RandomUint64BoundaryValue (Uint64 boundary1, Uint64 boundary2, SDL_bool validDomain)
 
static Sint64 SDLTest_GenerateSignedBoundaryValues (const Sint64 minValue, const Sint64 maxValue, Sint64 boundary1, Sint64 boundary2, SDL_bool validDomain)
 
Sint8 SDLTest_RandomSint8BoundaryValue (Sint8 boundary1, Sint8 boundary2, SDL_bool validDomain)
 
Sint16 SDLTest_RandomSint16BoundaryValue (Sint16 boundary1, Sint16 boundary2, SDL_bool validDomain)
 
Sint32 SDLTest_RandomSint32BoundaryValue (Sint32 boundary1, Sint32 boundary2, SDL_bool validDomain)
 
Sint64 SDLTest_RandomSint64BoundaryValue (Sint64 boundary1, Sint64 boundary2, SDL_bool validDomain)
 
float SDLTest_RandomUnitFloat ()
 
float SDLTest_RandomFloat ()
 
double SDLTest_RandomUnitDouble ()
 
double SDLTest_RandomDouble ()
 
char * SDLTest_RandomAsciiString ()
 
char * SDLTest_RandomAsciiStringWithMaximumLength (int maxLength)
 
char * SDLTest_RandomAsciiStringOfSize (int size)
 

Variables

static int fuzzerInvocationCounter = 0
 
static SDLTest_RandomContext rndContext
 

Function Documentation

void SDLTest_FuzzerInit ( Uint64  execKey)

Initializes the fuzzer for a test

Parameters
execKeyExecution "Key" that initializes the random number generator uniquely for the test.

Definition at line 63 of file SDL_test_fuzzer.c.

References fuzzerInvocationCounter, SDL_memset, and SDLTest_RandomInit().

Referenced by main(), and SDLTest_RunTest().

64 {
65  Uint32 a = (execKey >> 32) & 0x00000000FFFFFFFF;
66  Uint32 b = execKey & 0x00000000FFFFFFFF;
67  SDL_memset((void *)&rndContext, 0, sizeof(SDLTest_RandomContext));
70 }
uint32_t Uint32
Definition: SDL_stdinc.h:181
void SDLTest_RandomInit(SDLTest_RandomContext *rndContext, unsigned int xi, unsigned int ci)
Initialize random number generator with two integers.
static SDLTest_RandomContext rndContext
static int fuzzerInvocationCounter
GLboolean GLboolean GLboolean GLboolean a
GLboolean GLboolean GLboolean b
#define SDL_memset
static Sint64 SDLTest_GenerateSignedBoundaryValues ( const Sint64  minValue,
const Sint64  maxValue,
Sint64  boundary1,
Sint64  boundary2,
SDL_bool  validDomain 
)
static

Definition at line 334 of file SDL_test_fuzzer.c.

References SDL_TRUE, SDL_Unsupported, and SDLTest_RandomUint8().

Referenced by SDLTest_RandomSint16BoundaryValue(), SDLTest_RandomSint32BoundaryValue(), SDLTest_RandomSint64BoundaryValue(), and SDLTest_RandomSint8BoundaryValue().

335 {
336  Sint64 b1, b2;
337  Sint64 delta;
338  Sint64 tempBuf[4];
339  Uint8 index;
340 
341  /* Maybe swap */
342  if (boundary1 > boundary2) {
343  b1 = boundary2;
344  b2 = boundary1;
345  } else {
346  b1 = boundary1;
347  b2 = boundary2;
348  }
349 
350  index = 0;
351  if (validDomain == SDL_TRUE) {
352  if (b1 == b2) {
353  return b1;
354  }
355 
356  /* Generate up to 4 values within bounds */
357  delta = b2 - b1;
358  if (delta < 4) {
359  do {
360  tempBuf[index] = b1 + index;
361  index++;
362  } while (index < delta);
363  } else {
364  tempBuf[index] = b1;
365  index++;
366  tempBuf[index] = b1 + 1;
367  index++;
368  tempBuf[index] = b2 - 1;
369  index++;
370  tempBuf[index] = b2;
371  index++;
372  }
373  } else {
374  /* Generate up to 2 values outside of bounds */
375  if (b1 > minValue) {
376  tempBuf[index] = b1 - 1;
377  index++;
378  }
379 
380  if (b2 < maxValue) {
381  tempBuf[index] = b2 + 1;
382  index++;
383  }
384  }
385 
386  if (index == 0) {
387  /* There are no valid boundaries */
388  SDL_Unsupported();
389  return minValue;
390  }
391 
392  return tempBuf[SDLTest_RandomUint8() % index];
393 }
Uint8 SDLTest_RandomUint8()
uint8_t Uint8
Definition: SDL_stdinc.h:157
GLuint index
int64_t Sint64
Definition: SDL_stdinc.h:188
#define SDL_Unsupported()
Definition: SDL_error.h:53
static Uint64 SDLTest_GenerateUnsignedBoundaryValues ( const Uint64  maxValue,
Uint64  boundary1,
Uint64  boundary2,
SDL_bool  validDomain 
)
static

Definition at line 202 of file SDL_test_fuzzer.c.

References SDL_TRUE, SDL_Unsupported, and SDLTest_RandomUint8().

Referenced by SDLTest_RandomUint16BoundaryValue(), SDLTest_RandomUint32BoundaryValue(), SDLTest_RandomUint64BoundaryValue(), and SDLTest_RandomUint8BoundaryValue().

203 {
204  Uint64 b1, b2;
205  Uint64 delta;
206  Uint64 tempBuf[4];
207  Uint8 index;
208 
209  /* Maybe swap */
210  if (boundary1 > boundary2) {
211  b1 = boundary2;
212  b2 = boundary1;
213  } else {
214  b1 = boundary1;
215  b2 = boundary2;
216  }
217 
218  index = 0;
219  if (validDomain == SDL_TRUE) {
220  if (b1 == b2) {
221  return b1;
222  }
223 
224  /* Generate up to 4 values within bounds */
225  delta = b2 - b1;
226  if (delta < 4) {
227  do {
228  tempBuf[index] = b1 + index;
229  index++;
230  } while (index < delta);
231  } else {
232  tempBuf[index] = b1;
233  index++;
234  tempBuf[index] = b1 + 1;
235  index++;
236  tempBuf[index] = b2 - 1;
237  index++;
238  tempBuf[index] = b2;
239  index++;
240  }
241  } else {
242  /* Generate up to 2 values outside of bounds */
243  if (b1 > 0) {
244  tempBuf[index] = b1 - 1;
245  index++;
246  }
247 
248  if (b2 < maxValue) {
249  tempBuf[index] = b2 + 1;
250  index++;
251  }
252  }
253 
254  if (index == 0) {
255  /* There are no valid boundaries */
256  SDL_Unsupported();
257  return 0;
258  }
259 
260  return tempBuf[SDLTest_RandomUint8() % index];
261 }
Uint8 SDLTest_RandomUint8()
uint64_t Uint64
Definition: SDL_stdinc.h:194
uint8_t Uint8
Definition: SDL_stdinc.h:157
GLuint index
#define SDL_Unsupported()
Definition: SDL_error.h:53
int SDLTest_GetFuzzerInvocationCount ( void  )

Returns the invocation count for the fuzzer since last ...FuzzerInit.

Definition at line 73 of file SDL_test_fuzzer.c.

References fuzzerInvocationCounter.

Referenced by sdltest_getFuzzerInvocationCount(), and SDLTest_RunTest().

74 {
76 }
static int fuzzerInvocationCounter
char* SDLTest_RandomAsciiString ( void  )

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.

Note: Returned string needs to be deallocated.

Returns
Newly allocated random string; or NULL if length was invalid or string could not be allocated.

Definition at line 480 of file SDL_test_fuzzer.c.

References SDLTest_RandomAsciiStringWithMaximumLength().

Referenced by clipboard_testClipboardTextFunctions(), clipboard_testSetClipboardText(), and sdltest_randomAsciiString().

481 {
483 }
char * SDLTest_RandomAsciiStringWithMaximumLength(int maxLength)
char* SDLTest_RandomAsciiStringOfSize ( int  size)

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.

Parameters
sizeThe length of the generated string
Returns
Newly allocated random string; or NULL if size was invalid or string could not be allocated.

Definition at line 501 of file SDL_test_fuzzer.c.

References fuzzerInvocationCounter, NULL, SDL_InvalidParamError, SDL_malloc, and SDLTest_RandomIntegerInRange().

Referenced by hints_setHint(), keyboard_getScancodeFromNameNegative(), sdltest_randomAsciiStringOfSize(), SDLTest_RandomAsciiStringWithMaximumLength(), stdlib_getsetenv(), and video_getSetWindowData().

502 {
503  char *string;
504  int counter;
505 
506 
507  if(size < 1) {
508  SDL_InvalidParamError("size");
509  return NULL;
510  }
511 
512  string = (char *)SDL_malloc((size + 1) * sizeof(char));
513  if (string==NULL) {
514  return NULL;
515  }
516 
517  for(counter = 0; counter < size; ++counter) {
518  string[counter] = (char)SDLTest_RandomIntegerInRange(32, 126);
519  }
520 
521  string[counter] = '\0';
522 
524 
525  return string;
526 }
GLsizei const GLchar *const * string
#define SDL_InvalidParamError(param)
Definition: SDL_error.h:54
Sint32 SDLTest_RandomIntegerInRange(Sint32 pMin, Sint32 pMax)
GLsizeiptr size
static int fuzzerInvocationCounter
#define NULL
Definition: begin_code.h:164
GLuint counter
#define SDL_malloc
char* SDLTest_RandomAsciiStringWithMaximumLength ( int  maxLength)

Generates random null-terminated string. The maximum length for the string is defined by the maxLength parameter. String can contain ASCII characters from 32 to 126.

Note: Returned string needs to be deallocated.

Parameters
maxLengthThe maximum length of the generated string.
Returns
Newly allocated random string; or NULL if maxLength was invalid or string could not be allocated.

Definition at line 486 of file SDL_test_fuzzer.c.

References NULL, SDL_InvalidParamError, SDLTest_RandomAsciiStringOfSize(), and SDLTest_RandomUint32().

Referenced by SDLTest_RandomAsciiString(), and sdltest_randomAsciiStringWithMaximumLength().

487 {
488  int size;
489 
490  if(maxLength < 1) {
491  SDL_InvalidParamError("maxLength");
492  return NULL;
493  }
494 
495  size = (SDLTest_RandomUint32() % (maxLength + 1));
496 
497  return SDLTest_RandomAsciiStringOfSize(size);
498 }
Uint32 SDLTest_RandomUint32()
char * SDLTest_RandomAsciiStringOfSize(int size)
#define SDL_InvalidParamError(param)
Definition: SDL_error.h:54
GLsizei maxLength
GLsizeiptr size
#define NULL
Definition: begin_code.h:164
double SDLTest_RandomDouble ( void  )
Returns
random double.

Definition at line 464 of file SDL_test_fuzzer.c.

References fuzzerInvocationCounter, and SDLTest_RandomInt.

Referenced by sdltest_randomNumber().

465 {
466  double r = 0.0;
467  double s = 1.0;
468  do {
469  s /= UINT_MAX + 1.0;
470  r += (double)SDLTest_RandomInt(&rndContext) * s;
471  } while (s > DBL_EPSILON);
472 
474 
475  return r;
476 }
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
GLdouble s
Definition: SDL_opengl.h:2063
static SDLTest_RandomContext rndContext
static int fuzzerInvocationCounter
#define SDLTest_RandomInt(c)
float SDLTest_RandomFloat ( void  )
Returns
random float.

Definition at line 452 of file SDL_test_fuzzer.c.

References SDLTest_RandomUnitDouble().

Referenced by sdltest_randomNumber().

453 {
454  return (float) (SDLTest_RandomUnitDouble() * (double)2.0 * (double)FLT_MAX - (double)(FLT_MAX));
455 }
double SDLTest_RandomUnitDouble()
Sint32 SDLTest_RandomIntegerInRange ( Sint32  min,
Sint32  max 
)

Returns integer in range [min, max] (inclusive). Min and max values can be negative values. If Max in smaller than min, then the values are swapped. Min and max are the same value, that value will be returned.

Parameters
minMinimum inclusive value of returned random number
maxMaximum inclusive value of returned random number
Returns
Generated random integer in range

Definition at line 157 of file SDL_test_fuzzer.c.

References SDLTest_RandomUint32().

Referenced by _createVideoSuiteTestWindow(), _testGenericRWopsValidations(), audio_buildAudioCVT(), audio_convertAudio(), audio_enumerateAndNameAudioDevices(), audio_enumerateAndNameAudioDevicesNegativeTests(), audio_pauseUnpauseAudio(), events_addDelEventWatchWithUserdata(), keyboard_getKeyNameNegative(), keyboard_getSetModState(), keyboard_setTextInputRect(), main(), mouse_getMouseFocus(), mouse_warpMouseInWindow(), pixels_allocFreePalette(), pixels_calcGammaRamp(), rect_testEnclosePoints(), rect_testEnclosePointsParam(), rect_testEnclosePointsRepeatedInput(), rect_testEnclosePointsWithClipping(), rect_testHasIntersectionEmpty(), rect_testHasIntersectionInside(), rect_testHasIntersectionOutside(), rect_testHasIntersectionPartial(), rect_testHasIntersectionPoint(), rect_testIntersectRectAndLine(), rect_testIntersectRectAndLineEmpty(), rect_testIntersectRectAndLineInside(), rect_testIntersectRectAndLineOutside(), rect_testIntersectRectEmpty(), rect_testIntersectRectInside(), rect_testIntersectRectOutside(), rect_testIntersectRectPartial(), rect_testIntersectRectPoint(), rect_testRectEmpty(), rect_testRectEquals(), rect_testRectEqualsParam(), rect_testUnionRectEmpty(), rect_testUnionRectInside(), rect_testUnionRectOutside(), SDLTest_RandomAsciiStringOfSize(), sdltest_randomIntegerInRange(), stdlib_getsetenv(), timer_addRemoveTimer(), timer_delayAndGetTicks(), video_createWindowVariousFlags(), video_createWindowVariousPositions(), video_createWindowVariousSizes(), video_getClosestDisplayModeRandomResolution(), video_getNumDisplayModesNegative(), video_getSetWindowData(), video_getSetWindowMaximumSize(), video_getSetWindowMinimumSize(), video_getSetWindowPosition(), video_getSetWindowSize(), and video_getWindowId().

158 {
159  Sint64 min = pMin;
160  Sint64 max = pMax;
161  Sint64 temp;
162  Sint64 number;
163 
164  if(pMin > pMax) {
165  temp = min;
166  min = max;
167  max = temp;
168  } else if(pMin == pMax) {
169  return (Sint32)min;
170  }
171 
172  number = SDLTest_RandomUint32();
173  /* invocation count increment in preceeding call */
174 
175  return (Sint32)((number % ((max + 1) - min)) + min);
176 }
Uint32 SDLTest_RandomUint32()
int32_t Sint32
Definition: SDL_stdinc.h:175
int64_t Sint64
Definition: SDL_stdinc.h:188
Sint16 SDLTest_RandomSint16 ( void  )

Returns a random Sint16

Returns
Generated signed integer

Definition at line 103 of file SDL_test_fuzzer.c.

References fuzzerInvocationCounter, and SDLTest_RandomInt.

Referenced by sdltest_randomIntegerInRange(), and sdltest_randomNumber().

104 {
106 
107  return (Sint16) SDLTest_RandomInt(&rndContext) & 0x0000FFFF;
108 }
static SDLTest_RandomContext rndContext
static int fuzzerInvocationCounter
#define SDLTest_RandomInt(c)
int16_t Sint16
Definition: SDL_stdinc.h:163
Sint16 SDLTest_RandomSint16BoundaryValue ( Sint16  boundary1,
Sint16  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 RandomSint16BoundaryValue(SINT16_MIN, 99, SDL_FALSE) returns 100 RandomSint16BoundaryValue(SINT16_MIN, SINT16_MAX, SDL_FALSE) returns SINT16_MIN (== error value) with error set

Parameters
boundary1Lower boundary limit
boundary2Upper boundary limit
validDomainShould the generated boundary be valid (=within the bounds) or not?
Returns
Random boundary value for the given range and domain or SINT16_MIN with error set

Definition at line 408 of file SDL_test_fuzzer.c.

References SDLTest_GenerateSignedBoundaryValues().

Referenced by sdltest_randomBoundaryNumberSint16().

409 {
410  /* min & max values for Sint16 */
411  const Sint64 maxValue = SHRT_MAX;
412  const Sint64 minValue = SHRT_MIN;
413  return (Sint16)SDLTest_GenerateSignedBoundaryValues(minValue, maxValue,
414  (Sint64) boundary1, (Sint64) boundary2,
415  validDomain);
416 }
static Sint64 SDLTest_GenerateSignedBoundaryValues(const Sint64 minValue, const Sint64 maxValue, Sint64 boundary1, Sint64 boundary2, SDL_bool validDomain)
int64_t Sint64
Definition: SDL_stdinc.h:188
int16_t Sint16
Definition: SDL_stdinc.h:163
Sint32 SDLTest_RandomSint32 ( void  )

Returns a random integer

Returns
Generated integer

Definition at line 111 of file SDL_test_fuzzer.c.

References fuzzerInvocationCounter, and SDLTest_RandomInt.

Referenced by events_addDelEventWatch(), events_addDelEventWatchWithUserdata(), events_pushPumpAndPollUserevent(), sdltest_randomNumber(), SDLTest_RandomSint64(), SDLTest_RandomUint64(), video_getSetWindowMaximumSize(), video_getSetWindowMinimumSize(), video_getSetWindowPosition(), and video_getSetWindowSize().

112 {
114 
116 }
int32_t Sint32
Definition: SDL_stdinc.h:175
static SDLTest_RandomContext rndContext
static int fuzzerInvocationCounter
#define SDLTest_RandomInt(c)
Sint32 SDLTest_RandomSint32BoundaryValue ( Sint32  boundary1,
Sint32  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)

Parameters
boundary1Lower boundary limit
boundary2Upper boundary limit
validDomainShould the generated boundary be valid (=within the bounds) or not?
Returns
Random boundary value for the given range and domain or SINT32_MIN with error set

Definition at line 419 of file SDL_test_fuzzer.c.

References SDLTest_GenerateSignedBoundaryValues().

Referenced by sdltest_randomBoundaryNumberSint32(), and video_getNumDisplayModesNegative().

420 {
421  /* min & max values for Sint32 */
422  #if ((ULONG_MAX) == (UINT_MAX))
423  const Sint64 maxValue = LONG_MAX;
424  const Sint64 minValue = LONG_MIN;
425  #else
426  const Sint64 maxValue = INT_MAX;
427  const Sint64 minValue = INT_MIN;
428  #endif
429  return (Sint32)SDLTest_GenerateSignedBoundaryValues(minValue, maxValue,
430  (Sint64) boundary1, (Sint64) boundary2,
431  validDomain);
432 }
static Sint64 SDLTest_GenerateSignedBoundaryValues(const Sint64 minValue, const Sint64 maxValue, Sint64 boundary1, Sint64 boundary2, SDL_bool validDomain)
int32_t Sint32
Definition: SDL_stdinc.h:175
int64_t Sint64
Definition: SDL_stdinc.h:188
Sint64 SDLTest_RandomSint64 ( void  )

Returns random Sint64.

Returns
Generated signed integer

Definition at line 141 of file SDL_test_fuzzer.c.

References fuzzerInvocationCounter, and SDLTest_RandomSint32().

Referenced by sdltest_randomNumber().

142 {
143  Uint64 value = 0;
144  Uint32 *vp = (void *)&value;
145 
147 
148  vp[0] = SDLTest_RandomSint32();
149  vp[1] = SDLTest_RandomSint32();
150 
151  return value;
152 }
uint32_t Uint32
Definition: SDL_stdinc.h:181
uint64_t Uint64
Definition: SDL_stdinc.h:194
GLsizei const GLfloat * value
Sint32 SDLTest_RandomSint32()
static int fuzzerInvocationCounter
Sint64 SDLTest_RandomSint64BoundaryValue ( Sint64  boundary1,
Sint64  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 RandomSint64BoundaryValue(SINT64_MIN, SINT64_MAX, SDL_FALSE) returns SINT64_MIN (== error value) and error set

Parameters
boundary1Lower boundary limit
boundary2Upper boundary limit
validDomainShould the generated boundary be valid (=within the bounds) or not?
Returns
Random boundary value for the given range and domain or SINT64_MIN with error set

Definition at line 435 of file SDL_test_fuzzer.c.

References SDLTest_GenerateSignedBoundaryValues().

Referenced by sdltest_randomBoundaryNumberSint64().

436 {
437  /* min & max values for Sint64 */
438  const Sint64 maxValue = INT64_MAX;
439  const Sint64 minValue = INT64_MIN;
440  return SDLTest_GenerateSignedBoundaryValues(minValue, maxValue,
441  boundary1, boundary2,
442  validDomain);
443 }
static Sint64 SDLTest_GenerateSignedBoundaryValues(const Sint64 minValue, const Sint64 maxValue, Sint64 boundary1, Sint64 boundary2, SDL_bool validDomain)
int64_t Sint64
Definition: SDL_stdinc.h:188
Sint8 SDLTest_RandomSint8 ( void  )

Returns a random Sint8

Returns
Generated signed integer

Definition at line 87 of file SDL_test_fuzzer.c.

References fuzzerInvocationCounter, and SDLTest_RandomInt.

Referenced by sdltest_randomNumber().

88 {
90 
91  return (Sint8) SDLTest_RandomInt(&rndContext) & 0x000000FF;
92 }
int8_t Sint8
Definition: SDL_stdinc.h:151
static SDLTest_RandomContext rndContext
static int fuzzerInvocationCounter
#define SDLTest_RandomInt(c)
Sint8 SDLTest_RandomSint8BoundaryValue ( Sint8  boundary1,
Sint8  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 RandomSint8BoundaryValue(SINT8_MIN, 99, SDL_FALSE) returns 100 RandomSint8BoundaryValue(SINT8_MIN, SINT8_MAX, SDL_FALSE) returns SINT8_MIN (== error value) with error set

Parameters
boundary1Lower boundary limit
boundary2Upper boundary limit
validDomainShould the generated boundary be valid (=within the bounds) or not?
Returns
Random boundary value for the given range and domain or SINT8_MIN with error set

Definition at line 397 of file SDL_test_fuzzer.c.

References SDLTest_GenerateSignedBoundaryValues().

Referenced by sdltest_randomBoundaryNumberSint8().

398 {
399  /* min & max values for Sint8 */
400  const Sint64 maxValue = SCHAR_MAX;
401  const Sint64 minValue = SCHAR_MIN;
402  return (Sint8)SDLTest_GenerateSignedBoundaryValues(minValue, maxValue,
403  (Sint64) boundary1, (Sint64) boundary2,
404  validDomain);
405 }
static Sint64 SDLTest_GenerateSignedBoundaryValues(const Sint64 minValue, const Sint64 maxValue, Sint64 boundary1, Sint64 boundary2, SDL_bool validDomain)
int8_t Sint8
Definition: SDL_stdinc.h:151
int64_t Sint64
Definition: SDL_stdinc.h:188
Uint16 SDLTest_RandomUint16 ( void  )

Returns a random Uint16

Returns
Generated integer

Definition at line 95 of file SDL_test_fuzzer.c.

References fuzzerInvocationCounter, and SDLTest_RandomInt.

Referenced by rwops_testFileWriteReadEndian(), and sdltest_randomNumber().

96 {
98 
99  return (Uint16) SDLTest_RandomInt(&rndContext) & 0x0000FFFF;
100 }
static SDLTest_RandomContext rndContext
static int fuzzerInvocationCounter
#define SDLTest_RandomInt(c)
uint16_t Uint16
Definition: SDL_stdinc.h:169
Uint16 SDLTest_RandomUint16BoundaryValue ( Uint16  boundary1,
Uint16  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 RandomUint16BoundaryValue(0, 0xFFFF, SDL_FALSE) returns 0 (error set)

Parameters
boundary1Lower boundary limit
boundary2Upper boundary limit
validDomainShould the generated boundary be valid (=within the bounds) or not?
Returns
Random boundary value for the given range and domain or 0 with error set

Definition at line 275 of file SDL_test_fuzzer.c.

References SDLTest_GenerateUnsignedBoundaryValues().

Referenced by sdltest_randomBoundaryNumberUint16().

276 {
277  /* max value for Uint16 */
278  const Uint64 maxValue = USHRT_MAX;
280  (Uint64) boundary1, (Uint64) boundary2,
281  validDomain);
282 }
uint64_t Uint64
Definition: SDL_stdinc.h:194
uint16_t Uint16
Definition: SDL_stdinc.h:169
static Uint64 SDLTest_GenerateUnsignedBoundaryValues(const Uint64 maxValue, Uint64 boundary1, Uint64 boundary2, SDL_bool validDomain)
Uint32 SDLTest_RandomUint32 ( void  )

Returns a random positive integer

Returns
Generated integer

Definition at line 119 of file SDL_test_fuzzer.c.

References fuzzerInvocationCounter, and SDLTest_RandomInt.

Referenced by rwops_testFileWriteReadEndian(), SDLTest_RandomAsciiStringWithMaximumLength(), SDLTest_RandomIntegerInRange(), sdltest_randomNumber(), and SDLTest_RandomUnitFloat().

120 {
122 
124 }
uint32_t Uint32
Definition: SDL_stdinc.h:181
static SDLTest_RandomContext rndContext
static int fuzzerInvocationCounter
#define SDLTest_RandomInt(c)
Uint32 SDLTest_RandomUint32BoundaryValue ( Uint32  boundary1,
Uint32  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 RandomUint32BoundaryValue(0, 0xFFFFFFFF, SDL_FALSE) returns 0 (with error set)

Parameters
boundary1Lower boundary limit
boundary2Upper boundary limit
validDomainShould the generated boundary be valid (=within the bounds) or not?
Returns
Random boundary value for the given range and domain or 0 with error set

Definition at line 285 of file SDL_test_fuzzer.c.

References SDLTest_GenerateUnsignedBoundaryValues().

Referenced by sdltest_randomBoundaryNumberUint32().

286 {
287  /* max value for Uint32 */
288  #if ((ULONG_MAX) == (UINT_MAX))
289  const Uint64 maxValue = ULONG_MAX;
290  #else
291  const Uint64 maxValue = UINT_MAX;
292  #endif
294  (Uint64) boundary1, (Uint64) boundary2,
295  validDomain);
296 }
uint32_t Uint32
Definition: SDL_stdinc.h:181
uint64_t Uint64
Definition: SDL_stdinc.h:194
static Uint64 SDLTest_GenerateUnsignedBoundaryValues(const Uint64 maxValue, Uint64 boundary1, Uint64 boundary2, SDL_bool validDomain)
Uint64 SDLTest_RandomUint64 ( void  )

Returns random Uint64.

Returns
Generated integer

Definition at line 127 of file SDL_test_fuzzer.c.

References fuzzerInvocationCounter, and SDLTest_RandomSint32().

Referenced by rwops_testFileWriteReadEndian(), sdltest_randomNumber(), and SDLTest_RandomUnitDouble().

128 {
129  Uint64 value = 0;
130  Uint32 *vp = (void *)&value;
131 
133 
134  vp[0] = SDLTest_RandomSint32();
135  vp[1] = SDLTest_RandomSint32();
136 
137  return value;
138 }
uint32_t Uint32
Definition: SDL_stdinc.h:181
uint64_t Uint64
Definition: SDL_stdinc.h:194
GLsizei const GLfloat * value
Sint32 SDLTest_RandomSint32()
static int fuzzerInvocationCounter
Uint64 SDLTest_RandomUint64BoundaryValue ( Uint64  boundary1,
Uint64  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 RandomUint64BoundaryValue(0, 0xFFFFFFFFFFFFFFFF, SDL_FALSE) returns 0 (with error set)

Parameters
boundary1Lower boundary limit
boundary2Upper boundary limit
validDomainShould the generated boundary be valid (=within the bounds) or not?
Returns
Random boundary value for the given range and domain or 0 with error set

Definition at line 299 of file SDL_test_fuzzer.c.

References SDLTest_GenerateUnsignedBoundaryValues(), and UINT64_MAX.

Referenced by sdltest_randomBoundaryNumberUint64().

300 {
301  /* max value for Uint64 */
302  const Uint64 maxValue = UINT64_MAX;
304  (Uint64) boundary1, (Uint64) boundary2,
305  validDomain);
306 }
#define UINT64_MAX
Definition: testvulkan.c:39
uint64_t Uint64
Definition: SDL_stdinc.h:194
static Uint64 SDLTest_GenerateUnsignedBoundaryValues(const Uint64 maxValue, Uint64 boundary1, Uint64 boundary2, SDL_bool validDomain)
Uint8 SDLTest_RandomUint8 ( void  )

Returns a random Uint8

Returns
Generated integer

Definition at line 79 of file SDL_test_fuzzer.c.

References fuzzerInvocationCounter, and SDLTest_RandomInt.

Referenced by SDLTest_GenerateSignedBoundaryValues(), SDLTest_GenerateUnsignedBoundaryValues(), sdltest_getFuzzerInvocationCount(), sdltest_randomAsciiStringOfSize(), sdltest_randomAsciiStringWithMaximumLength(), sdltest_randomIntegerInRange(), and sdltest_randomNumber().

80 {
82 
83  return (Uint8) SDLTest_RandomInt(&rndContext) & 0x000000FF;
84 }
uint8_t Uint8
Definition: SDL_stdinc.h:157
static SDLTest_RandomContext rndContext
static int fuzzerInvocationCounter
#define SDLTest_RandomInt(c)
Uint8 SDLTest_RandomUint8BoundaryValue ( Uint8  boundary1,
Uint8  boundary2,
SDL_bool  validDomain 
)

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 RandomUint8BoundaryValue(0, 255, SDL_FALSE) returns 0 (error set)

Parameters
boundary1Lower boundary limit
boundary2Upper boundary limit
validDomainShould the generated boundary be valid (=within the bounds) or not?
Returns
Random boundary value for the given range and domain or 0 with error set

Definition at line 265 of file SDL_test_fuzzer.c.

References SDLTest_GenerateUnsignedBoundaryValues().

Referenced by sdltest_randomBoundaryNumberUint8().

266 {
267  /* max value for Uint8 */
268  const Uint64 maxValue = UCHAR_MAX;
270  (Uint64) boundary1, (Uint64) boundary2,
271  validDomain);
272 }
uint64_t Uint64
Definition: SDL_stdinc.h:194
uint8_t Uint8
Definition: SDL_stdinc.h:157
static Uint64 SDLTest_GenerateUnsignedBoundaryValues(const Uint64 maxValue, Uint64 boundary1, Uint64 boundary2, SDL_bool validDomain)
double SDLTest_RandomUnitDouble ( void  )
Returns
random double in range [0.0 - 1.0[

Definition at line 458 of file SDL_test_fuzzer.c.

References SDLTest_RandomUint64().

Referenced by SDLTest_RandomFloat(), and sdltest_randomNumber().

459 {
460  return (double) (SDLTest_RandomUint64() >> 11) * (1.0/9007199254740992.0);
461 }
Uint64 SDLTest_RandomUint64()
float SDLTest_RandomUnitFloat ( void  )
Returns
random float in range [0.0 - 1.0[

Definition at line 446 of file SDL_test_fuzzer.c.

References SDLTest_RandomUint32().

Referenced by pixels_calcGammaRamp(), and sdltest_randomNumber().

447 {
448  return SDLTest_RandomUint32() / (float) UINT_MAX;
449 }
Uint32 SDLTest_RandomUint32()

Variable Documentation

SDLTest_RandomContext rndContext
static

Context for shared random number generator

Definition at line 56 of file SDL_test_fuzzer.c.