2013-09-04 19:38:15 +02:00
|
|
|
/*
|
2017-05-01 13:11:11 +02:00
|
|
|
Copyright (c) 2007-2017 Contributors as noted in the AUTHORS file
|
2013-09-04 19:38:15 +02:00
|
|
|
|
2015-06-02 22:33:55 +02:00
|
|
|
This file is part of libzmq, the ZeroMQ core engine in C++.
|
2013-09-04 19:38:15 +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
|
2013-09-04 19:38:15 +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.
|
2013-09-04 19:38:15 +02:00
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
2018-02-01 11:46:09 +01:00
|
|
|
#if defined(ZMQ_HAVE_WINDOWS)
|
|
|
|
#include <winsock2.h>
|
|
|
|
#include <stdexcept>
|
2013-09-06 11:08:11 +02:00
|
|
|
#else
|
2018-02-01 11:46:09 +01:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <unistd.h>
|
2013-09-06 11:08:11 +02:00
|
|
|
#endif
|
|
|
|
|
2019-03-22 11:48:49 +01:00
|
|
|
void setUp ()
|
|
|
|
{
|
|
|
|
setup_test_context ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void tearDown ()
|
|
|
|
{
|
|
|
|
teardown_test_context ();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
2018-02-01 11:46:09 +01:00
|
|
|
#if defined(ZMQ_HAVE_WINDOWS)
|
2013-09-06 11:08:11 +02:00
|
|
|
|
2014-01-29 20:16:58 +01:00
|
|
|
void initialise_network (void)
|
2013-09-06 11:08:11 +02:00
|
|
|
{
|
|
|
|
WSADATA info;
|
2018-02-01 11:46:09 +01:00
|
|
|
if (WSAStartup (MAKEWORD (2, 0), &info) != 0)
|
|
|
|
throw std::runtime_error ("Could not start WSA");
|
2013-09-06 11:08:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#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"
|
2018-02-01 11:46:09 +01:00
|
|
|
"E: networking. Please fix this before running libzmq checks.\n");
|
2014-01-29 20:16:58 +01:00
|
|
|
}
|
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++) {
|
2018-02-01 11:46:09 +01:00
|
|
|
handle[count] = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
|
|
|
if (handle[count] == -1) {
|
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"
|
2018-02-01 11:46:09 +01: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++) {
|
2018-02-01 11:46:09 +01:00
|
|
|
close (handle[count]);
|
2015-05-31 00:57:53 +02:00
|
|
|
}
|
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
|
|
|
}
|