aboutsummaryrefslogtreecommitdiffstats
path: root/extras/libmemif/test
diff options
context:
space:
mode:
Diffstat (limited to 'extras/libmemif/test')
-rw-r--r--extras/libmemif/test/CMakeLists.txt35
-rw-r--r--extras/libmemif/test/main_test.c54
-rw-r--r--extras/libmemif/test/socket_test.c40
3 files changed, 82 insertions, 47 deletions
diff --git a/extras/libmemif/test/CMakeLists.txt b/extras/libmemif/test/CMakeLists.txt
new file mode 100644
index 00000000000..3681fd3e64b
--- /dev/null
+++ b/extras/libmemif/test/CMakeLists.txt
@@ -0,0 +1,35 @@
+# Copyright (c) 2017 Cisco and/or its affiliates.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
+
+set(HEADERS_DIR ${CMAKE_CURRENT_SOURCE_DIR})
+set(TEST_NAME libmemif-test)
+set(TEST_LIBS m rt)
+
+find_package(Subunit QUIET)
+if (NOT SUBUNIT_LIBRARY)
+ set(SUBUNIT_LIBRARY "")
+endif ()
+
+set(SOURCE_FILES
+ main_test.c
+ socket_test.c
+ unit_test.c
+)
+
+add_executable(${TEST_NAME} ${SOURCE_FILES})
+target_include_directories(${TEST_NAME} PRIVATE $<BUILD_INTERFACE:${HEADERS_DIR}>)
+target_link_libraries(${TEST_NAME} ${LIBMEMIF} ${CHECK_LIBRARY} ${SUBUNIT_LIBRARY} ${TEST_LIBS} ${CMAKE_THREAD_LIBS_INIT})
+
+add_test(unit_test unit-test) \ No newline at end of file
diff --git a/extras/libmemif/test/main_test.c b/extras/libmemif/test/main_test.c
index a5e0e3dc860..e4697beb56f 100644
--- a/extras/libmemif/test/main_test.c
+++ b/extras/libmemif/test/main_test.c
@@ -66,7 +66,7 @@ START_TEST (test_init)
if ((err =
memif_init (control_fd_update, TEST_APP_NAME, NULL,
- NULL)) != MEMIF_ERR_SUCCESS)
+ NULL, NULL)) != MEMIF_ERR_SUCCESS)
ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
libmemif_main_t *lm = &libmemif_main;
@@ -86,7 +86,7 @@ START_TEST (test_init_epoll)
int err;
if ((err =
- memif_init (NULL, TEST_APP_NAME, NULL, NULL)) != MEMIF_ERR_SUCCESS)
+ memif_init (NULL, TEST_APP_NAME, NULL, NULL, NULL)) != MEMIF_ERR_SUCCESS)
ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
libmemif_main_t *lm = &libmemif_main;
@@ -113,7 +113,7 @@ START_TEST (test_create)
if ((err =
memif_init (control_fd_update, TEST_APP_NAME, NULL,
- NULL)) != MEMIF_ERR_SUCCESS)
+ NULL, NULL)) != MEMIF_ERR_SUCCESS)
ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));
@@ -147,8 +147,8 @@ START_TEST (test_create)
ck_assert_ptr_ne (c->on_disconnect, NULL);
ck_assert_ptr_ne (c->on_interrupt, NULL);
- ck_assert_str_eq (c->args.interface_name, args.interface_name);
- ck_assert_str_eq (c->args.socket_filename, SOCKET_FILENAME);
+ ck_assert_str_eq ((char *)c->args.interface_name, (char *)args.interface_name);
+ ck_assert_str_eq ((char *)c->args.socket_filename, SOCKET_FILENAME);
struct itimerspec timer;
timerfd_gettime (lm->timerfd, &timer);
@@ -177,7 +177,7 @@ START_TEST (test_create_master)
if ((err =
memif_init (control_fd_update, TEST_APP_NAME, NULL,
- NULL)) != MEMIF_ERR_SUCCESS)
+ NULL, NULL)) != MEMIF_ERR_SUCCESS)
ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));
@@ -211,8 +211,8 @@ START_TEST (test_create_master)
ck_assert_ptr_ne (c->on_disconnect, NULL);
ck_assert_ptr_ne (c->on_interrupt, NULL);
- ck_assert_str_eq (c->args.interface_name, args.interface_name);
- ck_assert_str_eq (c->args.socket_filename, SOCKET_FILENAME);
+ ck_assert_str_eq ((char *)c->args.interface_name, (char *)args.interface_name);
+ ck_assert_str_eq ((char *)c->args.socket_filename, SOCKET_FILENAME);
struct stat file_stat;
@@ -238,7 +238,7 @@ START_TEST (test_create_mult)
if ((err =
memif_init (control_fd_update, TEST_APP_NAME, NULL,
- NULL)) != MEMIF_ERR_SUCCESS)
+ NULL, NULL)) != MEMIF_ERR_SUCCESS)
ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));
@@ -296,10 +296,10 @@ START_TEST (test_create_mult)
ck_assert_ptr_ne (c1->on_disconnect, NULL);
ck_assert_ptr_ne (c1->on_interrupt, NULL);
- ck_assert_str_eq (c->args.interface_name, args.interface_name);
- ck_assert_str_eq (c->args.socket_filename, SOCKET_FILENAME);
- ck_assert_str_eq (c1->args.interface_name, args.interface_name);
- ck_assert_str_eq (c1->args.socket_filename, SOCKET_FILENAME);
+ ck_assert_str_eq ((char *)c->args.interface_name, (char *)args.interface_name);
+ ck_assert_str_eq ((char *)c->args.socket_filename, SOCKET_FILENAME);
+ ck_assert_str_eq ((char *)c1->args.interface_name, (char *)args.interface_name);
+ ck_assert_str_eq ((char *)c1->args.socket_filename, SOCKET_FILENAME);
struct itimerspec timer;
timerfd_gettime (lm->timerfd, &timer);
@@ -330,7 +330,7 @@ START_TEST (test_control_fd_handler)
if ((err =
memif_init (control_fd_update, TEST_APP_NAME, NULL,
- NULL)) != MEMIF_ERR_SUCCESS)
+ NULL, NULL)) != MEMIF_ERR_SUCCESS)
ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));
@@ -401,7 +401,7 @@ START_TEST (test_buffer_alloc)
if ((err =
memif_init (control_fd_update, TEST_APP_NAME, NULL,
- NULL)) != MEMIF_ERR_SUCCESS)
+ NULL, NULL)) != MEMIF_ERR_SUCCESS)
ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));
@@ -495,7 +495,7 @@ START_TEST (test_tx_burst)
if ((err =
memif_init (control_fd_update, TEST_APP_NAME, NULL,
- NULL)) != MEMIF_ERR_SUCCESS)
+ NULL, NULL)) != MEMIF_ERR_SUCCESS)
ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));
@@ -600,7 +600,7 @@ START_TEST (test_rx_burst)
if ((err =
memif_init (control_fd_update, TEST_APP_NAME, NULL,
- NULL)) != MEMIF_ERR_SUCCESS)
+ NULL, NULL)) != MEMIF_ERR_SUCCESS)
ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));
@@ -689,7 +689,7 @@ START_TEST (test_get_details)
if ((err =
memif_init (control_fd_update, TEST_APP_NAME, NULL,
- NULL)) != MEMIF_ERR_SUCCESS)
+ NULL, NULL)) != MEMIF_ERR_SUCCESS)
ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));
@@ -718,11 +718,11 @@ START_TEST (test_get_details)
if ((err = memif_get_details (conn, &md, buf, buflen)) != MEMIF_ERR_SUCCESS)
ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
- ck_assert_str_eq (md.if_name, c->args.interface_name);
- ck_assert_str_eq (md.remote_if_name, c->remote_if_name);
- ck_assert_str_eq (md.remote_inst_name, c->remote_name);
- ck_assert_str_eq (md.secret, c->args.secret);
- ck_assert_str_eq (md.socket_filename, c->args.socket_filename);
+ ck_assert_str_eq ((char *)md.if_name, (char *)c->args.interface_name);
+ ck_assert_str_eq ((char *)md.remote_if_name, (char *)c->remote_if_name);
+ ck_assert_str_eq ((char *)md.remote_inst_name, (char *)c->remote_name);
+ ck_assert_str_eq ((char *)md.secret, (char *)c->args.secret);
+ ck_assert_str_eq ((char *)md.socket_filename, (char *)c->args.socket_filename);
ck_assert_uint_eq (md.id, c->args.interface_id);
ck_assert_uint_ne (md.role, c->args.is_master);
@@ -766,7 +766,7 @@ START_TEST (test_init_regions_and_queues)
if ((err =
memif_init (control_fd_update, TEST_APP_NAME, NULL,
- NULL)) != MEMIF_ERR_SUCCESS)
+ NULL, NULL)) != MEMIF_ERR_SUCCESS)
ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));
@@ -790,7 +790,7 @@ START_TEST (test_init_regions_and_queues)
ck_assert_ptr_ne (c->tx_queues, NULL);
ck_assert_ptr_ne (c->rx_queues, NULL);
- ck_assert_ptr_ne (c->regions->shm, NULL);
+ ck_assert_ptr_ne (c->regions->addr, NULL);
ck_assert_ptr_ne (c->tx_queues->ring, NULL);
ck_assert_ptr_ne (c->rx_queues->ring, NULL);
@@ -821,7 +821,7 @@ START_TEST (test_connect1)
if ((err =
memif_init (control_fd_update, TEST_APP_NAME, NULL,
- NULL)) != MEMIF_ERR_SUCCESS)
+ NULL, NULL)) != MEMIF_ERR_SUCCESS)
ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));
@@ -867,7 +867,7 @@ START_TEST (test_disconnect_internal)
if ((err =
memif_init (control_fd_update, TEST_APP_NAME, NULL,
- NULL)) != MEMIF_ERR_SUCCESS)
+ NULL, NULL)) != MEMIF_ERR_SUCCESS)
ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));
diff --git a/extras/libmemif/test/socket_test.c b/extras/libmemif/test/socket_test.c
index 720d68630d4..589bfd84cb7 100644
--- a/extras/libmemif/test/socket_test.c
+++ b/extras/libmemif/test/socket_test.c
@@ -49,7 +49,7 @@ START_TEST (test_msg_queue)
int err;
if ((err =
memif_init (control_fd_update, TEST_APP_NAME, NULL,
- NULL)) != MEMIF_ERR_SUCCESS)
+ NULL, NULL)) != MEMIF_ERR_SUCCESS)
ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
memif_connection_t conn;
@@ -97,7 +97,7 @@ START_TEST (test_enq_ack)
int err;
if ((err =
memif_init (control_fd_update, TEST_APP_NAME, NULL,
- NULL)) != MEMIF_ERR_SUCCESS)
+ NULL, NULL)) != MEMIF_ERR_SUCCESS)
ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
memif_connection_t conn;
conn.msg_queue = NULL;
@@ -117,7 +117,7 @@ START_TEST (test_enq_init)
int err;
if ((err =
memif_init (control_fd_update, TEST_APP_NAME, NULL,
- NULL)) != MEMIF_ERR_SUCCESS)
+ NULL, NULL)) != MEMIF_ERR_SUCCESS)
ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
memif_connection_t conn;
conn.msg_queue = NULL;
@@ -140,7 +140,7 @@ START_TEST (test_enq_init)
ck_assert_uint_eq (i->version, MEMIF_VERSION);
ck_assert_uint_eq (i->id, conn.args.interface_id);
ck_assert_uint_eq (i->mode, conn.args.mode);
- ck_assert_str_eq (i->secret, conn.args.secret);
+ ck_assert_str_eq ((char *)i->secret, (char *)conn.args.secret);
queue_free (&conn.msg_queue);
}
@@ -150,7 +150,7 @@ START_TEST (test_enq_add_region)
int err;
if ((err =
memif_init (control_fd_update, TEST_APP_NAME, NULL,
- NULL)) != MEMIF_ERR_SUCCESS)
+ NULL, NULL)) != MEMIF_ERR_SUCCESS)
ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
memif_connection_t conn;
conn.msg_queue = NULL;
@@ -186,7 +186,7 @@ START_TEST (test_enq_add_ring)
int err;
if ((err =
memif_init (control_fd_update, TEST_APP_NAME, NULL,
- NULL)) != MEMIF_ERR_SUCCESS)
+ NULL, NULL)) != MEMIF_ERR_SUCCESS)
ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
memif_connection_t conn;
@@ -227,7 +227,7 @@ START_TEST (test_enq_connect)
int err;
if ((err =
memif_init (control_fd_update, TEST_APP_NAME, NULL,
- NULL)) != MEMIF_ERR_SUCCESS)
+ NULL, NULL)) != MEMIF_ERR_SUCCESS)
ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
memif_connection_t conn;
conn.msg_queue = NULL;
@@ -242,7 +242,7 @@ START_TEST (test_enq_connect)
ck_assert_uint_eq (e->msg.type, MEMIF_MSG_TYPE_CONNECT);
ck_assert_int_eq (e->fd, -1);
- ck_assert_str_eq (e->msg.connect.if_name, TEST_IF_NAME);
+ ck_assert_str_eq ((char *)e->msg.connect.if_name, TEST_IF_NAME);
queue_free (&conn.msg_queue);
}
@@ -252,7 +252,7 @@ START_TEST (test_enq_connected)
int err;
if ((err =
memif_init (control_fd_update, TEST_APP_NAME, NULL,
- NULL)) != MEMIF_ERR_SUCCESS)
+ NULL, NULL)) != MEMIF_ERR_SUCCESS)
ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
memif_connection_t conn;
conn.msg_queue = NULL;
@@ -267,7 +267,7 @@ START_TEST (test_enq_connected)
ck_assert_uint_eq (e->msg.type, MEMIF_MSG_TYPE_CONNECTED);
ck_assert_int_eq (e->fd, -1);
- ck_assert_str_eq (e->msg.connect.if_name, TEST_IF_NAME);
+ ck_assert_str_eq ((char *)e->msg.connect.if_name, TEST_IF_NAME);
queue_free (&conn.msg_queue);
}
@@ -293,7 +293,7 @@ START_TEST (test_send_hello)
if ((err =
memif_init (control_fd_update, TEST_APP_NAME, NULL,
- NULL)) != MEMIF_ERR_SUCCESS)
+ NULL, NULL)) != MEMIF_ERR_SUCCESS)
ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
if ((err = memif_msg_send_hello (conn.fd)) != MEMIF_ERR_SUCCESS)
@@ -311,7 +311,7 @@ START_TEST (test_send_disconnect)
/* only possible fail if memif_msg_send fails... */
/* obsolete without socket */
if ((err =
- memif_msg_send_disconnect (conn.fd, "unit_test_dc",
+ memif_msg_send_disconnect (conn.fd, (uint8_t *)"unit_test_dc",
0)) != MEMIF_ERR_SUCCESS)
ck_assert_msg (err == MEMIF_ERR_BAD_FD, "err code: %u, err msg: %s", err,
memif_strerror (err));
@@ -346,7 +346,7 @@ START_TEST (test_recv_hello)
ck_assert_uint_eq (conn.run_args.num_s2m_rings, 2);
ck_assert_uint_eq (conn.run_args.num_m2s_rings, 2);
ck_assert_uint_eq (conn.run_args.log2_ring_size, 10);
- ck_assert_str_eq (conn.remote_name, TEST_IF_NAME);
+ ck_assert_str_eq ((char *)conn.remote_name, TEST_IF_NAME);
h->max_version = 9;
if ((err = memif_msg_receive_hello (&conn, &msg)) != MEMIF_ERR_SUCCESS)
@@ -391,7 +391,7 @@ START_TEST (test_recv_init)
if ((err =
memif_init (control_fd_update, TEST_APP_NAME, NULL,
- NULL)) != MEMIF_ERR_SUCCESS)
+ NULL, NULL)) != MEMIF_ERR_SUCCESS)
ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
if ((err = memif_msg_receive_init (&ms, -1, &msg)) != MEMIF_ERR_SUCCESS)
@@ -454,7 +454,7 @@ START_TEST (test_recv_add_region)
ck_assert_uint_eq (mr->fd, fd);
ck_assert_uint_eq (mr->region_size, 2048);
- ck_assert_ptr_eq (mr->shm, NULL);
+ ck_assert_ptr_eq (mr->addr, NULL);
}
END_TEST
@@ -507,7 +507,7 @@ START_TEST (test_recv_connect)
if ((err =
memif_init (control_fd_update, TEST_APP_NAME, NULL,
- NULL)) != MEMIF_ERR_SUCCESS)
+ NULL, NULL)) != MEMIF_ERR_SUCCESS)
ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
if ((err = memif_create (&c, &args, on_connect,
@@ -535,7 +535,7 @@ START_TEST (test_recv_connect)
if ((err = memif_msg_receive_connect (conn, &msg)) != MEMIF_ERR_SUCCESS)
ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
- ck_assert_str_eq (conn->remote_if_name, TEST_IF_NAME);
+ ck_assert_str_eq ((char *)conn->remote_if_name, TEST_IF_NAME);
}
END_TEST
@@ -552,7 +552,7 @@ START_TEST (test_recv_connected)
if ((err =
memif_init (control_fd_update, TEST_APP_NAME, NULL,
- NULL)) != MEMIF_ERR_SUCCESS)
+ NULL, NULL)) != MEMIF_ERR_SUCCESS)
ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
if ((err = memif_create (&c, &args, on_connect,
@@ -580,7 +580,7 @@ START_TEST (test_recv_connected)
if ((err = memif_msg_receive_connected (conn, &msg)) != MEMIF_ERR_SUCCESS)
ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
- ck_assert_str_eq (conn->remote_if_name, TEST_IF_NAME);
+ ck_assert_str_eq ((char *)conn->remote_if_name, TEST_IF_NAME);
}
END_TEST
@@ -597,7 +597,7 @@ START_TEST (test_recv_disconnect)
ck_assert_msg (err == MEMIF_ERR_DISCONNECT,
"err code: %u, err msg: %s", err, memif_strerror (err));
- ck_assert_str_eq (conn.remote_disconnect_string, "unit_test_dc");
+ ck_assert_str_eq ((char *)conn.remote_disconnect_string, "unit_test_dc");
}
END_TEST Suite *