valFuzz 1.0
|
Welcome to the official valFuzz documentation. This guide provides comprehensive information and practical examples to help you use valFuzz for your testing and fuzzing needs.
valFuzz is a minimal and lightweight fuzzing framework for C++23. It uses modern standards and techniques to provide a robust and efficient framework for testing and fuzzing for small-medium size projects without particular testing requirements. Despite this, the simpliciry of the library allows for easy extension and customization for your own need.
The library is composed of a header and a source file: include/valfuzz/valfuzz.hpp
and src/valfuzz.cpp
respectively. To use the library, you can simply include the header file in your project and add the source file to your build sources.
The library provides various macros for assertions to be used in your tests:
ASSERT
- Asserts that the given expression is true.ASSERT_EQ
- Asserts that the two given values are equal.ASSERT_NE
- Asserts that the two given values are not equal.ASSERT_LT
- Asserts that the first value is less than the second value.ASSERT_LE
- Asserts that the first value is less than or equal to the second value.ASSERT_GT
- Asserts that the first value is greater than the second value.ASSERT_GE
- Asserts that the first value is greater than or equal to the second value.ASSERT_THROW
- Asserts that the given expression throws an exception of the given type.ASSERT_NO_THROW
- Asserts that the given expression does not throw any exception.For example:
When an assertion fails, the program will output the test name, the line number and the assertion arguments that caused the failure. The program will then continue to run the other tests.
To run your first test, you need to define a test function using the TEST
macro. You will have to specify an unique name for the test and a string name for display purposes.
Tests are automatically registered and run when the program starts. You can run a particular test by specifying the test name after --test
as a command line argument:
It is often necessary to perform some setup and cleanup operations before tests are run. You can define those functions using the BEFORE
and AFTER
macros respectively. The setup function will be run before all tests and the cleanup function will be run after all tests.
valFuzz provides a simple interface for fuzzing your code. You can define a fuzz function using the FUZZME
macro, this function will be called repedetly on multiple threads until you stop the program. You can disable multithreading by passing --no-multithread
as a command line argument.
You can get random values using the T get_random<T>()
function, where T
is the type of the value you want to get. The function will return a random value of the given type, allowed types are:
int
float
double
char
std::string
After defining the fuzz function, you can run it by passing --fuzz
as a command line argument:
All tests and fuzz functions are run on multiple threads by default. You can disable multithreading by passing --no-multithread
as a command line argument.
You can pass the following command line arguments to the program:
--test <test_name>
- Run a specific test by name.--fuzz
- Run all fuzz functions.--fuzz <fuzz_name>
- Run a specific fuzz function by name.--no-multithread
- Disable multithreading.--verbose
- Enable verbose output.--max-threads <n>
- Set the maximum number of threads to use.--no-header
- Disable the header print at the start.--help
- Display help information.