@@ -191,8 +191,11 @@ endfunction(get_object_files_for_test)
191
191
# SRCS <list of .cpp files for the test>
192
192
# HDRS <list of .h files for the test>
193
193
# DEPENDS <list of dependencies>
194
+ # ARGS <list of command line arguments to be passed to the test>
195
+ # ENV <list of environment variables to set before running the test>
194
196
# COMPILE_OPTIONS <list of special compile options for this target>
195
197
# LINK_LIBRARIES <list of linking libraries for this target>
198
+ # LOADER_ARGS <list of special args to loaders (like the GPU loader)>
196
199
# )
197
200
function (create_libc_unittest fq_target_name)
198
201
if (NOT LLVM_INCLUDE_TESTS)
@@ -203,7 +206,7 @@ function(create_libc_unittest fq_target_name)
203
206
"LIBC_UNITTEST"
204
207
"NO_RUN_POSTBUILD;C_TEST" # Optional arguments
205
208
"SUITE;CXX_STANDARD" # Single value arguments
206
- "SRCS;HDRS;DEPENDS;COMPILE_OPTIONS;LINK_LIBRARIES;FLAGS" # Multi-value arguments
209
+ "SRCS;HDRS;DEPENDS;ARGS;ENV; COMPILE_OPTIONS;LINK_LIBRARIES;LOADER_ARGS ;FLAGS" # Multi-value arguments
207
210
${ARGN}
208
211
)
209
212
if (NOT LIBC_UNITTEST_SRCS)
@@ -316,6 +319,32 @@ function(create_libc_unittest fq_target_name)
316
319
317
320
target_link_libraries (${fq_build_target_name} PRIVATE ${link_libraries} )
318
321
322
+ if (TARGET libc.utils.gpu.loader)
323
+ add_dependencies (${fq_build_target_name} libc.utils.gpu.loader)
324
+ get_target_property (gpu_loader_exe libc.utils.gpu.loader "EXECUTABLE" )
325
+ endif ()
326
+
327
+ set (test_cmd ${LIBC_UNITTEST_ENV}
328
+ $<$<BOOL :${LIBC_TARGET_OS_IS_GPU} >:${gpu_loader_exe} > ${CMAKE_CROSSCOMPILING_EMULATOR} ${LIBC_UNITTEST_LOADER_ARGS}
329
+ $<TARGET_FILE:${fq_build_target_name} > ${LIBC_UNITTEST_ARGS} )
330
+ add_custom_target (
331
+ ${fq_target_name}
332
+ DEPENDS ${fq_target_name} -cmd
333
+ )
334
+
335
+ add_custom_command (
336
+ OUTPUT ${fq_target_name} -cmd
337
+ COMMAND ${test_cmd}
338
+ COMMAND_EXPAND_LISTS
339
+ COMMENT "Running unit test ${fq_target_name} "
340
+ ${LIBC_UNIT_TEST_JOB_POOL}
341
+ )
342
+
343
+ set_source_files_properties (${fq_target_name} -cmd
344
+ PROPERTIES
345
+ SYMBOLIC "TRUE"
346
+ )
347
+
319
348
if (NOT LIBC_UNITTEST_NO_RUN_POSTBUILD)
320
349
add_custom_target (
321
350
${fq_target_name}
0 commit comments