X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvcl%2Fvcl_test.h;h=68750af89a14a956c94a4040c50efbbc5b93ce0b;hb=0e88e851e058f4fb7cc690dbbdb19216ab360d1c;hp=0f3bd2d3a40ca983d55ca65d5815dd291e186a6b;hpb=e4d5a652a392c9f74501da5778a7fe161b183476;p=vpp.git diff --git a/src/vcl/vcl_test.h b/src/vcl/vcl_test.h index 0f3bd2d3a40..68750af89a1 100644 --- a/src/vcl/vcl_test.h +++ b/src/vcl/vcl_test.h @@ -23,6 +23,29 @@ #include #include +#define vtfail(_fn, _rv) \ +{ \ + errno = -_rv; \ + perror ("ERROR when calling " _fn); \ + fprintf (stderr, "\nERROR: " _fn " failed (errno = %d)!\n", -_rv); \ + exit (1); \ +} + +#define vterr(_fn, _rv) \ +{ \ + errno = -_rv; \ + fprintf (stderr, "\nERROR: " _fn " failed (errno = %d)!\n", -_rv); \ +} + +#define vtwrn(_fmt, _args...) \ + fprintf (stderr, "\nERROR: " _fmt "\n", ##_args) \ + +#define vtinf(_fmt, _args...) \ + fprintf (stdout, "vt: " _fmt "\n", __wrk_index, ##_args) + +#define vt_atomic_add(_ptr, _val) \ + __atomic_fetch_add (_ptr, _val, __ATOMIC_RELEASE) + static inline int vcl_test_read (int fd, uint8_t *buf, uint32_t nbytes, sock_test_stats_t *stats) @@ -54,11 +77,43 @@ vcl_test_read (int fd, uint8_t *buf, uint32_t nbytes, if (rx_bytes < 0) { - errno_val = errno; - perror ("ERROR in sock_test_read()"); - fprintf (stderr, "SOCK_TEST: ERROR: socket read " - "failed (errno = %d)!\n", errno_val); - errno = errno_val; + vterr ("vppcom_session_read()", -errno); + } + else if (stats) + stats->rx_bytes += rx_bytes; + + return (rx_bytes); +} + +static inline int +vcl_test_read_ds (int fd, vppcom_data_segments_t ds, sock_test_stats_t *stats) +{ + int rx_bytes, errno_val; + + do + { + if (stats) + stats->rx_xacts++; + rx_bytes = vppcom_session_read_segments (fd, ds); + + if (rx_bytes < 0) + { + errno = -rx_bytes; + rx_bytes = -1; + } + if (stats) + { + if ((rx_bytes == 0) || + ((rx_bytes < 0) && ((errno == EAGAIN) || (errno == EWOULDBLOCK)))) + stats->rx_eagain++; + } + } + while ((rx_bytes == 0) || + ((rx_bytes < 0) && ((errno == EAGAIN) || (errno == EWOULDBLOCK)))); + + if (rx_bytes < 0) + { + vterr ("vppcom_session_read()", -errno); } else if (stats) stats->rx_bytes += rx_bytes; @@ -70,9 +125,7 @@ static inline int vcl_test_write (int fd, uint8_t *buf, uint32_t nbytes, sock_test_stats_t *stats, uint32_t verbose) { - int tx_bytes = 0; - int nbytes_left = nbytes; - int rv, errno_val; + int tx_bytes = 0, nbytes_left = nbytes, rv; do { @@ -102,21 +155,13 @@ vcl_test_write (int fd, uint8_t *buf, uint32_t nbytes, nbytes_left = nbytes_left - rv; if (stats) stats->tx_incomp++; - if (verbose) - { - printf ("SOCK_TEST: WARNING: bytes written (%d) " - "!= bytes to write (%d)!\n", tx_bytes, nbytes); - } } } while (tx_bytes != nbytes); if (tx_bytes < 0) { - errno_val = errno; - perror ("ERROR in sock_test_write()"); - fprintf (stderr, "SOCK_TEST: ERROR: socket write failed " - "(errno = %d)!\n", errno_val); + vterr ("vpcom_session_write", -errno); } else if (stats) stats->tx_bytes += tx_bytes;