From 4c4aea6abd680b62132ead1c9cc943e3e489271d Mon Sep 17 00:00:00 2001 From: Gloria Mundi Date: Thu, 20 Nov 2025 17:45:28 +0100 Subject: enable _GLIBCXX_ASSERTIONS for sanitizer tests --- test/GNUmakefile | 2 +- test/graph/binary_lifting.cpp | 2 +- test/math/millerRabin.base32.cpp | 2 +- test/math/millerRabin.cpp | 2 +- test/math/rho.cpp | 2 +- test/util.h | 6 +++++- 6 files changed, 10 insertions(+), 6 deletions(-) diff --git a/test/GNUmakefile b/test/GNUmakefile index cc1b4f5..7aae024 100644 --- a/test/GNUmakefile +++ b/test/GNUmakefile @@ -3,7 +3,7 @@ TESTS = $(basename $(shell find . -path ./awk -prune -o -type f -name '*.cpp' -p AWK = $(basename $(shell find . -type f -name '*.awk')) CXX = g++ -std=gnu++20 -I awk/ -I ../content/ -O2 -Wall -Wextra -Wshadow -Werror SAN = -fsanitize=address,undefined -DSANITIZE -TIMEOUT = 300 +TIMEOUT = 5m test: $(TESTS:=.ok) $(TESTS:=.san.ok) diff --git a/test/graph/binary_lifting.cpp b/test/graph/binary_lifting.cpp index 20318da..abcd784 100644 --- a/test/graph/binary_lifting.cpp +++ b/test/graph/binary_lifting.cpp @@ -56,5 +56,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/math/millerRabin.base32.cpp b/test/math/millerRabin.base32.cpp index e9a4b57..70be2f8 100644 --- a/test/math/millerRabin.base32.cpp +++ b/test/math/millerRabin.base32.cpp @@ -98,7 +98,7 @@ void extra_tests() { bool expected = ssize(factors) == 1 && factors.begin()->second == 1; if (got != expected) cerr << "error: " << x << FAIL; } - if (t.time > 10) cerr << "too slow" << FAIL; + if (!sanitize && t.time > 10) cerr << "too slow" << FAIL; cerr << "stress tested: " << t.time << "ms" << endl; } diff --git a/test/math/millerRabin.cpp b/test/math/millerRabin.cpp index e7feba1..bdcdee6 100644 --- a/test/math/millerRabin.cpp +++ b/test/math/millerRabin.cpp @@ -90,7 +90,7 @@ void extra_tests() { bool expected = ssize(factors) == 1 && factors.begin()->second == 1; if (got != expected) cerr << "error: " << x << FAIL; } - if (t.time > 10) cerr << "too slow" << FAIL; + if (!sanitize && t.time > 10) cerr << "too slow" << FAIL; cerr << "stress tested: " << t.time << "ms" << endl; } diff --git a/test/math/rho.cpp b/test/math/rho.cpp index 9943a8c..2c8a319 100644 --- a/test/math/rho.cpp +++ b/test/math/rho.cpp @@ -92,7 +92,7 @@ void stress_test() { cerr << FAIL; } } - if (t.time > 100) cerr << "too slow" << FAIL; + if (!sanitize && t.time > 100) cerr << "too slow" << FAIL; cerr << "stress tested: " << t.time << "ms" << endl; } diff --git a/test/util.h b/test/util.h index 880ff04..98fd7f6 100644 --- a/test/util.h +++ b/test/util.h @@ -1,3 +1,7 @@ +#ifdef SANITIZE +# define _GLIBCXX_ASSERTIONS 1 +# define _GLIBCXX_SANITIZE_VECTOR 1 +#endif #include using namespace std; @@ -202,7 +206,7 @@ namespace detail { return 30/t; } - double speed = benchmark(); + double speed = sanitize ? numeric_limits::infinity() : benchmark(); } struct timer { -- cgit v1.2.3