diff options
Diffstat (limited to 'test')
| -rwxr-xr-x | test/fuzz.sh | 14 | ||||
| -rwxr-xr-x | test/test.sh | 9 | ||||
| -rw-r--r-- | test/util.h | 6 |
3 files changed, 26 insertions, 3 deletions
diff --git a/test/fuzz.sh b/test/fuzz.sh new file mode 100755 index 0000000..5b9b9d2 --- /dev/null +++ b/test/fuzz.sh @@ -0,0 +1,14 @@ +#!/bin/bash +set -e +cd "$(dirname "$0")" + +while true +do + seed="0" + while [[ $seed == 0* ]]; do + seed=$(tr -dc '0-9' </dev/random | head -c 18) + done + echo "Fuzz using seed: $seed" + echo + ./test.sh --seed=123 "$@" +done diff --git a/test/test.sh b/test/test.sh index 0ca230b..d34c446 100755 --- a/test/test.sh +++ b/test/test.sh @@ -6,6 +6,7 @@ export MALLOC_PERTURB_="$((2#01011001))" declare -A cppstandard cppstandard["string/suffixArray.cpp"]="gnu++20" +seedmacro="" test_file() { file=$(realpath --relative-to="${PWD}" "${1}") @@ -15,7 +16,7 @@ test_file() { if [[ -v cppstandard[$file] ]]; then std=${cppstandard[$file]} fi - g++ -std=$std "$file" -I ../content/ -O2 -Wall -Wextra -Wshadow -Werror + g++ -std=$std "$file" -I ../content/ -O2 -Wall -Wextra -Wshadow -Werror $seedmacro echo "running..." timeout --foreground 60s ./a.out echo "" @@ -48,8 +49,10 @@ list_missing() { if [ "$#" -ne 0 ]; then for arg in "$@" do - if [[ "$arg" == "--missing" ]]; then + if [[ $arg == "--missing" ]]; then list_missing + elif [[ $arg == --seed=* ]]; then + seedmacro="-DSEED=${arg:7}ll" elif [ -d "$arg" ]; then dir=$(realpath --relative-to="${PWD}" "$arg") find . -type f -path "./${dir}/*.cpp" -print0 | sort -z | while read -d $'\0' file @@ -58,6 +61,8 @@ if [ "$#" -ne 0 ]; then done elif [ -f "$arg" ]; then test_file "$arg" + else + echo "did not recognize: $arg" fi done else diff --git a/test/util.h b/test/util.h index bfa35d8..6f23b82 100644 --- a/test/util.h +++ b/test/util.h @@ -24,7 +24,11 @@ namespace details { } namespace Random { - mt19937_64 rng(3141592653589793238ll); + #ifdef SEED + mt19937_64 rng(SEED); + #else + mt19937_64 rng(3141592653589793238ll); + #endif template<typename T = ll> T integer(T l, T r) { return uniform_int_distribution<T>(l, r-1)(rng); |
