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

Latest commit

 

History

History
152 lines (114 loc) · 2.97 KB

File metadata and controls

152 lines (114 loc) · 2.97 KB
 
Jul 24, 2011
Jul 24, 2011
1
2
3
4
5
6
7
#include "../SDL_test.h"
#include "fuzzer.h"
//! context for test-specific random number generator
Jul 25, 2011
Jul 25, 2011
8
static RND_CTX rndContext;
Jul 24, 2011
Jul 24, 2011
9
Jul 25, 2011
Jul 25, 2011
10
11
char *
GenerateExecKey(char *runSeed, char *suiteName,
Jul 24, 2011
Jul 24, 2011
12
13
14
15
char *testName, int iterationNumber)
{
if(runSeed == NULL || suiteName == NULL ||
testName == NULL || iterationNumber < 0) {
Jul 25, 2011
Jul 25, 2011
16
17
fprintf(stderr, "Error: Incorrect parameter given to GenerateExecKey function\n");
return NULL;
Jul 24, 2011
Jul 24, 2011
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
}
char iterationString[256];
memset(iterationString, 0, sizeof(iterationString));
snprintf(iterationString, sizeof(iterationString), "%d", iterationNumber);
// combine the parameters
const int runSeedLength = strlen(runSeed);
const int suiteNameLength = strlen(suiteName);
const int testNameLength = strlen(testName);
const int iterationStringLength = strlen(iterationString);
// size of the entire + 3 for slashes and + 1 for '\0'
const int entireString = runSeedLength + suiteNameLength +
Jul 25, 2011
Jul 25, 2011
33
testNameLength + iterationStringLength + 3 + 1;
Jul 24, 2011
Jul 24, 2011
34
Jul 25, 2011
Jul 25, 2011
35
36
37
38
39
40
41
42
43
char *buffer = SDL_malloc(entireString);
if(!buffer) {
return NULL;
}
SDL_snprintf(buffer, entireString, "%s/%s/%s/%d", runSeed, suiteName,
testName, iterationNumber);
//printf("Debug: %s", buffer);
Jul 24, 2011
Jul 24, 2011
44
45
46
47
MD5_CTX md5Context;
utl_md5Init(&md5Context);
Jul 25, 2011
Jul 25, 2011
48
utl_md5Update(&md5Context, buffer, entireString);
Jul 24, 2011
Jul 24, 2011
49
50
utl_md5Final(&md5Context);
Jul 25, 2011
Jul 25, 2011
51
SDL_free(buffer);
Jul 24, 2011
Jul 24, 2011
52
Jul 25, 2011
Jul 25, 2011
53
54
55
56
57
const int keyLength = SDL_strlen(md5Context.digest);
char *key = SDL_malloc(keyLength);
SDL_snprintf(key, keyLength, "%s", md5Context.digest);
return key;
Jul 24, 2011
Jul 24, 2011
58
59
60
}
void
Jul 25, 2011
Jul 25, 2011
61
InitFuzzer(char *execKey)
Jul 24, 2011
Jul 24, 2011
62
{
Jul 25, 2011
Jul 25, 2011
63
64
65
66
67
//int a = execKey[8,9,10,11];
int a = execKey[8] | execKey[9] | execKey[10] | execKey[11];
int b = execKey[12] | execKey[13] | execKey[14] | execKey[15];
utl_randomInit(&rndContext, a, b);
Jul 24, 2011
Jul 24, 2011
68
69
70
71
72
73
74
75
76
77
78
}
void
DeinitFuzzer()
{
}
int
RandomInteger()
{
Jul 25, 2011
Jul 25, 2011
79
return utl_randomInt(&rndContext);
Jul 24, 2011
Jul 24, 2011
80
81
82
}
int
Jul 25, 2011
Jul 25, 2011
83
RandomPositiveInteger()
Jul 24, 2011
Jul 24, 2011
84
{
Jul 25, 2011
Jul 25, 2011
85
return abs(utl_randomInt(&rndContext));
Jul 25, 2011
Jul 25, 2011
86
87
88
89
90
91
92
93
94
}
int
RandomIntegerInRange(int min, int max)
{
if(min > max || (min - max) == 0) {
return -1; // Doesn't really make sense to return -1 on error?
}
Jul 25, 2011
Jul 25, 2011
95
int number = utl_randomInt(&rndContext);
Jul 24, 2011
Jul 24, 2011
96
97
number = abs(number);
Jul 25, 2011
Jul 25, 2011
98
return (number % ((max + 1) - min)) + min;
Jul 24, 2011
Jul 24, 2011
99
100
101
}
int
Jul 25, 2011
Jul 25, 2011
102
GenerateBoundaryValueForSize(const int size)
Jul 24, 2011
Jul 24, 2011
103
{
Jul 25, 2011
Jul 25, 2011
104
105
106
if(size < 0) {
return -1;
}
Jul 24, 2011
Jul 24, 2011
107
Jul 25, 2011
Jul 25, 2011
108
109
const int adjustment = RandomIntegerInRange(-1, 1);
int retValue = (1 << (RandomPositiveInteger() % size)) + adjustment;
Jul 24, 2011
Jul 24, 2011
110
111
112
113
return retValue;
}
Jul 25, 2011
Jul 25, 2011
114
115
116
117
118
119
120
121
122
123
124
125
126
int
RandomUint8BoundaryValue()
{
return GenerateBoundaryValueForSize(8);
}
int
RandomInt8BoundaryValue()
{
int value = GenerateBoundaryValueForSize(8);
return (RandomPositiveInteger() % 2 == 0 ? value : -value);
}
Jul 24, 2011
Jul 24, 2011
127
128
129
130
char *
RandomAsciiString()
{
Jul 25, 2011
Jul 25, 2011
131
132
133
134
135
136
137
138
139
140
return RandomAsciiStringWithMaximumLength(255);
}
char *
RandomAsciiStringWithMaximumLength(int maxSize)
{
if(maxSize < 0) {
return NULL;
}
Jul 25, 2011
Jul 25, 2011
141
int size = abs(RandomInteger) % maxSize;
Jul 24, 2011
Jul 24, 2011
142
143
144
145
char *string = SDL_malloc(size * sizeof(size));
int counter = 0;
for( ; counter < size; ++counter) {
Jul 25, 2011
Jul 25, 2011
146
string[counter] = (char) RandomIntegerInRange(1, 127);
Jul 24, 2011
Jul 24, 2011
147
148
}
Jul 25, 2011
Jul 25, 2011
149
150
string[counter] = '\0';
Jul 24, 2011
Jul 24, 2011
151
152
return string;
}