Skip to content

Commit 3baeae7

Browse files
authored
Merge pull request #574 from ldorau/Refactor_ipc_os_prov_consumer.c_and_ipc_os_prov_producer.c
Refactor ipc_os_prov_consumer.c and ipc_os_prov_producer.c
2 parents 4df5659 + 15640f8 commit 3baeae7

File tree

5 files changed

+576
-521
lines changed

5 files changed

+576
-521
lines changed

test/CMakeLists.txt

Lines changed: 59 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,9 @@ enable_testing()
2323

2424
set(UMF_TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
2525

26-
function(add_umf_test)
27-
# Parameters:
28-
#
29-
# * NAME - a name of the test
30-
# * SRCS - source files
31-
# * LIBS - libraries to be linked with
26+
function(build_umf_test)
27+
# Parameters: * NAME - a name of the test * SRCS - source files * LIBS -
28+
# libraries to be linked with
3229
set(oneValueArgs NAME)
3330
set(multiValueArgs SRCS LIBS)
3431
cmake_parse_arguments(
@@ -69,6 +66,30 @@ function(add_umf_test)
6966
${UMF_CMAKE_SOURCE_DIR}/src/utils
7067
${UMF_TEST_DIR}/common
7168
${UMF_TEST_DIR})
69+
endfunction()
70+
71+
function(add_umf_test)
72+
# Parameters: * NAME - a name of the test * SRCS - source files * LIBS -
73+
# libraries to be linked with
74+
set(oneValueArgs NAME)
75+
set(multiValueArgs SRCS LIBS)
76+
cmake_parse_arguments(
77+
ARG
78+
""
79+
"${oneValueArgs}"
80+
"${multiValueArgs}"
81+
${ARGN})
82+
83+
build_umf_test(
84+
NAME
85+
${ARG_NAME}
86+
SRCS
87+
${ARG_SRCS}
88+
LIBS
89+
${ARG_LIBS})
90+
91+
set(TEST_NAME umf-${ARG_NAME})
92+
set(TEST_TARGET_NAME umf_test-${ARG_NAME})
7293

7394
add_test(
7495
NAME ${TEST_NAME}
@@ -252,33 +273,30 @@ endif()
252273

253274
add_umf_test(NAME ipc SRCS ipcAPI.cpp)
254275

255-
function(build_umf_ipc_test name)
256-
set(BASE_NAME ${name})
257-
258-
foreach(loop_var IN ITEMS "producer" "consumer")
259-
set(EXEC_NAME umf_test-${BASE_NAME}_${loop_var})
260-
add_umf_executable(
261-
NAME ${EXEC_NAME}
262-
SRCS ${BASE_NAME}_${loop_var}.c
263-
LIBS umf)
264-
265-
target_include_directories(
266-
${EXEC_NAME} PRIVATE ${UMF_CMAKE_SOURCE_DIR}/src/utils
267-
${UMF_CMAKE_SOURCE_DIR}/include)
276+
function(add_umf_ipc_test)
277+
# Parameters: * TEST - a name of the test * SRC_DIR - source files directory
278+
# path
279+
set(oneValueArgs TEST SRC_DIR)
280+
cmake_parse_arguments(
281+
ARG
282+
""
283+
"${oneValueArgs}"
284+
""
285+
${ARGN})
268286

269-
target_link_directories(${EXEC_NAME} PRIVATE ${LIBHWLOC_LIBRARY_DIRS})
270-
endforeach(loop_var)
271-
endfunction()
287+
set(TEST_NAME umf-${ARG_TEST})
272288

273-
function(add_umf_ipc_test script)
274-
set(TEST_NAME umf-${script})
289+
if(DEFINED ARG_SRC_DIR)
290+
set(SRC_DIR ${ARG_SRC_DIR})
291+
else()
292+
set(SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR})
293+
endif()
275294

276-
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/${script}.sh
277-
DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
295+
file(COPY ${SRC_DIR}/${ARG_TEST}.sh DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
278296

279297
add_test(
280298
NAME ${TEST_NAME}
281-
COMMAND ${script}.sh
299+
COMMAND ${ARG_TEST}.sh
282300
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
283301

284302
set_tests_properties(${TEST_NAME} PROPERTIES LABELS "umf")
@@ -288,9 +306,20 @@ function(add_umf_ipc_test script)
288306
endfunction()
289307

290308
if(LINUX)
291-
build_umf_ipc_test(ipc_os_prov)
292-
add_umf_ipc_test(ipc_os_prov_anon_fd)
293-
add_umf_ipc_test(ipc_os_prov_shm)
309+
build_umf_test(
310+
NAME
311+
ipc_os_prov_consumer
312+
SRCS
313+
ipc_os_prov_consumer.c
314+
common/ipc_common.c)
315+
build_umf_test(
316+
NAME
317+
ipc_os_prov_producer
318+
SRCS
319+
ipc_os_prov_producer.c
320+
common/ipc_common.c)
321+
add_umf_ipc_test(TEST ipc_os_prov_anon_fd)
322+
add_umf_ipc_test(TEST ipc_os_prov_shm)
294323
else()
295324
message(STATUS "IPC tests are supported on Linux only - skipping")
296325
endif()

0 commit comments

Comments
 (0)