diff options
author | Martin Liska <mliska@suse.cz> | 2017-10-16 13:59:39 +0200 |
---|---|---|
committer | Martin Liska <marxin@gcc.gnu.org> | 2017-10-16 11:59:39 +0000 |
commit | a0df14998e226b604a1b4799f602a02090dbdbac (patch) | |
tree | cd4337fe1c8120f2a28bfd1a1f352c705acf21fe | |
parent | 1274f08639511172419f11c86be6c953f0c826a7 (diff) | |
download | gcc-a0df14998e226b604a1b4799f602a02090dbdbac.zip gcc-a0df14998e226b604a1b4799f602a02090dbdbac.tar.gz gcc-a0df14998e226b604a1b4799f602a02090dbdbac.tar.bz2 |
Add selftests for bitmap_set_range.
2017-10-16 Martin Liska <mliska@suse.cz>
* sbitmap.c (bitmap_bit_in_range_p_checking): New function.
(test_set_range): Likewise.
(test_range_functions): Rename to ...
(test_bit_in_range): ... this.
(sbitmap_c_tests): Add new test.
From-SVN: r253785
-rw-r--r-- | gcc/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/sbitmap.c | 60 |
2 files changed, 65 insertions, 3 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 456617b..3a85f8c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2017-10-16 Martin Liska <mliska@suse.cz> + + * sbitmap.c (bitmap_bit_in_range_p_checking): New function. + (test_set_range): Likewise. + (test_range_functions): Rename to ... + (test_bit_in_range): ... this. + (sbitmap_c_tests): Add new test. + 2017-10-16 Tamar Christina <tamar.christina@arm.com> * config/aarch64/arm_neon.h (vdot_u32, vdotq_u32, vdot_s32, vdotq_s32): New. diff --git a/gcc/sbitmap.c b/gcc/sbitmap.c index baef4d0..fdcf539 100644 --- a/gcc/sbitmap.c +++ b/gcc/sbitmap.c @@ -823,11 +823,64 @@ namespace selftest { /* Selftests for sbitmaps. */ +/* Checking function that uses both bitmap_bit_in_range_p and + loop of bitmap_bit_p and verifies consistent results. */ -/* Verify range functions for sbitmap. */ +static bool +bitmap_bit_in_range_p_checking (sbitmap s, unsigned int start, + unsigned end) +{ + bool r1 = bitmap_bit_in_range_p (s, start, end); + bool r2 = false; + + for (unsigned int i = start; i <= end; i++) + if (bitmap_bit_p (s, i)) + { + r2 = true; + break; + } + + ASSERT_EQ (r1, r2); + return r1; +} + +/* Verify bitmap_set_range functions for sbitmap. */ + +static void +test_set_range () +{ + sbitmap s = sbitmap_alloc (16); + bitmap_clear (s); + + bitmap_set_range (s, 0, 1); + ASSERT_TRUE (bitmap_bit_in_range_p_checking (s, 0, 0)); + ASSERT_FALSE (bitmap_bit_in_range_p_checking (s, 1, 15)); + bitmap_set_range (s, 15, 1); + ASSERT_FALSE (bitmap_bit_in_range_p_checking (s, 1, 14)); + ASSERT_TRUE (bitmap_bit_in_range_p_checking (s, 15, 15)); + + s = sbitmap_alloc (1024); + bitmap_clear (s); + bitmap_set_range (s, 512, 1); + ASSERT_FALSE (bitmap_bit_in_range_p_checking (s, 0, 511)); + ASSERT_FALSE (bitmap_bit_in_range_p_checking (s, 513, 1023)); + ASSERT_TRUE (bitmap_bit_in_range_p_checking (s, 512, 512)); + ASSERT_TRUE (bitmap_bit_in_range_p_checking (s, 508, 512)); + ASSERT_TRUE (bitmap_bit_in_range_p_checking (s, 508, 513)); + ASSERT_FALSE (bitmap_bit_in_range_p_checking (s, 508, 511)); + + bitmap_clear (s); + bitmap_set_range (s, 512, 64); + ASSERT_FALSE (bitmap_bit_in_range_p_checking (s, 0, 511)); + ASSERT_FALSE (bitmap_bit_in_range_p_checking (s, 512 + 64, 1023)); + ASSERT_TRUE (bitmap_bit_in_range_p_checking (s, 512, 512)); + ASSERT_TRUE (bitmap_bit_in_range_p_checking (s, 512 + 63, 512 + 63)); +} + +/* Verify bitmap_bit_in_range_p functions for sbitmap. */ static void -test_range_functions () +test_bit_in_range () { sbitmap s = sbitmap_alloc (1024); bitmap_clear (s); @@ -900,7 +953,8 @@ test_range_functions () void sbitmap_c_tests () { - test_range_functions (); + test_set_range (); + test_bit_in_range (); } } // namespace selftest |