2 * Copyright (C) 2010 Red Hat, Inc. All rights reserved.
4 * This file is part of LVM2.
6 * This copyrighted material is made available to anyone wishing to use,
7 * modify, copy, or redistribute it subject to the terms and conditions
8 * of the GNU General Public License v.2.
10 * You should have received a copy of the GNU General Public License
11 * along with this program; if not, write to the Free Software Foundation,
12 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15 #include "libdevmapper.h"
23 static void test_get_next(struct dm_pool *mem)
25 int i, j, last, first;
26 dm_bitset_t bs = dm_bitset_create(mem, NR_BITS);
28 for (i = 0; i < NR_BITS; i++)
29 assert(!dm_bit(bs, i));
31 for (i = 0, j = 1; i < NR_BITS; i += j, j++)
35 for (i = 0, j = 1; i < NR_BITS; i += j, j++) {
37 last = dm_bit_get_first(bs);
40 last = dm_bit_get_next(bs, last);
45 assert(dm_bit_get_next(bs, last) == -1);
48 static void bit_flip(dm_bitset_t bs, int bit)
50 int old = dm_bit(bs, bit);
52 dm_bit_clear(bs, bit);
57 static void test_equal(struct dm_pool *mem)
59 dm_bitset_t bs1 = dm_bitset_create(mem, NR_BITS);
60 dm_bitset_t bs2 = dm_bitset_create(mem, NR_BITS);
63 for (i = 0, j = 1; i < NR_BITS; i += j, j++) {
68 assert(dm_bitset_equal(bs1, bs2));
69 assert(dm_bitset_equal(bs2, bs1));
71 for (i = 0; i < NR_BITS; i++) {
73 assert(!dm_bitset_equal(bs1, bs2));
74 assert(!dm_bitset_equal(bs2, bs1));
76 assert(dm_bitset_equal(bs1, bs1)); /* comparing with self */
81 static void test_and(struct dm_pool *mem)
83 dm_bitset_t bs1 = dm_bitset_create(mem, NR_BITS);
84 dm_bitset_t bs2 = dm_bitset_create(mem, NR_BITS);
85 dm_bitset_t bs3 = dm_bitset_create(mem, NR_BITS);
88 for (i = 0, j = 1; i < NR_BITS; i += j, j++) {
93 dm_bit_and(bs3, bs1, bs2);
95 assert(dm_bitset_equal(bs1, bs2));
96 assert(dm_bitset_equal(bs1, bs3));
97 assert(dm_bitset_equal(bs2, bs3));
99 dm_bit_clear_all(bs1);
100 dm_bit_clear_all(bs2);
102 for (i = 0; i < NR_BITS; i++) {
109 dm_bit_and(bs3, bs1, bs2);
110 for (i = 0; i < NR_BITS; i++)
111 assert(!dm_bit(bs3, i));
114 int main(int argc, char **argv)
116 typedef void (*test_fn)(struct dm_pool *);
117 static test_fn tests[] = {
124 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++) {
125 struct dm_pool *mem = dm_pool_create("bitset test", 1024);
128 dm_pool_destroy(mem);