From dd6758d543e7672ed5cefa0dc9e1749c2a66b8db Mon Sep 17 00:00:00 2001 From: Kevin J Bowers Date: Sun, 16 Apr 2023 13:23:10 -0500 Subject: [PATCH] Unit test coverage for map_giant iterator and fix --- src/util/tmpl/fd_map_giant.c | 2 +- src/util/tmpl/test_map_giant.c | 35 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/util/tmpl/fd_map_giant.c b/src/util/tmpl/fd_map_giant.c index 07cd3f57a7..9b40a3f8dd 100644 --- a/src/util/tmpl/fd_map_giant.c +++ b/src/util/tmpl/fd_map_giant.c @@ -453,7 +453,7 @@ MAP_(iter_done)( MAP_T const * join, FD_FN_PURE static inline MAP_(iter_t) MAP_(iter_next)( MAP_T const * join, MAP_(iter_t) ele_rem ) { - for( ; ele_rem; ele_rem-- ) if( !MAP_(private_unbox_tag)( join[ ele_rem-1UL ].MAP_NEXT ) ) break; + for( ele_rem--; ele_rem; ele_rem-- ) if( !MAP_(private_unbox_tag)( join[ ele_rem-1UL ].MAP_NEXT ) ) break; return ele_rem; } diff --git a/src/util/tmpl/test_map_giant.c b/src/util/tmpl/test_map_giant.c index f61625f473..ab1c4f70a6 100644 --- a/src/util/tmpl/test_map_giant.c +++ b/src/util/tmpl/test_map_giant.c @@ -4,6 +4,7 @@ struct pair { ulong mykey; ulong mynext; uint val; + uint tag; }; typedef struct pair pair_t; @@ -54,6 +55,7 @@ main( int argc, ref[idx].mykey = (1UL<<63) | (fd_rng_ulong( rng )<<9) | idx; /* Every map key is unique and non-zero */ ref[idx].mynext = fd_rng_ulong( rng ); ref[idx].val = fd_rng_uint( rng ); + ref[idx].tag = 0U; tst[idx] = ref[idx]; } sort_pair_inplace( ref, max ); @@ -95,6 +97,8 @@ main( int argc, FD_TEST( !map_verify( map ) ); + uint tag = 0U; + for( ulong iter=0UL; itertag!=tag ); + p0->tag = tag; + cnt++; + } + FD_TEST( cnt==i ); + ulong ki = tst[i].mykey; uint vi = tst[i].val; @@ -133,6 +152,22 @@ main( int argc, /* Make sure map is full at this point */ FD_TEST( map_is_full( map ) ); + do { + tag++; + ulong cnt = 0UL; + for( map_iter_t iter = map_iter_init( map ); !map_iter_done( map, iter ); iter = map_iter_next( map, iter ) ) { + pair_t * p0 = map_iter_ele( map, iter ); + pair_t const * p1 = map_iter_ele_const( map, iter ); + FD_TEST( p0 ); + FD_TEST( p1 ); + FD_TEST( p1==(pair_t const *)p0 ); + FD_TEST( p0->tag!=tag ); + p0->tag = tag; + cnt++; + } + FD_TEST( cnt==max ); + } while(0); + /* Generate a different randomized deletion order */ shuffle_pair( rng, tst, max );