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
e45c8d75
Commit
e45c8d75
authored
Aug 03, 2011
by
Markus Kauppila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refining boundary value generator.
parent
c2b70264
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
151 additions
and
43 deletions
+151
-43
fuzzer.c
test/test-automation/fuzzer/fuzzer.c
+129
-31
fuzzer.h
test/test-automation/fuzzer/fuzzer.h
+11
-9
testdummy.c
test/test-automation/testdummy/testdummy.c
+11
-3
No files found.
test/test-automation/fuzzer/fuzzer.c
View file @
e45c8d75
...
@@ -35,6 +35,7 @@ GenerateExecKey(char *runSeed, char *suiteName,
...
@@ -35,6 +35,7 @@ GenerateExecKey(char *runSeed, char *suiteName,
}
}
// Change to itoa
char
iterationString
[
16
];
char
iterationString
[
16
];
memset
(
iterationString
,
0
,
sizeof
(
iterationString
));
memset
(
iterationString
,
0
,
sizeof
(
iterationString
));
SDL_snprintf
(
iterationString
,
sizeof
(
iterationString
)
-
1
,
"%d"
,
iterationNumber
);
SDL_snprintf
(
iterationString
,
sizeof
(
iterationString
)
-
1
,
"%d"
,
iterationNumber
);
...
@@ -69,14 +70,15 @@ GenerateExecKey(char *runSeed, char *suiteName,
...
@@ -69,14 +70,15 @@ GenerateExecKey(char *runSeed, char *suiteName,
//printf("Debug: digest = %s\n", execKey);
//printf("Debug: digest = %s\n", execKey);
Uint64
key
=
execKey
[
8
]
<<
56
|
// Casting fixes compiler warnings
execKey
[
9
]
<<
48
|
Uint64
key
=
((
Uint64
)
execKey
[
8
])
<<
56
|
execKey
[
10
]
<<
40
|
((
Uint64
)
execKey
[
9
])
<<
48
|
execKey
[
11
]
<<
32
|
((
Uint64
)
execKey
[
10
])
<<
40
|
execKey
[
12
]
<<
24
|
((
Uint64
)
execKey
[
11
])
<<
32
|
execKey
[
13
]
<<
16
|
((
Uint64
)
execKey
[
12
])
<<
24
|
execKey
[
14
]
<<
8
|
((
Uint64
)
execKey
[
13
])
<<
16
|
execKey
[
15
]
<<
0
;
((
Uint64
)
execKey
[
14
])
<<
8
|
((
Uint64
)
execKey
[
15
])
<<
0
;
return
key
;
return
key
;
}
}
...
@@ -99,54 +101,150 @@ DeinitFuzzer()
...
@@ -99,54 +101,150 @@ DeinitFuzzer()
}
}
int
Sint32
RandomInteger
()
RandomInteger
()
{
{
return
utl_randomInt
(
&
rndContext
);
return
utl_randomInt
(
&
rndContext
);
}
}
int
Uint32
RandomPositiveInteger
()
RandomPositiveInteger
()
{
{
return
abs
(
utl_randomInt
(
&
rndContext
)
);
return
utl_randomInt
(
&
rndContext
);
}
}
int
Sint32
RandomIntegerInRange
(
int
min
,
int
m
ax
)
RandomIntegerInRange
(
Sint32
pMin
,
Sint32
pM
ax
)
{
{
if
(
min
>
max
||
(
min
-
max
)
==
0
)
{
Sint64
min
=
(
Sint64
)
pMin
,
max
=
(
Sint64
)
pMax
;
return
-
1
;
// Doesn't really make sense to return -1 on error?
if
(
min
>
max
)
{
Sint64
temp
=
min
;
min
=
max
;
max
=
temp
;
}
else
if
(
min
==
max
)
{
return
min
;
}
}
int
number
=
utl_randomInt
(
&
rndContext
);
Sint32
number
=
abs
(
utl_randomInt
(
&
rndContext
));
number
=
abs
(
number
);
return
(
number
%
((
max
+
1
)
-
min
))
+
min
;
return
(
number
%
((
max
+
1
)
-
min
))
+
min
;
}
}
int
/*!
GenerateBoundaryValueForSize
(
const
int
size
)
* Generates boundary values between the given boundaries.
* Boundary values are inclusive. See the examples below.
* If boundary2 < boundary1, the values are swapped.
* If boundary1 == boundary2, value of boundary1 will be returned
*
* Generating boundary values for Uint8
* BoundaryValues(sizeof(Uint8), 10, 20, True) -> [10,11,19,20]
* BoundaryValues(sizeof(Uint8), 10, 20, False) -> [9,21]
* BoundaryValues(sizeof(Uint8), 0, 15, True) -> [0, 1, 14, 15]
* BoundaryValues(sizeof(Uint8), 0, 15, False) -> [16]
* BoundaryValues(sizeof(Uint8), 0, 255, False) -> []
*
* \param maxValue The biggest value that is acceptable for this data type.
* For instance, for Uint8 -> 255, Uint16 -> 65536 etc.
* \param pBoundary1 defines lower boundary
* \param pBoundary2 defines upper boundary
* \param validDomain Generate only for valid domain (for the data type)
*
* \param outBuffer The generated boundary values are put here
* \param outBufferSize Size of outBuffer
*
* \returns NULL on error, outBuffer on success
*
*/
Uint64
*
GenerateUnsignedBoundaryValues
(
const
Uint64
maxValue
,
Uint64
pBoundary1
,
Uint64
pBoundary2
,
SDL_bool
validDomain
,
Uint64
*
outBuffer
,
Uint32
*
outBufferSize
)
{
{
if
(
size
<
0
)
{
Uint64
boundary1
=
pBoundary1
,
boundary2
=
pBoundary2
;
return
-
1
;
if
(
outBuffer
!=
NULL
)
{
SDL_free
(
outBuffer
);
}
if
(
boundary1
>
boundary2
)
{
Uint64
temp
=
boundary1
;
boundary1
=
boundary2
;
boundary2
=
temp
;
}
Uint64
tempBuf
[
8
];
memset
(
tempBuf
,
0
,
8
*
sizeof
(
Uint64
));
Uint64
index
=
0
;
if
(
boundary1
==
boundary2
)
{
tempBuf
[
index
++
]
=
boundary1
;
}
}
else
if
(
validDomain
)
{
tempBuf
[
index
++
]
=
boundary1
;
tempBuf
[
index
++
]
=
boundary1
+
1
;
const
int
adjustment
=
RandomIntegerInRange
(
-
1
,
1
);
tempBuf
[
index
++
]
=
boundary2
-
1
;
int
retValue
=
(
1
<<
(
RandomPositiveInteger
()
%
size
))
+
adjustment
;
tempBuf
[
index
++
]
=
boundary2
;
}
else
{
if
(
boundary1
!=
0
)
{
tempBuf
[
index
++
]
=
boundary1
-
1
;
}
if
(
boundary2
!=
maxValue
)
{
tempBuf
[
index
++
]
=
boundary2
+
1
;
}
}
if
(
index
==
0
)
{
// There are no valid boundaries
return
NULL
;
}
return
retValue
;
// Create the return buffer
outBuffer
=
SDL_malloc
(
index
*
sizeof
(
Uint64
));
if
(
outBuffer
==
NULL
)
{
return
NULL
;
}
SDL_memcpy
(
outBuffer
,
tempBuf
,
index
*
sizeof
(
Uint64
));
*
outBufferSize
=
index
;
return
outBuffer
;
}
}
int
Uint8
RandomUint8BoundaryValue
()
RandomUint8BoundaryValue
(
Uint8
boundary1
,
Uint8
boundary2
,
SDL_bool
validDomain
)
{
{
return
GenerateBoundaryValueForSize
(
8
);
Uint64
*
buffer
=
NULL
;
Uint32
size
;
// max value for Uint8
const
Uint64
maxValue
=
255
;
buffer
=
GenerateUnsignedBoundaryValues
(
maxValue
,
(
Uint64
)
boundary1
,
(
Uint64
)
boundary2
,
validDomain
,
buffer
,
&
size
);
if
(
buffer
==
NULL
)
{
return
0
;
// Change to some better error value? What would be better?
}
Uint32
index
=
RandomInteger
()
%
size
;
Uint8
retVal
=
(
Uint8
)
buffer
[
index
];
SDL_free
(
buffer
);
return
retVal
;
}
}
int
RandomInt8BoundaryValue
()
Sint8
RandomSint8BoundaryValue
()
{
{
int
value
=
GenerateBoundaryValueForSize
(
8
);
int
value
=
0
;
//
GenerateBoundaryValueForSize(8);
return
(
RandomPositiveInteger
()
%
2
==
0
?
value
:
-
value
);
return
(
RandomPositiveInteger
()
%
2
==
0
?
value
:
-
value
);
}
}
...
@@ -164,7 +262,7 @@ RandomAsciiStringWithMaximumLength(int maxSize)
...
@@ -164,7 +262,7 @@ RandomAsciiStringWithMaximumLength(int maxSize)
return
NULL
;
return
NULL
;
}
}
int
size
=
abs
(
RandomInteger
)
%
maxSize
;
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
;
...
...
test/test-automation/fuzzer/fuzzer.h
View file @
e45c8d75
...
@@ -45,7 +45,7 @@ void DeinitFuzzer();
...
@@ -45,7 +45,7 @@ void DeinitFuzzer();
*
*
* \returns Generated integer
* \returns Generated integer
*/
*/
int
RandomInteger
();
Sint32
RandomInteger
();
/*!
/*!
...
@@ -53,29 +53,30 @@ int RandomInteger();
...
@@ -53,29 +53,30 @@ int RandomInteger();
*
*
* \returns Generated integer
* \returns Generated integer
*/
*/
int
RandomPositiveInteger
();
Uint32
RandomPositiveInteger
();
/*!
/*!
* todo add markup
* todo add markup
*/
*/
int
RandomUint8BoundaryValue
(
);
Uint8
RandomUint8BoundaryValue
(
Uint8
boundary1
,
Uint8
boundary2
,
SDL_bool
validDomain
);
/*!
/*!
* todo add markup
* todo add markup
*/
*/
int
RandomI
nt8BoundaryValue
();
Sint8
RandomSi
nt8BoundaryValue
();
/*!
/*!
* Returns integer in range [min, max]. Min and max
* Returns integer in range [min, max] (inclusive).
* value can be negative values as long as min is smaller than max.
* Min and max values can be negative values.
* Min and max also can't be the same value.
* If Max in smaller tham min, then the values are swapped.
* Min and max are the same value, that value will be returned.
*
*
* \returns Generated integer
or ? in error
* \returns Generated integer
*/
*/
int
RandomIntegerInRange
(
int
min
,
int
max
);
Sint32
RandomIntegerInRange
(
Sint32
min
,
Sint32
max
);
/*!
/*!
...
@@ -117,4 +118,5 @@ char *RandomAsciiStringWithMaximumLength(int maxLength);
...
@@ -117,4 +118,5 @@ char *RandomAsciiStringWithMaximumLength(int maxLength);
*/
*/
Uint64
GenerateExecKey
(
char
*
runSeed
,
char
*
suiteName
,
char
*
testName
,
int
interationNumber
);
Uint64
GenerateExecKey
(
char
*
runSeed
,
char
*
suiteName
,
char
*
testName
,
int
interationNumber
);
#endif
#endif
test/test-automation/testdummy/testdummy.c
View file @
e45c8d75
...
@@ -91,10 +91,18 @@ dummycase1(void *arg)
...
@@ -91,10 +91,18 @@ dummycase1(void *arg)
{
{
AssertEquals
(
5
,
5
,
"Assert message"
);
AssertEquals
(
5
,
5
,
"Assert message"
);
for
(;
0
;)
{
/*
Log
(
0
,
"uint8: %d"
,
RandomUint8BoundaryValue
());
for( ; 1 ; )
Log
(
0
,
"int8: %d"
,
RandomInt8BoundaryValue
());
Log(0, "uint8 (same value): %u", RandomPositiveInteger());
// */
//Log(0, "uint8 (same value): %d", RandomUint8BoundaryValue(200, 200, SDL_TRUE));
for
(;
1
;)
{
Log
(
0
,
"uint8: %u"
,
RandomUint8BoundaryValue
(
10
,
20
,
SDL_FALSE
));
//Log(0, "int8: %d", RandomInt8BoundaryValue());
}
}
for
(;
0
;)
{
for
(;
0
;)
{
...
...
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