valFuzz 1.0
Loading...
Searching...
No Matches
valfuzz.hpp File Reference
#include <algorithm>
#include <any>
#include <atomic>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <mutex>
#include <optional>
#include <print>
#include <string>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeinfo>
#include <utility>
#include <vector>

Go to the source code of this file.

Namespaces

namespace  valfuzz
 

Macros

#define ASSERT(cond)
 
#define ASSERT_EQ(a, b)
 
#define ASSERT_NE(a, b)
 
#define ASSERT_LT(a, b)
 
#define ASSERT_LE(a, b)
 
#define ASSERT_GT(a, b)
 
#define ASSERT_GE(a, b)
 
#define ASSERT_THROW(expr, exception)
 
#define ASSERT_NO_THROW(expr)
 
#define TEST(name, pretty_name)
 
#define BEFORE()
 
#define AFTER()
 
#define MAX_RANDOM_STRING_LEN   1024
 
#define FUZZME(fun_name, pretty_name)
 

Typedefs

typedef std::function< void(std::string)> valfuzz::test_function
 
typedef std::pair< std::string, test_functionvalfuzz::test_pair
 
typedef std::function< void(std::string)> valfuzz::fuzz_function
 
typedef std::pair< std::string, fuzz_functionvalfuzz::fuzz_pair
 

Functions

std::mutex & valfuzz::get_stream_mutex ()
 
std::atomic< long unsigned int > & valfuzz::get_max_num_threads ()
 
std::atomic< bool > & valfuzz::get_is_threaded ()
 
std::atomic< bool > & valfuzz::get_verbose ()
 
std::atomic< bool > & valfuzz::get_header ()
 
std::atomic< bool > & valfuzz::get_do_fuzzing ()
 
std::optional< std::string > & valfuzz::get_test_one ()
 
std::optional< std::string > & valfuzz::get_fuzz_one ()
 
void valfuzz::set_multithreaded (bool is_threaded)
 
void valfuzz::set_max_num_threads (long unsigned int max_num_threads)
 
void valfuzz::set_verbose (bool verbose)
 
void valfuzz::set_header (bool header)
 
void valfuzz::set_do_fuzzing (bool do_fuzzing)
 
void valfuzz::set_test_one (const std::string &test_one)
 
void valfuzz::set_fuzz_one (const std::string &fuzz_one)
 
void valfuzz::parse_args (int argc, char *argv[])
 
void valfuzz::print_header ()
 
std::deque< test_pair > & valfuzz::get_tests ()
 
std::vector< std::thread > & valfuzz::get_thread_pool ()
 
std::mutex & valfuzz::get_test_mutex ()
 
long unsigned int valfuzz::get_num_tests ()
 
std::function< void()> & valfuzz::get_function_execute_before ()
 
std::function< void()> & valfuzz::get_function_execute_after ()
 
void valfuzz::set_function_execute_before (std::function< void()> f)
 
void valfuzz::set_function_execute_after (std::function< void()> f)
 
void valfuzz::add_test (const std::string &name, test_function test)
 
std::optional< test_pairvalfuzz::pop_test_or_null ()
 
void valfuzz::run_one_test (const std::string &name)
 
void valfuzz::_run_tests ()
 
void valfuzz::run_tests ()
 
template<typename T >
valfuzz::get_random ()
 
std::deque< fuzz_pair > & valfuzz::get_fuzz_tests ()
 
std::atomic< long unsigned int > & valfuzz::get_iterations ()
 
long unsigned int valfuzz::get_num_fuzz_tests ()
 
void valfuzz::increment_iterations ()
 
std::optional< fuzz_pairvalfuzz::pop_fuzz_or_null ()
 
void valfuzz::add_fuzz_test (const std::string &name, fuzz_function test)
 
void valfuzz::run_one_fuzz (const std::string &name)
 
void valfuzz::_run_fuzz_tests ()
 
void valfuzz::run_fuzz_tests ()
 

Macro Definition Documentation

◆ AFTER

#define AFTER ( )
Value:
void after(); \
static struct after##_register \
{ \
after##_register() \
{ \
valfuzz::set_function_execute_after(after); \
} \
} after##_register_instance; \
void after()

Definition at line 210 of file valfuzz.hpp.

◆ ASSERT

#define ASSERT ( cond)
Value:
if (!(cond)) \
{ \
std::lock_guard<std::mutex> lock(valfuzz::get_stream_mutex()); \
std::cerr << "test: " << test_name << ", line: " << __LINE__ << ", "; \
std::cerr << "Assertion failed: " << #cond << std::endl; \
}
std::mutex & get_stream_mutex()
Definition valfuzz.cpp:62

Definition at line 54 of file valfuzz.hpp.

◆ ASSERT_EQ

#define ASSERT_EQ ( a,
b )
Value:
if ((a) != (b)) \
{ \
std::lock_guard<std::mutex> lock(valfuzz::get_stream_mutex()); \
std::cerr << "test: " << test_name << ", line: " << __LINE__ << ", "; \
std::cerr << "Assertion failed: " << #a << " != " << #b << std::endl; \
}

Definition at line 62 of file valfuzz.hpp.

◆ ASSERT_GE

#define ASSERT_GE ( a,
b )
Value:
if ((a) < (b)) \
{ \
std::lock_guard<std::mutex> lock(valfuzz::get_stream_mutex()); \
std::cerr << "test: " << test_name << ", line: " << __LINE__ << ", "; \
std::cerr << "Assertion failed: " << #a << " >= " << #b << std::endl; \
}

Definition at line 102 of file valfuzz.hpp.

◆ ASSERT_GT

#define ASSERT_GT ( a,
b )
Value:
if ((a) <= (b)) \
{ \
std::lock_guard<std::mutex> lock(valfuzz::get_stream_mutex()); \
std::cerr << "test: " << test_name << ", line: " << __LINE__ << ", "; \
std::cerr << "Assertion failed: " << #a << " > " << #b << std::endl; \
}

Definition at line 94 of file valfuzz.hpp.

◆ ASSERT_LE

#define ASSERT_LE ( a,
b )
Value:
if ((a) > (b)) \
{ \
std::lock_guard<std::mutex> lock(valfuzz::get_stream_mutex()); \
std::cerr << "test: " << test_name << ", line: " << __LINE__ << ", "; \
std::cerr << "Assertion failed: " << #a << " <= " << #b << std::endl; \
}

Definition at line 86 of file valfuzz.hpp.

◆ ASSERT_LT

#define ASSERT_LT ( a,
b )
Value:
if ((a) >= (b)) \
{ \
std::lock_guard<std::mutex> lock(valfuzz::get_stream_mutex()); \
std::cerr << "test: " << test_name << ", line: " << __LINE__ << ", "; \
std::cerr << "Assertion failed: " << #a << " < " << #b << std::endl; \
}

Definition at line 78 of file valfuzz.hpp.

◆ ASSERT_NE

#define ASSERT_NE ( a,
b )
Value:
if ((a) == (b)) \
{ \
std::lock_guard<std::mutex> lock(valfuzz::get_stream_mutex()); \
std::cerr << "test: " << test_name << ", line: " << __LINE__ << ", "; \
std::cerr << "Assertion failed: " << #a << " == " << #b << std::endl; \
}

Definition at line 70 of file valfuzz.hpp.

◆ ASSERT_NO_THROW

#define ASSERT_NO_THROW ( expr)
Value:
{ \
try \
{ \
expr; \
} \
catch (...) \
{ \
std::lock_guard<std::mutex> lock(valfuzz::get_stream_mutex()); \
std::cerr << "test: " << test_name << ", line: " << __LINE__ \
<< ", "; \
std::cerr << "Exception thrown" << std::endl; \
} \
}

Definition at line 130 of file valfuzz.hpp.

◆ ASSERT_THROW

#define ASSERT_THROW ( expr,
exception )
Value:
{ \
bool exception_thrown = false; \
try \
{ \
expr; \
} \
catch (const exception &e) \
{ \
exception_thrown = true; \
} \
if (!exception_thrown) \
{ \
std::lock_guard<std::mutex> lock(valfuzz::get_stream_mutex()); \
std::cerr << "test: " << test_name << ", line: " << __LINE__ \
<< ", "; \
std::cerr << "Exception not thrown: " << #exception << std::endl; \
} \
}

Definition at line 110 of file valfuzz.hpp.

◆ BEFORE

#define BEFORE ( )
Value:
void before(); \
static struct before##_register \
{ \
before##_register() \
{ \
valfuzz::set_function_execute_before(before); \
} \
} before##_register_instance; \
void before()

Definition at line 199 of file valfuzz.hpp.

◆ FUZZME

#define FUZZME ( fun_name,
pretty_name )
Value:
void fun_name([[maybe_unused]] const std::string &test_name); \
static struct fun_name##_register \
{ \
fun_name##_register() \
{ \
valfuzz::add_fuzz_test(pretty_name, fun_name); \
} \
} fun_name##_register_instance; \
void fun_name([[maybe_unused]] const std::string &test_name)

Definition at line 230 of file valfuzz.hpp.

◆ MAX_RANDOM_STRING_LEN

#define MAX_RANDOM_STRING_LEN   1024

Definition at line 223 of file valfuzz.hpp.

◆ TEST

#define TEST ( name,
pretty_name )
Value:
void name([[maybe_unused]] const std::string &test_name); \
static struct name##_register \
{ \
name##_register() \
{ \
valfuzz::add_test(pretty_name, name); \
} \
} name##_register_instance; \
void name([[maybe_unused]] const std::string &test_name)

Definition at line 188 of file valfuzz.hpp.