|
| 1 | +/* test_verify_tile.c injects mock inputs into the verify tile. |
| 2 | + Uses libc malloc instead of wksp alloc for better memory sanitization |
| 3 | + check accuracy. */ |
| 4 | + |
| 5 | +#define FD_TILE_TEST |
| 6 | +#include "fd_verify_tile.c" |
| 7 | +#include "../topo/fd_topob.h" |
| 8 | +#include "../quic/fd_tpu.h" |
| 9 | +#include <stdlib.h> |
| 10 | +#include <unistd.h> |
| 11 | + |
| 12 | +#define TCACHE_DEPTH (128UL) |
| 13 | + |
| 14 | +static void |
| 15 | +test_seccomp( void ) { |
| 16 | + int out_fds[2]; |
| 17 | + ulong nfds = populate_allowed_fds( NULL, NULL, 2UL, out_fds ); |
| 18 | + FD_TEST( nfds>=1 && nfds<=2 ); |
| 19 | + FD_TEST( out_fds[0]==STDERR_FILENO ); |
| 20 | + if( nfds==2 ) FD_TEST( out_fds[1]==fd_log_private_logfile_fd() ); |
| 21 | + |
| 22 | + struct sock_filter filter[ 32 ]; |
| 23 | + populate_allowed_seccomp( NULL, NULL, 32UL, filter ); |
| 24 | +} |
| 25 | + |
| 26 | +#define TEST_ALLOC_MAX (64UL) |
| 27 | +static void * test_allocs[ TEST_ALLOC_MAX ]; |
| 28 | +static ulong test_alloc_cnt; |
| 29 | + |
| 30 | +static void * |
| 31 | +test_malloc( ulong align, ulong sz ) { |
| 32 | + FD_TEST( test_alloc_cnt<TEST_ALLOC_MAX ); |
| 33 | + void * p = aligned_alloc( align, sz ); |
| 34 | + FD_TEST( p ); |
| 35 | + test_allocs[ test_alloc_cnt ] = p; |
| 36 | + test_alloc_cnt++; |
| 37 | + return p; |
| 38 | +} |
| 39 | + |
| 40 | +static void |
| 41 | +test_free_all( void ) { |
| 42 | + while( test_alloc_cnt ) free( test_allocs[ --test_alloc_cnt ] ); |
| 43 | +} |
| 44 | + |
| 45 | +static void |
| 46 | +mock_link_create( fd_topo_t * topo, |
| 47 | + char const * name ) { |
| 48 | +#define LINK_DEPTH (16UL) |
| 49 | + fd_topo_link_t * link = fd_topob_link( topo, name, "wksp", LINK_DEPTH, 0UL, 0UL ); |
| 50 | + ulong data_sz = fd_dcache_req_data_sz( FD_TPU_REASM_MTU, LINK_DEPTH, 1UL, 1 ); |
| 51 | + link->mcache = fd_mcache_join( fd_mcache_new( test_malloc( fd_mcache_align(), fd_mcache_footprint( LINK_DEPTH, 0UL ) ), LINK_DEPTH, 0UL, 0UL ) ); |
| 52 | + link->dcache = fd_dcache_join( fd_dcache_new( test_malloc( fd_dcache_align(), fd_dcache_footprint( data_sz, 0UL ) ), data_sz, 0UL ) ); |
| 53 | +} |
| 54 | + |
| 55 | +static fd_topo_t * |
| 56 | +mock_topo_create( void ) { |
| 57 | + fd_topo_t * topo = fd_topob_new( test_malloc( alignof(fd_topo_t), sizeof(fd_topo_t) ), "verify-test" ); |
| 58 | + |
| 59 | + fd_topo_wksp_t * wksp = fd_topob_wksp( topo, "wksp" ); |
| 60 | + wksp->wksp = NULL; |
| 61 | + |
| 62 | + fd_topo_tile_t * verify = fd_topob_tile( topo, "verify", "wksp", "wksp", 0UL, 0, 0 ); |
| 63 | + verify->verify.tcache_depth = TCACHE_DEPTH; |
| 64 | + |
| 65 | + fd_verify_ctx_t * ctx = test_malloc( scratch_align(), scratch_footprint( verify ) ); |
| 66 | + topo->objs[ verify->tile_obj_id ].offset = (ulong)ctx; |
| 67 | + |
| 68 | + mock_link_create( topo, "quic_verify" ); |
| 69 | + mock_link_create( topo, "bundle_verif" ); |
| 70 | + mock_link_create( topo, "gossip_verif" ); |
| 71 | + mock_link_create( topo, "send_txns" ); |
| 72 | + |
| 73 | + /* Declare link ins in opposite order than IN_KIND_* to check for in |
| 74 | + idx confusion */ |
| 75 | +#define IN_IDX_SEND 0 |
| 76 | +#define IN_IDX_GOSSIP 1 |
| 77 | +#define IN_IDX_BUNDLE 2 |
| 78 | +#define IN_IDX_QUIC 3 |
| 79 | + fd_topob_tile_in( topo, "verify", 0UL, "wksp", "send_txns", 0UL, 0, 1 ); |
| 80 | + fd_topob_tile_in( topo, "verify", 0UL, "wksp", "gossip_verif", 0UL, 0, 1 ); |
| 81 | + fd_topob_tile_in( topo, "verify", 0UL, "wksp", "bundle_verif", 0UL, 0, 1 ); |
| 82 | + fd_topob_tile_in( topo, "verify", 0UL, "wksp", "quic_verify", 0UL, 0, 1 ); |
| 83 | + |
| 84 | + return topo; |
| 85 | +} |
| 86 | + |
| 87 | +static void |
| 88 | +test_load_balance( void ) { |
| 89 | + test_free_all(); |
| 90 | + fd_topo_t * topo = mock_topo_create(); |
| 91 | + fd_topo_tile_t * tile = &topo->tiles[ fd_topo_find_tile( topo, "verify", 0UL ) ]; |
| 92 | + privileged_init( topo, tile ); |
| 93 | + unprivileged_init( topo, tile ); |
| 94 | + fd_verify_ctx_t * ctx = fd_topo_obj_laddr( topo, tile->tile_obj_id ); |
| 95 | + |
| 96 | + /* Tile should accept all traffic if it's the only tile */ |
| 97 | + ctx->round_robin_idx = 0UL; |
| 98 | + ctx->round_robin_cnt = 1UL; |
| 99 | + FD_TEST( before_frag( ctx, IN_IDX_BUNDLE, 0UL, 0UL )==0 ); |
| 100 | + FD_TEST( before_frag( ctx, IN_IDX_BUNDLE, 1UL, 0UL )==0 ); |
| 101 | + FD_TEST( before_frag( ctx, IN_IDX_BUNDLE, 0UL, 1UL )==0 ); |
| 102 | + FD_TEST( before_frag( ctx, IN_IDX_BUNDLE, 1UL, 1UL )==0 ); |
| 103 | + FD_TEST( before_frag( ctx, IN_IDX_QUIC, 0UL, 0UL )==0 ); |
| 104 | + FD_TEST( before_frag( ctx, IN_IDX_QUIC, 1UL, 0UL )==0 ); |
| 105 | + |
| 106 | + /* Tile 0 should accept all bundle traffic */ |
| 107 | + ctx->round_robin_idx = 0UL; |
| 108 | + ctx->round_robin_cnt = 4UL; |
| 109 | + FD_TEST( before_frag( ctx, IN_IDX_BUNDLE, 0UL, 1UL )==0 ); |
| 110 | + FD_TEST( before_frag( ctx, IN_IDX_BUNDLE, 1UL, 1UL )==0 ); |
| 111 | + |
| 112 | + /* Tile 0 should load balance other traffic */ |
| 113 | + FD_TEST( before_frag( ctx, IN_IDX_BUNDLE, 0UL, 0UL )==0 ); |
| 114 | + FD_TEST( before_frag( ctx, IN_IDX_BUNDLE, 1UL, 0UL )==1 ); |
| 115 | + FD_TEST( before_frag( ctx, IN_IDX_BUNDLE, 2UL, 0UL )==1 ); |
| 116 | + FD_TEST( before_frag( ctx, IN_IDX_QUIC, 0UL, 0UL )==0 ); |
| 117 | + FD_TEST( before_frag( ctx, IN_IDX_QUIC, 1UL, 0UL )==1 ); |
| 118 | + FD_TEST( before_frag( ctx, IN_IDX_QUIC, 2UL, 0UL )==1 ); |
| 119 | +} |
| 120 | + |
| 121 | +int |
| 122 | +main( int argc, |
| 123 | + char ** argv ) { |
| 124 | + fd_boot( &argc, &argv ); |
| 125 | + |
| 126 | + test_seccomp(); |
| 127 | + test_load_balance(); |
| 128 | + test_free_all(); |
| 129 | + /* further tests here ... */ |
| 130 | + |
| 131 | + FD_LOG_NOTICE(( "pass" )); |
| 132 | + fd_halt(); |
| 133 | + return 0; |
| 134 | +} |
0 commit comments