Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libSDL
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PocketInsanity
libSDL
Commits
279a841b
Commit
279a841b
authored
Jul 25, 2011
by
Markus Kauppila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refining the fuzzer. Adding new functions and fixing the old ones.
parent
fc76a5fa
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
99 additions
and
30 deletions
+99
-30
fuzzer.c
test/test-automation/fuzzer/fuzzer.c
+45
-19
fuzzer.h
test/test-automation/fuzzer/fuzzer.h
+45
-8
testdummy.c
test/test-automation/testdummy/testdummy.c
+9
-3
No files found.
test/test-automation/fuzzer/fuzzer.c
View file @
279a841b
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../SDL_test.h"
#include "../SDL_test.h"
...
@@ -77,43 +72,74 @@ RandomInteger()
...
@@ -77,43 +72,74 @@ RandomInteger()
}
}
int
int
RandomPositiveInteger
InRange
(
int
min
,
int
max
)
RandomPositiveInteger
(
)
{
{
return
abs
(
utl_randomInt
(
&
rndContext3
));
}
int
RandomIntegerInRange
(
int
min
,
int
max
)
{
if
(
min
>
max
||
(
min
-
max
)
==
0
)
{
return
-
1
;
// Doesn't really make sense to return -1 on error?
}
int
number
=
utl_randomInt
(
&
rndContext3
);
int
number
=
utl_randomInt
(
&
rndContext3
);
number
=
abs
(
number
);
number
=
abs
(
number
);
return
(
number
%
(
max
-
min
))
+
min
;
return
(
number
%
(
(
max
+
1
)
-
min
))
+
min
;
}
}
int
int
RandomBoundaryValue
(
const
int
max
)
GenerateBoundaryValueForSize
(
const
int
size
)
{
{
// Note: somehow integrate with RandomInteger?
if
(
size
<
0
)
{
// try to make more sensible & add new values
return
-
1
;
int
boundaryValues
[]
=
{
0
,
1
,
15
,
16
,
17
,
31
,
32
,
33
,
63
,
64
,
65
};
}
int
retValue
=
-
1
;
do
{
int
index
=
RandomPositiveIntegerInRange
(
0
,
10
);
retValue
=
boundaryValues
[
index
];
}
while
(
!
(
retValue
<=
max
)
);
const
int
adjustment
=
RandomIntegerInRange
(
-
1
,
1
);
int
retValue
=
(
1
<<
(
RandomPositiveInteger
()
%
size
))
+
adjustment
;
return
retValue
;
return
retValue
;
}
}
int
RandomUint8BoundaryValue
()
{
return
GenerateBoundaryValueForSize
(
8
);
}
int
RandomInt8BoundaryValue
()
{
int
value
=
GenerateBoundaryValueForSize
(
8
);
return
(
RandomPositiveInteger
()
%
2
==
0
?
value
:
-
value
);
}
char
*
char
*
RandomAsciiString
()
RandomAsciiString
()
{
{
const
int
size
=
abs
(
RandomInteger
);
return
RandomAsciiStringWithMaximumLength
(
255
);
}
char
*
RandomAsciiStringWithMaximumLength
(
int
maxSize
)
{
if
(
maxSize
<
0
)
{
return
NULL
;
}
const
int
size
=
abs
(
RandomInteger
)
%
maxSize
;
char
*
string
=
SDL_malloc
(
size
*
sizeof
(
size
));
char
*
string
=
SDL_malloc
(
size
*
sizeof
(
size
));
int
counter
=
0
;
int
counter
=
0
;
for
(
;
counter
<
size
;
++
counter
)
{
for
(
;
counter
<
size
;
++
counter
)
{
char
character
=
(
char
)
RandomPositiveIntegerInRange
(
0
,
127
);
char
character
=
(
char
)
RandomPositiveIntegerInRange
(
1
,
127
);
string
[
counter
]
=
character
;
string
[
counter
]
=
character
;
}
}
string
[
counter
]
=
'\0'
;
return
string
;
return
string
;
}
}
test/test-automation/fuzzer/fuzzer.h
View file @
279a841b
...
@@ -25,11 +25,13 @@
...
@@ -25,11 +25,13 @@
#include "utl_md5.h"
#include "utl_md5.h"
#include "utl_random.h"
#include "utl_random.h"
/*!
/*!
* Inits the fuzzer for a test
* Inits the fuzzer for a test
*/
*/
void
InitFuzzer
(
const
int
execKey
);
void
InitFuzzer
(
const
int
execKey
);
/*!
/*!
* Deinits the fuzzer (for a test)
* Deinits the fuzzer (for a test)
*/
*/
...
@@ -37,33 +39,68 @@ void DeinitFuzzer();
...
@@ -37,33 +39,68 @@ void DeinitFuzzer();
/*!
/*!
* Returns random integer
* Returns
a
random integer
*
*
* \returns Generated integer
* \returns Generated integer
*/
*/
int
RandomInteger
();
int
RandomInteger
();
/*!
/*!
* Returns
positive integer in range [min, max]
* Returns
a random positive integer
*
*
* \returns Generated integer
* \returns Generated integer
*/
*/
int
RandomPositiveIntegerInRange
(
int
min
,
int
max
);
int
RandomPositiveInteger
();
/*!
* Returns integer in range [min, max]. Min and max
* value can be negative values as long as min is smaller than max.
* Min and max also can't be the same value.
*
* \returns Generated integer or ? in error
*/
int
RandomIntegerInRange
(
int
min
,
int
max
);
/*!
/*!
* Generates random ASCII string
* Generates random null-terminated string. The maximum length for
* the string is 255 characters and it can contain ASCII characters
* from 1 to 127.
*
* Note: Returned string needs to be deallocated.
*
*
* \returns newly allocated random string
* \returns newly allocated random string
*/
*/
char
*
RandomAsciiString
();
char
*
RandomAsciiString
();
/*!
/*!
* Generates a random boundary value. Max is the biggest
* Generates random null-terminated string. The maximum length for
* value the function can return.
* the string is defined by maxLenght parameter.
* String can contain ASCII characters from 1 to 127.
*
* Note: Returned string needs to be deallocated.
*
*
* \returns a boundary value
* \param maxLength Maximum length of the generated string
*
* \returns newly allocated random string
*/
char
*
RandomAsciiStringWithMaximumLength
(
int
maxLength
);
/*!
* todo add markup
*/
*/
int
RandomBoundaryValue
(
const
int
max
);
int
RandomUint8BoundaryValue
();
/*!
* todo add markup
*/
int
RandomInt8BoundaryValue
();
/*!
/*!
* Generates execution key (used for random seed) for a test
* Generates execution key (used for random seed) for a test
...
...
test/test-automation/testdummy/testdummy.c
View file @
279a841b
...
@@ -91,9 +91,15 @@ dummycase1(void *arg)
...
@@ -91,9 +91,15 @@ dummycase1(void *arg)
{
{
AssertEquals
(
5
,
5
,
"Assert message"
);
AssertEquals
(
5
,
5
,
"Assert message"
);
for
(;
1
;)
{
Log
(
0
,
"uint8: %d"
,
RandomUint8BoundaryValue
());
Log
(
0
,
"int8: %d"
,
RandomInt8BoundaryValue
());
}
for
(;
0
;)
{
for
(;
0
;)
{
int
min
=
50
;
int
min
=
-
5
;
int
max
=
69
;
int
max
=
5
;
int
random
=
RandomPositiveIntegerInRange
(
min
,
max
);
int
random
=
RandomPositiveIntegerInRange
(
min
,
max
);
if
(
random
<
min
||
random
>
max
)
{
if
(
random
<
min
||
random
>
max
)
{
AssertFail
(
"Generated incorrect integer"
);
AssertFail
(
"Generated incorrect integer"
);
...
@@ -101,7 +107,7 @@ dummycase1(void *arg)
...
@@ -101,7 +107,7 @@ dummycase1(void *arg)
Log
(
0
,
"%d"
,
random
);
Log
(
0
,
"%d"
,
random
);
}
}
//Log(0, "Random: %s", RandomAsciiString
(
));
//Log(0, "Random: %s", RandomAsciiString
WithMaximumLength(2
));
}
}
void
void
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment