Skip to content

Commit ad16a6e

Browse files
committed
[SYCL][COMPAT] Tests refactored as e2e tests
- Test suite is now separated from the standard unittests. - Syclcompat needs to run device code, thus they can't be run in the BUILD + LIT action. - As they run Gtests, this is proposed following the sycl/test/Unit lit architecture. This results in a different target to keep existing e2e tests separated from syclcompat. - Dependency of unittests from sycl to sycl-toolchain
1 parent 831e1cc commit ad16a6e

File tree

12 files changed

+241
-71
lines changed

12 files changed

+241
-71
lines changed

sycl/cmake/modules/AddSYCLLibraryUnitTest.cmake

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,26 @@ macro(add_sycl_library_unittest test_suite_name)
1111
cmake_parse_arguments(ARG
1212
""
1313
""
14-
"SYCL_EXTRA_FLAGS;SOURCES"
14+
"SYCL_EXTRA_FLAGS;SOURCES;DEPENDANTS"
1515
${ARGN})
1616

1717
set(CXX_COMPILER clang++)
1818
if(MSVC)
1919
set(CXX_COMPILER clang-cl.exe)
2020
endif()
2121

22+
set(TRIPLES "spir64-unknown-unknown")
23+
if (SYCL_BUILD_PI_CUDA OR (SYCL_BUILD_PI_HIP AND "${SYCL_BUILD_PI_HIP_PLATFORM}" STREQUAL "NVIDIA"))
24+
set(TRIPLES "${TRIPLES},nvptx64-nvidia-cuda")
25+
endif()
26+
# FIXME: -Xsycl-target-backend=amdgcn-amd-amdhsa --offload-arch= for amd compilation
27+
if ((SYCL_BUILD_PI_HIP AND "${SYCL_BUILD_PI_HIP_PLATFORM}" STREQUAL "AMD"))
28+
set(TRIPLES "${TRIPLES},amdgcn-amd-amdhsa")
29+
endif()
30+
if (SYCL_BUILD_NATIVE_CPU)
31+
set(TRIPLES "${TRIPLES},native_cpu")
32+
endif()
33+
2234
set(DEVICE_COMPILER_EXECUTABLE ${LLVM_RUNTIME_OUTPUT_INTDIR}/${CXX_COMPILER})
2335
set(_OUTPUT_BIN ${CMAKE_CURRENT_BINARY_DIR}/${test_suite_name}Tests)
2436
set(_TESTS_TARGET ${test_suite_name}Tests)
@@ -53,39 +65,28 @@ macro(add_sycl_library_unittest test_suite_name)
5365

5466
add_custom_target(${_BIN_TARGET}
5567
COMMAND ${DEVICE_COMPILER_EXECUTABLE} -fsycl ${ARG_SOURCES}
68+
-fsycl-targets=${TRIPLES}
5669
-o ${_OUTPUT_BIN}
5770
${ARG_SYCL_EXTRA_FLAGS}
5871
${_INTERNAL_EXTRA_FLAGS}
5972
${INCLUDE_COMPILER_STRING}
6073
${_LIBRARIES}
6174
${_INTERNAL_LINKER_FLAGS}
62-
BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/${_TESTS_TARGET}
75+
BYPRODUCTS ${_OUTPUT_BIN}
76+
DEPENDS ${ARG_SOURCES}
6377
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
6478
COMMAND_EXPAND_LISTS)
6579

66-
add_dependencies(${_BIN_TARGET} sycl)
80+
add_dependencies(${_BIN_TARGET} sycl-toolchain)
6781
foreach(_lib ${ARG_LIBRARIES})
6882
add_dependencies(${_BIN_TARGET} ${_TARGET_DEPENDENCIES})
6983
endforeach()
70-
71-
add_dependencies(SYCLUnitTests ${_BIN_TARGET})
84+
foreach(_dep ${ARG_DEPENDANTS})
85+
add_dependencies(${_dep} ${_BIN_TARGET})
86+
endforeach()
7287

7388
add_executable(${_TESTS_TARGET} IMPORTED GLOBAL)
7489
set_target_properties(${_TESTS_TARGET} PROPERTIES
7590
IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR})
7691

77-
# Check target for Linux
78-
if (UNIX)
79-
add_custom_target(check-${test_suite_name}
80-
${CMAKE_COMMAND} -E
81-
env LD_LIBRARY_PATH="${CMAKE_BINARY_DIR}/lib"
82-
env SYCL_CONFIG_FILE_NAME=null.cfg
83-
env SYCL_DEVICELIB_NO_FALLBACK=1
84-
env SYCL_CACHE_DIR="${CMAKE_BINARY_DIR}/sycl_cache"
85-
${CMAKE_CURRENT_BINARY_DIR}/${_TESTS_TARGET}
86-
)
87-
add_dependencies(check-${test_suite_name} ${_BIN_TARGET})
88-
add_dependencies(check-sycl-unittests-libs check-${test_suite_name})
89-
endif()
90-
9192
endmacro()

sycl/test-e2e/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,5 @@ add_custom_target(check-sycl-e2e
7171

7272
add_subdirectory(External)
7373
add_subdirectory(ExtraTests)
74+
75+
add_subdirectory(Syclcompat)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#
2+
# Copyright (C) Codeplay Software Ltd.
3+
#
4+
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
# See https://llvm.org/LICENSE.txt for license information.
6+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11+
# License for the specific language governing permissions and limitations under
12+
# the License.
13+
#
14+
# SYCLcompat
15+
#
16+
if(SYCL_TEST_E2E_STANDALONE)
17+
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in"
18+
"${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py")
19+
else()
20+
configure_lit_site_cfg(
21+
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
22+
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py
23+
MAIN_CONFIG
24+
${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py
25+
)
26+
endif() # Standalone.
27+
28+
add_custom_target(check-sycl-e2e-syclcompat
29+
COMMAND ${Python3_EXECUTABLE} ${LLVM_LIT} ${SYCL_E2E_TESTS_LIT_FLAGS} .
30+
COMMENT "Running SYCLcompat End-to-End tests"
31+
DEPENDS ${SYCL_E2E_TEST_DEPS}
32+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
33+
USES_TERMINAL
34+
)
35+
add_dependencies(check-sycl-e2e check-sycl-e2e-syclcompat)
36+
37+
include(AddSYCLLibraryUnitTest)
38+
set(SYCL_EXTRA_FLAGS "-fsycl-unnamed-lambda;-fsycl-device-code-split=per_kernel")
39+
40+
add_sycl_library_unittest(syclcompat-base
41+
SYCL_EXTRA_FLAGS
42+
${SYCL_EXTRA_FLAGS}
43+
SOURCES
44+
Device.cpp
45+
Dim.cpp
46+
Defs.cpp
47+
DEPENDANTS
48+
check-sycl-e2e-syclcompat
49+
)
File renamed without changes.

sycl/test-e2e/Syclcompat/lit.cfg.py

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# -*- Python -*-
2+
3+
import os
4+
import platform
5+
import copy
6+
import subprocess
7+
8+
import lit.util
9+
import lit.formats
10+
11+
from lit.llvm import llvm_config
12+
from lit.llvm.subst import FindTool
13+
14+
# name: The name of this test suite.
15+
config.name = 'SYCL-Unit-syclcompat'
16+
17+
# suffixes: A list of file extensions to treat as test files.
18+
config.suffixes = []
19+
20+
# test_source_root: The root path where tests are located.
21+
# test_exec_root: The root path where tests should be run.
22+
config.test_exec_root = config.sycl_obj_root
23+
config.test_source_root = config.test_exec_root
24+
25+
# testFormat: The test format to use to interpret tests.
26+
config.test_format = lit.formats.GoogleTest('.', 'Tests')
27+
28+
# allow expanding substitutions that are based on other substitutions
29+
config.recursiveExpansionLimit = 10
30+
31+
# Cleanup environment variables which may affect tests
32+
possibly_dangerous_env_vars = ['COMPILER_PATH', 'RC_DEBUG_OPTIONS',
33+
'CINDEXTEST_PREAMBLE_FILE', 'LIBRARY_PATH',
34+
'CPATH', 'C_INCLUDE_PATH', 'CPLUS_INCLUDE_PATH',
35+
'OBJC_INCLUDE_PATH', 'OBJCPLUS_INCLUDE_PATH',
36+
'LIBCLANG_TIMING', 'LIBCLANG_OBJTRACKING',
37+
'LIBCLANG_LOGGING', 'LIBCLANG_BGPRIO_INDEX',
38+
'LIBCLANG_BGPRIO_EDIT', 'LIBCLANG_NOTHREADS',
39+
'LIBCLANG_RESOURCE_USAGE',
40+
'LIBCLANG_CODE_COMPLETION_LOGGING']
41+
42+
# Clang/Win32 may refer to %INCLUDE%. vsvarsall.bat sets it.
43+
if platform.system() != 'Windows':
44+
possibly_dangerous_env_vars.append('INCLUDE')
45+
46+
for name in possibly_dangerous_env_vars:
47+
if name in llvm_config.config.environment:
48+
del llvm_config.config.environment[name]
49+
50+
# Propagate some variables from the host environment.
51+
llvm_config.with_system_environment(['PATH', 'OCL_ICD_FILENAMES',
52+
'CL_CONFIG_DEVICES', 'SYCL_DEVICE_ALLOWLIST', 'SYCL_CONFIG_FILE_NAME'])
53+
54+
llvm_config.with_environment('PATH', config.lit_tools_dir, append_path=True)
55+
56+
# Configure LD_LIBRARY_PATH or corresponding os-specific alternatives
57+
if platform.system() == "Linux":
58+
llvm_config.with_system_environment(['LD_LIBRARY_PATH','LIBRARY_PATH','CPATH'])
59+
llvm_config.with_environment('LD_LIBRARY_PATH', config.sycl_libs_dir, append_path=True)
60+
61+
elif platform.system() == "Windows":
62+
llvm_config.with_system_environment(['LIB','CPATH','INCLUDE'])
63+
llvm_config.with_environment('LIB', config.sycl_libs_dir, append_path=True)
64+
llvm_config.with_environment('PATH', config.sycl_libs_dir, append_path=True)
65+
llvm_config.with_environment('LIB', os.path.join(config.dpcpp_root_dir, 'lib'), append_path=True)
66+
67+
elif platform.system() == "Darwin":
68+
llvm_config.with_system_environment('CPATH')
69+
llvm_config.with_environment('CPATH', "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1", append_path=True)
70+
llvm_config.with_environment('CPATH', "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/", append_path=True)
71+
llvm_config.with_environment('DYLD_LIBRARY_PATH', config.sycl_libs_dir)
72+
73+
llvm_config.with_environment('PATH', config.sycl_tools_dir, append_path=True)
74+
75+
lit_config.note("Targeted devices: {}".format(', '.join(config.sycl_devices)))
76+
77+
sycl_ls = FindTool('sycl-ls').resolve(llvm_config, config.llvm_tools_dir)
78+
if not sycl_ls:
79+
lit_config.fatal("can't find `sycl-ls`")
80+
81+
if len(config.sycl_devices) == 1 and config.sycl_devices[0] == 'all':
82+
devices = set()
83+
sp = subprocess.check_output(sycl_ls, text=True)
84+
for line in sp.splitlines():
85+
(backend, device, _) = line[1:].split(':', 2)
86+
devices.add('{}:{}'.format(backend, device))
87+
config.sycl_devices = list(devices)
88+
89+
lit_config.note("Expanded devices: {}".format(', '.join(config.sycl_devices)))
90+
91+
available_devices = {'opencl': ('cpu', 'gpu', 'acc'),
92+
'ext_oneapi_cuda':('gpu'),
93+
'ext_oneapi_level_zero':('gpu'),
94+
'ext_oneapi_hip':('gpu'),
95+
'ext_intel_esimd_emulator':('gpu'),
96+
'native_cpu':('cpu')}
97+
98+
for d in config.sycl_devices:
99+
be, dev = d.split(':')
100+
if be not in available_devices or dev not in available_devices[be]:
101+
lit_config.error('Unsupported device {}'.format(d))
102+
103+
llvm_config.with_environment('ONEAPI_DEVICE_SELECTOR', ';'.join(config.sycl_devices))
104+
lit_config.note("ONEAPI_DEVICE_SELECTOR={}".format(';'.join(config.sycl_devices)))
105+
106+
# If HIP_PLATFORM flag is not set, default to AMD, and check if HIP platform is supported
107+
supported_hip_platforms=["AMD", "NVIDIA"]
108+
if config.hip_platform == "":
109+
config.hip_platform = "AMD"
110+
if config.hip_platform not in supported_hip_platforms:
111+
lit_config.error("Unknown HIP platform '" + config.hip_platform + "' supported platforms are " + ', '.join(supported_hip_platforms))
112+
113+
# We use this to simply detect errors in sycl devices
114+
config.sycl_dev_features = {}
115+
for sycl_device in config.sycl_devices:
116+
env = copy.copy(llvm_config.config.environment)
117+
env['ONEAPI_DEVICE_SELECTOR'] = sycl_device
118+
if sycl_device.startswith('ext_oneapi_cuda:'):
119+
env['SYCL_PI_CUDA_ENABLE_IMAGE_SUPPORT'] = '1'
120+
# When using the ONEAPI_DEVICE_SELECTOR environment variable, sycl-ls
121+
# prints warnings that might derail a user thinking something is wrong
122+
# with their test run. It's just us filtering here, so silence them unless
123+
# we get an exit status.
124+
try:
125+
sp = subprocess.run([sycl_ls, '--verbose'], env=env, text=True,
126+
capture_output=True)
127+
sp.check_returncode()
128+
except subprocess.CalledProcessError as e:
129+
# capturing e allows us to see path resolution errors / system
130+
# permissions errors etc
131+
lit_config.fatal(f'Cannot list device aspects for {sycl_device}\n'
132+
f'{e}\n'
133+
f'stdout:{sp.stdout}\n'
134+
f'stderr:{sp.stderr}\n')
135+
136+
137+
# Set timeout for a single test
138+
try:
139+
import psutil
140+
lit_config.maxIndividualTestTime = 600
141+
except ImportError:
142+
pass
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@LIT_SITE_CFG_IN_HEADER@
2+
3+
import sys
4+
import platform
5+
6+
import site
7+
8+
site.addsitedir("@CMAKE_CURRENT_SOURCE_DIR@")
9+
10+
config.dpcpp_compiler = lit_config.params.get("dpcpp_compiler", "@SYCL_CXX_COMPILER@")
11+
config.dpcpp_root_dir= os.path.dirname(os.path.dirname(config.dpcpp_compiler))
12+
13+
config.llvm_tools_dir = os.path.join(config.dpcpp_root_dir, 'bin')
14+
config.lit_tools_dir = os.path.dirname("@TEST_SUITE_LIT@")
15+
config.sycl_tools_dir = config.llvm_tools_dir
16+
config.sycl_obj_root = "@CMAKE_CURRENT_BINARY_DIR@"
17+
config.sycl_libs_dir = os.path.join(config.dpcpp_root_dir, ('bin' if platform.system() == "Windows" else 'lib'))
18+
19+
config.hip_platform = "@HIP_PLATFORM@"
20+
21+
config.sycl_devices = lit_config.params.get("sycl_devices", "@SYCL_TEST_E2E_TARGETS@").split(';')
22+
23+
import lit.llvm
24+
lit.llvm.initialize(lit_config, config)
25+
26+
lit_config.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/lit.cfg.py")

sycl/test-e2e/lit.cfg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# suffixes: A list of file extensions to treat as test files.
2323
config.suffixes = ['.c', '.cpp']
2424

25-
config.excludes = ['Inputs']
25+
config.excludes = ['Inputs', 'Syclcompat']
2626

2727
# test_source_root: The root path where tests are located.
2828
config.test_source_root = os.path.dirname(__file__)

sycl/test/CMakeLists.txt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ if ((SYCL_BUILD_PI_HIP AND "${SYCL_BUILD_PI_HIP_PLATFORM}" STREQUAL "AMD"))
6565
set(TRIPLES "${TRIPLES},amdgcn-amd-amdhsa")
6666
endif()
6767

68-
add_lit_testsuite(check-sycl-combined-triples "Running device-agnostic SYCL regression tests for all avaialble triples"
68+
add_lit_testsuite(check-sycl-combined-triples "Running device-agnostic SYCL regression tests for all available triples"
6969
${CMAKE_CURRENT_BINARY_DIR}
7070
ARGS ${RT_TEST_ARGS}
7171
PARAMS "SYCL_TRIPLE=${TRIPLES}"
@@ -77,15 +77,6 @@ add_custom_target(check-sycl)
7777
add_dependencies(check-sycl check-sycl-combined-triples)
7878
set_target_properties(check-sycl PROPERTIES FOLDER "SYCL tests")
7979

80-
add_lit_testsuite(check-sycl-spirv "Running device-agnostic SYCL regression tests for SPIR-V"
81-
${CMAKE_CURRENT_BINARY_DIR}
82-
ARGS ${RT_TEST_ARGS}
83-
PARAMS "SYCL_TRIPLE=spir64-unknown-unknown"
84-
DEPENDS ${SYCL_TEST_DEPS}
85-
${SYCL_TEST_EXCLUDE}
86-
EXCLUDE_FROM_CHECK_ALL
87-
)
88-
8980
add_lit_testsuite(check-sycl-dumps "Running ABI dump tests only"
9081
${CMAKE_CURRENT_BINARY_DIR}
9182
ARGS ${RT_TEST_ARGS}

sycl/unittests/CMakeLists.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,3 @@ add_subdirectory(builtins)
5555
if (NOT WIN32)
5656
add_subdirectory(xpti_trace)
5757
endif()
58-
59-
# Library unit testing
60-
include(AddSYCLLibraryUnitTest)
61-
add_custom_target(check-sycl-unittests-libs)
62-
add_dependencies(check-sycl-unittests check-sycl-unittests-libs)
63-
64-
add_subdirectory(syclcompat)

sycl/unittests/syclcompat/CMakeLists.txt

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)