bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 5/6] bitset: tests: try harder to break it


From: Akim Demaille
Subject: [PATCH 5/6] bitset: tests: try harder to break it
Date: Thu, 19 Nov 2020 07:01:54 +0100

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 2bc68b9dc..cd595f41d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2020-11-19  Akim Demaille  <akim@lrde.epita.fr>
+
+       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  <akim@lrde.epita.fr>
 
        bitset: use ffs where possible in the vector implementation
diff --git a/tests/test-bitset.c b/tests/test-bitset.c
index fc0c6fbe9..9a2d7c521 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.29.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]