Skip to content

Commit fd3295f

Browse files
author
Siva Chandra Reddy
committed
[libc] Skip entrypoints not present in the entrypoints list.
Summary: If a test depends on a skipped entrypoint, then the test is also skipped. This setup will be useful as we gradually add support for more operating systems and target architectures. Reviewers: asteinhauser Differential Revision: https://reviews.llvm.org/D81489
1 parent 01e64c9 commit fd3295f

File tree

10 files changed

+106
-19
lines changed

10 files changed

+106
-19
lines changed

libc/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,22 @@ include(LLVMLibCCheckCpuFeatures)
6868

6969
add_subdirectory(include)
7070
add_subdirectory(config)
71+
72+
include("${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/${LIBC_TARGET_MACHINE}/entrypoints.txt")
73+
include("${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/${LIBC_TARGET_MACHINE}/headers.txt")
74+
75+
set(TARGET_ENTRYPOINT_NAME_LIST "")
76+
foreach(entrypoint IN LISTS TARGET_LIBC_ENTRYPOINTS TARGET_LIBM_ENTRYPOINTS)
77+
string(FIND ${entrypoint} "." last_dot_loc REVERSE)
78+
if(${last_dot_loc} EQUAL -1)
79+
message(FATAL "Invalid entrypoint target name ${entrypoint}; Expected a '.' "
80+
"(dot) in the name.")
81+
endif()
82+
math(EXPR name_loc "${last_dot_loc} + 1")
83+
string(SUBSTRING ${entrypoint} ${name_loc} -1 entrypoint_name)
84+
list(APPEND TARGET_ENTRYPOINT_NAME_LIST ${entrypoint_name})
85+
endforeach()
86+
7187
add_subdirectory(src)
7288
add_subdirectory(utils)
7389

libc/cmake/modules/LLVMLibCObjectRules.cmake

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,23 @@ function(add_entrypoint_object target_name)
8686
set(entrypoint_name ${ADD_ENTRYPOINT_OBJ_NAME})
8787
endif()
8888

89+
list(FIND TARGET_ENTRYPOINT_NAME_LIST ${entrypoint_name} entrypoint_name_index)
90+
if(${entrypoint_name_index} EQUAL -1)
91+
add_custom_target(${fq_target_name})
92+
set_target_properties(
93+
${fq_target_name}
94+
PROPERTIES
95+
"ENTRYPOINT_NAME" ${entrypoint_name}
96+
"TARGET_TYPE" ${ENTRYPOINT_OBJ_TARGET_TYPE}
97+
"OBJECT_FILE" ""
98+
"OBJECT_FILE_RAW" ""
99+
"DEPS" ""
100+
"SKIPPED" "YES"
101+
)
102+
message(STATUS "Skipping libc entrypoint ${fq_target_name}.")
103+
return()
104+
endif()
105+
89106
if(ADD_ENTRYPOINT_OBJ_ALIAS)
90107
# Alias targets help one add aliases to other entrypoint object targets.
91108
# One can use alias targets setup OS/machine independent entrypoint targets.

libc/cmake/modules/LLVMLibCTestRules.cmake

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@
33
# recursively produced by "add_entrypoint_object" and "add_object_library"
44
# targets.
55
# Usage:
6-
# get_object_files_for_test(<result var> <target0> [<target1> ...])
6+
# get_object_files_for_test(<result var>
7+
# <skipped_entrypoints_var>
8+
# <target0> [<target1> ...])
79
#
10+
# The list of object files is collected in <result_var>.
11+
# If skipped entrypoints were found, then <skipped_entrypoints_var> is
12+
# set to a true value.
813
# targetN is either an "add_entrypoint_target" target or an
914
# "add_object_library" target.
10-
function(get_object_files_for_test result)
15+
function(get_object_files_for_test result skipped_entrypoints_list)
1116
set(object_files "")
17+
set(skipped_list "")
1218
foreach(dep IN LISTS ARGN)
1319
get_target_property(dep_type ${dep} "TARGET_TYPE")
1420
if(NOT dep_type)
@@ -23,18 +29,29 @@ function(get_object_files_for_test result)
2329
list(APPEND object_files ${dep_object_files})
2430
endif()
2531
elseif(${dep_type} STREQUAL ${ENTRYPOINT_OBJ_TARGET_TYPE})
32+
get_target_property(is_skipped ${dep} "SKIPPED")
33+
if(is_skipped)
34+
list(APPEND skipped_list ${dep})
35+
continue()
36+
endif()
2637
get_target_property(object_file_raw ${dep} "OBJECT_FILE_RAW")
2738
if(object_file_raw)
2839
list(APPEND object_files ${object_file_raw})
2940
endif()
3041
endif()
3142

3243
get_target_property(indirect_deps ${dep} "DEPS")
33-
get_object_files_for_test(indirect_objfiles ${indirect_deps})
44+
get_object_files_for_test(
45+
indirect_objfiles indirect_skipped_list ${indirect_deps})
3446
list(APPEND object_files ${indirect_objfiles})
47+
if(indirect_skipped_list)
48+
list(APPEND skipped_list ${indirect_skipped_list})
49+
endif()
3550
endforeach(dep)
3651
list(REMOVE_DUPLICATES object_files)
3752
set(${result} ${object_files} PARENT_SCOPE)
53+
list(REMOVE_DUPLICATES skipped_list)
54+
set(${skipped_entrypoints_list} ${skipped_list} PARENT_SCOPE)
3855
endfunction(get_object_files_for_test)
3956

4057
# Rule to add a libc unittest.
@@ -68,8 +85,43 @@ function(add_libc_unittest target_name)
6885
"'add_entrypoint_object' targets.")
6986
endif()
7087

71-
7288
get_fq_target_name(${target_name} fq_target_name)
89+
get_fq_deps_list(fq_deps_list ${LIBC_UNITTEST_DEPENDS})
90+
get_object_files_for_test(
91+
link_object_files skipped_entrypoints_list ${fq_deps_list})
92+
if(skipped_entrypoints_list)
93+
# If a test is OS/target machine independent, it has to be skipped if the
94+
# OS/target machine combination does not provide any dependent entrypoints.
95+
# If a test is OS/target machine specific, then such a test will live is a
96+
# OS/target machine specific directory and will be skipped at the directory
97+
# level if required.
98+
#
99+
# There can potentially be a setup like this: A unittest is setup for a
100+
# OS/target machine independent object library, which in turn depends on a
101+
# machine specific object library. Such a test would be testing internals of
102+
# the libc and it is assumed that they will be rare in practice. So, they
103+
# can be skipped in the corresponding CMake files using platform specific
104+
# logic. This pattern is followed in the loader tests for example.
105+
#
106+
# Another pattern that is present currently is to detect machine
107+
# capabilities and add entrypoints and tests accordingly. That approach is
108+
# much lower level approach and is independent of the kind of skipping that
109+
# is happening here at the entrypoint level.
110+
111+
set(msg "Skipping unittest ${fq_target_name} as it has missing deps: "
112+
"${skipped_entrypoints_list}.")
113+
message(STATUS ${msg})
114+
add_custom_target(${fq_target_name})
115+
116+
# A post build custom command is used to avoid running the command always.
117+
add_custom_command(
118+
TARGET ${fq_target_name}
119+
POST_BUILD
120+
COMMAND ${CMAKE_COMMAND} -E echo ${msg}
121+
)
122+
return()
123+
endif()
124+
73125
add_executable(
74126
${fq_target_name}
75127
EXCLUDE_FROM_ALL
@@ -90,8 +142,6 @@ function(add_libc_unittest target_name)
90142
)
91143
endif()
92144

93-
get_fq_deps_list(fq_deps_list ${LIBC_UNITTEST_DEPENDS})
94-
get_object_files_for_test(link_object_files ${fq_deps_list})
95145
target_link_libraries(${fq_target_name} PRIVATE ${link_object_files})
96146

97147
set_target_properties(${fq_target_name}

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
set(LIBC_ENTRYPOINTS
1+
set(TARGET_LIBC_ENTRYPOINTS
22
# assert.h entrypoints
33
libc.src.assert.__assert_fail
44

@@ -43,7 +43,7 @@ set(LIBC_ENTRYPOINTS
4343
libc.src.unistd.write
4444
)
4545

46-
set(LIBM_ENTRYPOINTS
46+
set(TARGET_LIBM_ENTRYPOINTS
4747
# math.h entrypoints
4848
libc.src.math.ceil
4949
libc.src.math.ceilf

libc/config/linux/x86_64/headers.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
set(PUBLIC_HEADERS
1+
set(TARGET_PUBLIC_HEADERS
22
libc.include.assert_h
33
libc.include.errno
44
libc.include.math

libc/lib/CMakeLists.txt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
include("${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/${LIBC_TARGET_MACHINE}/entrypoints.txt")
2-
include("${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/${LIBC_TARGET_MACHINE}/headers.txt")
3-
41
add_entrypoint_library(
52
llvmlibc
63
DEPENDS
7-
${LIBC_ENTRYPOINTS}
4+
${TARGET_LIBC_ENTRYPOINTS}
85
)
96

107
add_entrypoint_library(
118
llvmlibm
129
DEPENDS
13-
${LIBM_ENTRYPOINTS}
10+
${TARGET_LIBM_ENTRYPOINTS}
1411
)
1512

1613
add_redirector_library(

libc/loader/linux/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ function(add_loader_object name)
5656
)
5757
endfunction()
5858

59+
if(NOT (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_MACHINE}))
60+
message(STATUS "Skipping loader for target machine ${LIBC_TARGET_MACHINE}")
61+
return()
62+
endif()
63+
5964
add_subdirectory(${LIBC_TARGET_MACHINE})
6065

6166
add_loader_object(

libc/test/loader/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function(add_loader_test target_name)
3838
)
3939

4040
get_fq_deps_list(fq_deps_list ${ADD_LOADER_TEST_DEPENDS})
41-
get_object_files_for_test(link_object_files ${fq_deps_list})
41+
get_object_files_for_test(link_object_files has_skipped_entrypoint_list ${fq_deps_list})
4242
target_link_libraries(${fq_target_name} ${link_object_files})
4343

4444
target_link_options(

libc/test/loader/linux/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
if(NOT (EXISTS ${LIBC_SOURCE_DIR}/loader/linux/${LIBC_TARGET_MACHINE}))
2+
message("Skipping loader tests for target machine ${LIBC_TARGET_MACHINE}.")
3+
return()
4+
endif()
5+
16
add_loader_test(
27
loader_args_test
38
SRC

libc/test/src/CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,10 @@ add_subdirectory(sys)
99
add_subdirectory(threads)
1010
add_subdirectory(unistd)
1111

12-
include("${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/${LIBC_TARGET_MACHINE}/entrypoints.txt")
13-
include("${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/${LIBC_TARGET_MACHINE}/headers.txt")
14-
1512
set(public_test ${CMAKE_CURRENT_BINARY_DIR}/public_integration_test.cpp)
1613

1714
set(entrypoints_name_list "")
18-
foreach(entry IN LISTS LIBC_ENTRYPOINTS LIBM_ENTRYPOINTS)
15+
foreach(entry IN LISTS TARGET_LIBC_ENTRYPOINTS TARGET_LIBM_ENTRYPOINTS)
1916
get_target_property(entry_name ${entry} "ENTRYPOINT_NAME")
2017
list(APPEND entrypoints_name_list ${entry_name})
2118
endforeach()

0 commit comments

Comments
 (0)