Skip to content

Commit 3226680

Browse files
esyrSashan
andcommitted
source/CMakeLists.txt: add run target
Add "run" target that runs all the tests with various options. Co-Authored-by: Alexandr Nedvedicky <[email protected]> Signed-off-by: Eugene Syromiatnikov <[email protected]>
1 parent 25b4fb1 commit 3226680

File tree

2 files changed

+225
-0
lines changed

2 files changed

+225
-0
lines changed

source/CMakeLists.txt

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@
8787
#
8888
# ./build/randbytes 10
8989
#
90+
# cmake also generates a run target. The run target serves as a
91+
# unit test which runs all commands. Use 'cmake --build build -t run' command
92+
# to run it. Note that if the build was configured without explicit
93+
# OPENSSL_ROOT_DIR set, one might wants to properly set run_certdir cache
94+
# variable beforehand.
9095
#
9196
# 32-bit builds
9297
# =============
@@ -128,6 +133,13 @@ add_library(perf perflib/perfhelper.c perflib/perfsslhelper.c perflib/threads.c
128133

129134
if(WIN32)
130135
target_sources(perf PRIVATE perflib/getopt.c perflib/basename.c perflib/err.c)
136+
#
137+
# windows release build on github workflow places places .exe files under
138+
# build\Release. This tweak hopes to place or .exe files under \build
139+
# for both build types.
140+
#
141+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIRECTORY}")
142+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIRECTORY}")
131143
endif()
132144

133145
target_include_directories(perf PUBLIC "${PROJECT_SOURCE_DIR}")
@@ -187,3 +199,196 @@ target_link_libraries(writeread PRIVATE perf)
187199

188200
add_executable(evp_hash evp_hash.c)
189201
target_link_libraries(evp_hash PRIVATE perf)
202+
203+
## Running tests
204+
# Options
205+
set(run_tests evp_fetch
206+
evp_hash
207+
evp_setpeer
208+
handshake
209+
newrawkey
210+
pkeyread
211+
providerdoall
212+
randbytes
213+
rsasign
214+
rwlocks
215+
sslnew
216+
#ssl_poll_perf
217+
writeread
218+
x509storeissuer
219+
CACHE STRING "List of tests to run")
220+
221+
# Per-test options, the format: test option values
222+
set(run_evp_fetch_pqs
223+
evp_fetch "" "" "-q"
224+
CACHE STRING "Post-quantum option for evp_fetch")
225+
set(run_evp_hash_operations
226+
evp_hash "" "" "-o deprecated" "-o evp_isolated" "-o evp_shared"
227+
CACHE STRING "Modes of operation for evp_hash")
228+
set(run_evp_hash_update_times
229+
evp_hash "" "" "-u 1" "-u 5"
230+
CACHE STRING "Digest update times for evp_hash")
231+
set(run_evp_hash_algorithms
232+
evp_hash "" "" "-a SHA1" "-a SHA224" "-a SHA256" "-a SHA384" "-a SHA512"
233+
CACHE STRING "Digest hash algorithms for evp_hash")
234+
set(run_evp_setpeer_keys
235+
evp_setpeer "-k" dh ec256 ec521 x25519 all
236+
CACHE STRING "Key types for evp_setpeer")
237+
set(run_newrawkey_algos
238+
newrawkey "-a" x25519 ml-kem-512 ml-kem-768 ml-kem-1024
239+
CACHE STRING "Algorithms for newrawkey")
240+
set(run_pkeyread_keys
241+
pkeyread "-k" dh dhx dsa ec rsa x25519 all
242+
CACHE STRING "Key types for pkeyread")
243+
set(run_pkeyread_fmts
244+
pkeyread "-f" pem der all
245+
CACHE STRING "Key formats for pkeyread")
246+
set(run_handshake_pools
247+
handshake "" "-p" "-P" "-l"
248+
CACHE STRING "Pool types for handshake")
249+
set(run_handshake_ctx_sharing
250+
handshake "" "" "-s"
251+
CACHE STRING "Context sharing option for handshake")
252+
set(run_handshake_pool_size
253+
handshake "" "" "-o 4" "-o 256"
254+
CACHE STRING "Pool size for handshake")
255+
set(run_handshake_secure_memory
256+
handshake "" "-S 1048576"
257+
CACHE STRING "Secure memory usage for handshake")
258+
set(run_writeread_ctx_sharing
259+
writeread "" "" "-s"
260+
CACHE STRING "Context sharing for writeread")
261+
set(run_writeread_dtls
262+
writeread "" "" "-d"
263+
CACHE STRING "DTLS mode for writeread")
264+
set(run_writeread_buffers
265+
writeread "" "" "-b 256" "-b 4096"
266+
CACHE STRING "Buffer size for writeread")
267+
268+
# The list of per-tet options
269+
set(run_opts run_evp_fetch_pqs
270+
run_evp_hash_operations
271+
run_evp_hash_update_times
272+
run_evp_hash_algorithms
273+
run_evp_setpeer_keys
274+
run_newrawkey_algos
275+
run_pkeyread_keys
276+
run_pkeyread_fmts
277+
run_handshake_pools
278+
run_handshake_ctx_sharing
279+
run_handshake_pool_size
280+
run_handshake_secure_memory
281+
run_writeread_ctx_sharing
282+
run_writeread_dtls
283+
run_writeread_buffers
284+
CACHE STRING "List of per-text options")
285+
286+
# Used across multiple tests
287+
set(run_certdir_tests handshake writeread x509storeissuer
288+
CACHE STRING "List of tests that require certdir parameter")
289+
file(TO_NATIVE_PATH "${OPENSSL_ROOT_DIR}/test/certs/" run_certdir_def_path)
290+
set(run_certdir "${run_certdir_def_path}"
291+
CACHE PATH "Path to certificates directory for tests that need it")
292+
293+
# Common options
294+
set(run_terse "" "-t"
295+
CACHE STRING "List of terse output options")
296+
set(run_threads 1 4
297+
CACHE STRING "List of thread counts")
298+
299+
add_custom_target(run
300+
COMMENT "Run perf tests"
301+
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
302+
303+
# Generate search path for later DLL copying
304+
if (WIN32)
305+
set(dll_search_dirs)
306+
foreach (f IN LISTS OPENSSL_CRYPTO_LIBRARIES OPENSSL_SSL_LIBRARIES)
307+
get_filename_component(f_dir "${f}" DIRECTORY)
308+
list(APPEND dll_search_dirs "${f_dir}")
309+
endforeach()
310+
endif()
311+
312+
# run targets generation
313+
foreach(test IN LISTS run_tests)
314+
set(cmds "${test}")
315+
316+
# test-specific options
317+
foreach(opt_name IN LISTS run_opts)
318+
set(opt "${${opt_name}}")
319+
list(GET opt 0 test_name)
320+
list(GET opt 1 test_opt)
321+
list(REMOVE_AT opt 0 1)
322+
323+
if(test IN_LIST test_name)
324+
set(new_cmds)
325+
foreach(cmd IN LISTS cmds)
326+
foreach(val IN LISTS opt)
327+
list(APPEND new_cmds "${cmd} ${test_opt} ${val}")
328+
endforeach()
329+
endforeach()
330+
set(cmds ${new_cmds})
331+
endif()
332+
endforeach()
333+
334+
# terse
335+
set(new_cmds)
336+
foreach(cmd IN LISTS cmds)
337+
foreach(val IN LISTS run_terse)
338+
list(APPEND new_cmds "${cmd} ${val}")
339+
endforeach()
340+
endforeach()
341+
set(cmds ${new_cmds})
342+
343+
# certdir
344+
if(test IN_LIST run_certdir_tests)
345+
set(new_cmds)
346+
foreach(cmd IN LISTS cmds)
347+
list(APPEND new_cmds "${cmd} ${run_certdir}")
348+
endforeach()
349+
set(cmds ${new_cmds})
350+
endif()
351+
352+
# threads
353+
set(new_cmds)
354+
foreach(cmd IN LISTS cmds)
355+
foreach(val IN LISTS run_threads)
356+
list(APPEND new_cmds "${cmd} ${val}")
357+
endforeach()
358+
endforeach()
359+
set(cmds ${new_cmds})
360+
361+
foreach(cmd IN LISTS cmds)
362+
string(REGEX REPLACE " *" ";" cmd "${cmd}")
363+
string(REGEX REPLACE "[^0-9A-Za-z]" "-" cmd_target_name "${cmd}")
364+
# A hack for lesser OSes that cannot normally distinguish lower-
365+
# and uppercase letters.
366+
if (WIN32 OR APPLE)
367+
string(REGEX REPLACE "[A-Z]" "\\0_" cmd_target_name
368+
"${cmd_target_name}")
369+
endif()
370+
string(REPLACE ";" " " cmd_desc "${cmd}")
371+
add_custom_target("run-${cmd_target_name}"
372+
COMMAND ${cmd}
373+
DEPENDS "${test}"
374+
COMMENT "Run ${cmd_desc}"
375+
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
376+
USES_TERMINAL)
377+
add_dependencies(run "run-${cmd_target_name}")
378+
379+
# A dirty hack to copy the dependent DLLs into the build directory so they
380+
# get picked up before the ones in the system directory or wherever.
381+
if(WIN32)
382+
if (NOT TARGET "${test}-copy-dlls")
383+
add_custom_target("${test}-copy-dlls"
384+
COMMAND ${CMAKE_COMMAND}
385+
-D TARGET_FILE=$<TARGET_FILE:${test}>
386+
-D TARGET_DIR=$<TARGET_FILE_DIR:${test}>
387+
-D "SEARCH_PATH=${dll_search_dirs}"
388+
-P "${CMAKE_CURRENT_SOURCE_DIR}/cmake/copy_reqs.cmake"
389+
COMMENT "Copying DLLs for ${test}")
390+
endif()
391+
add_dependencies("${run-${cmd_target_name}}" "${test}-copy-dlls")
392+
endif()
393+
endforeach()
394+
endforeach()

source/cmake/copy_reqs.cmake

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
include(GetPrerequisites)
2+
3+
get_prerequisites(${TARGET_FILE} prerequisites 1 1 "" "${SEARCH_PATHS}" "")
4+
5+
foreach(prerequisite ${prerequisites})
6+
gp_resolve_item("" ${prerequisite} "${TARGET_FILE}" "${SEARCH_PATHS}" prerequisite_final_path)
7+
get_filename_component(prerequisite_filename ${prerequisite_final_path} NAME)
8+
execute_process(
9+
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${prerequisite_final_path}" "${TARGET_DIR}"
10+
RESULT_VARIABLE copy_result
11+
OUTPUT_VARIABLE copy_output
12+
ERROR_VARIABLE copy_error
13+
)
14+
15+
if(copy_result EQUAL 0)
16+
message(STATUS "Copied DLL: ${prerequisite_filename} (from ${prerequisite_final_path})")
17+
else()
18+
message(WARNING "Failed to copy DLL: ${prerequisite_filename} from ${prerequisite_final_path}. Error: ${copy_error}")
19+
endif()
20+
endforeach()

0 commit comments

Comments
 (0)