LCOV - code coverage report
Current view: top level - flamenco/capture - fd_solcap_dump.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 44 0.0 %
Date: 2024-11-13 11:58:15 Functions: 0 3 0.0 %

          Line data    Source code
       1             : //  --file d2.bin --type vote_state_versioned
       2             : 
       3             : #define _GNU_SOURCE
       4             : #include <dlfcn.h>
       5             : 
       6             : #include "../fd_flamenco.h"
       7             : #include "../runtime/fd_runtime.h"
       8             : #include "../types/fd_types_yaml.h"
       9             : 
      10             : #include <errno.h>
      11             : #include <stdio.h>
      12             : #include <sys/stat.h> /* mkdir(2) */
      13             : #include <fcntl.h>    /* open(2) */
      14             : #include <unistd.h>   /* close(2) */
      15             : 
      16             : static void
      17           0 : usage( void ) {
      18           0 :   fprintf( stderr,
      19           0 :     "Usage: fd_solcap_dump --type <type> --file {FILE}\n"
      20           0 :     "\n"
      21           0 :     "dumps the contents of an account.\n"
      22           0 :     "\n"
      23           0 :     "Options:\n"
      24           0 :     "  --file         name                      filename to read\n"
      25           0 :     "  --type         <type>                    type of the data\n"
      26           0 :     "\n" );
      27           0 : }
      28             : 
      29           0 : ulong foo_lkasjdf( void ) {
      30           0 :   return fd_vote_state_versioned_footprint();
      31           0 : }
      32             : 
      33           0 : int fd_flamenco_type_lookup(const char *type, fd_types_funcs_t * t) {
      34           0 :   char fp[255];
      35             : 
      36           0 : #pragma GCC diagnostic ignored "-Wpedantic"
      37           0 :   sprintf(fp, "%s_footprint", type);
      38           0 :   t->footprint_fun = dlsym(RTLD_DEFAULT, fp);
      39             : 
      40           0 :   sprintf(fp, "%s_align", type);
      41           0 :   t->align_fun =  dlsym(RTLD_DEFAULT, fp);
      42             : 
      43           0 :   sprintf(fp, "%s_new", type);
      44           0 :   t->new_fun =  dlsym(RTLD_DEFAULT, fp);
      45             : 
      46           0 :   sprintf(fp, "%s_decode", type);
      47           0 :   t->decode_fun =  dlsym(RTLD_DEFAULT, fp);
      48             : 
      49           0 :   sprintf(fp, "%s_walk", type);
      50           0 :   t->walk_fun =  dlsym(RTLD_DEFAULT, fp);
      51             : 
      52           0 :   sprintf(fp, "%s_encode", type);
      53           0 :   t->encode_fun =  dlsym(RTLD_DEFAULT, fp);
      54             : 
      55           0 :   sprintf(fp, "%s_destroy", type);
      56           0 :   t->destroy_fun =  dlsym(RTLD_DEFAULT, fp);
      57             : 
      58           0 :   sprintf(fp, "%s_size", type);
      59           0 :   t->size_fun =  dlsym(RTLD_DEFAULT, fp);
      60             : 
      61           0 :   if ((  t->footprint_fun == NULL) ||
      62           0 :       (  t->align_fun == NULL) ||
      63           0 :       (  t->new_fun == NULL) ||
      64           0 :       (  t->decode_fun == NULL) ||
      65           0 :       (  t->walk_fun == NULL) ||
      66           0 :       (  t->encode_fun == NULL) ||
      67           0 :       (  t->destroy_fun == NULL) ||
      68           0 :       (  t->size_fun == NULL))
      69           0 :     return -1;
      70           0 :   return 0;
      71           0 : }
      72             : 
      73             : int
      74             : main( int     argc,
      75             :       char ** argv ) {
      76             :   fd_boot( &argc, &argv );
      77             :   fd_flamenco_boot( &argc, &argv );
      78             : 
      79             :   /* Command line handling */
      80             : 
      81             :   for( int i=1; i<argc; i++ ) {
      82             :     if( 0==strcmp( argv[i], "--help" ) ) {
      83             :       usage();
      84             :       return 0;
      85             :     }
      86             :   }
      87             : 
      88             :   char const * _page_sz   = fd_env_strip_cmdline_cstr ( &argc, &argv, "--page-sz",    NULL, "gigantic" );
      89             :   ulong        page_cnt   = fd_env_strip_cmdline_ulong( &argc, &argv, "--page-cnt",   NULL, 2UL        );
      90             :   ulong        scratch_mb = fd_env_strip_cmdline_ulong( &argc, &argv, "--scratch-mb", NULL, 1024UL     );
      91             :   char const * type       = fd_env_strip_cmdline_cstr ( &argc, &argv, "--type",       NULL, NULL       );
      92             :   char const * file       = fd_env_strip_cmdline_cstr ( &argc, &argv, "--file",       NULL, NULL       );
      93             : 
      94             :   if ((NULL == type) || (NULL == file)) {
      95             :     usage();
      96             :     return 0;
      97             :   }
      98             : 
      99             :   ulong page_sz = fd_cstr_to_shmem_page_sz( _page_sz );
     100             : 
     101             :   fd_wksp_t * wksp = fd_wksp_new_anonymous( page_sz, page_cnt, fd_log_cpu_id(), "wksp", 0UL );
     102             :   if( FD_UNLIKELY( !wksp ) ) FD_LOG_ERR(( "fd_wksp_new_anonymous() failed" ));
     103             : 
     104             :   /* Create scratch allocator */
     105             : 
     106             :   ulong  smax = scratch_mb << 20;
     107             :   void * smem = fd_wksp_alloc_laddr( wksp, fd_scratch_smem_align(), smax, 1UL );
     108             :   if( FD_UNLIKELY( !smem ) ) FD_LOG_ERR(( "Failed to alloc scratch mem" ));
     109             : # define SCRATCH_DEPTH (4UL)
     110             :   ulong fmem[ SCRATCH_DEPTH ] __attribute((aligned(FD_SCRATCH_FMEM_ALIGN)));
     111             :   fd_scratch_attach( smem, fmem, smax, SCRATCH_DEPTH );
     112             :   fd_scratch_push();
     113             : 
     114             :   /* Read file */
     115             : 
     116             :   uchar * data;
     117             :   ulong   data_sz;
     118             :   do {
     119             :     /* Open and stat file */
     120             :     int fd = open( file, O_RDONLY );
     121             :     FD_TEST( fd>=0 );
     122             :     struct stat statbuf[1];
     123             :     FD_TEST( 0==fstat( fd, statbuf ) );
     124             :     data_sz = (ulong)statbuf->st_size;
     125             : 
     126             :     /* Allocate scratch buffer for file */
     127             :     FD_TEST( fd_scratch_alloc_is_safe( /* align */ 1UL, data_sz ) );
     128             :     data = fd_scratch_alloc( /* align */ 1UL, data_sz );
     129             : 
     130             :     /* Copy file into memory */
     131             :     FD_TEST( (ssize_t)data_sz == read( fd, data, data_sz ) );
     132             :     FD_TEST( 0==close( fd ) );
     133             :   } while(0);
     134             : 
     135             :   /* Decode file */
     136             : 
     137             :   fd_bincode_decode_ctx_t decode = {
     138             :     .data    = data,
     139             :     .dataend = data + data_sz,
     140             :     .valloc  = fd_scratch_virtual()
     141             :   };
     142             : 
     143             :   fd_flamenco_yaml_t * yaml =
     144             :     fd_flamenco_yaml_init( fd_flamenco_yaml_new(
     145             :       fd_scratch_alloc( fd_flamenco_yaml_align(), fd_flamenco_yaml_footprint() ) ),
     146             :       stdout );
     147             : 
     148             :   fd_types_funcs_t f;
     149             :   if (fd_flamenco_type_lookup(type, &f) != 0)
     150             :     FD_LOG_ERR (( "lookup for %s failed", type));
     151             : 
     152             :   char *d = fd_valloc_malloc( decode.valloc, f.align_fun(), f.footprint_fun() );
     153             :   if (NULL == d)
     154             :     FD_LOG_ERR (( "valloc_malloc failed for %lu", f.footprint_fun()));
     155             : 
     156             :   f.new_fun(d);
     157             :   int err = f.decode_fun( d, &decode );
     158             :   if( FD_UNLIKELY( err!=0 ) ) return err;
     159             : 
     160             :   f.walk_fun(yaml, d, fd_flamenco_yaml_walk, NULL, 0U );
     161             : 
     162             :   fd_scratch_pop();
     163             :   fd_scratch_detach( NULL );
     164             :   fd_flamenco_halt();
     165             :   fd_halt();
     166             :   return 0;
     167             : }

Generated by: LCOV version 1.14