16 #ifndef __vcl_test_h__ 17 #define __vcl_test_h__ 23 #include <vcl/vppcom.h> 25 #define vtfail(_fn, _rv) \ 28 perror ("ERROR when calling " _fn); \ 29 fprintf (stderr, "\nERROR: " _fn " failed (errno = %d)!\n", -_rv); \ 33 #define vterr(_fn, _rv) \ 36 fprintf (stderr, "\nERROR: " _fn " failed (errno = %d)!\n", -_rv); \ 39 #define vtwrn(_fmt, _args...) \ 40 fprintf (stderr, "\nERROR: " _fmt "\n", ##_args) \ 42 #define vtinf(_fmt, _args...) \ 43 fprintf (stdout, "vt<w%u>: " _fmt "\n", __wrk_index, ##_args) 45 #define vt_atomic_add(_ptr, _val) \ 46 __atomic_fetch_add (_ptr, _val, __ATOMIC_RELEASE) 48 #define VCL_TEST_TOKEN_HELP "#H" 49 #define VCL_TEST_TOKEN_EXIT "#X" 50 #define VCL_TEST_TOKEN_VERBOSE "#V" 51 #define VCL_TEST_TOKEN_TXBUF_SIZE "#T:" 52 #define VCL_TEST_TOKEN_NUM_TEST_SESS "#I:" 53 #define VCL_TEST_TOKEN_NUM_WRITES "#N:" 54 #define VCL_TEST_TOKEN_RXBUF_SIZE "#R:" 55 #define VCL_TEST_TOKEN_SHOW_CFG "#C" 56 #define VCL_TEST_TOKEN_RUN_UNI "#U" 57 #define VCL_TEST_TOKEN_RUN_BI "#B" 59 #define VCL_TEST_SERVER_PORT 22000 60 #define VCL_TEST_LOCALHOST_IPADDR "127.0.0.1" 62 #define VCL_TEST_CFG_CTRL_MAGIC 0xfeedface 63 #define VCL_TEST_CFG_NUM_WRITES_DEF 1000000 64 #define VCL_TEST_CFG_TXBUF_SIZE_DEF 8192 65 #define VCL_TEST_CFG_RXBUF_SIZE_DEF (64*VCL_TEST_CFG_TXBUF_SIZE_DEF) 66 #define VCL_TEST_CFG_BUF_SIZE_MIN 128 67 #define VCL_TEST_CFG_MAX_TEST_SESS 32 68 #define VCL_TEST_CFG_MAX_EPOLL_EVENTS 16 70 #define VCL_TEST_DELAY_DISCONNECT 1 71 #define VCL_TEST_SEPARATOR_STRING \ 72 " -----------------------------\n" 82 typedef struct __attribute__ ((packed))
110 struct timespec start;
111 struct timespec stop;
131 "-----BEGIN CERTIFICATE-----\r\n" 132 "MIID5zCCAs+gAwIBAgIJALeMYCEHrTtJMA0GCSqGSIb3DQEBCwUAMIGJMQswCQYD\r\n" 133 "VQQGEwJVUzELMAkGA1UECAwCQ0ExETAPBgNVBAcMCFNhbiBKb3NlMQ4wDAYDVQQK\r\n" 134 "DAVDaXNjbzEOMAwGA1UECwwFZmQuaW8xFjAUBgNVBAMMDXRlc3R0bHMuZmQuaW8x\r\n" 135 "IjAgBgkqhkiG9w0BCQEWE3ZwcC1kZXZAbGlzdHMuZmQuaW8wHhcNMTgwMzA1MjEx\r\n" 136 "NTEyWhcNMjgwMzAyMjExNTEyWjCBiTELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAkNB\r\n" 137 "MREwDwYDVQQHDAhTYW4gSm9zZTEOMAwGA1UECgwFQ2lzY28xDjAMBgNVBAsMBWZk\r\n" 138 "LmlvMRYwFAYDVQQDDA10ZXN0dGxzLmZkLmlvMSIwIAYJKoZIhvcNAQkBFhN2cHAt\r\n" 139 "ZGV2QGxpc3RzLmZkLmlvMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA\r\n" 140 "4C1k8a1DuStgggqT4o09fP9sJ2dC54bxhS/Xk2VEfaIZ222WSo4X/syRVfVy9Yah\r\n" 141 "cpI1zJ/RDxaZSFhgA+nPZBrFMsrULkrdAOpOVj8eDEp9JuWdO2ODSoFnCvLxcYWB\r\n" 142 "Yc5kHryJpEaGJl1sFQSesnzMFty/59ta0stk0Fp8r5NhIjWvSovGzPo6Bhz+VS2c\r\n" 143 "ebIZh4x1t2hHaFcgm0qJoJ6DceReWCW8w+yOVovTolGGq+bpb2Hn7MnRSZ2K2NdL\r\n" 144 "+aLXpkZbS/AODP1FF2vTO1mYL290LO7/51vJmPXNKSDYMy5EvILr5/Vq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Q2eZgtut1PXtBtNl17/b85uv293Fm\r\n" 179 "VDISVcsk3eLNS8zIiT6afUoWlxAwXEs0v5WRfjl4radkGvgGiJpJYvyeM67877RB\r\n" 180 "EDSKc/X8ESLfOB44iGvZUEMG6zJFscx9DgN25iQZAoGAbyd+JEWwdVH9/K3IH1t2\r\n" 181 "PBkZX17kNWv+iVM1WyFjbe++vfKZCrOJiyiqhDeEqgrP3AuNMlaaduC3VRC3G5oV\r\n" 182 "Mj1tlhDWQ/qhvKdCKNdIVQYDE75nw+FRWV8yYkHAnXYW3tNoweDIwixE0hkPR1bc\r\n" 183 "oEjPLVNtx8SOj/M4rhaPT3I=\r\n" "-----END PRIVATE KEY-----\r\n";
233 uint8_t *lb = realloc (*buf, (
size_t) alloc_size);
246 vtwrn (
"realloc failed. using buffer size %d instead of %u",
247 *bufsize, alloc_size);
292 printf (
" test config (%p):\n" 296 "%-5s test: %s (%d)\n" 297 " ctrl handle: %d (0x%x)\n" 298 "%-5s num test sockets: %u (0x%08x)\n" 299 "%-5s verbose: %s (%d)\n" 300 "%-5s rxbuf size: %lu (0x%08lx)\n" 301 "%-5s txbuf size: %lu (0x%08lx)\n" 302 "%-5s num writes: %lu (0x%08lx)\n" 303 " client tx bytes: %lu (0x%08lx)\n" 305 (
void *) cfg, cfg->
magic, cfg->seq_num,
311 cfg->ctrl_handle, cfg->ctrl_handle,
313 cfg->num_test_sessions, cfg->num_test_sessions,
315 cfg->verbose ?
"on" :
"off", cfg->verbose,
317 cfg->rxbuf_size, cfg->rxbuf_size,
319 cfg->txbuf_size, cfg->txbuf_size,
321 cfg->num_writes, cfg->num_writes,
322 cfg->total_bytes, cfg->total_bytes);
327 uint8_t show_rx, uint8_t show_tx, uint8_t verbose)
329 struct timespec diff;
330 double duration, rate;
331 uint64_t total_bytes;
333 if ((stats->
stop.tv_nsec - stats->
start.tv_nsec) < 0)
335 diff.tv_sec = stats->
stop.tv_sec - stats->
start.tv_sec - 1;
336 diff.tv_nsec = stats->
stop.tv_nsec - stats->
start.tv_nsec + 1e9;
340 diff.tv_sec = stats->
stop.tv_sec - stats->
start.tv_sec;
341 diff.tv_nsec = stats->
stop.tv_nsec - stats->
start.tv_nsec;
343 duration = (double) diff.tv_sec + (1e-9 * diff.tv_nsec);
346 rate = (double) total_bytes *8 / duration / 1e9;
347 printf (
"\n%s: Streamed %lu bytes\n" 348 " in %lf seconds (%lf Gbps %s-duplex)!\n",
349 header, total_bytes, duration, rate,
350 (show_rx && show_tx) ?
"full" :
"half");
355 " tx stats (0x%p):\n" 357 " writes: %lu (0x%08lx)\n" 358 " tx bytes: %lu (0x%08lx)\n" 359 " tx eagain: %u (0x%08x)\n" 360 " tx incomplete: %u (0x%08x)\n",
361 (
void *) stats, stats->
tx_xacts, stats->tx_xacts,
362 stats->tx_bytes, stats->tx_bytes,
363 stats->tx_eagain, stats->tx_eagain,
364 stats->tx_incomp, stats->tx_incomp);
369 " rx stats (0x%p):\n" 371 " reads: %lu (0x%08lx)\n" 372 " rx bytes: %lu (0x%08lx)\n" 373 " rx eagain: %u (0x%08x)\n" 374 " rx incomplete: %u (0x%08x)\n",
375 (
void *) stats, stats->
rx_xacts, stats->rx_xacts,
376 stats->rx_bytes, stats->rx_bytes,
377 stats->rx_eagain, stats->rx_eagain,
378 stats->rx_incomp, stats->rx_incomp);
381 printf (
" start.tv_sec: %ld\n" 382 " start.tv_nsec: %ld\n" 383 " stop.tv_sec: %ld\n" 384 " stop.tv_nsec: %ld\n",
386 stats->
stop.tv_sec, stats->
stop.tv_nsec);
394 if (a->tv_sec < b->tv_sec)
396 else if (a->tv_sec > b->tv_sec)
398 else if (a->tv_nsec < b->tv_nsec)
400 else if (a->tv_nsec > b->tv_nsec)
416 rx_bytes = vppcom_session_read (fd, buf, nbytes);
425 if ((rx_bytes == 0) ||
427 && ((errno == EAGAIN) || (errno == EWOULDBLOCK))))
429 else if (rx_bytes < nbytes)
433 while ((rx_bytes == 0) ||
434 ((rx_bytes < 0) && ((errno == EAGAIN) || (errno == EWOULDBLOCK))));
438 vterr (
"vppcom_session_read()", -errno);
455 rx_bytes = vppcom_session_read_segments (fd, ds);
464 if ((rx_bytes == 0) ||
466 && ((errno == EAGAIN) || (errno == EWOULDBLOCK))))
470 while ((rx_bytes == 0) ||
471 ((rx_bytes < 0) && ((errno == EAGAIN) || (errno == EWOULDBLOCK))));
475 vterr (
"vppcom_session_read()", -errno);
487 int tx_bytes = 0, nbytes_left = nbytes, rv;
493 rv = vppcom_session_write (fd, buf, nbytes_left);
497 if ((errno == EAGAIN || errno == EWOULDBLOCK) && stats)
503 nbytes_left = nbytes_left - rv;
509 while (tx_bytes != nbytes);
513 vterr (
"vpcom_session_write", -errno);
#define VCL_TEST_TOKEN_RXBUF_SIZE
uint32_t vcl_test_crt_rsa_len
Optimized string handling code, including c11-compliant "safe C library" variants.
uint32_t num_test_qsessions
uint32_t num_test_sessions
#define VCL_TEST_TOKEN_NUM_WRITES
static void vcl_test_stats_dump(char *header, vcl_test_stats_t *stats, uint8_t show_rx, uint8_t show_tx, uint8_t verbose)
static char * vcl_test_type_str(vcl_test_t t)
static int vcl_test_read_ds(int fd, vppcom_data_segments_t ds, vcl_test_stats_t *stats)
#define VCL_TEST_SEPARATOR_STRING
static void vcl_test_session_buf_alloc(vcl_test_session_t *socket)
static void vcl_test_cfg_dump(vcl_test_cfg_t *cfg, uint8_t is_client)
#define VCL_TEST_CFG_CTRL_MAGIC
#define VCL_TEST_TOKEN_RUN_BI
static void vcl_test_cfg_init(vcl_test_cfg_t *cfg)
#define VCL_TEST_TOKEN_TXBUF_SIZE
#define VCL_TEST_TOKEN_VERBOSE
uint32_t num_test_sessions_perq
static void vcl_test_buf_alloc(vcl_test_cfg_t *cfg, uint8_t is_rxbuf, uint8_t **buf, uint32_t *bufsize)
static int vcl_test_read(int fd, uint8_t *buf, uint32_t nbytes, vcl_test_stats_t *stats)
static int vcl_test_write(int fd, uint8_t *buf, uint32_t nbytes, vcl_test_stats_t *stats, uint32_t verbose)
uint32_t vcl_test_key_rsa_len
#define VCL_TEST_CFG_NUM_WRITES_DEF
#define VCL_TEST_TOKEN_RUN_UNI
static int vcl_comp_tspec(struct timespec *a, struct timespec *b)
static void vcl_test_stats_accumulate(vcl_test_stats_t *accum, vcl_test_stats_t *incr)
#define VCL_TEST_CFG_RXBUF_SIZE_DEF
#define VCL_TEST_CFG_TXBUF_SIZE_DEF
#define VCL_TEST_TOKEN_NUM_TEST_SESS
static int vcl_test_cfg_verify(vcl_test_cfg_t *cfg, vcl_test_cfg_t *valid_cfg)
#define vtwrn(_fmt, _args...)