Skip to content

Commit 365ae7a

Browse files
authored
[compiler-rt][sanitizer_common] Make sanitizer_common tests work for other Apple Platforms (#150994)
This commit addresses a longstanding TODO comment, by doing the following: * Modifies the CMakeLists to add the new test configs * Modifies the relevant lit file to add the required envs * Fixes the FileCheck match in `Darwin/symbolizer-function-offset-atos.cpp` * XFAILs any appropriate tests rdar://107758331
1 parent 950f8a8 commit 365ae7a

File tree

7 files changed

+65
-3
lines changed

7 files changed

+65
-3
lines changed

compiler-rt/test/sanitizer_common/CMakeLists.txt

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ foreach(tool ${SUPPORTED_TOOLS})
6565
list(REMOVE_ITEM TEST_ARCH x86_64)
6666
endif()
6767

68-
# TODO(dliew): We should iterate over the different
69-
# Apple platforms, not just macOS.
7068
foreach(arch ${TEST_ARCH})
7169
set(SANITIZER_COMMON_LIT_TEST_MODE ${tool})
7270
set(SANITIZER_COMMON_TEST_TARGET_ARCH ${arch})
@@ -99,6 +97,60 @@ foreach(tool ${SUPPORTED_TOOLS})
9997
endforeach()
10098
endforeach()
10199

100+
# iOS and iOS simulator test suites
101+
# These are not added into "check-all", in order to run these tests, use
102+
# "check-sanitizer-iossim-arm64" and similar. They also require an extra environment
103+
# variable to select which iOS device or simulator to use, e.g.:
104+
# SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER="iPhone 16"
105+
if(APPLE)
106+
set(SANITIZER_APPLE_PLATFORMS ${SANITIZER_COMMON_SUPPORTED_OS})
107+
108+
foreach(platform ${SANITIZER_APPLE_PLATFORMS})
109+
if ("${platform}" STREQUAL "osx")
110+
# Skip macOS because it's handled by the code above that builds tests for the host machine.
111+
continue()
112+
endif()
113+
list_intersect(
114+
SANITIZER_COMMON_TEST_${platform}_ARCHS
115+
ALL_SANITIZER_COMMON_SUPPORTED_ARCH
116+
DARWIN_${platform}_ARCHS
117+
)
118+
foreach(arch ${SANITIZER_COMMON_TEST_${platform}_ARCHS})
119+
set(SANITIZER_COMMON_TESTSUITES_${platform}_${arch})
120+
foreach(tool ${SUPPORTED_TOOLS})
121+
if ("${tool}" STREQUAL "lsan")
122+
continue()
123+
endif()
124+
125+
set(SANITIZER_COMMON_LIT_TEST_MODE ${tool})
126+
127+
get_test_cflags_for_apple_platform(
128+
"${platform}"
129+
"${arch}"
130+
SANITIZER_COMMON_TEST_TARGET_CFLAGS)
131+
set(CONFIG_NAME "${tool}-${arch}-${platform}")
132+
set(SANITIZER_COMMON_TEST_CONFIG_SUFFIX "-${arch}-${platform}")
133+
set(SANITIZER_COMMON_TEST_APPLE_PLATFORM "${platform}")
134+
set(SANITIZER_COMMON_TEST_TARGET_ARCH "${arch}")
135+
set(SANITIZER_COMMON_TEST_MIN_DEPLOYMENT_TARGET_FLAG "${DARWIN_${platform}_MIN_VER_FLAG}")
136+
configure_lit_site_cfg(
137+
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
138+
${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py)
139+
140+
list(APPEND SANITIZER_COMMON_TESTSUITES_${platform}_${arch}
141+
${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
142+
endforeach()
143+
144+
add_lit_testsuite(check-sanitizer-${platform}-${arch}
145+
"sanitizer-common ${platform} ${arch} tests"
146+
${SANITIZER_COMMON_TESTSUITES_${platform}_${arch}}
147+
EXCLUDE_FROM_CHECK_ALL
148+
DEPENDS ${SANITIZER_COMMON_TEST_DEPS})
149+
endforeach()
150+
endforeach()
151+
endif()
152+
153+
102154
# Unit tests.
103155
configure_lit_site_cfg(
104156
${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in

compiler-rt/test/sanitizer_common/TestCases/Darwin/print-stack-trace-in-code-loaded-after-fork.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
// rdar://problem/61793759 and rdar://problem/62126022.
77
// UNSUPPORTED: lsan
88

9+
// XFAIL: iossim
10+
911
#include <stdio.h>
1012

1113
#ifdef SHARED_LIB

compiler-rt/test/sanitizer_common/TestCases/Darwin/symbolizer-function-offset-atos.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ int main() {
3333
return 0;
3434
}
3535

36-
// CHECK: Using atos found at:
36+
// CHECK: {{Using atos (found at|at user-specified path):}}
3737

3838
// These `function_offset` patterns are designed to disallow `0x0` which is the
3939
// value printed for `kUnknown`.

compiler-rt/test/sanitizer_common/TestCases/Posix/dedup_token_length_test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
// XFAIL: (darwin && ubsan && (arm64-target-arch || arm64e-target-arch))
1616

1717
// XFAIL: target={{.*netbsd.*}} && !asan
18+
// XFAIL: darwin && ubsan
1819

1920
volatile int *null = 0;
2021

compiler-rt/test/sanitizer_common/TestCases/Posix/posix_spawn.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
// Older versions of Android do not have certain posix_spawn* functions.
44
// UNSUPPORTED: android
55

6+
// Simulators expect certain envars to be set, but this test overwrites
7+
// env when spawning the child process.
8+
// XFAIL: iossim
9+
610
#include <assert.h>
711
#include <spawn.h>
812
#include <stdio.h>

compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_trace_pc_guard.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// UNSUPPORTED: x86_64h-darwin && lsan
77
// XFAIL: tsan
88
// XFAIL: android && asan
9+
// XFAIL: ios
910

1011
// RUN: rm -rf %t_workdir
1112
// RUN: mkdir -p %t_workdir

compiler-rt/test/sanitizer_common/lit.site.cfg.py.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
config.name_suffix = "@CONFIG_NAME@"
55
config.tool_name = "@SANITIZER_COMMON_LIT_TEST_MODE@"
66
config.target_cflags = "@SANITIZER_COMMON_TEST_TARGET_CFLAGS@"
7+
config.apple_platform = "@SANITIZER_COMMON_TEST_APPLE_PLATFORM@"
8+
config.apple_platform_min_deployment_target_flag = "@SANITIZER_COMMON_TEST_MIN_DEPLOYMENT_TARGET_FLAG@"
79
config.target_arch = "@SANITIZER_COMMON_TEST_TARGET_ARCH@"
810

911
config.arm_thumb = "@COMPILER_RT_ARM_THUMB@"

0 commit comments

Comments
 (0)