2010-08-27 21:13:45 +02:00
|
|
|
/*
|
2017-05-01 13:11:11 +02:00
|
|
|
Copyright (c) 2007-2017 Contributors as noted in the AUTHORS file
|
2010-08-27 21:13:45 +02:00
|
|
|
|
2015-06-02 22:33:55 +02:00
|
|
|
This file is part of libzmq, the ZeroMQ core engine in C++.
|
2010-08-27 21:13:45 +02:00
|
|
|
|
2015-06-02 22:33:55 +02:00
|
|
|
libzmq is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU Lesser General Public License (LGPL) as published
|
|
|
|
by the Free Software Foundation; either version 3 of the License, or
|
2010-08-27 21:13:45 +02:00
|
|
|
(at your option) any later version.
|
|
|
|
|
2015-06-02 22:33:55 +02:00
|
|
|
As a special exception, the Contributors give you permission to link
|
|
|
|
this library with independent modules to produce an executable,
|
|
|
|
regardless of the license terms of these independent modules, and to
|
|
|
|
copy and distribute the resulting executable under terms of your choice,
|
|
|
|
provided that you also meet, for each linked independent module, the
|
|
|
|
terms and conditions of the license of that module. An independent
|
|
|
|
module is a module which is not derived from or based on this library.
|
|
|
|
If you modify this library, you must extend this exception to your
|
|
|
|
version of the library.
|
|
|
|
|
|
|
|
libzmq is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
|
|
|
License for more details.
|
2010-08-27 21:13:45 +02:00
|
|
|
|
2010-10-30 15:08:28 +02:00
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
2010-08-27 21:13:45 +02:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2013-05-16 20:29:55 +02:00
|
|
|
#ifndef __TESTUTIL_HPP_INCLUDED__
|
|
|
|
#define __TESTUTIL_HPP_INCLUDED__
|
2010-08-27 21:13:45 +02:00
|
|
|
|
2016-02-12 11:31:38 +01:00
|
|
|
#if defined ZMQ_CUSTOM_PLATFORM_HPP
|
2018-02-01 11:46:09 +01:00
|
|
|
#include "platform.hpp"
|
2015-09-11 22:42:26 +02:00
|
|
|
#else
|
2018-02-01 11:46:09 +01:00
|
|
|
#include "../src/platform.hpp"
|
2015-09-11 22:42:26 +02:00
|
|
|
#endif
|
2016-05-02 20:39:13 +02:00
|
|
|
#include "../include/zmq.h"
|
|
|
|
#include "../src/stdint.hpp"
|
2013-08-17 14:43:45 +02:00
|
|
|
|
2013-11-06 13:30:41 +01:00
|
|
|
// This defines the settle time used in tests; raise this if we
|
|
|
|
// get test failures on slower systems due to binds/connects not
|
|
|
|
// settled. Tested to work reliably at 1 msec on a fast PC.
|
2018-02-01 11:46:09 +01:00
|
|
|
#define SETTLE_TIME 300 // In msec
|
2017-05-01 13:11:11 +02:00
|
|
|
// Commonly used buffer size for ZMQ_LAST_ENDPOINT
|
2019-02-06 15:09:14 +01:00
|
|
|
// this used to be sizeof ("tcp://[::ffff:127.127.127.127]:65536"), but this
|
|
|
|
// may be too short for ipc wildcard binds, e.g.
|
|
|
|
#define MAX_SOCKET_STRING 256
|
2017-05-01 13:11:11 +02:00
|
|
|
|
|
|
|
// We need to test codepaths with non-random bind ports. List them here to
|
|
|
|
// keep them unique, to allow parallel test runs.
|
|
|
|
#define ENDPOINT_0 "tcp://127.0.0.1:5555"
|
|
|
|
#define ENDPOINT_1 "tcp://127.0.0.1:5556"
|
|
|
|
#define ENDPOINT_2 "tcp://127.0.0.1:5557"
|
|
|
|
#define ENDPOINT_3 "tcp://127.0.0.1:5558"
|
|
|
|
#define ENDPOINT_4 "udp://127.0.0.1:5559"
|
|
|
|
#define ENDPOINT_5 "udp://127.0.0.1:5560"
|
2019-03-19 00:27:01 +01:00
|
|
|
#define PORT_6 5561
|
2013-11-06 13:30:41 +01:00
|
|
|
|
2012-08-23 22:40:30 +02:00
|
|
|
#undef NDEBUG
|
2013-08-17 14:43:45 +02:00
|
|
|
|
2018-05-14 20:49:58 +02:00
|
|
|
// duplicated from fd.hpp
|
|
|
|
#ifdef ZMQ_HAVE_WINDOWS
|
2019-03-19 00:27:01 +01:00
|
|
|
#include <winsock2.h>
|
|
|
|
#include <ws2tcpip.h>
|
|
|
|
#include <stdexcept>
|
2018-05-14 20:49:58 +02:00
|
|
|
#define close closesocket
|
|
|
|
typedef int socket_size_t;
|
2019-03-23 11:27:12 +01:00
|
|
|
inline const char *as_setsockopt_opt_t (const void *opt)
|
2018-05-15 13:49:50 +02:00
|
|
|
{
|
|
|
|
return static_cast<const char *> (opt);
|
|
|
|
}
|
2018-05-14 20:49:58 +02:00
|
|
|
#if defined _MSC_VER && _MSC_VER <= 1400
|
|
|
|
typedef UINT_PTR fd_t;
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
retired_fd = (fd_t) (~0)
|
|
|
|
};
|
|
|
|
#else
|
|
|
|
typedef SOCKET fd_t;
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
retired_fd = (fd_t) INVALID_SOCKET
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
typedef size_t socket_size_t;
|
2019-03-23 11:27:12 +01:00
|
|
|
inline const void *as_setsockopt_opt_t (const void *opt_)
|
2018-05-15 13:49:50 +02:00
|
|
|
{
|
2018-05-27 13:01:36 +02:00
|
|
|
return opt_;
|
2018-05-15 13:49:50 +02:00
|
|
|
}
|
2018-05-14 20:49:58 +02:00
|
|
|
typedef int fd_t;
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
retired_fd = -1
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2018-02-01 11:46:09 +01:00
|
|
|
#define LIBZMQ_UNUSED(object) (void) object
|
2017-08-19 13:18:51 +02:00
|
|
|
|
2013-05-16 20:29:55 +02:00
|
|
|
// Bounce a message from client to server and back
|
|
|
|
// For REQ/REP or DEALER/DEALER pairs only
|
2019-03-23 11:27:12 +01:00
|
|
|
void bounce (void *server_, void *client_);
|
2010-08-27 21:13:45 +02:00
|
|
|
|
2013-08-31 02:56:59 +02:00
|
|
|
// Same as bounce, but expect messages to never arrive
|
|
|
|
// for security or subscriber reasons.
|
2019-03-23 11:27:12 +01:00
|
|
|
void expect_bounce_fail (void *server_, void *client_);
|
2013-08-31 02:56:59 +02:00
|
|
|
|
2013-06-28 11:42:54 +02:00
|
|
|
// Receive 0MQ string from socket and convert into C string
|
|
|
|
// Caller must free returned string. Returns NULL if the context
|
|
|
|
// is being terminated.
|
2019-03-23 11:27:12 +01:00
|
|
|
char *s_recv (void *socket_);
|
2013-06-28 11:42:54 +02:00
|
|
|
|
2019-03-23 13:03:57 +01:00
|
|
|
bool streq (const char *lhs, const char *rhs);
|
|
|
|
bool strneq (const char *lhs, const char *rhs);
|
2013-06-28 11:42:54 +02:00
|
|
|
|
2019-03-23 11:27:12 +01:00
|
|
|
extern const char *SEQ_END;
|
2013-07-02 15:04:31 +02:00
|
|
|
|
|
|
|
// Sends a message composed of frames that are C strings or null frames.
|
|
|
|
// The list must be terminated by SEQ_END.
|
|
|
|
// Example: s_send_seq (req, "ABC", 0, "DEF", SEQ_END);
|
2015-09-11 22:42:26 +02:00
|
|
|
|
2019-03-23 11:27:12 +01:00
|
|
|
void s_send_seq (void *socket_, ...);
|
2013-07-02 15:04:31 +02:00
|
|
|
|
|
|
|
// Receives message a number of frames long and checks that the frames have
|
|
|
|
// the given data which can be either C strings or 0 for a null frame.
|
|
|
|
// The list must be terminated by SEQ_END.
|
|
|
|
// Example: s_recv_seq (rep, "ABC", 0, "DEF", SEQ_END);
|
2015-09-11 22:42:26 +02:00
|
|
|
|
2019-03-23 11:27:12 +01:00
|
|
|
void s_recv_seq (void *socket_, ...);
|
2013-07-02 15:04:31 +02:00
|
|
|
|
2013-07-05 17:58:01 +02:00
|
|
|
|
2014-04-28 11:30:04 +02:00
|
|
|
// Sets a zero linger period on a socket and closes it.
|
2019-03-23 11:27:12 +01:00
|
|
|
void close_zero_linger (void *socket_);
|
2013-07-05 17:58:01 +02:00
|
|
|
|
2019-03-23 11:27:12 +01:00
|
|
|
void setup_test_environment (void);
|
2013-08-17 14:43:45 +02:00
|
|
|
|
2013-11-06 13:30:41 +01:00
|
|
|
// Provide portable millisecond sleep
|
2015-09-11 22:42:26 +02:00
|
|
|
// http://www.cplusplus.com/forum/unices/60161/
|
|
|
|
// http://en.cppreference.com/w/cpp/thread/sleep_for
|
|
|
|
|
2019-03-23 11:27:12 +01:00
|
|
|
void msleep (int milliseconds_);
|
2013-10-18 11:12:48 +02:00
|
|
|
|
2016-04-18 17:20:58 +02:00
|
|
|
// check if IPv6 is available (0/false if not, 1/true if it is)
|
|
|
|
// only way to reliably check is to actually open a socket and try to bind it
|
2019-03-23 11:27:12 +01:00
|
|
|
int is_ipv6_available (void);
|
2013-10-18 11:12:48 +02:00
|
|
|
|
2018-03-09 17:47:42 +01:00
|
|
|
// check if tipc is available (0/false if not, 1/true if it is)
|
|
|
|
// only way to reliably check is to actually open a socket and try to bind it
|
|
|
|
// as it depends on a non-default kernel module to be already loaded
|
2019-03-23 11:27:12 +01:00
|
|
|
int is_tipc_available (void);
|
2018-03-09 17:47:42 +01:00
|
|
|
|
2018-04-30 16:56:17 +02:00
|
|
|
// Wrapper around 'inet_pton' for systems that don't support it (e.g. Windows
|
|
|
|
// XP)
|
2019-03-23 11:27:12 +01:00
|
|
|
int test_inet_pton (int af_, const char *src_, void *dst_);
|
2018-04-30 16:56:17 +02:00
|
|
|
|
2019-03-19 00:27:01 +01:00
|
|
|
// Binds an ipv4 BSD socket to an ephemeral port, returns the compiled sockaddr
|
2019-03-23 11:27:12 +01:00
|
|
|
struct sockaddr_in bind_bsd_socket (int socket);
|
2019-03-19 00:27:01 +01:00
|
|
|
|
2010-08-27 21:13:45 +02:00
|
|
|
#endif
|