LCOV - code coverage report
Current view: top level - flamenco/runtime/tests/harness - fd_harness_common.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 96 0.0 %
Date: 2025-08-05 05:04:49 Functions: 0 7 0.0 %

          Line data    Source code
       1             : #include "fd_harness_common.h"
       2             : #include "../../fd_system_ids.h"
       3             : #include "../../context/fd_exec_slot_ctx.h"
       4             : #include "../../sysvar/fd_sysvar_recent_hashes.h"
       5             : #include "../../program/fd_program_cache.h"
       6             : 
       7             : ulong
       8           0 : fd_runtime_fuzz_runner_align( void ) {
       9           0 :   return alignof(fd_runtime_fuzz_runner_t);
      10           0 : }
      11             : 
      12             : ulong
      13           0 : fd_runtime_fuzz_runner_footprint( void ) {
      14           0 :   ulong txn_max = 4+fd_tile_cnt();
      15           0 :   uint rec_max  = 1024;
      16             : 
      17           0 :   ulong l = FD_LAYOUT_INIT;
      18           0 :   l = FD_LAYOUT_APPEND( l, fd_runtime_fuzz_runner_align(), sizeof(fd_runtime_fuzz_runner_t) );
      19           0 :   l = FD_LAYOUT_APPEND( l, fd_funk_align(),                fd_funk_footprint( txn_max, rec_max ) );
      20             :   /* Spad memory is not included in the footprint since its allocated separately at the beginning of a fuzzing run */
      21           0 :   return FD_LAYOUT_FINI( l, fd_runtime_fuzz_runner_align() );
      22           0 : }
      23             : 
      24             : fd_runtime_fuzz_runner_t *
      25             : fd_runtime_fuzz_runner_new( void *       mem,
      26             :                             void *       spad_mem,
      27             :                             fd_banks_t * banks,
      28             :                             fd_bank_t *  bank,
      29           0 :                             ulong        wksp_tag ) {
      30           0 :   ulong txn_max = 4+fd_tile_cnt();
      31           0 :   uint rec_max  = 1024;
      32             : 
      33           0 :   FD_SCRATCH_ALLOC_INIT( l, mem );
      34           0 :   void * runner_mem = FD_SCRATCH_ALLOC_APPEND( l, fd_runtime_fuzz_runner_align(), sizeof(fd_runtime_fuzz_runner_t) );
      35           0 :   void * funk_mem   = FD_SCRATCH_ALLOC_APPEND( l, fd_funk_align(),                fd_funk_footprint( txn_max, rec_max ) );
      36           0 :   FD_SCRATCH_ALLOC_FINI( l, fd_runtime_fuzz_runner_align() );
      37             : 
      38           0 :   fd_runtime_fuzz_runner_t * runner = runner_mem;
      39             : 
      40           0 :   fd_funk_t * funk = fd_funk_join( runner->funk, fd_funk_new( funk_mem, wksp_tag, (ulong)fd_tickcount(), txn_max, rec_max ) );
      41           0 :   if( FD_UNLIKELY( !funk ) ) {
      42           0 :     FD_LOG_WARNING(( "fd_funk_new() failed" ));
      43           0 :     return NULL;
      44           0 :   }
      45             : 
      46             :   /* Create spad */
      47           0 :   runner->spad = fd_spad_join( fd_spad_new( spad_mem, FD_RUNTIME_TRANSACTION_EXECUTION_FOOTPRINT_FUZZ ) );
      48           0 :   runner->wksp = fd_wksp_containing( runner->spad );
      49             : 
      50             :   /* Reuse the same bank for each iteration of the fuzzer */
      51           0 :   runner->banks = banks;
      52           0 :   runner->bank  = bank;
      53             : 
      54           0 :   return runner;
      55           0 : }
      56             : 
      57             : void *
      58           0 : fd_runtime_fuzz_runner_delete( fd_runtime_fuzz_runner_t * runner ) {
      59           0 :   if( FD_UNLIKELY( !runner ) ) return NULL;
      60           0 :   void * shfunk;
      61           0 :   fd_funk_leave( runner->funk, &shfunk );
      62           0 :   fd_funk_delete( shfunk );
      63           0 :   if( FD_UNLIKELY( fd_spad_verify( runner->spad ) ) ) {
      64           0 :     FD_LOG_ERR(( "fd_spad_verify() failed" ));
      65           0 :   }
      66           0 :   if( FD_UNLIKELY( fd_spad_frame_used( runner->spad )!=0 ) ) {
      67           0 :     FD_LOG_ERR(( "stray spad frame frame_used=%lu", fd_spad_frame_used( runner->spad ) ));
      68           0 :   }
      69           0 :   runner->spad = NULL;
      70           0 :   return runner;
      71           0 : }
      72             : 
      73             : int
      74             : fd_runtime_fuzz_load_account( fd_txn_account_t *                acc,
      75             :                               fd_funk_t *                       funk,
      76             :                               fd_funk_txn_t *                   funk_txn,
      77             :                               fd_exec_test_acct_state_t const * state,
      78           0 :                               uchar                             reject_zero_lamports ) {
      79           0 :   if( reject_zero_lamports && state->lamports==0UL ) {
      80           0 :     return 0;
      81           0 :   }
      82             : 
      83           0 :   fd_txn_account_init( acc );
      84           0 :   ulong size = 0UL;
      85           0 :   if( state->data ) size = state->data->size;
      86             : 
      87           0 :   fd_pubkey_t pubkey[1];  memcpy( pubkey, state->address, sizeof(fd_pubkey_t) );
      88             : 
      89             :   /* Account must not yet exist */
      90           0 :   if( FD_UNLIKELY( fd_funk_get_acc_meta_readonly( funk, funk_txn, pubkey, NULL, NULL, NULL) ) ) {
      91           0 :     return 0;
      92           0 :   }
      93             : 
      94           0 :   assert( funk );
      95           0 :   int err = fd_txn_account_init_from_funk_mutable( /* acc         */ acc,
      96           0 :                                                    /* pubkey      */ pubkey,
      97           0 :                                                    /* funk        */ funk,
      98           0 :                                                    /* txn         */ funk_txn,
      99           0 :                                                    /* do_create   */ 1,
     100           0 :                                                    /* min_data_sz */ size );
     101           0 :   assert( err==FD_ACC_MGR_SUCCESS );
     102           0 :   if( state->data ) {
     103           0 :     acc->vt->set_data( acc, state->data->bytes, size );
     104           0 :   }
     105             : 
     106           0 :   acc->starting_lamports = state->lamports;
     107           0 :   acc->starting_dlen     = size;
     108           0 :   acc->vt->set_lamports( acc, state->lamports );
     109           0 :   acc->vt->set_executable( acc, state->executable );
     110           0 :   acc->vt->set_rent_epoch( acc, state->rent_epoch );
     111           0 :   acc->vt->set_owner( acc, (fd_pubkey_t const *)state->owner );
     112             : 
     113             :   /* make the account read-only by default */
     114           0 :   acc->vt->set_readonly( acc );
     115             : 
     116           0 :   fd_txn_account_mutable_fini( acc, funk, funk_txn );
     117             : 
     118           0 :   return 1;
     119           0 : }
     120             : 
     121             : int
     122             : fd_runtime_fuzz_restore_features( fd_features_t *                    features,
     123           0 :                                   fd_exec_test_feature_set_t const * feature_set ) {
     124           0 :   fd_features_disable_all( features );
     125           0 :   for( ulong j=0UL; j < feature_set->features_count; j++ ) {
     126           0 :     ulong                   prefix = feature_set->features[j];
     127           0 :     fd_feature_id_t const * id     = fd_feature_id_query( prefix );
     128           0 :     if( FD_UNLIKELY( !id ) ) {
     129           0 :       FD_LOG_WARNING(( "unsupported feature ID 0x%016lx", prefix ));
     130           0 :       return 0;
     131           0 :     }
     132             :     /* Enabled since genesis */
     133           0 :     fd_features_set( features, id, 0UL );
     134           0 :   }
     135           0 :   return 1;
     136           0 : }
     137             : 
     138             : void
     139             : fd_runtime_fuzz_refresh_program_cache( fd_exec_slot_ctx_t *              slot_ctx,
     140             :                                        fd_exec_test_acct_state_t const * acct_states,
     141             :                                        ulong                             acct_states_count,
     142           0 :                                        fd_spad_t *                       runtime_spad ) {
     143           0 :   for( ushort i=0; i<acct_states_count; i++ ) {
     144           0 :     fd_pubkey_t pubkey[1] = {0};
     145           0 :     memcpy( &pubkey, acct_states[i].address, sizeof(fd_pubkey_t) );
     146           0 :     fd_program_cache_update_program( slot_ctx, pubkey, runtime_spad );
     147           0 :   }
     148           0 : }

Generated by: LCOV version 1.14