Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ivg/fuzzing-utils

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fuzzing Utils

Library for creating FUZZ_TEST() macros to use along-side Google Test-style TEST() macros.

Usage

Include the fuzzing_utils.h header in your test files:

#include "fuzzing_utils.h"

Then, define your fuzz test cases using the FUZZ_TEST() macro:

FUZZ_TEST(MyTest, FuzzMyTestFunction) {
    INIT_FUZZ_TEST;
    // initialize variables with FuzzedDataProvider "provider"
    // call your test function with fuzzed data
}

For example, if you have a test that looks like:

TEST(FooTest, TestFoo) {
  test_foo("hello", 42);
}

This allows you to create a FUZZ_TEST fixture that looks like:

FUZZ_TEST(FooTest, FuzzTestFoo) {
    INIT_FUZZ_TEST;
    std::string str = provider.ConsumeRandomLengthString();
    int num = provider.ConsumeIntegral<int>();
    test_foo(str, num);
}

Finally, at the bottom of your test file, you need to define your main() function to conditionally run the fuzz tests on the presence of a command line argument (file input, standard for most fuzzers):

int main(int argc, char **argv) {
    ::testing::InitGoogleTest(&argc, argv);

    if (argc > 1) {
        RunFuzzTests(argv[1]);
        return 0;
    }

    return RUN_ALL_TESTS(); 
}

About

Header files for converting unit tests into fuzzing harnesses

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 85.5%
  • C 14.5%