2023-06-05 01:16:05 +02:00
|
|
|
/* SPDX-License-Identifier: MPL-2.0 */
|
2013-09-04 19:38:15 +02:00
|
|
|
|
2013-09-15 20:07:33 +02:00
|
|
|
#include "testutil.hpp"
|
2019-03-22 11:48:49 +01:00
|
|
|
#include "testutil_unity.hpp"
|
2013-09-15 20:07:33 +02:00
|
|
|
|
2013-09-06 11:08:11 +02:00
|
|
|
#if defined(ZMQ_HAVE_WINDOWS)
|
2013-10-04 18:51:47 +02:00
|
|
|
#include <winsock2.h>
|
2013-09-15 20:07:33 +02:00
|
|
|
#include <stdexcept>
|
2013-09-06 11:08:11 +02:00
|
|
|
#else
|
2013-09-15 20:07:33 +02:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <unistd.h>
|
2013-09-06 11:08:11 +02:00
|
|
|
#endif
|
|
|
|
|
2019-03-24 17:51:28 +01:00
|
|
|
SETUP_TEARDOWN_TESTCONTEXT
|
2019-03-22 11:48:49 +01:00
|
|
|
|
2018-05-13 14:18:08 +02:00
|
|
|
// Solaris has a default of 256 max files per process
|
|
|
|
#ifdef ZMQ_HAVE_SOLARIS
|
|
|
|
#define MAX_SOCKETS 200
|
|
|
|
#else
|
|
|
|
#define MAX_SOCKETS 1000
|
|
|
|
#endif
|
|
|
|
|
2013-09-06 11:08:11 +02:00
|
|
|
#if defined(ZMQ_HAVE_WINDOWS)
|
|
|
|
|
2014-01-29 20:16:58 +01:00
|
|
|
void initialise_network (void)
|
2013-09-06 11:08:11 +02:00
|
|
|
{
|
|
|
|
WSADATA info;
|
|
|
|
if (WSAStartup (MAKEWORD (2, 0), &info) != 0)
|
|
|
|
throw std::runtime_error ("Could not start WSA");
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2014-01-29 20:16:58 +01:00
|
|
|
void initialise_network (void)
|
2013-09-06 11:08:11 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2013-09-04 19:38:15 +02:00
|
|
|
|
2019-03-22 11:48:49 +01:00
|
|
|
void test_localhost ()
|
2013-09-04 19:38:15 +02:00
|
|
|
{
|
2014-01-29 20:16:58 +01:00
|
|
|
// Check that we have local networking via ZeroMQ
|
2019-03-22 11:48:49 +01:00
|
|
|
void *dealer = test_context_socket (ZMQ_DEALER);
|
2017-05-01 13:11:11 +02:00
|
|
|
if (zmq_bind (dealer, "tcp://127.0.0.1:*") == -1) {
|
2019-03-22 11:48:49 +01:00
|
|
|
TEST_FAIL_MESSAGE (
|
|
|
|
"E: Cannot find 127.0.0.1 -- your system does not have local\n"
|
2014-01-29 20:16:58 +01:00
|
|
|
"E: networking. Please fix this before running libzmq checks.\n");
|
|
|
|
}
|
2019-03-22 11:48:49 +01:00
|
|
|
|
|
|
|
test_context_socket_close (dealer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_max_sockets ()
|
|
|
|
{
|
2013-09-04 19:38:15 +02:00
|
|
|
// Check that we can create 1,000 sockets
|
2018-05-14 20:56:30 +02:00
|
|
|
fd_t handle[MAX_SOCKETS];
|
2013-09-04 19:38:15 +02:00
|
|
|
int count;
|
2018-05-13 14:18:08 +02:00
|
|
|
for (count = 0; count < MAX_SOCKETS; count++) {
|
2013-09-04 19:38:15 +02:00
|
|
|
handle[count] = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
2020-04-27 22:32:27 +02:00
|
|
|
if (handle[count] == retired_fd) {
|
2013-09-04 19:38:15 +02:00
|
|
|
printf ("W: Only able to create %d sockets on this box\n", count);
|
2019-03-22 11:48:49 +01:00
|
|
|
const char msg[] =
|
|
|
|
"I: Tune your system to increase maximum allowed file handles\n"
|
2018-05-13 14:19:07 +02:00
|
|
|
#if !defined(ZMQ_HAVE_WINDOWS)
|
2019-03-22 11:48:49 +01:00
|
|
|
"I: Run 'ulimit -n 1200' in bash\n"
|
2013-09-04 19:38:15 +02:00
|
|
|
#endif
|
2019-03-22 11:48:49 +01:00
|
|
|
;
|
|
|
|
TEST_FAIL_MESSAGE (msg);
|
2013-09-04 19:38:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Release the socket handles
|
2018-05-13 14:18:08 +02:00
|
|
|
for (count = 0; count < MAX_SOCKETS; count++) {
|
2015-05-31 00:57:53 +02:00
|
|
|
close (handle[count]);
|
|
|
|
}
|
2019-03-22 11:48:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// This test case stresses the system to shake out known configuration
|
|
|
|
// problems. We're direct system calls when necessary. Some code may
|
|
|
|
// need wrapping to be properly portable.
|
|
|
|
|
|
|
|
int main (void)
|
|
|
|
{
|
|
|
|
initialise_network ();
|
2016-02-05 12:56:45 +01:00
|
|
|
|
2019-03-22 11:48:49 +01:00
|
|
|
UNITY_BEGIN ();
|
|
|
|
RUN_TEST (test_localhost);
|
|
|
|
RUN_TEST (test_max_sockets);
|
|
|
|
return UNITY_END ();
|
2013-09-04 19:38:15 +02:00
|
|
|
}
|