aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormsardara <msardara+fdio@cisco.com>2018-12-11 18:36:55 +0100
committerDamjan Marion <dmarion@me.com>2018-12-17 09:25:18 +0000
commit8f554b793c68fd5271334bf0e167dabc4c9ac73d (patch)
treea54ad410cdf3a839473551a59354956e3dc563cf
parentd6e9aecfd67ebfd012873eb24b72221f13e8f089 (diff)
Added CMake building system for libmemif
Added Cpack support for building libmemif DEB/RPM packages Fixed compilation errors in libmemif test and examples Change-Id: I59a237a4ca8eb08840857d5b0e666f3a8d74411d Signed-off-by: msardara <msardara+fdio@cisco.com>
-rw-r--r--build-data/packages/libmemif.mk39
-rw-r--r--extras/libmemif/CMakeLists.txt68
-rw-r--r--extras/libmemif/cmake/FindCheck.cmake71
-rw-r--r--extras/libmemif/cmake/FindSubunit.cmake47
-rw-r--r--extras/libmemif/examples/CMakeLists.txt36
-rw-r--r--extras/libmemif/examples/icmp_responder-zero-copy-slave/main.c2
-rw-r--r--extras/libmemif/src/CMakeLists.txt43
-rw-r--r--extras/libmemif/src/main.c34
-rw-r--r--extras/libmemif/src/memif.h2
-rw-r--r--extras/libmemif/src/socket.c4
-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
13 files changed, 405 insertions, 70 deletions
diff --git a/build-data/packages/libmemif.mk b/build-data/packages/libmemif.mk
index a4be1803aae..9bce09b5f25 100644
--- a/build-data/packages/libmemif.mk
+++ b/build-data/packages/libmemif.mk
@@ -1,3 +1,40 @@
+# Copyright (c) 2017-2018 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.
+
libmemif_source = extras
-libmemif_configure_subdir = libmemif
+libmemif_configure_subdir = libmemif
+
+ifneq ($(shell which cmake3),)
+CMAKE?=cmake3
+else
+CMAKE?=cmake
+endif
+
+libmemif_cmake_args ?=
+libmemif_cmake_args += -DCMAKE_INSTALL_PREFIX:PATH=$(PACKAGE_INSTALL_DIR)
+libmemif_cmake_args += -DCMAKE_C_FLAGS="$($(TAG)_TAG_CFLAGS)"
+libmemif_cmake_args += -DCMAKE_SHARED_LINKER_FLAGS="$($(TAG)_TAG_LDFLAGS)"
+libmemif_cmake_args += -DCMAKE_PREFIX_PATH:PATH="$(PACKAGE_INSTALL_DIR)/../vpp"
+
+# Use devtoolset on centos 7
+ifneq ($(wildcard /opt/rh/devtoolset-7/enable),)
+libmemif_cmake_args += -DCMAKE_PROGRAM_PATH:PATH="/opt/rh/devtoolset-7/root/bin"
+endif
+
+libmemif_configure = \
+ cd $(PACKAGE_BUILD_DIR) && \
+ $(CMAKE) -G Ninja $(libmemif_cmake_args) $(call find_source_fn,$(PACKAGE_SOURCE))$(PACKAGE_SUBDIR)
+
+libmemif_build = $(CMAKE) --build $(PACKAGE_BUILD_DIR) -- $(MAKE_PARALLEL_FLAGS)
+libmemif_install = $(CMAKE) --build $(PACKAGE_BUILD_DIR) -- install
diff --git a/extras/libmemif/CMakeLists.txt b/extras/libmemif/CMakeLists.txt
new file mode 100644
index 00000000000..263bd18d1df
--- /dev/null
+++ b/extras/libmemif/CMakeLists.txt
@@ -0,0 +1,68 @@
+# 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)
+
+project(memif)
+set(CMAKE_C_STANDARD 11)
+
+include(CheckCCompilerFlag)
+include(CheckFunctionExists)
+
+set(VPP_SRC "${CMAKE_CURRENT_SOURCE_DIR}/../../src")
+execute_process(
+ COMMAND find ${VPP_SRC} -type d -name "cmake"
+ OUTPUT_VARIABLE CMAKE_DEPS_FOLDER
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+)
+include(${CMAKE_DEPS_FOLDER}/library.cmake)
+include(${CMAKE_DEPS_FOLDER}/pack.cmake)
+
+if (NOT CMAKE_BUILD_TYPE)
+ message(STATUS "No build type selected, default to Release")
+ set(CMAKE_BUILD_TYPE "Release")
+endif ()
+
+set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -DMEMIF_DBG -DICMP_DBG")
+set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
+set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib)
+set(CMAKE_INSTALL_MESSAGE NEVER)
+
+find_package(Threads REQUIRED)
+include_directories(${CMAKE_THREADS_INCLUDE_DIRS})
+
+check_function_exists(memfd_create HAVE_MEMFD_CREATE)
+if(${HAVE_MEMFD_CREATE})
+ add_definitions(-DHAVE_MEMFD_CREATE)
+endif()
+
+include_directories(src)
+set(LIBMEMIF memif)
+
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
+find_package(Check 0.10.0)
+if (CHECK_FOUND)
+ include_directories(${CHECK_INCLUDE_DIR})
+ add_definitions(-DMEMIF_UNIT_TEST)
+ add_subdirectory(test)
+ enable_testing()
+endif ()
+
+add_subdirectory(src)
+add_subdirectory(examples)
+
+add_vpp_packaging(
+ NAME "memif"
+ VENDOR "fd.io"
+ DESCRIPTION "Shared Memory Interface"
+)
diff --git a/extras/libmemif/cmake/FindCheck.cmake b/extras/libmemif/cmake/FindCheck.cmake
new file mode 100644
index 00000000000..e5f399c5449
--- /dev/null
+++ b/extras/libmemif/cmake/FindCheck.cmake
@@ -0,0 +1,71 @@
+# Copyright (c) 2018 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.
+
+########################################
+#
+# Find the Libcheck library and includes
+# This module sets:
+# CHECK_FOUND: True if Libcheck was found
+# CHECK_LIBRARY: The Libcheck library
+# CHECK_INCLUDE_DIR: The Libcheck include dir
+#
+
+set(CHECK_SEARCH_PATH_LIST
+ ${CHECK_HOME}
+ $ENV{CHECK_HOME}
+ /usr/local
+ /opt
+ /usr
+)
+
+find_path(CHECK_INCLUDE_DIR check.h
+ HINTS ${CHECK_SEARCH_PATH_LIST}
+ PATH_SUFFIXES include
+ DOC "Find the check includes"
+)
+
+find_library(CHECK_LIBRARY NAMES check
+ HINTS ${CHECK_SEARCH_PATH_LIST}
+ PATH_SUFFIXES lib
+ DOC "Find the check libraries"
+)
+
+execute_process(
+ COMMAND grep "CHECK_MICRO_VERSION" ${CHECK_INCLUDE_DIR}/check.h
+ COMMAND grep -Eo [0-9]+
+ OUTPUT_VARIABLE CHECK_MICRO_VERSION
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+)
+
+execute_process(
+ COMMAND grep "CHECK_MINOR_VERSION" ${CHECK_INCLUDE_DIR}/check.h
+ COMMAND grep -Eo [0-9]+
+ OUTPUT_VARIABLE CHECK_MINOR_VERSION
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+)
+
+execute_process(
+ COMMAND grep "CHECK_MAJOR_VERSION" ${CHECK_INCLUDE_DIR}/check.h
+ COMMAND grep -Eo [0-9]+
+ OUTPUT_VARIABLE CHECK_MAJOR_VERSION
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+)
+
+set(CHECK_VERSION "${CHECK_MAJOR_VERSION}.${CHECK_MINOR_VERSION}.${CHECK_MICRO_VERSION}")
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(
+ Check
+ REQUIRED_VARS CHECK_LIBRARY CHECK_INCLUDE_DIR
+ VERSION_VAR CHECK_VERSION
+) \ No newline at end of file
diff --git a/extras/libmemif/cmake/FindSubunit.cmake b/extras/libmemif/cmake/FindSubunit.cmake
new file mode 100644
index 00000000000..121cb5f10e2
--- /dev/null
+++ b/extras/libmemif/cmake/FindSubunit.cmake
@@ -0,0 +1,47 @@
+# Copyright (c) 2018 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.
+
+########################################
+#
+# Find the Libsubunit library and includes
+# This module sets:
+# SUBUNIT_FOUND: True if Libsubunit was found
+# SUBUNIT_LIBRARY: The Libsubunit library
+# SUBUNIT_INCLUDE_DIR: The Libsubunit include dir
+#
+
+set(SUBUNIT_SEARCH_PATH_LIST
+ ${SUBUNIT_HOME}
+ $ENV{SUBUNIT_HOME}
+ /usr/local
+ /opt
+ /usr
+)
+
+find_path(SUBUNIT_INCLUDE_DIR
+ NAMES child.h
+ HINTS ${SUBUNIT_SEARCH_PATH_LIST}
+ PATH_SUFFIXES include subunit
+)
+
+find_library(SUBUNIT_LIBRARY
+ NAMES subunit
+ PATH_SUFFIXES lib
+ HINTS ${SUBUNIT_SEARCH_PATH_LIST}
+)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(
+ Subunit
+ REQUIRED_VARS SUBUNIT_LIBRARY SUBUNIT_INCLUDE_DIR
+) \ No newline at end of file
diff --git a/extras/libmemif/examples/CMakeLists.txt b/extras/libmemif/examples/CMakeLists.txt
new file mode 100644
index 00000000000..52b8f54216d
--- /dev/null
+++ b/extras/libmemif/examples/CMakeLists.txt
@@ -0,0 +1,36 @@
+# 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}/icmp_responder)
+
+set(COMMON_SOURCE_FILES
+ icmp_responder/icmp_proto.c)
+
+list(APPEND EXAMPLES_LIST
+ icmp_responder/main.c
+ icmp_responder-epoll/main.c
+ icmp_responder-mt/main.c
+ icmp_responder-eb/main.c
+ icmp_responder-zero-copy-slave/main.c
+)
+
+foreach (EXAMPLE_SRC ${EXAMPLES_LIST})
+ string(FIND ${EXAMPLE_SRC} "/" INDEX)
+ string(SUBSTRING ${EXAMPLE_SRC} 0 ${INDEX} EXECUTABLE)
+ add_executable(${EXECUTABLE} ${COMMON_SOURCE_FILES} ${EXAMPLE_SRC})
+ target_include_directories(${EXECUTABLE} PRIVATE $<BUILD_INTERFACE:${HEADERS_DIR}>)
+ target_link_libraries(${EXECUTABLE} ${LIBMEMIF} ${CMAKE_THREAD_LIBS_INIT})
+endforeach()
+
diff --git a/extras/libmemif/examples/icmp_responder-zero-copy-slave/main.c b/extras/libmemif/examples/icmp_responder-zero-copy-slave/main.c
index 47f3ce5b01d..aad33039bd8 100644
--- a/extras/libmemif/examples/icmp_responder-zero-copy-slave/main.c
+++ b/extras/libmemif/examples/icmp_responder-zero-copy-slave/main.c
@@ -1248,7 +1248,7 @@ main ()
/* if valid callback is passed as argument, fd event polling will be done by user
all file descriptors and events will be passed to user in this callback */
/* if callback is set to NULL libmemif will handle fd event polling */
- err = memif_init (control_fd_update, APP_NAME, NULL, NULL);
+ err = memif_init (control_fd_update, APP_NAME, NULL, NULL, NULL);
if (err != MEMIF_ERR_SUCCESS)
{
INFO ("memif_init: %s", memif_strerror (err));
diff --git a/extras/libmemif/src/CMakeLists.txt b/extras/libmemif/src/CMakeLists.txt
new file mode 100644
index 00000000000..09a2e4e6005
--- /dev/null
+++ b/extras/libmemif/src/CMakeLists.txt
@@ -0,0 +1,43 @@
+# 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})
+
+list(APPEND MEMIF_HEADERS
+ libmemif.h
+ memif.h
+)
+
+list(APPEND MEMIF_PRIVATE_HEADERS
+ memif_private.h
+ socket.h
+)
+
+list(APPEND MEMIF_SOURCES
+ main.c
+ socket.c
+)
+
+include_directories(${HEADERS_DIR})
+
+add_vpp_library(${LIBMEMIF}
+ SOURCES ${MEMIF_SOURCES}
+
+ INSTALL_HEADERS ${MEMIF_HEADERS}
+
+ LINK_LIBRARIES ${CMAKE_THREAD_LIBS_INIT}
+
+ COMPONENT libmemif
+)
diff --git a/extras/libmemif/src/main.c b/extras/libmemif/src/main.c
index 782442d440b..c6a62bb2ddc 100644
--- a/extras/libmemif/src/main.c
+++ b/extras/libmemif/src/main.c
@@ -632,7 +632,7 @@ memif_create (memif_conn_handle_t * c, memif_conn_args_t * args,
memif_interrupt_t * on_interrupt, void *private_ctx)
{
libmemif_main_t *lm = &libmemif_main;
- int err, i, index, sockfd = -1;
+ int err, i, index = 0, sockfd = -1;
memif_list_elt_t list_elt;
memif_connection_t *conn = (memif_connection_t *) * c;
if (conn != NULL)
@@ -892,7 +892,7 @@ error:
int
memif_control_fd_handler (int fd, uint8_t events)
{
- int i, rv, sockfd = -1, err = MEMIF_ERR_SUCCESS; /* 0 */
+ int i, sockfd = -1, err = MEMIF_ERR_SUCCESS; /* 0 */
uint16_t num;
memif_list_elt_t *e = NULL;
memif_connection_t *conn;
@@ -902,6 +902,10 @@ memif_control_fd_handler (int fd, uint8_t events)
uint64_t b;
ssize_t size;
size = read (fd, &b, sizeof (b));
+
+ if (size == -1)
+ goto error;
+
for (i = 0; i < lm->control_list_len; i++)
{
if ((lm->control_list[i].key < 0)
@@ -1042,11 +1046,8 @@ error:
int
memif_poll_event (int timeout)
{
- libmemif_main_t *lm = &libmemif_main;
- memif_list_elt_t *elt;
- struct epoll_event evt, *e;
- int en = 0, err = MEMIF_ERR_SUCCESS, i = 0; /* 0 */
- uint16_t num;
+ struct epoll_event evt;
+ int en = 0, err = MEMIF_ERR_SUCCESS; /* 0 */
uint32_t events = 0;
uint64_t counter = 0;
ssize_t r = 0;
@@ -1066,6 +1067,9 @@ memif_poll_event (int timeout)
if (evt.data.fd == poll_cancel_fd)
{
r = read (evt.data.fd, &counter, sizeof (counter));
+ if (r == -1)
+ return MEMIF_ERR_DISCONNECTED;
+
return MEMIF_ERR_POLL_CANCEL;
}
if (evt.events & EPOLLIN)
@@ -1308,7 +1312,6 @@ memif_connect1 (memif_connection_t * c)
memif_region_t *mr;
memif_queue_t *mq;
int i;
- uint16_t num;
for (i = 0; i < c->regions_num; i++)
{
@@ -1530,11 +1533,8 @@ memif_init_queues (libmemif_main_t * lm, memif_connection_t * conn)
int
memif_init_regions_and_queues (memif_connection_t * conn)
{
- memif_ring_t *ring = NULL;
memif_region_t *r;
- int i, j;
libmemif_main_t *lm = &libmemif_main;
- memif_list_elt_t e;
/* region 0. rings */
memif_add_region (lm, conn, /* has_buffers */ 0);
@@ -1595,7 +1595,7 @@ memif_buffer_enq_tx (memif_conn_handle_t conn, uint16_t qid,
uint16_t mask = (1 << mq->log2_ring_size) - 1;
uint16_t ring_size;
uint16_t slot, ns;
- int i, err = MEMIF_ERR_SUCCESS; /* 0 */
+ int err = MEMIF_ERR_SUCCESS; /* 0 */
*count_out = 0;
ring_size = (1 << mq->log2_ring_size);
@@ -1645,7 +1645,6 @@ memif_buffer_enq_tx (memif_conn_handle_t conn, uint16_t qid,
err = MEMIF_ERR_NOBUF_RING;
}
-error:
return err;
}
@@ -1670,12 +1669,12 @@ memif_buffer_alloc (memif_conn_handle_t conn, uint16_t qid,
libmemif_main_t *lm = &libmemif_main;
memif_queue_t *mq = &c->tx_queues[qid];
memif_ring_t *ring = mq->ring;
- memif_buffer_t *b0, *b1;
+ memif_buffer_t *b0;
uint16_t mask = (1 << mq->log2_ring_size) - 1;
uint32_t offset_mask = c->run_args.buffer_size - 1;
uint16_t ring_size;
uint16_t slot, ns;
- int i, err = MEMIF_ERR_SUCCESS; /* 0 */
+ int err = MEMIF_ERR_SUCCESS; /* 0 */
uint16_t dst_left, src_left;
uint16_t saved_count;
memif_buffer_t *saved_b;
@@ -1772,7 +1771,6 @@ no_ns:
err = MEMIF_ERR_NOBUF_RING;
}
-error:
return err;
}
@@ -1919,7 +1917,7 @@ memif_rx_burst (memif_conn_handle_t conn, uint16_t qid,
uint16_t cur_slot, last_slot;
uint16_t ns;
uint16_t mask = (1 << mq->log2_ring_size) - 1;
- memif_buffer_t *b0, *b1;
+ memif_buffer_t *b0;
*rx = 0;
uint64_t b;
@@ -1992,7 +1990,7 @@ memif_get_details (memif_conn_handle_t conn, memif_details_t * md,
return MEMIF_ERR_NOCONN;
int err = MEMIF_ERR_SUCCESS, i;
- ssize_t l0, l1, total_l;
+ ssize_t l0, l1;
l0 = 0;
l1 = strlen ((char *) c->args.interface_name);
diff --git a/extras/libmemif/src/memif.h b/extras/libmemif/src/memif.h
index 3fbce91d68f..776baaf8a3a 100644
--- a/extras/libmemif/src/memif.h
+++ b/extras/libmemif/src/memif.h
@@ -18,6 +18,8 @@
#ifndef _MEMIF_H_
#define _MEMIF_H_
+#include <stdint.h>
+
#ifndef MEMIF_CACHELINE_SIZE
#define MEMIF_CACHELINE_SIZE 64
#endif
diff --git a/extras/libmemif/src/socket.c b/extras/libmemif/src/socket.c
index b25b0261d77..e1c3bd4a257 100644
--- a/extras/libmemif/src/socket.c
+++ b/extras/libmemif/src/socket.c
@@ -375,7 +375,6 @@ memif_msg_receive_init (memif_socket_t * ms, int fd, memif_msg_t * msg)
uint8_t err_string[96];
memset (err_string, 0, sizeof (char) * 96);
int err = MEMIF_ERR_SUCCESS; /* 0 */
- int err_disc;
if (i->version != MEMIF_VERSION)
{
DBG ("MEMIF_VER_ERR");
@@ -691,7 +690,6 @@ memif_msg_receive (int ifd)
return MEMIF_ERR_MFMSG;
}
- struct ucred *cr = 0;
struct cmsghdr *cmsg;
cmsg = CMSG_FIRSTHDR (&mh);
@@ -701,7 +699,7 @@ memif_msg_receive (int ifd)
{
if (cmsg->cmsg_type == SCM_CREDENTIALS)
{
- cr = (struct ucred *) CMSG_DATA (cmsg);
+ /* Do nothing */ ;
}
else if (cmsg->cmsg_type == SCM_RIGHTS)
{
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 *