From 4a959de38cb2daf81cfabccbcbcfeb7ffd28b9c6 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Wed, 18 Nov 2020 21:37:34 +0100 Subject: [PATCH] bitset: tests: try harder to break it bitset_list (used in bitset_first, bitset_next, bitset_count, BITSET_FOR_EACH, etc.) uses a cache of size BITSET_LIST_SIZE (1024). None of our tests current try bitsets bigger than this. * tests/test-bitset.c (compare): Be ready to use bitsets larger than BITSET_LIST_SIZE. (main): Likewise. While at it, also exercise super small bitsets. --- ChangeLog | 8 ++++++++ tests/test-bitset.c | 28 ++++++++++++++++++---------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index afad46b25c..6775744036 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2020-11-19 Akim Demaille + + bitset: tests: try harder to break it + * tests/test-bitset.c (compare): Be ready to use bitsets larger than + BITSET_LIST_SIZE. + (main): Likewise. + While at it, also exercise super small bitsets. + 2020-11-19 Akim Demaille bitset: use ffs where possible in the vector implementation diff --git a/tests/test-bitset.c b/tests/test-bitset.c index fc0c6fbe9e..9a2d7c5216 100644 --- a/tests/test-bitset.c +++ b/tests/test-bitset.c @@ -22,8 +22,8 @@ #define RANDOM(n) (rand () % (n)) -static -void assert_bitset_equal (bitset bs1, bitset bs2) +static void +assert_bitset_equal (bitset bs1, bitset bs2) { debug_bitset (bs1); debug_bitset (bs2); @@ -32,8 +32,8 @@ void assert_bitset_equal (bitset bs1, bitset bs2) ASSERT (bitset_test (bs1, i) == bitset_test (bs2, i)); } -static -void bitset_random (bitset bs) +static void +bitset_random (bitset bs) { for (bitset_bindex i = 0; i < bitset_size (bs); ++i) bitset_set (bs, RANDOM (2)); @@ -43,10 +43,12 @@ void bitset_random (bitset bs) /* Check various operations on random bitsets with two different implementations. */ -static -void compare (enum bitset_attr a, enum bitset_attr b) +static void +compare (enum bitset_attr a, enum bitset_attr b) { - const int nbits = RANDOM (256); + /* bitset_list (used in many operations) uses a cache whose size is + BITSET_LIST_SIZE */ + const int nbits = RANDOM (2 * BITSET_LIST_SIZE); /* Four read only random initial values of type A. */ const bitset asrc0 = bitset_create (nbits, a); @@ -356,10 +358,16 @@ check_attributes (enum bitset_attr attr, int nbits) int main (void) { - for (int i = 0; i < 2; ++i) + for (int i = 0; i < 4; ++i) { - /* table bitsets have elements that store 256 bits. */ - int nbits = i == 0 ? 32 : 257; + /* table bitsets have elements that store 256 bits. bitset_list + (used in many operations) uses a cache whose size is + BITSET_LIST_SIZE. */ + int nbits = + i == 0 ? 1 + : i == 1 ? 32 + : i == 2 ? 257 + : (BITSET_LIST_SIZE + 1); check_attributes (BITSET_FIXED, nbits); check_attributes (BITSET_VARIABLE, nbits); check_attributes (BITSET_DENSE, nbits); -- 2.39.5