diff options
author | Joe Thornber <thornber@redhat.com> | 2010-07-20 15:25:39 +0000 |
---|---|---|
committer | Joe Thornber <thornber@redhat.com> | 2010-07-20 15:25:39 +0000 |
commit | 66392e66609b0bc47ab46df989d1cced735f94ad (patch) | |
tree | be32fafa8c6209f574ababafe03c3d629e09f626 /unit-tests | |
parent | 15106c50644ec949c27d616720421bbfc16c7f80 (diff) | |
download | lvm2-66392e66609b0bc47ab46df989d1cced735f94ad.tar.gz lvm2-66392e66609b0bc47ab46df989d1cced735f94ad.tar.xz lvm2-66392e66609b0bc47ab46df989d1cced735f94ad.zip |
Add a unit test for the recent changes to dm_bit_get_next()
Diffstat (limited to 'unit-tests')
-rw-r--r-- | unit-tests/datastruct/Makefile.in | 32 | ||||
-rw-r--r-- | unit-tests/datastruct/TESTS | 1 | ||||
-rw-r--r-- | unit-tests/datastruct/bitset_t.c | 40 |
3 files changed, 73 insertions, 0 deletions
diff --git a/unit-tests/datastruct/Makefile.in b/unit-tests/datastruct/Makefile.in new file mode 100644 index 00000000..e99198db --- /dev/null +++ b/unit-tests/datastruct/Makefile.in @@ -0,0 +1,32 @@ +# +# Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. +# Copyright (C) 2004-2010 Red Hat, Inc. All rights reserved. +# +# This file is part of LVM2. +# +# This copyrighted material is made available to anyone wishing to use, +# modify, copy, or redistribute it subject to the terms and conditions +# of the GNU General Public License v.2. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +top_builddir = @top_builddir@ + +SOURCES=\ + bitset_t.c + +TARGETS=\ + bitset_t + +include $(top_builddir)/make.tmpl + +INCLUDES += -I$(top_srcdir)/libdm +DM_DEPS = $(top_builddir)/libdm/libdevmapper.so +DM_LIBS = -ldevmapper $(LIBS) + +bitset_t: bitset_t.o $(DM_DEPS) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ bitset_t.o $(DM_LIBS) diff --git a/unit-tests/datastruct/TESTS b/unit-tests/datastruct/TESTS new file mode 100644 index 00000000..ba88fb78 --- /dev/null +++ b/unit-tests/datastruct/TESTS @@ -0,0 +1 @@ +bitset iteration:$TEST_TOOL ./bitset_t
\ No newline at end of file diff --git a/unit-tests/datastruct/bitset_t.c b/unit-tests/datastruct/bitset_t.c new file mode 100644 index 00000000..380944d7 --- /dev/null +++ b/unit-tests/datastruct/bitset_t.c @@ -0,0 +1,40 @@ +#include "libdevmapper.h" + +#include <assert.h> + +enum { + NR_BITS = 137 +}; + +int main(int argc, char **argv) +{ + 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); + + for (i = 0; i < NR_BITS; i++) + assert(!dm_bit(bs, i)); + + for (i = 0, j = 1; i < NR_BITS; i += j, j++) + dm_bit_set(bs, i); + + first = 1; + for (i = 0, j = 1; i < NR_BITS; i += j, j++) { + if (first) { + last = dm_bit_get_first(bs); + first = 0; + } else + last = dm_bit_get_next(bs, last); + + assert(last == i); + } + + assert(dm_bit_get_next(bs, last) == -1); + dm_pool_destroy(mem); + + return 0; +} + |