Skip to content

Commit 58ef151

Browse files
authored
Merge pull request #585
[SYCL][PI] Fix PI unittests and always build them
2 parents 2de1379 + f086599 commit 58ef151

File tree

10 files changed

+165
-34
lines changed

10 files changed

+165
-34
lines changed

buildbot/configure.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@ def do_configure(args):
2626
"-DLLVM_EXTERNAL_PROJECTS=sycl;llvm-spirv",
2727
"-DLLVM_EXTERNAL_SYCL_SOURCE_DIR={}".format(sycl_dir),
2828
"-DLLVM_EXTERNAL_LLVM_SPIRV_SOURCE_DIR={}".format(spirv_dir),
29-
"-DLLVM_ENABLE_PROJECTS=clang;llvm-spirv;sycl",
29+
"-DLLVM_ENABLE_PROJECTS=clang;sycl;llvm-spirv",
3030
"-DOpenCL_INCLUDE_DIR={}".format(ocl_header_dir),
3131
"-DOpenCL_LIBRARY={}".format(icd_loader_lib),
3232
"-DLLVM_BUILD_TOOLS=OFF",
3333
"-DSYCL_ENABLE_WERROR=ON",
3434
"-DLLVM_ENABLE_ASSERTIONS=ON",
3535
"-DCMAKE_INSTALL_PREFIX={}".format(install_dir),
36+
"-DSYCL_INCLUDE_TESTS=ON", # Explicitly include all kinds of SYCL tests.
3637
llvm_dir]
3738

3839
print(cmake_cmd)

sycl/CMakeLists.txt

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,23 @@ add_custom_target( sycl-toolchain
159159
COMMENT "Building SYCL compiler toolchain..."
160160
)
161161

162-
add_subdirectory( test )
163-
add_subdirectory( unittests )
164-
add_subdirectory( tools )
162+
if (NOT DEFINED LLVM_INCLUDE_TESTS)
163+
set(LLVM_INCLUDE_TESTS ON)
164+
endif()
165+
166+
option(SYCL_INCLUDE_TESTS
167+
"Generate build targets for the SYCL unit tests."
168+
${LLVM_INCLUDE_TESTS})
169+
170+
add_subdirectory(tools)
171+
172+
if(SYCL_INCLUDE_TESTS)
173+
if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include/gtest/gtest.h)
174+
add_subdirectory(unittests)
175+
list(APPEND SYCL_TEST_DEPS SYCLUnitTests)
176+
endif()
177+
add_subdirectory(test)
178+
endif()
165179

166180
# Package deploy support
167181
# Listed here are component names contributing the package

sycl/test/CMakeLists.txt

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,41 @@ set(LLVM_TOOLS_DIR "${LLVM_BINARY_DIR}/bin/")
44
set(CLANG_IN_BUILD "${LLVM_BINARY_DIR}/bin/clang")
55
set(CLANGXX_IN_BUILD "${LLVM_BINARY_DIR}/bin/clang++")
66

7-
set(SYCL_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
8-
set(SYCL_TESTS_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
9-
set(SYCL_TESTS_BINARY_DIR ${SYCL_BINARY_DIR}/test)
7+
get_target_property(SYCL_BINARY_DIR sycl-toolchain BINARY_DIR)
8+
get_target_property(SYCL_SOURCE_DIR sycl-toolchain SOURCE_DIR)
9+
10+
set(SYCL_INCLUDE "${dst_dir}")
1011

1112
set(RT_TEST_ARGS ${RT_TEST_ARGS} "-v")
1213

1314
configure_lit_site_cfg(
14-
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
15-
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
15+
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
16+
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py
17+
MAIN_CONFIG
18+
${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py
19+
)
20+
21+
configure_lit_site_cfg(
22+
${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in
23+
${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg.py
1624
MAIN_CONFIG
17-
${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg
25+
${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.cfg.py
26+
)
27+
28+
list(APPEND SYCL_TEST_DEPS
29+
sycl-toolchain
30+
FileCheck
31+
get_device_count_by_type
32+
llvm-config
1833
)
1934

2035
add_lit_testsuite(check-sycl "Running the SYCL regression tests"
2136
${CMAKE_CURRENT_BINARY_DIR}
2237
ARGS ${RT_TEST_ARGS}
23-
DEPENDS sycl-toolchain FileCheck get_device_count_by_type llvm-config
38+
DEPENDS ${SYCL_TEST_DEPS}
2439
)
2540
set_target_properties(check-sycl PROPERTIES FOLDER "SYCL tests")
41+
42+
add_lit_testsuites(SYCL ${CMAKE_CURRENT_SOURCE_DIR}
43+
DEPENDS ${SYCL_TEST_DEPS}
44+
)

sycl/test/Unit/lit.cfg.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# -*- Python -*-
2+
3+
# Configuration file for the 'lit' test runner.
4+
5+
import os
6+
import platform
7+
import subprocess
8+
9+
import lit.formats
10+
import lit.util
11+
12+
# name: The name of this test suite.
13+
config.name = 'SYCL-Unit'
14+
15+
# suffixes: A list of file extensions to treat as test files.
16+
config.suffixes = []
17+
18+
# test_source_root: The root path where tests are located.
19+
# test_exec_root: The root path where tests should be run.
20+
config.test_exec_root = os.path.join(config.sycl_obj_root, 'unittests')
21+
config.test_source_root = config.test_exec_root
22+
23+
# testFormat: The test format to use to interpret tests.
24+
config.test_format = lit.formats.GoogleTest(config.llvm_build_mode, 'Tests')
25+
26+
# Propagate the temp directory. Windows requires this because it uses \Windows\
27+
# if none of these are present.
28+
if 'TMP' in os.environ:
29+
config.environment['TMP'] = os.environ['TMP']
30+
if 'TEMP' in os.environ:
31+
config.environment['TEMP'] = os.environ['TEMP']
32+
33+
# Propagate path to symbolizer for ASan/MSan.
34+
for symbolizer in ['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH']:
35+
if symbolizer in os.environ:
36+
config.environment[symbolizer] = os.environ[symbolizer]
37+
38+
def find_shlibpath_var():
39+
if platform.system() in ['Linux', 'FreeBSD', 'NetBSD', 'SunOS']:
40+
yield 'LD_LIBRARY_PATH'
41+
elif platform.system() == 'Darwin':
42+
yield 'DYLD_LIBRARY_PATH'
43+
elif platform.system() == 'Windows':
44+
yield 'PATH'
45+
elif platform.system() == 'AIX':
46+
yield 'LIBPATH'
47+
48+
for shlibpath_var in find_shlibpath_var():
49+
# in stand-alone builds, shlibdir is clang's build tree
50+
# while llvm_libs_dir is installed LLVM (and possibly older clang)
51+
shlibpath = os.path.pathsep.join(
52+
(config.shlibdir,
53+
config.llvm_libs_dir,
54+
config.environment.get(shlibpath_var, '')))
55+
config.environment[shlibpath_var] = shlibpath
56+
break
57+
else:
58+
lit_config.warning("unable to inject shared library path on '{}'"
59+
.format(platform.system()))

sycl/test/Unit/lit.site.cfg.py.in

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
@LIT_SITE_CFG_IN_HEADER@
2+
3+
import sys
4+
5+
config.llvm_src_root = "@LLVM_SOURCE_DIR@"
6+
config.llvm_obj_root = "@LLVM_BINARY_DIR@"
7+
config.llvm_tools_dir = "@LLVM_TOOLS_DIR@"
8+
config.llvm_libs_dir = "@LLVM_LIBS_DIR@"
9+
config.llvm_build_mode = "@LLVM_BUILD_MODE@"
10+
config.clang_obj_root = "@CLANG_BINARY_DIR@"
11+
config.enable_shared = @ENABLE_SHARED@
12+
config.shlibdir = "@SHLIBDIR@"
13+
config.target_triple = "@TARGET_TRIPLE@"
14+
config.sycl_obj_root = "@SYCL_BINARY_DIR@"
15+
16+
# Support substitution of the tools_dir, libs_dirs, and build_mode with user
17+
# parameters. This is used when we can't determine the tool dir at
18+
# configuration time.
19+
try:
20+
config.llvm_tools_dir = config.llvm_tools_dir % lit_config.params
21+
config.llvm_libs_dir = config.llvm_libs_dir % lit_config.params
22+
config.llvm_build_mode = config.llvm_build_mode % lit_config.params
23+
except KeyError:
24+
e = sys.exc_info()[1]
25+
key, = e.args
26+
lit_config.fatal("unable to find %r parameter, use '--param=%s=VALUE'" % (key,key))
27+
28+
# Let the main config do the real work.
29+
lit_config.load_config(config, "@SYCL_SOURCE_DIR@/test/Unit/lit.cfg.py")

sycl/test/lit.cfg renamed to sycl/test/lit.cfg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# Configuration file for the 'lit' test runner.
1515

1616
# name: The name of this test suite.
17-
config.name = 'SYCLUnitTests'
17+
config.name = 'SYCL'
1818

1919
# testFormat: The test format to use to interpret tests.
2020
#
@@ -31,7 +31,7 @@
3131
config.test_source_root = os.path.dirname(__file__)
3232

3333
# test_exec_root: The root path where tests should be run.
34-
config.test_exec_root = os.path.join(config.sycl_dir, 'test')
34+
config.test_exec_root = os.path.join(config.sycl_obj_root, 'test')
3535

3636
if platform.system() == "Linux":
3737
# Propagate 'LD_LIBRARY_PATH' through the environment.

sycl/test/lit.site.cfg.in renamed to sycl/test/lit.site.cfg.py.in

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ config.llvm_build_bins_dir = "@LLVM_BUILD_BINARY_DIRS@"
1111
config.llvm_binary_dir = "@LLVM_BINARY_DIR@"
1212
config.opencl_include = "@OPENCL_INCLUDE@"
1313
config.sycl_include = "@SYCL_INCLUDE@"
14+
config.sycl_obj_root = "@SYCL_BINARY_DIR@"
1415

15-
config.sycl_tests_binary_dir = "@SYCL_TESTS_BINARY_DIR@"
16-
config.sycl_dir = "@SYCL_BINARY_DIR@"
1716

1817
import lit.llvm
1918
lit.llvm.initialize(lit_config, config)
2019

2120
# Let the main config do the real work.
22-
lit_config.load_config(config, "@SYCL_TESTS_ROOT_DIR@/lit.cfg")
21+
lit_config.load_config(config, "@SYCL_SOURCE_DIR@/test/lit.cfg.py")

sycl/unittests/CMakeLists.txt

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
1-
add_custom_target(PiUnitTests)
2-
set_target_properties(PiUnitTests PROPERTIES FOLDER "Tests")
1+
add_custom_target(SYCLUnitTests)
2+
set_target_properties(SYCLUnitTests PROPERTIES FOLDER "SYCL tests")
33

4-
function(add_llvm_unittest test_dirname)
5-
add_unittest(PiUnitTests ${test_dirname} ${ARGN})
6-
endfunction()
4+
# add_sycl_unittest(test_dirname file1.cpp, file2.cpp ...)
5+
#
6+
# Will compile the list of files together and link against SYCL.
7+
# Produces a binary names `basename(test_dirname)`.
8+
function(add_sycl_unittest test_dirname)
9+
# Enable exception handling for these unit tests
10+
set(LLVM_REQUIRES_EH 1)
711

8-
function(add_llvm_unittest_with_input_files test_dirname)
9-
add_unittest_with_input_files(PiUnitTests ${test_dirname} ${ARGN})
12+
add_unittest(SYCLUnitTests ${test_dirname} ${ARGN})
13+
target_link_libraries(${test_dirname}
14+
PRIVATE
15+
sycl
16+
LLVMTestingSupport
17+
OpenCL-Headers
18+
)
19+
target_include_directories(${test_dirname} PRIVATE SYSTEM ${sycl_inc_dir})
20+
# LLVM gtest uses LLVM utilities that require C++-14
21+
# CXX_STANDARD_REQUIRED makes CXX_STANDARD a hard requirement.
22+
set_target_properties(${test_dirname}
23+
PROPERTIES
24+
CXX_STANDARD 14
25+
CXX_STANDARD_REQUIRED ON
26+
)
1027
endfunction()
1128

12-
add_subdirectory(pi)
29+
add_subdirectory(pi)

sycl/unittests/pi/CMakeLists.txt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
1-
set(CMAKE_CXX_STANDARD 11)
2-
set(CMAKE_CXX_STANDARD_REQUIRED ON)
31
set(CMAKE_CXX_EXTENSIONS OFF)
42

5-
# Enable exception handling for these unit tests
6-
set(LLVM_REQUIRES_EH 1)
7-
add_llvm_unittest(PiTests
3+
add_sycl_unittest(PiTests
84
PlatformTest.cpp
9-
)
10-
11-
add_dependencies(PiTests sycl)
12-
target_link_libraries(PiTests PRIVATE sycl LLVMTestingSupport)
5+
)

sycl/unittests/pi/PlatformTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "CL/sycl/detail/pi.hpp"
109
#include <CL/sycl.hpp>
10+
#include <CL/sycl/detail/pi.hpp>
1111
#include <gtest/gtest.h>
1212
#include <memory>
1313

0 commit comments

Comments
 (0)