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

Go to the source code of this file.

Macros

#define _GNU_SOURCE
 

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)
 
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)
 
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
 

Macro Definition Documentation

#define _GNU_SOURCE

Definition at line 37 of file SDL_test_fuzzer.c.

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 62 of file SDL_test_fuzzer.c.

References fuzzerInvocationCounter, SDL_memset, and SDLTest_RandomInit().

Referenced by main(), and SDLTest_RunTest().

63 {
64  Uint32 a = (execKey >> 32) & 0x00000000FFFFFFFF;
65  Uint32 b = execKey & 0x00000000FFFFFFFF;
66  SDL_memset((void *)&rndContext, 0, sizeof(SDLTest_RandomContext));
69 }
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:155
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
Sint64 SDLTest_GenerateSignedBoundaryValues ( const Sint64  minValue,
const Sint64  maxValue,
Sint64  boundary1,
Sint64  boundary2,
SDL_bool  validDomain 
)

Definition at line 333 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().

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

Definition at line 201 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().

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

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

Definition at line 72 of file SDL_test_fuzzer.c.

References fuzzerInvocationCounter.

Referenced by sdltest_getFuzzerInvocationCount(), and SDLTest_RunTest().

73 {
75 }
static int fuzzerInvocationCounter
char* SDLTest_RandomAsciiString ( )

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 479 of file SDL_test_fuzzer.c.

References SDLTest_RandomAsciiStringWithMaximumLength().

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

480 {
482 }
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 500 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().

501 {
502  char *string;
503  int counter;
504 
505 
506  if(size < 1) {
507  SDL_InvalidParamError("size");
508  return NULL;
509  }
510 
511  string = (char *)SDL_malloc((size + 1) * sizeof(char));
512  if (string==NULL) {
513  return NULL;
514  }
515 
516  for(counter = 0; counter < size; ++counter) {
517  string[counter] = (char)SDLTest_RandomIntegerInRange(32, 126);
518  }
519 
520  string[counter] = '\0';
521 
523 
524  return string;
525 }
GLsizei const GLchar *const * string
#define SDL_InvalidParamError(param)
Definition: SDL_error.h:54
GLsizeiptr size
Sint32 SDLTest_RandomIntegerInRange(Sint32 pMin, Sint32 pMax)
static int fuzzerInvocationCounter
#define NULL
Definition: begin_code.h:143
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 485 of file SDL_test_fuzzer.c.

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

Referenced by SDLTest_RandomAsciiString(), and sdltest_randomAsciiStringWithMaximumLength().

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

Definition at line 463 of file SDL_test_fuzzer.c.

References fuzzerInvocationCounter, and SDLTest_RandomInt.

Referenced by sdltest_randomNumber().

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

Definition at line 451 of file SDL_test_fuzzer.c.

References SDLTest_RandomUnitDouble().

Referenced by sdltest_randomNumber().

452 {
453  return (float) (SDLTest_RandomUnitDouble() * (double)2.0 * (double)FLT_MAX - (double)(FLT_MAX));
454 }
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 156 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().

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

Returns a random Sint16

Returns
Generated signed integer

Definition at line 102 of file SDL_test_fuzzer.c.

References fuzzerInvocationCounter, and SDLTest_RandomInt.

Referenced by sdltest_randomIntegerInRange(), and sdltest_randomNumber().

103 {
105 
106  return (Sint16) SDLTest_RandomInt(&rndContext) & 0x0000FFFF;
107 }
static SDLTest_RandomContext rndContext
static int fuzzerInvocationCounter
#define SDLTest_RandomInt(c)
int16_t Sint16
A signed 16-bit integer type.
Definition: SDL_stdinc.h:143
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 407 of file SDL_test_fuzzer.c.

References SDLTest_GenerateSignedBoundaryValues().

Referenced by sdltest_randomBoundaryNumberSint16().

408 {
409  /* min & max values for Sint16 */
410  const Sint64 maxValue = SHRT_MAX;
411  const Sint64 minValue = SHRT_MIN;
412  return (Sint16)SDLTest_GenerateSignedBoundaryValues(minValue, maxValue,
413  (Sint64) boundary1, (Sint64) boundary2,
414  validDomain);
415 }
int64_t Sint64
A signed 64-bit integer type.
Definition: SDL_stdinc.h:160
Sint64 SDLTest_GenerateSignedBoundaryValues(const Sint64 minValue, const Sint64 maxValue, Sint64 boundary1, Sint64 boundary2, SDL_bool validDomain)
int16_t Sint16
A signed 16-bit integer type.
Definition: SDL_stdinc.h:143
Sint32 SDLTest_RandomSint32 ( )

Returns a random integer

Returns
Generated integer

Definition at line 110 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().

111 {
113 
115 }
int32_t Sint32
A signed 32-bit integer type.
Definition: SDL_stdinc.h:151
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 418 of file SDL_test_fuzzer.c.

References SDLTest_GenerateSignedBoundaryValues().

Referenced by sdltest_randomBoundaryNumberSint32(), and video_getNumDisplayModesNegative().

419 {
420  /* min & max values for Sint32 */
421  #if ((ULONG_MAX) == (UINT_MAX))
422  const Sint64 maxValue = LONG_MAX;
423  const Sint64 minValue = LONG_MIN;
424  #else
425  const Sint64 maxValue = INT_MAX;
426  const Sint64 minValue = INT_MIN;
427  #endif
428  return (Sint32)SDLTest_GenerateSignedBoundaryValues(minValue, maxValue,
429  (Sint64) boundary1, (Sint64) boundary2,
430  validDomain);
431 }
int32_t Sint32
A signed 32-bit integer type.
Definition: SDL_stdinc.h:151
int64_t Sint64
A signed 64-bit integer type.
Definition: SDL_stdinc.h:160
Sint64 SDLTest_GenerateSignedBoundaryValues(const Sint64 minValue, const Sint64 maxValue, Sint64 boundary1, Sint64 boundary2, SDL_bool validDomain)
Sint64 SDLTest_RandomSint64 ( )

Returns random Sint64.

Returns
Generated signed integer

Definition at line 140 of file SDL_test_fuzzer.c.

References fuzzerInvocationCounter, and SDLTest_RandomSint32().

Referenced by sdltest_randomNumber().

141 {
142  Uint64 value = 0;
143  Uint32 *vp = (void *)&value;
144 
146 
147  vp[0] = SDLTest_RandomSint32();
148  vp[1] = SDLTest_RandomSint32();
149 
150  return value;
151 }
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:155
uint64_t Uint64
An unsigned 64-bit integer type.
Definition: SDL_stdinc.h:164
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 434 of file SDL_test_fuzzer.c.

References SDLTest_GenerateSignedBoundaryValues().

Referenced by sdltest_randomBoundaryNumberSint64().

435 {
436  /* min & max values for Sint64 */
437  const Sint64 maxValue = LLONG_MAX;
438  const Sint64 minValue = LLONG_MIN;
439  return SDLTest_GenerateSignedBoundaryValues(minValue, maxValue,
440  boundary1, boundary2,
441  validDomain);
442 }
int64_t Sint64
A signed 64-bit integer type.
Definition: SDL_stdinc.h:160
Sint64 SDLTest_GenerateSignedBoundaryValues(const Sint64 minValue, const Sint64 maxValue, Sint64 boundary1, Sint64 boundary2, SDL_bool validDomain)
Sint8 SDLTest_RandomSint8 ( )

Returns a random Sint8

Returns
Generated signed integer

Definition at line 86 of file SDL_test_fuzzer.c.

References fuzzerInvocationCounter, and SDLTest_RandomInt.

Referenced by sdltest_randomNumber().

87 {
89 
90  return (Sint8) SDLTest_RandomInt(&rndContext) & 0x000000FF;
91 }
int8_t Sint8
A signed 8-bit integer type.
Definition: SDL_stdinc.h:135
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 396 of file SDL_test_fuzzer.c.

References SDLTest_GenerateSignedBoundaryValues().

Referenced by sdltest_randomBoundaryNumberSint8().

397 {
398  /* min & max values for Sint8 */
399  const Sint64 maxValue = SCHAR_MAX;
400  const Sint64 minValue = SCHAR_MIN;
401  return (Sint8)SDLTest_GenerateSignedBoundaryValues(minValue, maxValue,
402  (Sint64) boundary1, (Sint64) boundary2,
403  validDomain);
404 }
int8_t Sint8
A signed 8-bit integer type.
Definition: SDL_stdinc.h:135
int64_t Sint64
A signed 64-bit integer type.
Definition: SDL_stdinc.h:160
Sint64 SDLTest_GenerateSignedBoundaryValues(const Sint64 minValue, const Sint64 maxValue, Sint64 boundary1, Sint64 boundary2, SDL_bool validDomain)
Uint16 SDLTest_RandomUint16 ( )

Returns a random Uint16

Returns
Generated integer

Definition at line 94 of file SDL_test_fuzzer.c.

References fuzzerInvocationCounter, and SDLTest_RandomInt.

Referenced by rwops_testFileWriteReadEndian(), and sdltest_randomNumber().

95 {
97 
98  return (Uint16) SDLTest_RandomInt(&rndContext) & 0x0000FFFF;
99 }
static SDLTest_RandomContext rndContext
static int fuzzerInvocationCounter
#define SDLTest_RandomInt(c)
uint16_t Uint16
An unsigned 16-bit integer type.
Definition: SDL_stdinc.h:147
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 274 of file SDL_test_fuzzer.c.

References SDLTest_GenerateUnsignedBoundaryValues().

Referenced by sdltest_randomBoundaryNumberUint16().

275 {
276  /* max value for Uint16 */
277  const Uint64 maxValue = USHRT_MAX;
279  (Uint64) boundary1, (Uint64) boundary2,
280  validDomain);
281 }
uint64_t Uint64
An unsigned 64-bit integer type.
Definition: SDL_stdinc.h:164
Uint64 SDLTest_GenerateUnsignedBoundaryValues(const Uint64 maxValue, Uint64 boundary1, Uint64 boundary2, SDL_bool validDomain)
uint16_t Uint16
An unsigned 16-bit integer type.
Definition: SDL_stdinc.h:147
Uint32 SDLTest_RandomUint32 ( )

Returns a random positive integer

Returns
Generated integer

Definition at line 118 of file SDL_test_fuzzer.c.

References fuzzerInvocationCounter, and SDLTest_RandomInt.

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

119 {
121 
123 }
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:155
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 284 of file SDL_test_fuzzer.c.

References SDLTest_GenerateUnsignedBoundaryValues().

Referenced by sdltest_randomBoundaryNumberUint32().

285 {
286  /* max value for Uint32 */
287  #if ((ULONG_MAX) == (UINT_MAX))
288  const Uint64 maxValue = ULONG_MAX;
289  #else
290  const Uint64 maxValue = UINT_MAX;
291  #endif
293  (Uint64) boundary1, (Uint64) boundary2,
294  validDomain);
295 }
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:155
uint64_t Uint64
An unsigned 64-bit integer type.
Definition: SDL_stdinc.h:164
Uint64 SDLTest_GenerateUnsignedBoundaryValues(const Uint64 maxValue, Uint64 boundary1, Uint64 boundary2, SDL_bool validDomain)
Uint64 SDLTest_RandomUint64 ( )

Returns random Uint64.

Returns
Generated integer

Definition at line 126 of file SDL_test_fuzzer.c.

References fuzzerInvocationCounter, and SDLTest_RandomSint32().

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

127 {
128  Uint64 value = 0;
129  Uint32 *vp = (void *)&value;
130 
132 
133  vp[0] = SDLTest_RandomSint32();
134  vp[1] = SDLTest_RandomSint32();
135 
136  return value;
137 }
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:155
uint64_t Uint64
An unsigned 64-bit integer type.
Definition: SDL_stdinc.h:164
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 298 of file SDL_test_fuzzer.c.

References SDLTest_GenerateUnsignedBoundaryValues().

Referenced by sdltest_randomBoundaryNumberUint64().

299 {
300  /* max value for Uint64 */
301  const Uint64 maxValue = ULLONG_MAX;
303  (Uint64) boundary1, (Uint64) boundary2,
304  validDomain);
305 }
uint64_t Uint64
An unsigned 64-bit integer type.
Definition: SDL_stdinc.h:164
Uint64 SDLTest_GenerateUnsignedBoundaryValues(const Uint64 maxValue, Uint64 boundary1, Uint64 boundary2, SDL_bool validDomain)
Uint8 SDLTest_RandomUint8 ( )

Returns a random Uint8

Returns
Generated integer

Definition at line 78 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().

79 {
81 
82  return (Uint8) SDLTest_RandomInt(&rndContext) & 0x000000FF;
83 }
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:139
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 264 of file SDL_test_fuzzer.c.

References SDLTest_GenerateUnsignedBoundaryValues().

Referenced by sdltest_randomBoundaryNumberUint8().

265 {
266  /* max value for Uint8 */
267  const Uint64 maxValue = UCHAR_MAX;
269  (Uint64) boundary1, (Uint64) boundary2,
270  validDomain);
271 }
uint64_t Uint64
An unsigned 64-bit integer type.
Definition: SDL_stdinc.h:164
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:139
Uint64 SDLTest_GenerateUnsignedBoundaryValues(const Uint64 maxValue, Uint64 boundary1, Uint64 boundary2, SDL_bool validDomain)
double SDLTest_RandomUnitDouble ( )
Returns
random double in range [0.0 - 1.0[

Definition at line 457 of file SDL_test_fuzzer.c.

References SDLTest_RandomUint64().

Referenced by SDLTest_RandomFloat(), and sdltest_randomNumber().

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

Definition at line 445 of file SDL_test_fuzzer.c.

References SDLTest_RandomUint32().

Referenced by pixels_calcGammaRamp(), and sdltest_randomNumber().

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

Variable Documentation

SDLTest_RandomContext rndContext
static

Context for shared random number generator

Definition at line 55 of file SDL_test_fuzzer.c.