Skip to content

Commit 41d4d7d

Browse files
committed
Refactor ipc_os_prov_consumer.c and ipc_os_prov_producer.c
Refactor ipc_os_prov_consumer.c and ipc_os_prov_producer.c. Split the code into functions, move them to the common directory and prepare them to be reused in a future similar tests. Signed-off-by: Lukasz Dorau <[email protected]>
1 parent 7d0f8c4 commit 41d4d7d

File tree

5 files changed

+574
-519
lines changed

5 files changed

+574
-519
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}
@@ -249,33 +270,30 @@ endif()
249270

250271
add_umf_test(NAME ipc SRCS ipcAPI.cpp)
251272

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

266-
target_link_directories(${EXEC_NAME} PRIVATE ${LIBHWLOC_LIBRARY_DIRS})
267-
endforeach(loop_var)
268-
endfunction()
284+
set(TEST_NAME umf-${ARG_TEST})
269285

270-
function(add_umf_ipc_test script)
271-
set(TEST_NAME umf-${script})
286+
if(DEFINED ARG_SRC_DIR)
287+
set(SRC_DIR ${ARG_SRC_DIR})
288+
else()
289+
set(SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR})
290+
endif()
272291

273-
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/${script}.sh
274-
DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
292+
file(COPY ${SRC_DIR}/${ARG_TEST}.sh DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
275293

276294
add_test(
277295
NAME ${TEST_NAME}
278-
COMMAND ${script}.sh
296+
COMMAND ${ARG_TEST}.sh
279297
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
280298

281299
set_tests_properties(${TEST_NAME} PROPERTIES LABELS "umf")
@@ -285,9 +303,20 @@ function(add_umf_ipc_test script)
285303
endfunction()
286304

287305
if(LINUX)
288-
build_umf_ipc_test(ipc_os_prov)
289-
add_umf_ipc_test(ipc_os_prov_anon_fd)
290-
add_umf_ipc_test(ipc_os_prov_shm)
306+
build_umf_test(
307+
NAME
308+
ipc_os_prov_consumer
309+
SRCS
310+
ipc_os_prov_consumer.c
311+
common/ipc_common.c)
312+
build_umf_test(
313+
NAME
314+
ipc_os_prov_producer
315+
SRCS
316+
ipc_os_prov_producer.c
317+
common/ipc_common.c)
318+
add_umf_ipc_test(TEST ipc_os_prov_anon_fd)
319+
add_umf_ipc_test(TEST ipc_os_prov_shm)
291320
else()
292321
message(STATUS "IPC tests are supported on Linux only - skipping")
293322
endif()

0 commit comments

Comments
 (0)