diff --git a/Rakefile b/Rakefile index b956ac6..59bbcc4 100644 --- a/Rakefile +++ b/Rakefile @@ -12,7 +12,6 @@ TEST_MODULES = Dir["tests/check_*.c"].map { |n| n[12..-3] } if DEBUG LDFLAGS << ["-g"] CCFLAGS << ["-g -DDEBUG"] - LIBS << ["efence"] end rule 'default' => 'flexnbd' @@ -38,7 +37,7 @@ rule 'flexnbd' => OBJECTS do |t| gcc_link(t.name, t.sources) end -rule(/tests\/check_[a-z]+$/ => [ proc { |target| target+".o" } ]) do |t| +rule(/tests\/check_[a-z]+$/ => [ proc { |target| [target+".o", "util.o"] } ]) do |t| gcc_link(t.name, t.sources + [LIBCHECK]) end diff --git a/tests/check_bitset.c b/tests/check_bitset.c index 8c72c27..c71051c 100644 --- a/tests/check_bitset.c +++ b/tests/check_bitset.c @@ -4,7 +4,7 @@ START_TEST(test_bit_set) { - unsigned char num; + uint64_t num = 0; char *bits = (char*) # #define TEST_BIT_SET(bit, newvalue) \ @@ -15,22 +15,128 @@ START_TEST(test_bit_set) TEST_BIT_SET(1, 3); TEST_BIT_SET(2, 7); TEST_BIT_SET(7, 0x87); + TEST_BIT_SET(63, 0x8000000000000087); } END_TEST START_TEST(test_bit_clear) { - unsigned char num = 255; + uint64_t num = 0xffffffffffffffff; char *bits = (char*) # #define TEST_BIT_CLEAR(bit, newvalue) \ bit_clear(bits, (bit)); \ fail_unless(num == (newvalue), "num was %x instead of %x", num, (newvalue)); - TEST_BIT_CLEAR(0, 0xfe); - TEST_BIT_CLEAR(1, 0xfc); - TEST_BIT_CLEAR(2, 0xf8); - TEST_BIT_CLEAR(7, 0x78); + TEST_BIT_CLEAR(0, 0xfffffffffffffffe); + TEST_BIT_CLEAR(1, 0xfffffffffffffffc); + TEST_BIT_CLEAR(2, 0xfffffffffffffff8); + TEST_BIT_CLEAR(7, 0xffffffffffffff78); + TEST_BIT_CLEAR(63,0x7fffffffffffff78); +} +END_TEST + +START_TEST(test_bit_tests) +{ + uint64_t num = 0x5555555555555555; + char *bits = (char*) # + + fail_unless(bit_has_value(bits, 0, 1), "bit_has_value malfunction"); + fail_unless(bit_has_value(bits, 1, 0), "bit_has_value malfunction"); + fail_unless(bit_has_value(bits, 63, 0), "bit_has_value malfunction"); + fail_unless(bit_is_set(bits, 0), "bit_is_set malfunction"); + fail_unless(bit_is_clear(bits, 1), "bit_is_clear malfunction"); + fail_unless(bit_is_set(bits, 62), "bit_is_set malfunction"); + fail_unless(bit_is_clear(bits, 63), "bit_is_clear malfunction"); +} +END_TEST + +START_TEST(test_bit_ranges) +{ + char buffer[4160]; + uint64_t *longs = (unsigned long*) buffer; + uint64_t i; + + memset(buffer, 0, 4160); + + for (i=0; i<64; i++) { + bit_set_range(buffer, i*64, i); + fail_unless( + longs[i] == (1L<bits; + + bitset_set_range(map,0,50); + ck_assert_int_eq(1, *num); + bitset_set_range(map,99,1); + ck_assert_int_eq(1, *num); + bitset_set_range(map,100,1); + ck_assert_int_eq(3, *num); + bitset_set_range(map,0,800); + ck_assert_int_eq(255, *num); + bitset_set_range(map,1499,2); + ck_assert_int_eq(0xc0ff, *num); + bitset_clear_range(map,1499,2); + ck_assert_int_eq(255, *num); + + *num = 0; + bitset_set_range(map, 1499, 2); + bitset_clear_range(map, 1300, 200); + ck_assert_int_eq(0x8000, *num); + + *num = 0; + bitset_set_range(map, 0, 6400); + ck_assert_int_eq(0xffffffffffffffff, *num); + bitset_clear_range(map, 3200, 400); + ck_assert_int_eq(0xfffffff0ffffffff, *num); } END_TEST @@ -40,6 +146,10 @@ Suite* bitset_suite() TCase *tc_core = tcase_create("bitset"); tcase_add_test(tc_core, test_bit_set); tcase_add_test(tc_core, test_bit_clear); + tcase_add_test(tc_core, test_bit_tests); + tcase_add_test(tc_core, test_bit_ranges); + tcase_add_test(tc_core, test_bit_runs); + tcase_add_test(tc_core, test_bitset); suite_add_tcase(s, tc_core); return s; @@ -55,3 +165,4 @@ int main(void) srunner_free(sr); return (number_failed == 0) ? 0 : 1; } +