Skip to content

Commit 239d78f

Browse files
riptlripatel-fd
authored andcommitted
Add basic verify tile test
1 parent ea15783 commit 239d78f

File tree

5 files changed

+143
-6
lines changed

5 files changed

+143
-6
lines changed

src/disco/topo/fd_topob.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fd_topob_new( void * mem,
3131
return topo;
3232
}
3333

34-
void
34+
fd_topo_wksp_t *
3535
fd_topob_wksp( fd_topo_t * topo,
3636
char const * name ) {
3737
if( FD_UNLIKELY( !topo || !name || !strlen( name ) ) ) FD_LOG_ERR(( "NULL args" ));
@@ -43,6 +43,7 @@ fd_topob_wksp( fd_topo_t * topo,
4343
wksp->id = topo->wksp_cnt;
4444
wksp->is_locked = 1;
4545
topo->wksp_cnt++;
46+
return wksp;
4647
}
4748

4849
fd_topo_obj_t *

src/disco/topo/fd_topob.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fd_topob_new( void * mem,
3636
must be unique and adding the same workspace twice will produce an
3737
error. */
3838

39-
void
39+
fd_topo_wksp_t *
4040
fd_topob_wksp( fd_topo_t * topo,
4141
char const * name );
4242

src/disco/verify/Local.mk

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
ifdef FD_HAS_ALLOCA
22
$(call add-objs,fd_verify_tile,fd_disco)
3-
$(call make-unit-test,test_tiles_verify,test_verify,fd_ballet fd_tango fd_util)
4-
$(call run-unit-test,test_tiles_verify)
3+
$(call make-unit-test,test_verify,test_verify,fd_ballet fd_tango fd_util)
4+
$(call make-unit-test,test_verify_tile,test_verify_tile,fd_disco fd_ballet fd_tango fd_util)
5+
$(call run-unit-test,test_verify)
6+
$(call run-unit-test,test_verify_tile)
57
endif

src/disco/verify/fd_verify_tile.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
#include "../metrics/fd_metrics.h"
44
#include "generated/fd_verify_tile_seccomp.h"
55

6-
#include <linux/unistd.h>
7-
86
#define IN_KIND_QUIC (0UL)
97
#define IN_KIND_BUNDLE (1UL)
108
#define IN_KIND_GOSSIP (2UL)
@@ -249,6 +247,7 @@ populate_allowed_fds( fd_topo_t const * topo,
249247

250248
#include "../stem/fd_stem.c"
251249

250+
#ifndef FD_TILE_TEST
252251
fd_topo_run_tile_t fd_tile_verify = {
253252
.name = "verify",
254253
.populate_allowed_seccomp = populate_allowed_seccomp,
@@ -259,3 +258,4 @@ fd_topo_run_tile_t fd_tile_verify = {
259258
.unprivileged_init = unprivileged_init,
260259
.run = stem_run,
261260
};
261+
#endif

src/disco/verify/test_verify_tile.c

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
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

Comments
 (0)