Add fuzz testing of input programs.

When the --fuzz-test command-line option is given, the input program
will be randomly perturbed by the lexer in an effort to trigger
assertions or crashes in the compiler (neither of which should ever
happen, even for malformed programs.)
This commit is contained in:
Matt Pharr
2012-02-06 13:59:14 -08:00
parent b7c5af7e64
commit 3efbc71a01
6 changed files with 366 additions and 105 deletions

39
sym.cpp
View File

@@ -354,3 +354,42 @@ SymbolTable::Print() {
depth += 4;
}
}
inline int ispcRand() {
#ifdef ISPC_IS_WINDOWS
return rand();
#else
return lrand48();
#endif
}
Symbol *
SymbolTable::RandomSymbol() {
int v = ispcRand() % variables.size();
if (variables[v]->size() == 0)
return NULL;
int count = ispcRand() % variables[v]->size();
SymbolMapType::iterator iter = variables[v]->begin();
while (count-- > 0) {
++iter;
Assert(iter != variables[v]->end());
}
return iter->second;
}
const Type *
SymbolTable::RandomType() {
int v = ispcRand() % types.size();
if (types[v]->size() == 0)
return NULL;
int count = ispcRand() % types[v]->size();
TypeMapType::iterator iter = types[v]->begin();
while (count-- > 0) {
++iter;
Assert(iter != types[v]->end());
}
return iter->second;
}