public inbox for lvm2-cvs@sourceware.org
help / color / mirror / Atom feed
* LVM2/unit-tests/datastruct bitset_t.c
@ 2010-07-20 15:26 thornber
  0 siblings, 0 replies; 2+ messages in thread
From: thornber @ 2010-07-20 15:26 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	thornber@sourceware.org	2010-07-20 15:26:43

Modified files:
	unit-tests/datastruct: bitset_t.c 

Log message:
	[UNIT-TESTS] add test for the recent dm_bitset_equal() function

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/unit-tests/datastruct/bitset_t.c.diff?cvsroot=lvm2&r1=1.1&r2=1.2

--- LVM2/unit-tests/datastruct/bitset_t.c	2010/07/20 15:25:39	1.1
+++ LVM2/unit-tests/datastruct/bitset_t.c	2010/07/20 15:26:43	1.2
@@ -6,14 +6,10 @@
         NR_BITS = 137
 };
 
-int main(int argc, char **argv)
+static void test_get_next(struct dm_pool *mem)
 {
         int i, j, last, first;
-        dm_bitset_t bs;
-        struct dm_pool *mem = dm_pool_create("bitset test", 1024);
-
-        assert(mem);
-        bs = dm_bitset_create(mem, NR_BITS);
+        dm_bitset_t bs = dm_bitset_create(mem, NR_BITS);
 
         for (i = 0; i < NR_BITS; i++)
                 assert(!dm_bit(bs, i));
@@ -33,7 +29,56 @@
         }
 
         assert(dm_bit_get_next(bs, last) == -1);
-        dm_pool_destroy(mem);
+}
+
+static void bit_flip(dm_bitset_t bs, int bit)
+{
+        int old = dm_bit(bs, bit);
+        if (old)
+                dm_bit_clear(bs, bit);
+        else
+                dm_bit_set(bs, bit);
+}
+
+static void test_equal(struct dm_pool *mem)
+{
+        dm_bitset_t bs1 = dm_bitset_create(mem, NR_BITS);
+        dm_bitset_t bs2 = dm_bitset_create(mem, NR_BITS);
+
+        int i, j;
+        for (i = 0, j = 1; i < NR_BITS; i += j, j++) {
+                dm_bit_set(bs1, i);
+                dm_bit_set(bs2, i);
+        }
+
+        assert(dm_bitset_equal(bs1, bs2));
+        assert(dm_bitset_equal(bs2, bs1));
+
+        for (i = 0; i < NR_BITS; i++) {
+                bit_flip(bs1, i);
+                assert(!dm_bitset_equal(bs1, bs2));
+                assert(!dm_bitset_equal(bs2, bs1));
+
+                assert(dm_bitset_equal(bs1, bs1)); /* comparing with self */
+                bit_flip(bs1, i);
+        }
+}
+
+int main(int argc, char **argv)
+{
+        typedef void (*test_fn)(struct dm_pool *);
+        static test_fn tests[] = {
+                test_get_next,
+                test_equal
+        };
+
+        int i;
+        for (i = 0; i < sizeof(tests) / sizeof(*tests); i++) {
+                struct dm_pool *mem = dm_pool_create("bitset test", 1024);
+                assert(mem);
+                tests[i](mem);
+                dm_pool_destroy(mem);
+        }
 
         return 0;
 }


^ permalink raw reply	[flat|nested] 2+ messages in thread

* LVM2/unit-tests/datastruct bitset_t.c
@ 2010-07-20 15:28 thornber
  0 siblings, 0 replies; 2+ messages in thread
From: thornber @ 2010-07-20 15:28 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	thornber@sourceware.org	2010-07-20 15:28:22

Modified files:
	unit-tests/datastruct: bitset_t.c 

Log message:
	[UNIT-TEST] test for recent dm_bit_and() function

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/unit-tests/datastruct/bitset_t.c.diff?cvsroot=lvm2&r1=1.2&r2=1.3

--- LVM2/unit-tests/datastruct/bitset_t.c	2010/07/20 15:26:43	1.2
+++ LVM2/unit-tests/datastruct/bitset_t.c	2010/07/20 15:28:22	1.3
@@ -64,12 +64,46 @@
         }
 }
 
+static void test_and(struct dm_pool *mem)
+{
+        dm_bitset_t bs1 = dm_bitset_create(mem, NR_BITS);
+        dm_bitset_t bs2 = dm_bitset_create(mem, NR_BITS);
+        dm_bitset_t bs3 = dm_bitset_create(mem, NR_BITS);
+
+        int i, j;
+        for (i = 0, j = 1; i < NR_BITS; i += j, j++) {
+                dm_bit_set(bs1, i);
+                dm_bit_set(bs2, i);
+        }
+
+        dm_bit_and(bs3, bs1, bs2);
+
+        assert(dm_bitset_equal(bs1, bs2));
+        assert(dm_bitset_equal(bs1, bs3));
+        assert(dm_bitset_equal(bs2, bs3));
+
+        dm_bit_clear_all(bs1);
+        dm_bit_clear_all(bs2);
+
+        for (i = 0; i < NR_BITS; i++) {
+                if (i % 2)
+                        dm_bit_set(bs1, i);
+                else
+                        dm_bit_set(bs2, i);
+        }
+
+        dm_bit_and(bs3, bs1, bs2);
+        for (i = 0; i < NR_BITS; i++)
+                assert(!dm_bit(bs3, i));
+}
+
 int main(int argc, char **argv)
 {
         typedef void (*test_fn)(struct dm_pool *);
         static test_fn tests[] = {
                 test_get_next,
-                test_equal
+                test_equal,
+                test_and
         };
 
         int i;


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-07-20 15:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-20 15:26 LVM2/unit-tests/datastruct bitset_t.c thornber
2010-07-20 15:28 thornber

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).