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: 2 3 66.7 %
Date: 2026-05-16 06:43:53 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       10254 : #define FD_QUIC_TEST_SERVER_IP4 FD_IP4_ADDR( 127, 0, 0, 1 )
      14       10254 : #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             : void
     108             : fd_quic_test_cb_tls_keylog( void *       quic_ctx,
     109             :                             char const * line );
     110             : 
     111             : FD_PROTOTYPES_END
     112             : 
     113             : /* fd_quic_udpsock is a command-line helper for creating an UDP channel
     114             :    over AF_XDP or UDP sockets. */
     115             : 
     116             : struct fd_quic_udpsock {
     117             :   int type;
     118           0 : # define FD_QUIC_UDPSOCK_TYPE_UDPSOCK 2
     119             : 
     120             :   uint   listen_ip;
     121             :   ushort listen_port;
     122             : 
     123             :   fd_wksp_t * wksp;  /* Handle to the workspace owning the objects */
     124             :   union {
     125             :     struct {
     126             :       fd_udpsock_t * sock;
     127             :       int            sock_fd;
     128             :     } udpsock;
     129             :   };
     130             : 
     131             :   fd_aio_t const * aio;
     132             : };
     133             : typedef struct fd_quic_udpsock fd_quic_udpsock_t;
     134             : 
     135             : FD_PROTOTYPES_BEGIN
     136             : 
     137             : fd_quic_udpsock_t *
     138             : fd_quic_client_create_udpsock(fd_quic_udpsock_t * udpsock,
     139             :                               fd_wksp_t *      wksp,
     140             :                               fd_aio_t const * rx_aio,
     141             :                               uint listen_ip);
     142             : 
     143             : fd_quic_udpsock_t *
     144             : fd_quic_udpsock_create( void *           _sock,
     145             :                         int *            argc,
     146             :                         char ***         argv,
     147             :                         fd_wksp_t *      wksp,
     148             :                         fd_aio_t const * rx_aio );
     149             : 
     150             : void *
     151             : fd_quic_udpsock_destroy( fd_quic_udpsock_t * udpsock );
     152             : 
     153             : void
     154             : fd_quic_udpsock_service( fd_quic_udpsock_t const * udpsock );
     155             : 
     156             : 
     157             : /* fd_quic_netem injects packet loss and reordering into an aio link. */
     158             : 
     159             : struct fd_quic_netem_reorder_buf {
     160             :   ulong sz;
     161             :   uchar buf[2048];
     162             : };
     163             : 
     164             : struct fd_quic_netem {
     165             :   fd_aio_t         local;
     166             :   fd_aio_t const * dst;
     167             :   float            thresh_drop;
     168             :   float            thresh_reorder;
     169             : 
     170             :   struct fd_quic_netem_reorder_buf reorder_buf[2];
     171             :   int                              reorder_mru; /* most recently written reorder buf */
     172             : 
     173             :   ulong  drop_sequence; /* defines a drop-sequence for next 64 outgoing packets */
     174             : 
     175             :   long * now_ptr;         /* points to test 'now' */
     176             :   long   one_way_latency;
     177             : };
     178             : 
     179             : typedef struct fd_quic_netem fd_quic_netem_t;
     180             : 
     181             : fd_quic_netem_t *
     182             : fd_quic_netem_init( fd_quic_netem_t * netem,
     183             :                     float             thres_drop,
     184             :                     float             thres_reorder,
     185             :                     long            * now_ptr );
     186             : 
     187             : /* fd_quic_netem_set_drop sets a drop sequence for outgoing packets.
     188             :    'drop_sequence' is an ordered bitset interpreted from right to left,
     189             :    where 1 signals a drop. This function can specify behavior for at most
     190             :    the next 64 packets. Subsequent calls to this function overwrite the
     191             :    previous call. Non-zero thres_drop and/or thres_reorder only apply if
     192             :    packet is not dropped by the deterministic drop_sequence.
     193             :    To get only deterministic drops, set thres_drop and thres_reorder to 0. */
     194             : 
     195             : void
     196             : fd_quic_netem_set_drop( fd_quic_netem_t * netem,
     197             :                         ulong             drop_sequence );
     198             : 
     199             : /* fd_quic_netem_set_one_way_latency sets the one_way_latency
     200             :    for the network emulation. Each outgoing packet will increment
     201             :    *now_ptr by one_way_latency. */
     202             : 
     203             : void
     204             : fd_quic_netem_set_one_way_latency( fd_quic_netem_t * netem,
     205             :                                    long              one_way_latency );
     206             : 
     207             : /* fd_quic_netem_send implements fd_aio_send for fd_quic_netem_t. */
     208             : 
     209             : int
     210             : fd_quic_netem_send( void *                    ctx, /* fd_quic_net_em_t */
     211             :                     fd_aio_pkt_info_t const * batch,
     212             :                     ulong                     batch_cnt,
     213             :                     ulong *                   opt_batch_idx,
     214             :                     int                       flush );
     215             : 
     216             : FD_PROTOTYPES_END
     217             : 
     218             : #endif /* HEADER_fd_src_waltz_quic_tests_fd_quic_test_helpers_h */

Generated by: LCOV version 1.14