Skip to content

ForAllSecure/mayhem-cmake-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mayhem CMake Example

To build calculator target

cmake -S . -B build
cmake --build build --target calculator_app

LibFuzzer target

To build libfuzzer target

CC=clang CXX=clang++ cmake -S . -B build -DBUILD_FUZZ=ON
cmake --build build --target fuzz_calculator

Tests

To build tests

cmake -S . -B build -DBUILD_TESTS=ON
cmake --build build --target test_calculator
cmake --build build --target gtest_calculator
cmake --build build --target combined_test_calculator
cmake --build build --target harness_utils_test_calculator
cmake --build build --target fuzzing_utils_test_calculator

Code Coverage

You can download code coverage generated by Mayhem:

# to-do

If you'd like to generate coverage manually, an easy way to do this is:

# to-do

Then generate and view the HTML report with:

# to-do

Gtest Integration

Under the test directory, there are a couple of examples of how to integrate Gtest with Mayhem.

  • test_calculator shows basic unit testing without any infrastructure such as Google Test.

  • gtest_calculator is a simple example of using Gtest, with test fixtures for each function in Calculator.

  • combined_test_calculator extracts the test fixture behavior into a test function, and conditionally either executes Gtest or the test functions with generated inputs.

You can run this on Mayhem with:

# to-do
  • harness_utils_test_calculator is an example inlining harness functionality via a HARNESS macro. The test functions are designed to take a buffer and size, and the HARNESS macro automatically calls the test function with the generated inputs.

  • fuzzing_utils_test_calculator declares a FUZZ_TEST fixture that providers a fuzzed data provider. The FUZZ_TEST fixtures are conditionally called based on the presence of a file on the command line; otherwise, the TEST fixtures run normally.

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

TEST(CalculatorTest, TestAdd) {
  test_add(1, 2);
}

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

FUZZ_TEST(CalculatorTest, FuzzTestAdd) {
    INIT_FUZZ_TEST;
    int x = provider.ConsumeIntegral<int>();
    int y = provider.ConsumeIntegral<int>();
    test_add(x, y);
}

Run this on Mayhem with:

# to-do

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published