From 205afc493f24fb62e27cdcecc5d95d4b2f8b2a25 Mon Sep 17 00:00:00 2001 From: Antonis Geralis Date: Fri, 9 Sep 2022 19:52:36 +0300 Subject: [PATCH] experimental: adjust weights --- drchaos/mutator.nim | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/drchaos/mutator.nim b/drchaos/mutator.nim index 8e7156e..a91aab6 100644 --- a/drchaos/mutator.nim +++ b/drchaos/mutator.nim @@ -18,9 +18,9 @@ template `+!`(p: pointer; s: int): untyped = cast[pointer](cast[ByteAddress](p) +% s) const - RandomToDefaultRatio = 100 # The chance of returning an uninitalized type. - DefaultMutateWeight = 1_000_000 # The default weight of items sampled by the reservoir sampler. - MaxInitializeDepth = 200 # The post-processor prunes nested non-copyMem types. + RandomToDefaultRatio = 100 # The chance of returning an uninitalized type. + DefaultMutateWeight = 125_000 # The default weight of items sampled by the reservoir sampler. + MaxInitializeDepth = 200 # The post-processor prunes nested non-copyMem types. type ByteSized* = int8|uint8|byte|bool|char # Run LibFuzzer's mutate for sequences of these types. @@ -262,7 +262,7 @@ template sampleAttempt(call: untyped) = proc sample[T: distinct](x: T; s: var Sampler; r: var Rand; res: var int) = when compiles(mutate(x, 0, false, r)): - sampleAttempt(attempt(s, r, DefaultMutateWeight, res)) + sampleAttempt(attempt(s, r, DefaultMutateWeight*sizeof(x), res)) # distinct bool lol else: sample(x.distinctBase, s, r, res) @@ -270,39 +270,39 @@ proc sample(x: bool; s: var Sampler; r: var Rand; res: var int) = sampleAttempt(attempt(s, r, DefaultMutateWeight, res)) proc sample(x: char; s: var Sampler; r: var Rand; res: var int) = - sampleAttempt(attempt(s, r, DefaultMutateWeight, res)) + sampleAttempt(attempt(s, r, DefaultMutateWeight*sizeof(x), res)) proc sample[T: enum](x: T; s: var Sampler; r: var Rand; res: var int) = - sampleAttempt(attempt(s, r, DefaultMutateWeight, res)) + sampleAttempt(attempt(s, r, DefaultMutateWeight*sizeof(x), res)) proc sample[T](x: set[T]; s: var Sampler; r: var Rand; res: var int) = - sampleAttempt(attempt(s, r, DefaultMutateWeight, res)) + sampleAttempt(attempt(s, r, DefaultMutateWeight*sizeof(x), res)) proc sample[T: SomeNumber](x: T; s: var Sampler; r: var Rand; res: var int) = - sampleAttempt(attempt(s, r, DefaultMutateWeight, res)) + sampleAttempt(attempt(s, r, DefaultMutateWeight*sizeof(x), res)) proc sample[T](x: seq[T]; s: var Sampler; r: var Rand; res: var int) = - sampleAttempt(attempt(s, r, DefaultMutateWeight, res)) + sampleAttempt(attempt(s, r, DefaultMutateWeight*sizeof(x), res)) proc sample(x: string; s: var Sampler; r: var Rand; res: var int) = - sampleAttempt(attempt(s, r, DefaultMutateWeight, res)) + sampleAttempt(attempt(s, r, DefaultMutateWeight*sizeof(x), res)) proc sample[T: tuple|object](x: T; s: var Sampler; r: var Rand; res: var int) = when compiles(mutate(x, 0, false, r)): - sampleAttempt(attempt(s, r, DefaultMutateWeight, res)) + sampleAttempt(attempt(s, r, DefaultMutateWeight*sizeof(x), res)) else: for v in fields(x): sample(v, s, r, res) proc sample[T](x: ref T; s: var Sampler; r: var Rand; res: var int) = when compiles(mutate(x, 0, false, r)): - sampleAttempt(attempt(s, r, DefaultMutateWeight, res)) + sampleAttempt(attempt(s, r, DefaultMutateWeight*sizeof(x), res)) else: if x != nil: sample(x[], s, r, res) proc sample[S, T](x: array[S, T]; s: var Sampler; r: var Rand; res: var int) = when compiles(mutate(x, 0, false, r)): - sampleAttempt(attempt(s, r, DefaultMutateWeight, res)) + sampleAttempt(attempt(s, r, DefaultMutateWeight*sizeof(x), res)) else: for i in low(x)..high(x): sample(x[i], s, r, res)