14#if __cplusplus >= 202002L
17 static std::atomic<bool>
24#if __cplusplus >= 202002L
27 static std::atomic<bool>
34#if __cplusplus >= 202002L
37 static std::optional<std::string>
38 test_one = std::nullopt;
44#if __cplusplus >= 202002L
47 static std::optional<std::string>
48 fuzz_one = std::nullopt;
54 static std::atomic<long unsigned int> seed =
55 (
long unsigned int) std::time(
nullptr);
62 is_threaded_ref = is_threaded;
68 max_num_threads_ref = max_num_threads;
74 verbose_ref = verbose;
86 do_fuzzing_ref = do_fuzzing;
92 test_one_ref = test_one;
98 fuzz_one_ref = fuzz_one;
108 " __ ____ _| | ___| _ ________\n"
109 " \\ \\ / / _` | | |_ | | | |_ /_ /\n"
110 " \\ V / (_| | | _|| |_| |/ / / / \n"
111 " \\_/ \\__,_|_|_| \\__,_/___/___|\n"
113 "A modern testing & fuzzing library for C++\n";
125 std::cout <<
"Settings:\n";
126 std::cout <<
" - Multithreaded: " << is_threaded <<
"\n";
127 std::cout <<
" - Max threads: " << max_num_threads <<
"\n";
128 std::cout <<
" - Run Fuzzs: " << do_fuzzing <<
"\n";
129 std::cout <<
" - Run Benchmarks: " << do_benchmarks <<
"\n";
130 std::cout <<
" - Verbose: " << verbose <<
"\n";
131 std::cout <<
" - Reporter: " << reporter_id <<
"\n";
137 for (
int i = 1; i < argc; i++)
139 if (std::string(argv[i]) ==
"--test")
148 std::cerr <<
"Test name not provided\n";
152 else if (std::string(argv[i]) ==
"--fuzz")
156 else if (std::string(argv[i]) ==
"--fuzz-one")
166 std::cerr <<
"Fuzz test name not provided\n";
170 else if (std::string(argv[i]) ==
"--benchmark")
174 else if (std::string(argv[i]) ==
"--num-iterations")
183 std::cerr <<
"Number of iterations not provided\n";
187 else if (std::string(argv[i]) ==
"--run-one-benchmark")
194 if (b.first == argv[i + 1])
202 std::cerr <<
"Benchmark \"" << argv[i + 1] <<
"\" not found\n";
211 else if (std::string(argv[i]) ==
"--report")
221 std::cerr <<
"Report file not provided\n";
225 else if (std::string(argv[i]) ==
"--reporter")
234 std::cerr <<
"Reporter " << argv[i + 1] <<
" unrecognised\n";
238 else if (std::string(argv[i]) ==
"--no-multithread")
242 else if (std::string(argv[i]) ==
"--verbose")
246 else if (std::string(argv[i]) ==
"--max-threads")
255 std::cerr <<
"Number of threads not provided\n";
259 else if (std::string(argv[i]) ==
"--no-header")
263 else if (std::string(argv[i]) ==
"--seed")
272 std::cerr <<
"Seed not provided\n";
276 else if (std::string(argv[i]) ==
"--help")
279 std::cout <<
"Usage: valfuzz [options]\n";
280 std::cout <<
"Options:\n";
282 std::cout <<
" TESTS \n";
283 std::cout <<
" --test <name>: run a specific test\n";
284 std::cout <<
" --no-multithread: run tests in a single thread\n";
285 std::cout <<
" --max-threads <num>: set the maximum number of threads\n";
287 std::cout <<
" FUZZING \n";
288 std::cout <<
" --fuzz: run fuzz tests\n";
289 std::cout <<
" --fuzz-one <name>: run a specific fuzz test\n";
291 std::cout <<
" BENCHMARK \n";
292 std::cout <<
" --benchmark: run benchmarks\n";
293 std::cout <<
" --num-iterations <num>: set the number of "
294 "iterations for benchmarks\n";
295 std::cout <<
" --run-one-benchmark <name>: run a specific benchmark\n";
296 std::cout <<
" --report <file>: save benchmark results to a file\n";
298 <<
" --reporter <name>: use a custom reporter, currently supported\n";
299 std::cout <<
" are default, csv, none\n";
301 std::cout <<
" GENERAL \n";
302 std::cout <<
" --verbose: print test names\n";
303 std::cout <<
" --no-header: do not print the header at the start\n";
304 std::cout <<
" --seed <seed>: set the seed for PRNG\n";
305 std::cout <<
" --help: print this help message\n";
310 std::cerr <<
"Unknown option: " << argv[i] <<
"\n";
323 std::srand((
unsigned int) seed);
326 gen.seed(seed.load());
334 std::cout <<
"Seed: " << seed <<
"\n";
336 <<
" benchmarks...\n";
342 std::cout <<
"Saved results to file \n";
356 std::cout <<
"Seed: " << seed <<
"\n";
371 std::cout <<
"Seed: " << seed <<
"\n";
373 <<
" fuzz tests...\n";
382 std::cerr <<
"Failed\n";
387 std::cout <<
"Done\n";
std::atomic< bool > & get_header()
bool & get_do_benchmarks()
void set_save_file(const std::filesystem::path &save_to_file_path)
long unsigned int get_num_fuzz_tests()
void set_reporter(std::string rep)
std::function< void()> & get_function_execute_after()
void set_num_iterations_benchmark(int num_iterations_benchmark)
std::atomic< long unsigned int > & get_max_num_threads()
void set_save_to_file(bool save_to_file)
long unsigned int get_num_tests()
int main(int argc, char **argv)
std::atomic< bool > & get_verbose()
void run_one_fuzz(const std::string &name)
void run_one_test(const std::string &name)
std::atomic< bool > & get_do_fuzzing()
void set_do_fuzzing(bool do_fuzzing)
void set_fuzz_one(const std::string &fuzz_one)
std::optional< std::string > & get_fuzz_one()
void set_test_one(const std::string &test_one)
void set_one_benchmark(const std::string &one_benchmark)
void set_multithreaded(bool is_threaded)
std::ofstream & get_save_file()
std::atomic< bool > & get_is_threaded()
void set_do_benchmarks(bool do_benchmarks)
void set_header(bool header)
unsigned long get_num_benchmarks()
std::atomic< bool > & get_save_to_file()
reporter_engine reporter_eg
void set_max_num_threads(long unsigned int max_num_threads)
std::atomic< bool > & get_has_failed_once()
void set_seed(long unsigned int new_seed)
std::function< void()> & get_function_execute_before()
std::atomic< long unsigned int > & get_seed()
std::optional< std::string > & get_test_one()
void parse_args(int argc, char *argv[])
std::mt19937 & get_random_engine()
std::deque< benchmark_pair > & get_benchmarks()
void set_verbose(bool verbose)
void set_run_one_benchmark(bool run_one_benchmark)
std::mutex & get_stream_mutex()
std::string & get_reporter()