Skip to content

Commit bad7c0c

Browse files
committed
add ENV to unit test
1 parent 8154f3f commit bad7c0c

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

Diff for: libc/cmake/modules/LLVMLibCTestRules.cmake

+30-1
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,11 @@ endfunction(get_object_files_for_test)
191191
# SRCS <list of .cpp files for the test>
192192
# HDRS <list of .h files for the test>
193193
# 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>
194196
# COMPILE_OPTIONS <list of special compile options for this target>
195197
# LINK_LIBRARIES <list of linking libraries for this target>
198+
# LOADER_ARGS <list of special args to loaders (like the GPU loader)>
196199
# )
197200
function(create_libc_unittest fq_target_name)
198201
if(NOT LLVM_INCLUDE_TESTS)
@@ -203,7 +206,7 @@ function(create_libc_unittest fq_target_name)
203206
"LIBC_UNITTEST"
204207
"NO_RUN_POSTBUILD;C_TEST" # Optional arguments
205208
"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
207210
${ARGN}
208211
)
209212
if(NOT LIBC_UNITTEST_SRCS)
@@ -316,6 +319,32 @@ function(create_libc_unittest fq_target_name)
316319

317320
target_link_libraries(${fq_build_target_name} PRIVATE ${link_libraries})
318321

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+
319348
if(NOT LIBC_UNITTEST_NO_RUN_POSTBUILD)
320349
add_custom_target(
321350
${fq_target_name}

0 commit comments

Comments
 (0)