LCOV - code coverage report
Current view: top level - flamenco/runtime/tests - fd_solfuzz_private.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 53 0.0 %
Date: 2025-11-25 04:50:41 Functions: 0 35 0.0 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_flamenco_runtime_tests_fd_solfuzz_private_h
       2             : #define HEADER_fd_src_flamenco_runtime_tests_fd_solfuzz_private_h
       3             : 
       4             : /* fd_solfuzz_private.h contains internal components for the solfuzz
       5             :    Protobuf shim. */
       6             : 
       7             : #include "fd_solfuzz.h"
       8             : #include "../../features/fd_features.h"
       9             : #include "../../../ballet/nanopb/pb_encode.h"
      10             : #include "../../../ballet/nanopb/pb_decode.h"
      11             : #include "generated/context.pb.h"
      12             : 
      13             : #if FD_HAS_FLATCC
      14             : #include "flatcc/flatcc_builder.h"
      15             : #include "flatbuffers/generated/context_reader.h"
      16             : #endif
      17             : 
      18             : FD_PROTOTYPES_BEGIN
      19             : 
      20             : #undef ns
      21           0 : #define SOL_COMPAT_NS(x) FLATBUFFERS_WRAP_NAMESPACE(fd_org_solana_sealevel_v2, x)
      22             : 
      23           0 : #define SOL_COMPAT_V2_SUCCESS (0)
      24             : #define SOL_COMPAT_V2_FAILURE (-1)
      25             : 
      26             : /* Creates / overwrites an account in funk given an input account state.
      27             :    On success, loads the account into acc.  Optionally, reject any
      28             :    zero-lamport accounts from being loaded in. */
      29             : int
      30             : fd_solfuzz_pb_load_account( fd_txn_account_t *                acc,
      31             :                             fd_accdb_user_t *                 accdb,
      32             :                             fd_funk_txn_xid_t const *         xid,
      33             :                             fd_exec_test_acct_state_t const * state,
      34             :                             uchar                             reject_zero_lamports );
      35             : 
      36             : /* Activates features in the runtime given an input feature set.  Fails
      37             :    if a passed-in feature is unknown / not supported. */
      38             : int
      39             : fd_solfuzz_pb_restore_features( fd_features_t *                    features,
      40             :                                 fd_exec_test_feature_set_t const * feature_set );
      41             : 
      42             : #if FD_HAS_FLATCC
      43             : /* Flatbuffers variant of the above. This function call should never
      44             :    fail (all passed in features should be supported). Throws FD_LOG_ERR
      45             :    if any unsupported features are inputted. */
      46             : void
      47             : fd_solfuzz_fb_restore_features( fd_features_t *                   features,
      48             :                                 SOL_COMPAT_NS(FeatureSet_table_t) feature_set );
      49             : #endif
      50             : 
      51             : typedef ulong( exec_test_run_pb_fn_t )( fd_solfuzz_runner_t *,
      52             :                                         void const *,
      53             :                                         void **,
      54             :                                         void *,
      55             :                                         ulong );
      56             : 
      57             : static inline void
      58             : fd_solfuzz_pb_execute_wrapper( fd_solfuzz_runner_t *   runner,
      59             :                                void const *            input,
      60             :                                void **                 output,
      61           0 :                                exec_test_run_pb_fn_t * exec_test_run_fn ) {
      62           0 :   ulong out_bufsz = 100000000;  /* 100 MB */
      63           0 :   void * out0 = fd_spad_alloc( runner->spad, 1UL, out_bufsz );
      64           0 :   FD_TEST( out_bufsz <= fd_spad_alloc_max( runner->spad, 1UL ) );
      65             : 
      66           0 :   ulong out_used = exec_test_run_fn( runner, input, output, out0, out_bufsz );
      67           0 :   if( FD_UNLIKELY( !out_used ) ) {
      68           0 :     *output = NULL;
      69           0 :   }
      70           0 : }
      71             : 
      72             : typedef int( exec_test_run_fb_fn_t )( fd_solfuzz_runner_t *, void const * );
      73             : 
      74             : #if FD_HAS_FLATCC
      75             : /* Returns SOL_COMPAT_V2_SUCCESS on success and SOL_COMPAT_V2_FAILURE on
      76             :    failure */
      77             : static inline int
      78             : fd_solfuzz_fb_execute_wrapper( fd_solfuzz_runner_t *   runner,
      79             :                                void const *            input,
      80           0 :                                exec_test_run_fb_fn_t * exec_test_run_fn ) {
      81           0 :   FD_SPAD_FRAME_BEGIN( runner->spad ) {
      82           0 :     flatcc_builder_reset( runner->fb_builder );
      83           0 :     return exec_test_run_fn( runner, input );
      84           0 :   } FD_SPAD_FRAME_END;
      85           0 : }
      86             : #endif /* FD_HAS_FLATCC */
      87             : 
      88             : /* Utils */
      89             : 
      90             : static FD_FN_UNUSED void *
      91             : sol_compat_decode_lenient( void *               decoded,
      92             :                            uchar const *        in,
      93             :                            ulong                in_sz,
      94           0 :                            pb_msgdesc_t const * decode_type ) {
      95           0 :   pb_istream_t istream = pb_istream_from_buffer( in, in_sz );
      96           0 :   int decode_ok = pb_decode_ex( &istream, decode_type, decoded, PB_DECODE_NOINIT );
      97           0 :   if( !decode_ok ) {
      98           0 :     pb_release( decode_type, decoded );
      99           0 :     return NULL;
     100           0 :   }
     101           0 :   return decoded;
     102           0 : }
     103             : 
     104             : static FD_FN_UNUSED void *
     105             : sol_compat_decode( void *               decoded,
     106             :                    uchar const *        in,
     107             :                    ulong                in_sz,
     108           0 :                    pb_msgdesc_t const * decode_type ) {
     109           0 :   pb_istream_t istream = pb_istream_from_buffer( in, in_sz );
     110           0 :   int decode_ok = pb_decode_ex( &istream, decode_type, decoded, PB_DECODE_NOINIT );
     111           0 :   if( !decode_ok ) {
     112           0 :     pb_release( decode_type, decoded );
     113           0 :     return NULL;
     114           0 :   }
     115           0 :   ulong size;
     116           0 :   if( FD_UNLIKELY( !pb_get_encoded_size( &size, decode_type, decoded ) ) ) {
     117           0 :     pb_release( decode_type, decoded );
     118           0 :     return NULL;
     119           0 :   }
     120           0 :   if( FD_UNLIKELY( size != in_sz ) ) {
     121           0 :     pb_release( decode_type, decoded );
     122           0 :     return NULL;
     123           0 :   }
     124           0 :   return decoded;
     125           0 : }
     126             : 
     127             : static FD_FN_UNUSED void const *
     128             : sol_compat_encode( uchar *              out,
     129             :                    ulong *              out_sz,
     130             :                    void const *         to_encode,
     131           0 :                    pb_msgdesc_t const * encode_type ) {
     132           0 :   pb_ostream_t ostream = pb_ostream_from_buffer( out, *out_sz );
     133           0 :   int encode_ok = pb_encode( &ostream, encode_type, to_encode );
     134           0 :   if( !encode_ok ) {
     135           0 :     return NULL;
     136           0 :   }
     137           0 :   *out_sz = ostream.bytes_written;
     138           0 :   return to_encode;
     139           0 : }
     140             : 
     141             : FD_PROTOTYPES_END
     142             : 
     143             : #endif /* HEADER_fd_src_flamenco_runtime_tests_fd_solfuzz_private_h */

Generated by: LCOV version 1.14