Add fuzz test
This commit is contained in:
parent
61bae43e01
commit
1996de769b
|
@ -1,6 +1,7 @@
|
|||
nimcache
|
||||
*.exe
|
||||
nimble.develop
|
||||
nimble.paths
|
||||
nimble-win.paths
|
||||
nimble-linux.paths
|
||||
build/
|
||||
vendor/
|
||||
|
|
12
config.nims
12
config.nims
|
@ -8,6 +8,14 @@
|
|||
# those terms.
|
||||
|
||||
# begin Nimble config (version 1)
|
||||
when fileExists("nimble.paths"):
|
||||
include "nimble.paths"
|
||||
when defined(windows):
|
||||
when fileExists("nimble-win.paths"):
|
||||
include "nimble-win.paths"
|
||||
elif fileExists("nimble.paths"):
|
||||
include "nimble.paths"
|
||||
elif defined(linux):
|
||||
when fileExists("nimble-win.paths"):
|
||||
include "nimble-linux.paths"
|
||||
elif fileExists("nimble.paths"):
|
||||
include "nimble.paths"
|
||||
# end Nimble config
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
# json-serialization
|
||||
# Copyright (c) 2023 Status Research & Development GmbH
|
||||
# Licensed under either of
|
||||
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||
# at your option.
|
||||
# This file may not be copied, modified, or distributed except according to
|
||||
# those terms.
|
||||
|
||||
import
|
||||
testutils/fuzzing,
|
||||
faststreams,
|
||||
../json_serialization/lexer
|
||||
|
||||
template prepareLexer(T: type, payload: untyped) =
|
||||
var stream = unsafeMemoryInput(payload)
|
||||
var lex = init(JsonLexer, stream)
|
||||
var value: JsonValueRef[T]
|
||||
lex.scanValue(value)
|
||||
|
||||
test:
|
||||
prepareLexer(string, payload)
|
||||
prepareLexer(uint64, payload)
|
|
@ -0,0 +1,29 @@
|
|||
# json-serialization
|
||||
# Copyright (c) 2023 Status Research & Development GmbH
|
||||
# Licensed under either of
|
||||
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||
# at your option.
|
||||
# This file may not be copied, modified, or distributed except according to
|
||||
# those terms.
|
||||
|
||||
import
|
||||
testutils/fuzzing,
|
||||
faststreams,
|
||||
../json_serialization/parser
|
||||
|
||||
func toReader(input: openArray[byte]): JsonReader[DefaultFlavor] =
|
||||
var stream = unsafeMemoryInput(input)
|
||||
JsonReader[DefaultFlavor].init(stream)
|
||||
|
||||
proc executeParser(payload: openArray[byte]) =
|
||||
try:
|
||||
var r = toReader(payload)
|
||||
let z = r.parseValue(uint64)
|
||||
discard z
|
||||
except JsonReaderError:
|
||||
discard
|
||||
|
||||
test:
|
||||
executeParser(payload)
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
## Fuzz test manual
|
||||
|
||||
You need to install [testutils](https://github.com/status-im/nim-testutils) and
|
||||
[chronicles](https://github.com/status-im/nim-chronicles).
|
||||
Then read documentation over there to prepare your execution environment.
|
||||
|
||||
### Compatibility
|
||||
|
||||
These fuzzers can be compiled with Nim v1.6.16 or newer.
|
||||
|
||||
### Available fuzz test
|
||||
|
||||
* fuzz_lexer
|
||||
* fuzz_parser
|
||||
|
||||
### Manually with libFuzzer/llvmFuzer
|
||||
#### Compiling
|
||||
```sh
|
||||
nim c -d:llvmFuzzer -d:release -d:chronicles_log_level=FATAL --noMain --cc=clang --passC="-fsanitize=fuzzer" --passL="-fsanitize=fuzzer" fuzzer/fuzz_lexer
|
||||
```
|
||||
|
||||
#### Starting the Fuzzer
|
||||
Starting the fuzzer is as simple as running the compiled program:
|
||||
```sh
|
||||
./fuzz_lexer corpus_dir -runs=1000000
|
||||
```
|
||||
|
||||
To see the available options:
|
||||
```sh
|
||||
./fuzz_lexer test=1
|
||||
```
|
||||
|
||||
You can also use the application to verify a specific test case:
|
||||
```sh
|
||||
./fuzz_lexer input_file
|
||||
```
|
|
@ -14,7 +14,7 @@ version = "0.2.0"
|
|||
author = "Status Research & Development GmbH"
|
||||
description = "Flexible JSON serialization not relying on run-time type information"
|
||||
license = "Apache License 2.0"
|
||||
skipDirs = @["tests"]
|
||||
skipDirs = @["tests", "fuzzer"]
|
||||
|
||||
requires "nim >= 1.6.0",
|
||||
"serialization",
|
||||
|
|
Loading…
Reference in New Issue