[fuzzer] make multi-process execution more verbose; fix mutation to actually respect mutation depth and to never produce empty units

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@228170 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Kostya Serebryany
2015-02-04 19:10:20 +00:00
parent 70e83e3a1c
commit eb884daa38
6 changed files with 46 additions and 18 deletions

View File

@ -31,18 +31,25 @@ static char RandCh() {
return Special[rand() % (sizeof(Special) - 1)];
}
// Mutate U in place.
void Mutate(Unit *U, size_t MaxLen) {
assert(MaxLen > 0);
assert(U->size() <= MaxLen);
if (U->empty()) {
for (size_t i = 0; i < MaxLen; i++)
U->push_back(RandCh());
return;
}
assert(!U->empty());
switch (rand() % 3) {
case 0:
if (U->size())
if (U->size() > 1) {
U->erase(U->begin() + rand() % U->size());
break;
break;
}
// Fallthrough
case 1:
if (U->empty()) {
U->push_back(RandCh());
} else if (U->size() < MaxLen) {
if (U->size() < MaxLen) {
U->insert(U->begin() + rand() % U->size(), RandCh());
} else { // At MaxLen.
uint8_t Ch = RandCh();
@ -51,12 +58,13 @@ void Mutate(Unit *U, size_t MaxLen) {
}
break;
default:
if (!U->empty()) {
size_t idx = rand() % U->size();
(*U)[idx] = FlipRandomBit((*U)[idx]);
{
size_t Idx = rand() % U->size();
(*U)[Idx] = FlipRandomBit((*U)[Idx]);
}
break;
}
assert(!U->empty());
}
} // namespace fuzzer