Skip to content

Commit

Permalink
Improve fuzzing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ckormanyos committed Sep 26, 2024
1 parent 9531849 commit 2e1356b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 32 deletions.
10 changes: 5 additions & 5 deletions test/fuzzing/test_fuzzing_add.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

// cd /mnt/c/Users/ckorm/Documents/Ks/PC_Software/NumericalPrograms/ExtendedNumberTypes/wide_integer
// clang++ -g -O2 -fsanitize=fuzzer,address,undefined -I. -I/mnt/c/boost/boost_1_85_0 test/fuzzing/test_fuzzing_add.cpp -o test_fuzzing_add
// clang++ -std=c++20 -g -O2 -fsanitize=fuzzer,address,undefined -I. -I/mnt/c/boost/boost_1_85_0 test/fuzzing/test_fuzzing_add.cpp -o test_fuzzing_add
// ./test_fuzzing_add -max_total_time=180

#include <math/wide_integer/uintwide_t.h>
Expand Down Expand Up @@ -49,11 +49,11 @@ auto fuzzing::eval_add(const std::uint8_t* data, std::size_t size) -> bool

if((size > std::size_t { UINT8_C(1) }) && (size <= std::size_t { max_size * 2U }))
{
local_uint_type a_local { };
local_uint_type b_local { };
local_uint_type a_local { 0U };
local_uint_type b_local { 0U };

boost_uint_type a_boost { };
boost_uint_type b_boost { };
boost_uint_type a_boost { 0U };
boost_uint_type b_boost { 0U };

// Import data into their respective uintwide_t a and b values.
import_bits
Expand Down
10 changes: 5 additions & 5 deletions test/fuzzing/test_fuzzing_div.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

// cd /mnt/c/Users/ckorm/Documents/Ks/PC_Software/NumericalPrograms/ExtendedNumberTypes/wide_integer
// clang++ -g -O2 -fsanitize=fuzzer,address,undefined -I. -I/mnt/c/boost/boost_1_85_0 test/fuzzing/test_fuzzing_div.cpp -o test_fuzzing_div
// clang++ -std=c++20 -g -O2 -fsanitize=fuzzer,address,undefined -I. -I/mnt/c/boost/boost_1_85_0 test/fuzzing/test_fuzzing_div.cpp -o test_fuzzing_div
// ./test_fuzzing_div -max_total_time=180

#include <math/wide_integer/uintwide_t.h>
Expand Down Expand Up @@ -49,11 +49,11 @@ auto fuzzing::eval_div(const std::uint8_t* data, std::size_t size) -> bool

if((size > std::size_t { UINT8_C(1) }) && (size <= std::size_t { max_size * 2U }))
{
local_uint_type a_local { };
local_uint_type b_local { };
local_uint_type a_local { 0U };
local_uint_type b_local { 0U };

boost_uint_type a_boost { };
boost_uint_type b_boost { };
boost_uint_type a_boost { 0U };
boost_uint_type b_boost { 0U };

// Import data into their respective uintwide_t a and b values.
import_bits
Expand Down
10 changes: 5 additions & 5 deletions test/fuzzing/test_fuzzing_mul.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

// cd /mnt/c/Users/ckorm/Documents/Ks/PC_Software/NumericalPrograms/ExtendedNumberTypes/wide_integer
// clang++ -g -O2 -fsanitize=fuzzer,address,undefined -I. -I/mnt/c/boost/boost_1_85_0 test/fuzzing/test_fuzzing_mul.cpp -o test_fuzzing_mul
// clang++ -std=c++20 -g -O2 -fsanitize=fuzzer,address,undefined -I. -I/mnt/c/boost/boost_1_85_0 test/fuzzing/test_fuzzing_mul.cpp -o test_fuzzing_mul
// ./test_fuzzing_mul -max_total_time=180

#include <math/wide_integer/uintwide_t.h>
Expand Down Expand Up @@ -49,11 +49,11 @@ auto fuzzing::eval_mul(const std::uint8_t* data, std::size_t size) -> bool

if((size > std::size_t { UINT8_C(1) }) && (size <= std::size_t { max_size * 2U }))
{
local_uint_type a_local { };
local_uint_type b_local { };
local_uint_type a_local { 0U };
local_uint_type b_local { 0U };

boost_uint_type a_boost { };
boost_uint_type b_boost { };
boost_uint_type a_boost { 0U };
boost_uint_type b_boost { 0U };

// Import data into their respective uintwide_t a and b values.
import_bits
Expand Down
22 changes: 10 additions & 12 deletions test/fuzzing/test_fuzzing_prime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

// cd /mnt/c/Users/ckorm/Documents/Ks/PC_Software/NumericalPrograms/ExtendedNumberTypes/wide_integer
// clang++ -g -O2 -fsanitize=fuzzer,address,undefined -I. -I/mnt/c/boost/boost_1_85_0 test/fuzzing/test_fuzzing_prime.cpp -o test_fuzzing_prime
// clang++ -std=c++20 -g -O2 -fsanitize=fuzzer,address,undefined -I. -I/mnt/c/boost/boost_1_85_0 test/fuzzing/test_fuzzing_prime.cpp -o test_fuzzing_prime
// ./test_fuzzing_prime -max_total_time=180

#include <math/wide_integer/uintwide_t.h>
Expand Down Expand Up @@ -64,32 +64,30 @@ auto fuzzing::eval_prime(const std::uint8_t* data, std::size_t size) -> bool
distribution_type distribution1;
distribution_type distribution2;

local_uint_type p0 { };
local_uint_type p0 { 0U };

// Import the random data into the prime candidate.
import_bits
(
p0,
data,
data + size,
8U
data + size
);

const bool miller_rabin_result_local { miller_rabin(p0, 25U, distribution2, generator2) };

const boost_uint_type
pb
auto from_string =
[](const local_uint_type& ui)
{
[&p0]()
{
std::stringstream strm { };
std::stringstream strm { };

strm << p0;
strm << ui;

return strm.str();
}()
return boost_uint_type { strm.str() };
};

const boost_uint_type pb { std::move(from_string(p0)) };

// Ensure that both uintwide_t as well as boost obtain
// the same prime (or non-prime) result.

Expand Down
10 changes: 5 additions & 5 deletions test/fuzzing/test_fuzzing_sub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

// cd /mnt/c/Users/ckorm/Documents/Ks/PC_Software/NumericalPrograms/ExtendedNumberTypes/wide_integer
// clang++ -g -O2 -fsanitize=fuzzer,address,undefined -I. -I/mnt/c/boost/boost_1_85_0 test/fuzzing/test_fuzzing_sub.cpp -o test_fuzzing_sub
// clang++ -std=c++20 -g -O2 -fsanitize=fuzzer,address,undefined -I. -I/mnt/c/boost/boost_1_85_0 test/fuzzing/test_fuzzing_sub.cpp -o test_fuzzing_sub
// ./test_fuzzing_sub -max_total_time=180

#include <math/wide_integer/uintwide_t.h>
Expand Down Expand Up @@ -49,11 +49,11 @@ auto fuzzing::eval_sub(const std::uint8_t* data, std::size_t size) -> bool

if((size > std::size_t { UINT8_C(1) }) && (size <= std::size_t { max_size * 2U }))
{
local_uint_type a_local { };
local_uint_type b_local { };
local_uint_type a_local { 0U };
local_uint_type b_local { 0U };

boost_uint_type a_boost { };
boost_uint_type b_boost { };
boost_uint_type a_boost { 0U };
boost_uint_type b_boost { 0U };

// Import data into their respective uintwide_t a and b values.
import_bits
Expand Down

0 comments on commit 2e1356b

Please sign in to comment.