LCOV - code coverage report
Current view: top level - waltz/quic/tests - fd_quic_test_helpers.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 3 0.0 %
Date: 2026-11-26 02:16:43 Functions: 0 0 -

          Line data    Source code
       1             : #ifndef HEADER_fd_src_waltz_quic_tests_fd_quic_test_helpers_h
       2             : #define HEADER_fd_src_waltz_quic_tests_fd_quic_test_helpers_h
       3             : 
       4             : #include "../fd_quic.h"
       5             : #include "../../aio/fd_aio_pcapng.h"
       6             : #include "../../udpsock/fd_udpsock.h"
       7             : #include "../../tls/test_tls_helper.h"
       8             : #include "../../../ballet/txn/fd_txn.h" /* FD_TXN_MTU */
       9             : #include "../../../util/net/fd_ip4.h"
      10             : 
      11             : #include <stdio.h>
      12             : 
      13           0 : #define FD_QUIC_TEST_SERVER_IP4 FD_IP4_ADDR( 127, 0, 0, 1 )
      14           0 : #define FD_QUIC_TEST_CLIENT_IP4 FD_IP4_ADDR( 127, 0, 0, 2 )
      15             : 
      16             : /* Common helpers for QUIC tests.  The tests using these gain the
      17             :    following command-line options:
      18             : 
      19             :      --pcap <path>   Append test traffic to pcapng 1.0 at given file
      20             :                      path (encryption secrets included) */
      21             : 
      22             : /* fd_quic_virtual_pair_t is used to connect two local QUICs via
      23             :    direct fd_aio.  Optionally supports packet capture. */
      24             : 
      25             : struct fd_quic_virtual_pair {
      26             :   fd_quic_t * quic_a;
      27             :   fd_quic_t * quic_b;
      28             : 
      29             :   /* aio_{a2b,b2a} point to the first hop of each aio chain */
      30             :   fd_aio_t const * aio_a2b;
      31             :   fd_aio_t const * aio_b2a;
      32             : 
      33             :   fd_aio_pcapng_t pcapng_a2b;
      34             :   fd_aio_pcapng_t pcapng_b2a;
      35             : };
      36             : typedef struct fd_quic_virtual_pair fd_quic_virtual_pair_t;
      37             : 
      38             : FD_PROTOTYPES_BEGIN
      39             : 
      40             : extern FILE * fd_quic_test_pcap;
      41             : 
      42             : /* fd_quic_test_boot boots the QUIC test environment.
      43             :    Should be called after fd_boot().
      44             : 
      45             :    fd_quic_test_halt halts the QUIC test environment.
      46             :    Should be called before fd_halt(). */
      47             : 
      48             : void
      49             : fd_quic_test_boot( int *    pargc,
      50             :                    char *** pargv );
      51             : void
      52             : fd_quic_test_halt( void );
      53             : 
      54             : void
      55             : fd_quic_config_anonymous( fd_quic_t * quic,
      56             :                           int         role );
      57             : 
      58             : void
      59             : fd_quic_config_test_signer( fd_quic_t *              quic,
      60             :                             fd_tls_test_sign_ctx_t * sign_ctx );
      61             : 
      62             : /* fd_quic_new_anonymous creates an anonymous QUIC instance with the
      63             :    given limits.  Vacant config fields are auto-generated, except for
      64             :    role (server or client). Returns QUIC instance without local join on
      65             :    success.  Halts program on error. Caller is responsible for cleaning
      66             :    up QUIC. */
      67             : 
      68             : fd_quic_t *
      69             : fd_quic_new_anonymous( fd_wksp_t *              wksp,
      70             :                        fd_quic_limits_t const * limits,
      71             :                        int                      role,
      72             :                        fd_rng_t *               rng );
      73             : 
      74             : /* fd_quic_new_anonymous_small is like fd_quic_new_anonymous but with
      75             :    arbitrary small limits for convenience. */
      76             : 
      77             : fd_quic_t *
      78             : fd_quic_new_anonymous_small( fd_wksp_t * wksp,
      79             :                              int         role,
      80             :                              fd_rng_t *  rng );
      81             : 
      82             : /* fd_quic_sync_clocks sets the clock of two QUICs to 'now'. */
      83             : 
      84             : void
      85             : fd_quic_sync_clocks( fd_quic_t * quicA,
      86             :                      fd_quic_t * quicB,
      87             :                      long        now );
      88             : 
      89             : /* fd_quic_virtual_pair_init sets up an aio loop between the two given QUIC
      90             :    objects.  That is, an fd_aio_send() call by quicA will trigger
      91             :    a synchronous callback to the aio receive to the quicB.  (FIXME This
      92             :    assumes no reentrancy in QUIC)  If user requested pcap, causes
      93             :    packets to get logged.  May only be called once per thread.  Any
      94             :    allocated resources get released at halt. */
      95             : 
      96             : void
      97             : fd_quic_virtual_pair_init( fd_quic_virtual_pair_t * pair,
      98             :                            fd_quic_t * quicA,
      99             :                            fd_quic_t * quicB );
     100             : 
     101             : /* fd_quic_virtual_pair_fini destroys an aio loop between the two given
     102             :    QUIC objects. */
     103             : 
     104             : void
     105             : fd_quic_virtual_pair_fini( fd_quic_virtual_pair_t * pair );
     106             : 
     107             : /* fd_quic_test_stream_send sends data as stream_id (see
     108             :    fd_quic_conn_tx_stream) in a packet of its own out the quic's aio.
     109             :    Returns 1 on success and 0 on failure.  On success, the packet number
     110             :    is written to *opt_pkt_num if non-NULL. */
     111             : 
     112             : int
     113             : fd_quic_test_stream_send( fd_quic_conn_t * conn,
     114             :                           ulong            stream_id,
     115             :                           void const *     data,
     116             :                           ulong            data_sz,
     117             :                           ulong *          opt_pkt_num );
     118             : 
     119             : void
     120             : fd_quic_test_cb_tls_keylog( void *       quic_ctx,
     121             :                             char const * line );
     122             : 
     123             : FD_PROTOTYPES_END
     124             : 
     125             : /* fd_quic_udpsock is a command-line helper for creating an UDP channel
     126             :    over AF_XDP or UDP sockets. */
     127             : 
     128             : struct fd_quic_udpsock {
     129             :   int type;
     130           0 : # define FD_QUIC_UDPSOCK_TYPE_UDPSOCK 2
     131             : 
     132             :   uint   listen_ip;
     133             :   ushort listen_port;
     134             : 
     135             :   fd_wksp_t * wksp;  /* Handle to the workspace owning the objects */
     136             :   union {
     137             :     struct {
     138             :       fd_udpsock_t * sock;
     139             :       int            sock_fd;
     140             :     } udpsock;
     141             :   };
     142             : 
     143             :   fd_aio_t const * aio;
     144             : };
     145             : typedef struct fd_quic_udpsock fd_quic_udpsock_t;
     146             : 
     147             : FD_PROTOTYPES_BEGIN
     148             : 
     149             : fd_quic_udpsock_t *
     150             : fd_quic_client_create_udpsock(fd_quic_udpsock_t * udpsock,
     151             :                               fd_wksp_t *      wksp,
     152             :                               fd_aio_t const * rx_aio,
     153             :                               uint listen_ip);
     154             : 
     155             : fd_quic_udpsock_t *
     156             : fd_quic_udpsock_create( void *           _sock,
     157             :                         int *            argc,
     158             :                         char ***         argv,
     159             :                         fd_wksp_t *      wksp,
     160             :                         fd_aio_t const * rx_aio );
     161             : 
     162             : void *
     163             : fd_quic_udpsock_destroy( fd_quic_udpsock_t * udpsock );
     164             : 
     165             : void
     166             : fd_quic_udpsock_service( fd_quic_udpsock_t const * udpsock );
     167             : 
     168             : 
     169             : /* fd_quic_netem injects packet loss and reordering into an aio link. */
     170             : 
     171             : struct fd_quic_netem_reorder_buf {
     172             :   ulong sz;
     173             :   uchar buf[2048];
     174             : };
     175             : 
     176             : struct fd_quic_netem {
     177             :   fd_aio_t         local;
     178             :   fd_aio_t const * dst;
     179             :   float            thresh_drop;
     180             :   float            thresh_reorder;
     181             : 
     182             :   struct fd_quic_netem_reorder_buf reorder_buf[2];
     183             :   int                              reorder_mru; /* most recently written reorder buf */
     184             : 
     185             :   ulong  drop_sequence; /* defines a drop-sequence for next 64 outgoing packets */
     186             : 
     187             :   long * now_ptr;         /* points to test 'now' */
     188             :   long   one_way_latency;
     189             : };
     190             : 
     191             : typedef struct fd_quic_netem fd_quic_netem_t;
     192             : 
     193             : fd_quic_netem_t *
     194             : fd_quic_netem_init( fd_quic_netem_t * netem,
     195             :                     float             thres_drop,
     196             :                     float             thres_reorder,
     197             :                     long            * now_ptr );
     198             : 
     199             : /* fd_quic_netem_set_drop sets a drop sequence for outgoing packets.
     200             :    'drop_sequence' is an ordered bitset interpreted from right to left,
     201             :    where 1 signals a drop. This function can specify behavior for at most
     202             :    the next 64 packets. Subsequent calls to this function overwrite the
     203             :    previous call. Non-zero thres_drop and/or thres_reorder only apply if
     204             :    packet is not dropped by the deterministic drop_sequence.
     205             :    To get only deterministic drops, set thres_drop and thres_reorder to 0. */
     206             : 
     207             : void
     208             : fd_quic_netem_set_drop( fd_quic_netem_t * netem,
     209             :                         ulong             drop_sequence );
     210             : 
     211             : /* fd_quic_netem_set_one_way_latency sets the one_way_latency
     212             :    for the network emulation. Each outgoing packet will increment
     213             :    *now_ptr by one_way_latency. */
     214             : 
     215             : void
     216             : fd_quic_netem_set_one_way_latency( fd_quic_netem_t * netem,
     217             :                                    long              one_way_latency );
     218             : 
     219             : /* fd_quic_netem_send implements fd_aio_send for fd_quic_netem_t. */
     220             : 
     221             : int
     222             : fd_quic_netem_send( void *                    ctx, /* fd_quic_net_em_t */
     223             :                     fd_aio_pkt_info_t const * batch,
     224             :                     ulong                     batch_cnt,
     225             :                     ulong *                   opt_batch_idx,
     226             :                     int                       flush );
     227             : 
     228             : FD_PROTOTYPES_END
     229             : 
     230             : #endif /* HEADER_fd_src_waltz_quic_tests_fd_quic_test_helpers_h */

Generated by: LCOV version 1.14