LCOV - code coverage report
Current view: top level - util/spad - fd_spad.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 63 63 100.0 %
Date: 2024-11-13 11:58:15 Functions: 11 11 100.0 %

          Line data    Source code
       1             : #include "fd_spad.h"
       2             : #include "../log/fd_log.h"
       3             : 
       4             : int
       5      187479 : fd_spad_verify( fd_spad_t const * spad ) {
       6             : 
       7      749916 : # define TEST(c) do { if( FD_UNLIKELY( !(c) ) ) { FD_LOG_WARNING(( "FAIL: %s", #c )); return -1; } } while(0)
       8             : 
       9             :   /* Test spad is a current local join */
      10             : 
      11      187479 :   TEST( spad!=NULL );
      12      187479 :   TEST( spad->magic==FD_SPAD_MAGIC );
      13             : 
      14             :   /* Extract the metadata */
      15             : 
      16      187479 :   ulong frame_free = spad->frame_free; TEST( frame_free<=FD_SPAD_FRAME_MAX );
      17      187479 :   ulong mem_used   = spad->mem_used;   TEST( mem_used  <=spad->mem_max     );
      18             : 
      19             :   /* If there are no frames, there should be no memory used.  Otherwise,
      20             :      make sure the mem_used and frames are properly ordered starting
      21             :      from 0. */
      22             : 
      23      187479 :   if( frame_free==FD_SPAD_FRAME_MAX ) FD_TEST( !mem_used );
      24      168108 :   else {
      25      168108 :     FD_TEST( mem_used >= spad->off[ frame_free ] );
      26     1589046 :     for( ulong idx=frame_free; idx<FD_SPAD_FRAME_MAX-1UL; idx++ ) FD_TEST( spad->off[ idx ]>=spad->off[ idx+1UL ] );
      27      168108 :     FD_TEST( !spad->off[ FD_SPAD_FRAME_MAX-1UL] );
      28      168108 :   }
      29             : 
      30      187479 : # undef TEST
      31             : 
      32      187479 :   return 0;
      33      187479 : }
      34             : 
      35             : ulong
      36             : fd_spad_alloc_max_debug( fd_spad_t const * spad,
      37     2606853 :                          ulong             align ) {
      38     2606853 :   if( FD_UNLIKELY( !fd_spad_frame_used( spad )               ) ) FD_LOG_CRIT(( "not in a frame" ));
      39     2606853 :   if( FD_UNLIKELY( (!!align) & (!fd_ulong_is_pow2( align ) ) ) ) FD_LOG_CRIT(( "bad align"      ));
      40     2606853 :   return fd_spad_alloc_max( spad, align );
      41     2606853 : }
      42             : 
      43             : void *
      44           6 : fd_spad_frame_lo_debug( fd_spad_t * spad ) {
      45           6 :   if( FD_UNLIKELY( !fd_spad_frame_used( spad ) ) ) FD_LOG_CRIT(( "not in a frame" ));
      46           6 :   return fd_spad_frame_lo( spad );
      47           6 : }
      48             : 
      49             : void *
      50           3 : fd_spad_frame_hi_debug( fd_spad_t * spad ) {
      51           3 :   if( FD_UNLIKELY( !fd_spad_frame_used( spad ) ) ) FD_LOG_CRIT(( "not in a frame" ));
      52           3 :   return fd_spad_frame_hi( spad );
      53           3 : }
      54             : 
      55             : void
      56     1629213 : fd_spad_push_debug( fd_spad_t * spad ) {
      57     1629213 :   if( FD_UNLIKELY( !fd_spad_frame_free( spad ) ) ) FD_LOG_CRIT(( "too many frames" ));
      58     1629213 :   fd_spad_push( spad );
      59     1629213 : }
      60             : 
      61             : void
      62     1623216 : fd_spad_pop_debug( fd_spad_t * spad ) {
      63     1623216 :   if( FD_UNLIKELY( !fd_spad_frame_used( spad ) ) ) FD_LOG_CRIT(( "not in a frame" ));
      64     1623216 :   fd_spad_pop( spad );
      65     1623216 : }
      66             : 
      67             : void *
      68             : fd_spad_alloc_debug( fd_spad_t * spad,
      69             :                      ulong       align,
      70     1120002 :                      ulong       sz ) {
      71     1120002 :   if( FD_UNLIKELY( !fd_spad_frame_used( spad )               ) ) FD_LOG_CRIT(( "not in a frame"  ));
      72     1120002 :   if( FD_UNLIKELY( (!!align) & (!fd_ulong_is_pow2( align ) ) ) ) FD_LOG_CRIT(( "bad align"       ));
      73     1120002 :   if( FD_UNLIKELY( fd_spad_alloc_max( spad, align )<sz       ) ) FD_LOG_CRIT(( "bad sz"          ));
      74     1120002 :   return fd_spad_alloc( spad, align, sz );
      75     1120002 : }
      76             : 
      77             : void
      78             : fd_spad_trim_debug( fd_spad_t * spad,
      79     2237808 :                     void *      hi ) {
      80     2237808 :   if( FD_UNLIKELY( !fd_spad_frame_used( spad )                 ) ) FD_LOG_CRIT(( "not in a frame"    ));
      81     2237808 :   if( FD_UNLIKELY( ((ulong)fd_spad_frame_lo( spad ))>(ulong)hi ) ) FD_LOG_CRIT(( "hi below frame_lo" ));
      82     2237808 :   if( FD_UNLIKELY( ((ulong)fd_spad_frame_hi( spad ))<(ulong)hi ) ) FD_LOG_CRIT(( "hi above frame_hi" ));
      83     2237808 :   fd_spad_trim( spad, hi );
      84     2237808 : }
      85             : 
      86             : void *
      87             : fd_spad_prepare_debug( fd_spad_t * spad,
      88             :                        ulong       align,
      89     1676562 :                        ulong       max ) {
      90     1676562 :   if( FD_UNLIKELY( !fd_spad_frame_used( spad )               ) ) FD_LOG_CRIT(( "not in a frame" ));
      91     1676562 :   if( FD_UNLIKELY( (!!align) & (!fd_ulong_is_pow2( align ) ) ) ) FD_LOG_CRIT(( "bad align"      ));
      92     1676562 :   if( FD_UNLIKELY( fd_spad_alloc_max( spad, align )<max      ) ) FD_LOG_CRIT(( "bad max"        ));
      93     1676562 :   return fd_spad_prepare( spad, align, max );
      94     1676562 : }
      95             : 
      96             : void
      97      558702 : fd_spad_cancel_debug( fd_spad_t * spad ) {
      98      558702 :   if( FD_UNLIKELY( !fd_spad_frame_used( spad ) ) ) FD_LOG_CRIT(( "not in a frame" ));
      99             :   /* FIXME: check if in prepare?  needs extra state and a lot of extra
     100             :      tracking that state */
     101      558702 :   fd_spad_cancel( spad );
     102      558702 : }
     103             : 
     104             : void
     105             : fd_spad_publish_debug( fd_spad_t * spad,
     106     1117860 :                        ulong       sz ) {
     107     1117860 :   if( FD_UNLIKELY( !fd_spad_frame_used( spad )       ) ) FD_LOG_CRIT(( "not in a frame" ));
     108     1117860 :   if( FD_UNLIKELY( fd_spad_alloc_max( spad, 1UL )<sz ) ) FD_LOG_CRIT(( "bad sz"         ));
     109             :   /* FIXME: check if in prepare?  needs extra state and a lot of extra
     110             :      tracking that state */
     111     1117860 :   fd_spad_publish( spad, sz );
     112     1117860 : }

Generated by: LCOV version 1.14