Crowbar OCaml Library

repository·master·Indexed 41 days ago

https://github.com/stedolan/crowbar

An OCaml library for property-based testing that combines QuickCheck-style random testing with AFL (American Fuzzy Lop) bug-finding capabilities. It allows developers to define properties using Crowbar.check_eq or Crowbar.check and execute them in either a fully random test mode or a high-performance AFL fuzzing mode.

Tokens
498
Snippets
4
Records
4
Agent score
3%

What's inside Crowbar

  1. Run Crowbar in AFL mode

    master

    To use the high-performance AFL fuzzing mode, you must have afl-fuzz installed.

    1. Create an input directory containing at least one non-empty file.
    2. Create an output directory for AFL to store findings.
    3. Run the test binary using afl-fuzz with the @@ placeholder to pass inputs to the binary.
    afl-fuzz -i test/input -o output ./my_rad_test.exe @@

    When AFL discovers an input that causes a property to fail, it will be reported as a crash.

  2. Write Crowbar tests in OCaml

    master

    To test your software, define a property using Crowbar.check_eq or Crowbar.check, then register it using Crowbar.add_test. You must specify a name, a list of types to vary (e.g., [int]), and a function that takes those types as arguments to execute the test.

    Example of an identity property test:

    let identity x =
      Crowbar.check_eq x x
    
    let () =
      Crowbar.(add_test ~name:"identity function" [int] (fun i -> identity i))
  3. Build Crowbar tests

    master

    Include crowbar in your project's dependencies. Ensure you build a native-code executable, not bytecode.

    To enable AFL-based fuzzing, you must build your tests using an OCaml compiler with AFL instrumentation enabled. The easiest way is to use an opam switch with the +afl tag.

    $ opam switch 4.06.0+afl
    $ eval `opam config env`
    $ ./build_my_rad_test.sh
    $ opam switch 4.06.0+afl
    $ eval `opam config env`
    $ ./build_my_rad_test.sh # or your relevant build runes
  4. Run Crowbar in fully random test mode

    master

    To run tests in a simple QuickCheck-like mode where Crowbar tests propositions against totally random input, execute your compiled binary with no arguments.

    $ ./my_rad_test.exe | head -5