Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
L
libzmq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
libzmq
Commits
06e713e9
Commit
06e713e9
authored
Mar 22, 2019
by
Simon Giesecke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Problem: tests without test framework
Solution: migrate to Unity
parent
4ab38143
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
23 deletions
+30
-23
Makefile.am
Makefile.am
+2
-1
test_many_sockets.cpp
tests/test_many_sockets.cpp
+28
-22
No files found.
Makefile.am
View file @
06e713e9
...
...
@@ -681,7 +681,8 @@ tests_test_getsockopt_memset_LDADD = src/libzmq.la ${UNITY_LIBS}
tests_test_getsockopt_memset_CPPFLAGS
=
${
UNITY_CPPFLAGS
}
tests_test_many_sockets_SOURCES
=
tests/test_many_sockets.cpp
tests_test_many_sockets_LDADD
=
src/libzmq.la
tests_test_many_sockets_LDADD
=
src/libzmq.la
${
UNITY_LIBS
}
tests_test_many_sockets_CPPFLAGS
=
${
UNITY_CPPFLAGS
}
tests_test_diffserv_SOURCES
=
tests/test_diffserv.cpp
tests_test_diffserv_LDADD
=
src/libzmq.la
${
UNITY_LIBS
}
...
...
tests/test_many_sockets.cpp
View file @
06e713e9
...
...
@@ -28,75 +28,81 @@
*/
#include "testutil.hpp"
#include <zmq.h>
#include "testutil_unity.hpp"
#include <stdio.h>
#include <stdlib.h>
#include <vector>
void
setUp
()
{
setup_test_context
();
}
void
tearDown
()
{
teardown_test_context
();
}
void
test_system_max
()
{
// Keep allocating sockets until we run out of system resources
const
int
no_of_sockets
=
2
*
65536
;
void
*
ctx
=
zmq_ctx_new
();
zmq_ctx_set
(
ctx
,
ZMQ_MAX_SOCKETS
,
no_of_sockets
);
zmq_ctx_set
(
get_test_context
(),
ZMQ_MAX_SOCKETS
,
no_of_sockets
);
std
::
vector
<
void
*>
sockets
;
while
(
true
)
{
void
*
socket
=
zmq_socket
(
ctx
,
ZMQ_PAIR
);
void
*
socket
=
zmq_socket
(
get_test_context
()
,
ZMQ_PAIR
);
if
(
!
socket
)
break
;
sockets
.
push_back
(
socket
);
}
assert
(
static_cast
<
int
>
(
sockets
.
size
())
<=
no_of_sockets
);
TEST_ASSERT_LESS_OR_EQUAL
(
no_of_sockets
,
static_cast
<
int
>
(
sockets
.
size
()));
printf
(
"Socket creation failed after %i sockets
\n
"
,
static_cast
<
int
>
(
sockets
.
size
()));
// System is out of resources, further calls to zmq_socket should return NULL
for
(
unsigned
int
i
=
0
;
i
<
10
;
++
i
)
{
void
*
socket
=
zmq_socket
(
ctx
,
ZMQ_PAIR
);
assert
(
socket
==
NULL
);
void
*
socket
=
zmq_socket
(
get_test_context
()
,
ZMQ_PAIR
);
TEST_ASSERT_NULL
(
socket
);
}
// Clean up.
for
(
unsigned
int
i
=
0
;
i
<
sockets
.
size
();
++
i
)
zmq_close
(
sockets
[
i
]);
zmq_ctx_destroy
(
ctx
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_close
(
sockets
[
i
]));
}
void
test_zmq_default_max
()
{
// Keep allocating sockets until we hit the default limit
void
*
ctx
=
zmq_ctx_new
();
std
::
vector
<
void
*>
sockets
;
while
(
true
)
{
void
*
socket
=
zmq_socket
(
ctx
,
ZMQ_PAIR
);
void
*
socket
=
zmq_socket
(
get_test_context
()
,
ZMQ_PAIR
);
if
(
!
socket
)
break
;
sockets
.
push_back
(
socket
);
}
// We may stop sooner if system has fewer available sockets
assert
(
sockets
.
size
()
<=
ZMQ_MAX_SOCKETS_DFLT
);
TEST_ASSERT_LESS_OR_EQUAL
(
ZMQ_MAX_SOCKETS_DFLT
,
sockets
.
size
()
);
// Further calls to zmq_socket should return NULL
for
(
unsigned
int
i
=
0
;
i
<
10
;
++
i
)
{
void
*
socket
=
zmq_socket
(
ctx
,
ZMQ_PAIR
);
assert
(
socket
==
NULL
);
void
*
socket
=
zmq_socket
(
get_test_context
()
,
ZMQ_PAIR
);
TEST_ASSERT_NULL
(
socket
);
}
// Clean up
for
(
unsigned
int
i
=
0
;
i
<
sockets
.
size
();
++
i
)
zmq_close
(
sockets
[
i
]);
zmq_ctx_destroy
(
ctx
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_close
(
sockets
[
i
]));
}
int
main
(
void
)
{
setup_test_environment
();
test_system_max
();
test_zmq_default_max
(
);
return
0
;
UNITY_BEGIN
();
RUN_TEST
(
test_system_max
);
RUN_TEST
(
test_zmq_default_max
);
return
UNITY_END
()
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment