Commit 06e713e9 authored by Simon Giesecke's avatar Simon Giesecke

Problem: tests without test framework

Solution: migrate to Unity
parent 4ab38143
...@@ -681,7 +681,8 @@ tests_test_getsockopt_memset_LDADD = src/libzmq.la ${UNITY_LIBS} ...@@ -681,7 +681,8 @@ tests_test_getsockopt_memset_LDADD = src/libzmq.la ${UNITY_LIBS}
tests_test_getsockopt_memset_CPPFLAGS = ${UNITY_CPPFLAGS} tests_test_getsockopt_memset_CPPFLAGS = ${UNITY_CPPFLAGS}
tests_test_many_sockets_SOURCES = tests/test_many_sockets.cpp 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_SOURCES = tests/test_diffserv.cpp
tests_test_diffserv_LDADD = src/libzmq.la ${UNITY_LIBS} tests_test_diffserv_LDADD = src/libzmq.la ${UNITY_LIBS}
......
...@@ -28,75 +28,81 @@ ...@@ -28,75 +28,81 @@
*/ */
#include "testutil.hpp" #include "testutil.hpp"
#include <zmq.h> #include "testutil_unity.hpp"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <vector> #include <vector>
void setUp ()
{
setup_test_context ();
}
void tearDown ()
{
teardown_test_context ();
}
void test_system_max () void test_system_max ()
{ {
// Keep allocating sockets until we run out of system resources // Keep allocating sockets until we run out of system resources
const int no_of_sockets = 2 * 65536; const int no_of_sockets = 2 * 65536;
void *ctx = zmq_ctx_new (); zmq_ctx_set (get_test_context (), ZMQ_MAX_SOCKETS, no_of_sockets);
zmq_ctx_set (ctx, ZMQ_MAX_SOCKETS, no_of_sockets);
std::vector<void *> sockets; std::vector<void *> sockets;
while (true) { while (true) {
void *socket = zmq_socket (ctx, ZMQ_PAIR); void *socket = zmq_socket (get_test_context (), ZMQ_PAIR);
if (!socket) if (!socket)
break; break;
sockets.push_back (socket); 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", printf ("Socket creation failed after %i sockets\n",
static_cast<int> (sockets.size ())); static_cast<int> (sockets.size ()));
// System is out of resources, further calls to zmq_socket should return NULL // System is out of resources, further calls to zmq_socket should return NULL
for (unsigned int i = 0; i < 10; ++i) { for (unsigned int i = 0; i < 10; ++i) {
void *socket = zmq_socket (ctx, ZMQ_PAIR); void *socket = zmq_socket (get_test_context (), ZMQ_PAIR);
assert (socket == NULL); TEST_ASSERT_NULL (socket);
} }
// Clean up. // Clean up.
for (unsigned int i = 0; i < sockets.size (); ++i) for (unsigned int i = 0; i < sockets.size (); ++i)
zmq_close (sockets[i]); TEST_ASSERT_SUCCESS_ERRNO (zmq_close (sockets[i]));
zmq_ctx_destroy (ctx);
} }
void test_zmq_default_max () void test_zmq_default_max ()
{ {
// Keep allocating sockets until we hit the default limit // Keep allocating sockets until we hit the default limit
void *ctx = zmq_ctx_new ();
std::vector<void *> sockets; std::vector<void *> sockets;
while (true) { while (true) {
void *socket = zmq_socket (ctx, ZMQ_PAIR); void *socket = zmq_socket (get_test_context (), ZMQ_PAIR);
if (!socket) if (!socket)
break; break;
sockets.push_back (socket); sockets.push_back (socket);
} }
// We may stop sooner if system has fewer available sockets // 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 // Further calls to zmq_socket should return NULL
for (unsigned int i = 0; i < 10; ++i) { for (unsigned int i = 0; i < 10; ++i) {
void *socket = zmq_socket (ctx, ZMQ_PAIR); void *socket = zmq_socket (get_test_context (), ZMQ_PAIR);
assert (socket == NULL); TEST_ASSERT_NULL (socket);
} }
// Clean up // Clean up
for (unsigned int i = 0; i < sockets.size (); ++i) for (unsigned int i = 0; i < sockets.size (); ++i)
zmq_close (sockets[i]); TEST_ASSERT_SUCCESS_ERRNO (zmq_close (sockets[i]));
zmq_ctx_destroy (ctx);
} }
int main (void) int main (void)
{ {
setup_test_environment (); setup_test_environment ();
test_system_max (); UNITY_BEGIN ();
test_zmq_default_max (); RUN_TEST (test_system_max);
RUN_TEST (test_zmq_default_max);
return 0; return UNITY_END ();
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment