LCOV - code coverage report
Current view: top level - app/shared - fd_tile_unit_test.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 45 74 60.8 %
Date: 2025-09-18 04:41:32 Functions: 1 1 100.0 %

          Line data    Source code
       1             : #include "fd_tile_unit_test.h"
       2             : #include "../../app/platform/fd_file_util.h"
       3             : #include "../../app/shared/fd_obj_callbacks.c"
       4             : #include "../../app/firedancer/callbacks.c"
       5             : #include "../../app/shared/fd_action.h"
       6             : #include <errno.h>    /* errno */
       7             : #include <sys/mman.h> /* MAP_FAILED */
       8             : 
       9             : extern fd_topo_obj_callbacks_t fd_obj_cb_mcache;
      10             : extern fd_topo_obj_callbacks_t fd_obj_cb_dcache;
      11             : extern fd_topo_obj_callbacks_t fd_obj_cb_fseq;
      12             : extern fd_topo_obj_callbacks_t fd_obj_cb_metrics;
      13             : extern fd_topo_obj_callbacks_t fd_obj_cb_opaque;
      14             : extern fd_topo_obj_callbacks_t fd_obj_cb_dbl_buf;
      15             : extern fd_topo_obj_callbacks_t fd_obj_cb_neigh4_hmap;
      16             : extern fd_topo_obj_callbacks_t fd_obj_cb_fib4;
      17             : extern fd_topo_obj_callbacks_t fd_obj_cb_keyswitch;
      18             : extern fd_topo_obj_callbacks_t fd_obj_cb_tile;
      19             : extern fd_topo_obj_callbacks_t fd_obj_cb_store;
      20             : extern fd_topo_obj_callbacks_t fd_obj_cb_fec_sets;
      21             : extern fd_topo_obj_callbacks_t fd_obj_cb_txncache;
      22             : extern fd_topo_obj_callbacks_t fd_obj_cb_exec_spad;
      23             : extern fd_topo_obj_callbacks_t fd_obj_cb_banks;
      24             : extern fd_topo_obj_callbacks_t fd_obj_cb_funk;
      25             : extern fd_topo_obj_callbacks_t fd_obj_cb_bank_hash_cmp;
      26             : 
      27             : fd_topo_obj_callbacks_t * CALLBACKS[] = {
      28             :   &fd_obj_cb_mcache,
      29             :   &fd_obj_cb_dcache,
      30             :   &fd_obj_cb_fseq,
      31             :   &fd_obj_cb_metrics,
      32             :   &fd_obj_cb_opaque,
      33             :   &fd_obj_cb_dbl_buf,
      34             :   &fd_obj_cb_neigh4_hmap,
      35             :   &fd_obj_cb_fib4,
      36             :   &fd_obj_cb_keyswitch,
      37             :   &fd_obj_cb_tile,
      38             :   &fd_obj_cb_store,
      39             :   &fd_obj_cb_fec_sets,
      40             :   &fd_obj_cb_txncache,
      41             :   &fd_obj_cb_exec_spad,
      42             :   &fd_obj_cb_banks,
      43             :   &fd_obj_cb_funk,
      44             :   &fd_obj_cb_bank_hash_cmp,
      45             :   NULL,
      46             : };
      47             : 
      48             : /* Dummy tiles to fill up the topology. It works with both
      49             :    fdctl's and firedancer's topologies. */
      50             : fd_topo_run_tile_t dummy_tile_net    = { .name = "net"    };
      51             : fd_topo_run_tile_t dummy_tile_netlnk = { .name = "netlnk" };
      52             : fd_topo_run_tile_t dummy_tile_sock   = { .name = "sock"   };
      53             : fd_topo_run_tile_t dummy_tile_quic   = { .name = "quic"   };
      54             : fd_topo_run_tile_t dummy_tile_bundle = { .name = "bundle" };
      55             : fd_topo_run_tile_t dummy_tile_verify = { .name = "verify" };
      56             : fd_topo_run_tile_t dummy_tile_dedup  = { .name = "dedup"  };
      57             : fd_topo_run_tile_t dummy_tile_pack   = { .name = "pack"   };
      58             : fd_topo_run_tile_t dummy_tile_shred  = { .name = "shred"  };
      59             : fd_topo_run_tile_t dummy_tile_sign   = { .name = "sign"   };
      60             : fd_topo_run_tile_t dummy_tile_metric = { .name = "metric" };
      61             : fd_topo_run_tile_t dummy_tile_cswtch = { .name = "cswtch" };
      62             : fd_topo_run_tile_t dummy_tile_gui    = { .name = "gui"    };
      63             : fd_topo_run_tile_t dummy_tile_plugin = { .name = "plugin" };
      64             : fd_topo_run_tile_t dummy_tile_bencho = { .name = "bencho" };
      65             : fd_topo_run_tile_t dummy_tile_benchg = { .name = "benchg" };
      66             : fd_topo_run_tile_t dummy_tile_benchs = { .name = "benchs" };
      67             : fd_topo_run_tile_t dummy_tile_pktgen = { .name = "pktgen" };
      68             : fd_topo_run_tile_t dummy_tile_resolv = { .name = "resolv" };
      69             : fd_topo_run_tile_t dummy_tile_poh    = { .name = "poh"    };
      70             : fd_topo_run_tile_t dummy_tile_bank   = { .name = "bank"   };
      71             : fd_topo_run_tile_t dummy_tile_store  = { .name = "store"  };
      72             : fd_topo_run_tile_t dummy_tile_gossvf = { .name = "gossvf" };
      73             : fd_topo_run_tile_t dummy_tile_gossip = { .name = "gossip" };
      74             : fd_topo_run_tile_t dummy_tile_repair = { .name = "repair" };
      75             : fd_topo_run_tile_t dummy_tile_send   = { .name = "send"   };
      76             : fd_topo_run_tile_t dummy_tile_replay = { .name = "replay" };
      77             : fd_topo_run_tile_t dummy_tile_exec   = { .name = "exec"   };
      78             : fd_topo_run_tile_t dummy_tile_tower  = { .name = "tower"  };
      79             : fd_topo_run_tile_t dummy_tile_writer = { .name = "writer" };
      80             : fd_topo_run_tile_t dummy_tile_rpcsrv = { .name = "rpcsrv" };
      81             : fd_topo_run_tile_t dummy_tile_snaprd = { .name = "snaprd" };
      82             : fd_topo_run_tile_t dummy_tile_snapdc = { .name = "snapdc" };
      83             : fd_topo_run_tile_t dummy_tile_snapin = { .name = "snapin" };
      84             : fd_topo_run_tile_t dummy_tile_arch_f = { .name = "arch_f" };
      85             : fd_topo_run_tile_t dummy_tile_arch_w = { .name = "arch_w" };
      86             : fd_topo_run_tile_t dummy_tile_scap   = { .name = "scap"   };
      87             : fd_topo_run_tile_t dummy_tile_genesi = { .name = "genesi" };
      88             : fd_topo_run_tile_t dummy_tile_ipecho = { .name = "ipecho" };
      89             : 
      90             : fd_topo_run_tile_t * TILES[] = {
      91             :   NULL, /* Placeholder for tile under test (it must appear first). */
      92             :   &dummy_tile_net,
      93             :   &dummy_tile_netlnk,
      94             :   &dummy_tile_sock,
      95             :   &dummy_tile_quic,
      96             :   &dummy_tile_bundle,
      97             :   &dummy_tile_verify,
      98             :   &dummy_tile_dedup,
      99             :   &dummy_tile_pack,
     100             :   &dummy_tile_shred,
     101             :   &dummy_tile_sign,
     102             :   &dummy_tile_metric,
     103             :   &dummy_tile_cswtch,
     104             :   &dummy_tile_gui,
     105             :   &dummy_tile_plugin,
     106             :   &dummy_tile_bencho,
     107             :   &dummy_tile_benchg,
     108             :   &dummy_tile_benchs,
     109             :   &dummy_tile_pktgen,
     110             :   &dummy_tile_resolv,
     111             :   &dummy_tile_poh,
     112             :   &dummy_tile_bank,
     113             :   &dummy_tile_store,
     114             :   &dummy_tile_gossvf,
     115             :   &dummy_tile_gossip,
     116             :   &dummy_tile_repair,
     117             :   &dummy_tile_send,
     118             :   &dummy_tile_replay,
     119             :   &dummy_tile_exec,
     120             :   &dummy_tile_tower,
     121             :   &dummy_tile_writer,
     122             :   &dummy_tile_rpcsrv,
     123             :   &dummy_tile_snaprd,
     124             :   &dummy_tile_snapdc,
     125             :   &dummy_tile_snapin,
     126             :   &dummy_tile_arch_f,
     127             :   &dummy_tile_arch_w,
     128             :   &dummy_tile_scap,
     129             :   &dummy_tile_genesi,
     130             :   &dummy_tile_ipecho,
     131             :   NULL,
     132             : };
     133             : 
     134             : action_t * ACTIONS[] = {
     135             :   NULL,
     136             : };
     137             : 
     138             : fd_topo_tile_t *
     139             : fd_tile_unit_test_init( char const *         default_topo_config_path,
     140             :                         char const *         override_topo_config_path,
     141             :                         char const *         user_topo_config_path,
     142             :                         int                  netns,
     143             :                         int                  is_firedancer,
     144             :                         int                  is_local_cluster,
     145             :                         void (*fd_topo_initialize_)(config_t *),
     146             :                         fd_topo_run_tile_t * topo_run_tile,
     147           6 :                         config_t *           out_config ) {
     148             :   /* The tile-under-test must be placed at index 0 in TILES. */
     149           6 :   TILES[0] = topo_run_tile;
     150             : 
     151             :   /* Default topo config. */
     152           6 :   char * default_config = NULL;
     153           6 :   ulong default_config_sz = 0UL;
     154           6 :   if( FD_UNLIKELY( default_topo_config_path==NULL ) ) {
     155           0 :     FD_LOG_WARNING(( "undefined default_config_path" ));
     156           0 :     return NULL;
     157           6 :   };
     158           6 :   default_config = fd_file_util_read_all( default_topo_config_path, &default_config_sz );
     159           6 :   if( FD_UNLIKELY( default_config==MAP_FAILED ) ) {
     160           0 :     FD_LOG_WARNING(( "failed to read default config file `%s` (%d-%s)", default_topo_config_path, errno, fd_io_strerror( errno ) ));
     161           0 :     return NULL;
     162           0 :   }
     163             : 
     164             :   /* Override topo config. */
     165           6 :   char * override_config = NULL;
     166           6 :   ulong override_config_sz = 0UL;
     167           6 :   if( FD_LIKELY( override_topo_config_path ) ) {
     168           0 :     override_config = fd_file_util_read_all( override_topo_config_path, &override_config_sz );
     169           0 :     if( FD_UNLIKELY( override_config==MAP_FAILED ) ){
     170           0 :       FD_LOG_WARNING(( "failed to read user config file `%s` (%d-%s)", override_topo_config_path, errno, fd_io_strerror( errno ) ));
     171           0 :       return NULL;
     172           0 :     }
     173           0 :   }
     174             : 
     175             :   /* User topo config. */
     176           6 :   char * user_config = NULL;
     177           6 :   ulong user_config_sz = 0UL;
     178           6 :   if( FD_LIKELY( user_topo_config_path ) ) {
     179           0 :     user_config = fd_file_util_read_all( user_topo_config_path, &user_config_sz );
     180           0 :     if( FD_UNLIKELY( user_config==MAP_FAILED ) ){
     181           0 :       FD_LOG_WARNING(( "failed to read user config file `%s` (%d-%s)", user_topo_config_path, errno, fd_io_strerror( errno ) ));
     182           0 :       return NULL;
     183           0 :     }
     184           0 :   }
     185             : 
     186             :   /* Load config. */
     187           6 :   fd_memset( out_config, 0, sizeof( config_t ) ); /* This step is needed (see w->wksp check). */
     188             : 
     189           6 :   fd_config_load( is_firedancer, netns, is_local_cluster,
     190           6 :                   default_config, default_config_sz,
     191           6 :                   override_config, override_topo_config_path, override_config_sz,
     192           6 :                   user_config, user_config_sz, user_topo_config_path,
     193           6 :                   out_config );
     194             : 
     195             :   /* Initialize topo. */
     196           6 :   fd_topo_initialize_( out_config );
     197             : 
     198             :   /* Process test tile. */
     199           6 :   fd_topo_tile_t * test_tile = NULL;
     200          42 :   for( ulong i=0; i<out_config->topo.tile_cnt; i++ ) {
     201          42 :     if( !strcmp( out_config->topo.tiles[ i ].name, topo_run_tile->name ) ) {
     202           6 :       test_tile = &out_config->topo.tiles[ i ];
     203         198 :       for( ulong j=0; j<test_tile->uses_obj_cnt; j++ ) {
     204         192 :         if( FD_UNLIKELY( test_tile->uses_obj_id[j] >= out_config->topo.obj_cnt ) ) {
     205           0 :           FD_LOG_WARNING(( "test_tile->uses_obj_id[%lu] %lu exceeds config->topo.obj_cnt %lu", j, test_tile->uses_obj_id[j], out_config->topo.obj_cnt ));
     206           0 :           return NULL;
     207           0 :         }
     208         192 :         fd_topo_obj_t * o = &out_config->topo.objs[ test_tile->uses_obj_id[j] ];
     209         192 :         fd_topo_wksp_t * w = &out_config->topo.workspaces[ o->wksp_id ];
     210         192 :         if( FD_UNLIKELY( w->wksp != NULL ) ) continue; /* the workspace has already been initialized */
     211          57 :         FD_LOG_NOTICE(( "Creating workspace %s (--page-cnt %lu, --page-sz %lu, --cpu-idx %lu)", w->name, w->page_cnt, w->page_sz, fd_shmem_cpu_idx( w->numa_idx ) ));
     212          57 :         ulong cpu_idx = fd_shmem_cpu_idx( w->numa_idx );
     213          57 :         w->wksp = fd_wksp_new_anon( w->name, w->page_sz, 1UL, &w->page_cnt, &cpu_idx, 0U, w->part_max );
     214             :         // w->wksp = fd_wksp_new_anonymous( w->page_sz,  w->page_cnt, fd_shmem_cpu_idx( w->numa_idx ), w->name, 0UL );
     215          57 :         if( FD_UNLIKELY( w->wksp==NULL ) ) {
     216           0 :           FD_LOG_WARNING(( "w->wksp==NULL for o->wksp_id %lu for test_tile->uses_obj_id[%lu] %lu", o->wksp_id, j, test_tile->uses_obj_id[j] ));
     217           0 :           return NULL;
     218           0 :         }
     219          57 :         ulong offset = fd_wksp_alloc( w->wksp, fd_topo_workspace_align(), w->known_footprint, 1UL );
     220             :         /* TODO assert offset==gaddr_lo ? */
     221          57 :         if( FD_UNLIKELY( !offset ) ) {
     222           0 :           FD_LOG_WARNING(( "fd_wksp_alloc failed with offset %lu", offset ));
     223           0 :           return NULL;
     224           0 :         }
     225          57 :         fd_topo_wksp_new( &out_config->topo, w, CALLBACKS );
     226          57 :       }
     227           6 :       break;
     228           6 :     }
     229          42 :   }
     230           6 :   if( FD_UNLIKELY( test_tile==NULL ) ) {
     231           0 :     FD_LOG_WARNING(( "test_tile==NULL" ));
     232           0 :     return NULL;
     233           0 :   }
     234           6 :   fd_topo_fill_tile( &out_config->topo, test_tile );
     235           6 :   return test_tile;
     236           6 : }

Generated by: LCOV version 1.14