2 * Copyright (c) 2017 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 #ifndef __vcl_test_h__
17 #define __vcl_test_h__
23 #include <vcl/vppcom.h>
24 #include <vcl/sock_test_common.h>
26 #define vtfail(_fn, _rv) \
29 perror ("ERROR when calling " _fn); \
30 fprintf (stderr, "\nERROR: " _fn " failed (errno = %d)!\n", -_rv); \
34 #define vterr(_fn, _rv) \
37 fprintf (stderr, "\nERROR: " _fn " failed (errno = %d)!\n", -_rv); \
40 #define vtwrn(_fmt, _args...) \
41 fprintf (stderr, "\nERROR: " _fmt "\n", ##_args) \
43 #define vtinf(_fmt, _args...) \
44 fprintf (stdout, "vt<w%u>: " _fmt "\n", __wrk_index, ##_args)
46 #define vt_atomic_add(_ptr, _val) \
47 __atomic_fetch_add (_ptr, _val, __ATOMIC_RELEASE)
50 vcl_test_read (int fd, uint8_t *buf, uint32_t nbytes,
51 sock_test_stats_t *stats)
53 int rx_bytes, errno_val;
59 rx_bytes = vppcom_session_read (fd, buf, nbytes);
68 if ((rx_bytes == 0) ||
69 ((rx_bytes < 0) && ((errno == EAGAIN) || (errno == EWOULDBLOCK))))
71 else if (rx_bytes < nbytes)
75 while ((rx_bytes == 0) ||
76 ((rx_bytes < 0) && ((errno == EAGAIN) || (errno == EWOULDBLOCK))));
80 vterr ("vppcom_session_read()", -errno);
83 stats->rx_bytes += rx_bytes;
89 vcl_test_read_ds (int fd, vppcom_data_segments_t ds, sock_test_stats_t *stats)
91 int rx_bytes, errno_val;
97 rx_bytes = vppcom_session_read_segments (fd, ds);
106 if ((rx_bytes == 0) ||
107 ((rx_bytes < 0) && ((errno == EAGAIN) || (errno == EWOULDBLOCK))))
111 while ((rx_bytes == 0) ||
112 ((rx_bytes < 0) && ((errno == EAGAIN) || (errno == EWOULDBLOCK))));
116 vterr ("vppcom_session_read()", -errno);
119 stats->rx_bytes += rx_bytes;
125 vcl_test_write (int fd, uint8_t *buf, uint32_t nbytes,
126 sock_test_stats_t *stats, uint32_t verbose)
129 int nbytes_left = nbytes;
136 rv = vppcom_session_write (fd, buf, nbytes_left);
144 if ((errno == EAGAIN) || (errno == EWOULDBLOCK))
155 if (tx_bytes != nbytes)
157 nbytes_left = nbytes_left - rv;
162 } while (tx_bytes != nbytes);
167 perror ("ERROR in sock_test_write()");
168 fprintf (stderr, "SOCK_TEST: ERROR: socket write failed "
169 "(errno = %d)!\n", errno_val);
172 stats->tx_bytes += tx_bytes;
177 #endif /* __vcl_test_h__ */