strtabs demo mutator
This commit is contained in:
parent
4662b4215a
commit
a0e4a1c6ed
|
@ -154,8 +154,8 @@ This is only necessary for destructor-based types. `mutate`, `default` and `==`
|
||||||
- Don't `echo` in a fuzz target as it slows down execution speed.
|
- Don't `echo` in a fuzz target as it slows down execution speed.
|
||||||
- Prefer `-d:danger|release` for maximum performance.
|
- Prefer `-d:danger|release` for maximum performance.
|
||||||
- Once you have a crash you can recompile with `-d:debug` and pass the crashing test case as parameter.
|
- Once you have a crash you can recompile with `-d:debug` and pass the crashing test case as parameter.
|
||||||
- With this line `when defined(dumpFuzzInput): debugEcho(x)` in a target and `-d:dumpFuzzInput`, observe the crashing input.
|
- Use `debugEcho(x)` in a target to print the crashing input.
|
||||||
- You could compile without sanitizers, AddressSanitizer slows down by 2x, but it's not recommended.
|
- You could compile without sanitizers, AddressSanitizer slows down programs by ~2x, but it's not recommended.
|
||||||
|
|
||||||
### What's not supported
|
### What's not supported
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ when isMainModule:
|
||||||
proc default(_: typedesc[HtmlNode]): HtmlNode =
|
proc default(_: typedesc[HtmlNode]): HtmlNode =
|
||||||
HtmlNode(tag: text, s: "")
|
HtmlNode(tag: text, s: "")
|
||||||
|
|
||||||
func fuzzTarget(x: HtmlNode) =
|
proc fuzzTarget(x: HtmlNode) =
|
||||||
when defined(dumpFuzzInput): debugEcho(x)
|
when defined(dumpFuzzInput): debugEcho(x)
|
||||||
# Here you could feed `$x` to htmlparser.parseHtml and make sure it doesn't crash.
|
# Here you could feed `$x` to htmlparser.parseHtml and make sure it doesn't crash.
|
||||||
#var errors: seq[string] = @[]
|
#var errors: seq[string] = @[]
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
import drchaos/mutator, std/[strtabs, random]
|
||||||
|
|
||||||
|
proc mutate(data: var StringTableRef; sizeIncreaseHint: int; enforceChanges: bool; r: var Rand) =
|
||||||
|
var value: seq[tuple[key, value: string]]
|
||||||
|
for p in pairs(data):
|
||||||
|
value.add p
|
||||||
|
repeatMutateInplace(mutateSeq(value, tmp, 2, sizeIncreaseHint, r))
|
||||||
|
clear(data)
|
||||||
|
for key, val in value.items:
|
||||||
|
data[key] = val
|
||||||
|
|
||||||
|
proc mutate(value: var string; sizeIncreaseHint: int; enforceChanges: bool; r: var Rand) =
|
||||||
|
repeatMutate(mutateUtf8String(move value, 4, sizeIncreaseHint, r))
|
||||||
|
|
||||||
|
proc default(_: typedesc[StringTableRef]): StringTableRef =
|
||||||
|
newStringTable(modeCaseSensitive)
|
||||||
|
|
||||||
|
func fuzzTarget(x: StringTableRef) =
|
||||||
|
doAssert x != {"key1": "val1", "key2": "val2"}.newStringTable
|
||||||
|
|
||||||
|
defaultMutator(fuzzTarget)
|
|
@ -1,5 +1,6 @@
|
||||||
# WARNING: This mutator crashes for OrderedTable and it's too slow with Table.
|
# WARNING: This mutator crashes for OrderedTable and it's too slow with Table.
|
||||||
# TODO: split into files and make it compile again.
|
# TODO: split into files and make it compile again.
|
||||||
|
# Use https://nim-lang.org/docs/importutils.html
|
||||||
import random
|
import random
|
||||||
include std/tables
|
include std/tables
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,6 @@ func fuzzTarget(x: ContentNode) =
|
||||||
ContentNode(kind: Text, textStr: "mychild"),
|
ContentNode(kind: Text, textStr: "mychild"),
|
||||||
ContentNode(kind: Br)
|
ContentNode(kind: Br)
|
||||||
])
|
])
|
||||||
doAssert x != data
|
doAssert x != x
|
||||||
|
|
||||||
defaultMutator(fuzzTarget)
|
defaultMutator(fuzzTarget)
|
||||||
|
|
Loading…
Reference in New Issue