libmemif: added tests

This patch provides unit tests for libmemif written in Unity

Type: test

Signed-off-by: Daniel Béreš <dberes@cisco.com>
Signed-off-by: Mohsin Kazmi <sykazmi@cisco.com>
Change-Id: I19116def6e6d28efd5f460c93911245474a11321
This commit is contained in:
Daniel Béreš
2023-01-19 10:19:27 +01:00
committed by Dave Wallace
parent 56e17cf7a2
commit 9853342194
8 changed files with 881 additions and 1 deletions

View File

@ -18,6 +18,35 @@ set(CMAKE_C_STANDARD 11)
include(CheckCCompilerFlag)
include(CheckFunctionExists)
find_package(Git REQUIRED)
include(ExternalProject)
set(UNITY unity_project)
ExternalProject_Add(
unity_project
GIT_REPOSITORY https://github.com/ThrowTheSwitch/Unity.git
GIT_TAG cf949f45ca6d172a177b00da21310607b97bc7a7
PREFIX ${PROJECT_BINARY_DIR}/external/${UNITY}
INSTALL_COMMAND cmake --install . --prefix ${PROJECT_BINARY_DIR}
)
set_source_files_properties(
${PROJECT_BINARY_DIR}/external/${UNITY}/src/${UNITY}/src/unity.c
${PROJECT_BINARY_DIR}/external/${UNITY}/src/${UNITY}/extras/fixture/src/unity_fixture.c
${PROJECT_BINARY_DIR}/external/${UNITY}/src/${UNITY}/extras/memory/src/unity_memory.c
PROPERTIES GENERATED TRUE)
add_library(unity STATIC
${PROJECT_BINARY_DIR}/external/${UNITY}/src/${UNITY}/src/unity.c
${PROJECT_BINARY_DIR}/external/${UNITY}/src/${UNITY}/extras/fixture/src/unity_fixture.c
${PROJECT_BINARY_DIR}/external/${UNITY}/src/${UNITY}/extras/memory/src/unity_memory.c
)
target_include_directories(unity PUBLIC
${PROJECT_BINARY_DIR}/external/${UNITY}/src/${UNITY}/src/
${PROJECT_BINARY_DIR}/external/${UNITY}/src/${UNITY}/extras/fixture/src/
${PROJECT_BINARY_DIR}/external/${UNITY}/src/${UNITY}/extras/memory/src/
)
add_dependencies(unity unity_project)
if (NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type selected, default to Release")
@ -42,6 +71,9 @@ include_directories(src)
add_subdirectory(src)
add_subdirectory(examples)
enable_testing()
include(CTest)
add_subdirectory(test)
##############################################################################
# Packaging
##############################################################################

View File

@ -49,6 +49,26 @@ Use ``-?`` flag to display help::
-? Show help and exit.
-v Show libmemif and memif version information and exit.
Running tests:
--------------
Tests needs to their proper functioning Unity framework which is depended externally and cloned from official git repository::
mkdir -p extras/libmemif/build
cd extras/libmemif/build
cmake ..
make
ctest
``ctest`` will execute the tests and print out brief information about test suites with their statuses.
In case we want verbose: ::
ctest --verbose
ctest --extra-verbose
If there are any needs to debug tests, just add to cmake command ``-DCMAKE_BUILD_TYPE=Debug`` flag.
Use Cases
---------

View File

@ -412,11 +412,12 @@ memif_connect_handler (memif_fd_event_type_t type, void *private_ctx)
if (ms->timer_fd >= 0)
{
uint64_t u64;
ssize_t __attribute__ ((unused)) r;
/*
Have to read the timer fd else it stays read-ready
and makes epoll_pwait() return without sleeping
*/
read (ms->timer_fd, &u64, sizeof (u64));
r = read (ms->timer_fd, &u64, sizeof (u64));
}
/* loop ms->slave_interfaces and request connection for disconnected ones */

View File

@ -0,0 +1,2 @@
add_subdirectory(suite_socket)
add_subdirectory(suite_main)

View File

@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.0)
set (This MemifMainTest)
set (Sources
memif_main_test.c)
add_executable(${This} ${Sources})
target_link_libraries(${This} PUBLIC
unity
memif
)
add_test(
NAME ${This}
COMMAND ${This}
)

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.0)
set (This MemifSocketTest)
set (Sources
memif_socket_test.c)
add_executable(${This} ${Sources})
target_link_libraries(${This} PUBLIC
unity
memif
)
add_test(
NAME ${This}
COMMAND ${This}
)

File diff suppressed because it is too large Load Diff