Provide standalone fuzz target for producing coverage reports
This commit is contained in:
parent
0af7f69658
commit
421fa292cf
|
@ -74,7 +74,7 @@ be overloaded. Which is especially useful when `nil` for `ref` is not an accepta
|
|||
|
||||
### Needed config
|
||||
|
||||
Add these flags to either `<filename>.nims`, `config.nims`, `nim.cfg` or directly pass to the compiler:
|
||||
Add these flags to either `<filename>.nims`, `config.nims`, `nim.cfg` or directly pass to the nim compiler:
|
||||
|
||||
```nim
|
||||
--cc: clang
|
||||
|
|
|
@ -562,10 +562,11 @@ proc myMutator*[T](x: var T; sizeIncreaseHint: Natural; r: var Rand) {.nimcall.}
|
|||
runPostProcessor(x, MaxInitializeDepth, r)
|
||||
|
||||
template initializeImpl*() =
|
||||
proc NimMain() {.importc: "NimMain".}
|
||||
when not defined(fuzzerStandalone):
|
||||
proc NimMain() {.importc: "NimMain".}
|
||||
|
||||
proc LLVMFuzzerInitialize(): cint {.exportc.} =
|
||||
NimMain()
|
||||
proc LLVMFuzzerInitialize(): cint {.exportc.} =
|
||||
NimMain()
|
||||
|
||||
template mutatorImpl*(target, mutator, typ: untyped) =
|
||||
mixin default
|
||||
|
@ -627,13 +628,16 @@ template mutatorImpl*(target, mutator, typ: untyped) =
|
|||
when compileOption("exceptions", "goto"):
|
||||
{.emit: "nimTestErrorFlag();".}
|
||||
|
||||
proc LLVMFuzzerCustomMutator(data: ptr UncheckedArray[byte]; len, maxLen: int;
|
||||
seed: int64): int {.exportc.} =
|
||||
try:
|
||||
result = customMutatorImpl(toOpenArray(data, 0, len-1), maxLen, seed)
|
||||
finally:
|
||||
when compileOption("exceptions", "goto"):
|
||||
{.emit: "nimTestErrorFlag();".}
|
||||
when defined(fuzzerStandalone):
|
||||
include standalone
|
||||
else:
|
||||
proc LLVMFuzzerCustomMutator(data: ptr UncheckedArray[byte]; len, maxLen: int;
|
||||
seed: int64): int {.exportc.} =
|
||||
try:
|
||||
result = customMutatorImpl(toOpenArray(data, 0, len-1), maxLen, seed)
|
||||
finally:
|
||||
when compileOption("exceptions", "goto"):
|
||||
{.emit: "nimTestErrorFlag();".}
|
||||
|
||||
proc commonImpl(target, mutator: NimNode): NimNode =
|
||||
let typ = getImpl(target).params[^1][1]
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
import std/[os, strformat, strutils]
|
||||
|
||||
proc standaloneFuzzTarget =
|
||||
stderr.write &"StandaloneFuzzTarget: running {paramCount()} inputs\n"
|
||||
#discard initialize()
|
||||
for i in 1..paramCount():
|
||||
stderr.write &"Running: {paramStr(i)}\n"
|
||||
var buf = readFile(paramStr(i))
|
||||
discard LLVMFuzzerTestOneInput(cast[ptr UncheckedArray[byte]](cstring(buf)), buf.len)
|
||||
stderr.write &"Done: {paramStr(i)}: ({formatSize(buf.len)})\n"
|
||||
|
||||
standaloneFuzzTarget()
|
Loading…
Reference in New Issue