Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for drchaos #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion testutils.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ bin = @["ntu"]
#srcDir = "testutils"

requires "nim >= 1.2.0",
"unittest2"
"unittest2",
"drchaos"

proc execCmd(cmd: string) =
echo "execCmd: " & cmd
Expand Down
14 changes: 14 additions & 0 deletions testutils/fuzzing.nim
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,20 @@ template test*(body: untyped): untyped =

fuzzerCall()

when defined(llvmFuzzer):
import drchaos/mutator

template test*(typ: typedesc, body: untyped): untyped =
## Test block to do the actual test that will be fuzzed in a loop.
##
## Within this test block there is access to the structured input `typ`
## which contains the payload provided by the fuzzer.
mixin initImpl
initImpl()
func fuzzTarget(payload {.inject.}: typ) =
body
mutatorImpl(fuzzTarget, myMutator, typ)

when defined(clangfast) and not defined(llvmFuzzer):
## Can be used for deferred instrumentation.
## Should be placed on a suitable location in the code where the delayed
Expand Down
6 changes: 3 additions & 3 deletions testutils/fuzzing_engines.nim
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const

# Can also test in debug mode obviously, but might be slower
# Can turn on more logging, in case of libFuzzer it will get very verbose though
defaultFlags = "-d:release -d:chronicles_log_level=fatal " &
defaultFlags = "-d:release -d:useMalloc -g -d:chronicles_log_level=fatal " &
"--hints:off --warnings:off --verbosity:0"

type
Expand Down Expand Up @@ -96,7 +96,7 @@ proc aflExec*(target: string,
exec fuzzCmd

proc libFuzzerCompile*(target: string) =
let libFuzzerOptions = &"-d:llvmFuzzer --noMain {libFuzzerClang}"
let libFuzzerOptions = &"-d:llvmFuzzer -d:noSignalHandler --noMain {libFuzzerClang}"
let compileCmd = &"nim c {defaultFlags} {libFuzzerOptions} {q target}"
exec compileCmd

Expand All @@ -108,7 +108,7 @@ proc libFuzzerExec*(target: string, corpusDir: string) =
exec &"{q target} {q corpusDir}"

proc honggfuzzCompile*(target: string) =
let honggfuzzOptions = &"-d:llvmFuzzer --noMain {honggfuzzClang}"
let honggfuzzOptions = &"-d:llvmFuzzer -d:noSignalHandler --noMain {honggfuzzClang}"
let compileCmd = &"nim c {defaultFlags} {honggfuzzOptions} {q target}"
exec compileCmd

Expand Down