Skip to content

Commit 74c2f43

Browse files
committed
Refactor testing rules:
1. If ORC_RT_LLVM_TOOLS_DIR is not defined but LLVM_BINARY_DIR is then the latter is used to set a value for ORC_RT_LLVM_TOOLS_DIR ("${LLVM_BINARY_DIR}/bin"). 2. If ORC_RT_LLVM_TOOLS_DIR is available it is used to find the testing tools (so far just `FileCheck` and `not`). 3. If the test tools are available then the check-orc-rt target is enabled. The lit config files have also been cut down, and the unit test updated to compile and return a passing result.
1 parent 6957220 commit 74c2f43

File tree

9 files changed

+110
-148
lines changed

9 files changed

+110
-148
lines changed

orc-rt/CMakeLists.txt

Lines changed: 15 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@
66

77
cmake_minimum_required(VERSION 3.20.0)
88

9-
option(LLVM_RT_INCLUDE_TESTS "Build orcrt tests." ${LLVM_INCLUDE_TESTS})
10-
11-
129
set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)
1310
include(${LLVM_COMMON_CMAKE_UTILS}/Modules/CMakePolicy.cmake
1411
NO_POLICY_SCOPE)
1512

16-
if (ORC_RT_INCLUDE_TESTS)
17-
set(LLVM_INCLUDE_UTILS YES)
18-
endif()
19-
2013
project(OrcRT LANGUAGES C CXX ASM)
2114

15+
list(INSERT CMAKE_MODULE_PATH 0
16+
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
17+
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
18+
"${CMAKE_CURRENT_SOURCE_DIR}/../runtimes/cmake/Modules"
19+
"${LLVM_COMMON_CMAKE_UTILS}"
20+
"${LLVM_COMMON_CMAKE_UTILS}/Modules"
21+
)
22+
2223
include(GNUInstallDirs)
2324

2425
#===============================================================================
@@ -29,12 +30,16 @@ option(ORC_RT_INCLUDE_DOCS "Build the ORC-RT documentation." ON)
2930
option(ORC_RT_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON)
3031
option(ORC_RT_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
3132
option(ORC_RT_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
33+
option(ORC_RT_INCLUDE_TESTS "Build ORC-RT tests." ${LLVM_INCLUDE_TESTS})
3234

3335
set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to")
3436
set(CMAKE_CXX_STANDARD_REQUIRED YES)
3537
set(CMAKE_CXX_EXTENSIONS NO)
3638
set(CMAKE_FOLDER "orc-rt")
3739

40+
set(ORC_RT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
41+
set(ORC_RT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
42+
3843
#===============================================================================
3944
# Setup Source Code
4045
#===============================================================================
@@ -47,50 +52,7 @@ add_subdirectory(include)
4752
add_subdirectory(lib)
4853
add_subdirectory(tools)
4954

50-
if(LLVM_INCLUDE_TESTS)
51-
if(NOT TARGET FileCheck)
52-
find_program(FILECHECK_EXE
53-
NAMES FileCheck
54-
HINTS ${LLVM_RT_TOOLS_BINARY_DIR}
55-
DOC "FileCheck executable")
56-
endif()
57-
if(FILECHECK_EXE)
58-
add_executable(FileCheck IMPORTED GLOBAL)
59-
set_property(TARGET FileCheck PROPERTY IMPORTED_LOCATION "${FILECHECK_EXE}")
60-
message(DEBUG "Using FileCheck: ${FILECHECK_EXE}")
61-
endif()
62-
if(NOT TARGET count)
63-
find_program(COUNT_EXE
64-
NAMES count
65-
HINTS ${LLVM_RT_TOOLS_BINARY_DIR}
66-
DOC "count executable")
67-
endif()
68-
if(COUNT_EXE)
69-
add_executable(count IMPORTED GLOBAL)
70-
set_property(TARGET count PROPERTY IMPORTED_LOCATION "${COUNT_EXE}")
71-
message(DEBUG "Using count: ${COUNT_EXE}")
72-
endif()
73-
if(NOT TARGET not)
74-
find_program(NOT_EXE
75-
NAMES not
76-
HINTS ${LLVM_RT_TOOLS_BINARY_DIR}
77-
DOC "not executable")
78-
endif()
79-
if(NOT_EXE)
80-
add_executable(not IMPORTED GLOBAL)
81-
set_property(TARGET not PROPERTY IMPORTED_LOCATION "${NOT_EXE}")
82-
message(DEBUG "Using not: ${NOT_EXE}")
83-
endif()
84-
85-
set(ORCRT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
86-
set(ORCRT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
87-
55+
if(ORC_RT_INCLUDE_TESTS)
8856
add_subdirectory(test)
89-
set(UNITTEST_DIR ${LLVM_THIRD_PARTY_DIR}/unittest)
90-
if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h)
91-
if (NOT TARGET gtest)
92-
add_subdirectory(${UNITTEST_DIR} third-party/unittest)
93-
endif()
94-
add_subdirectory(unittests)
95-
endif()
96-
endif()
57+
add_subdirectory(unittests)
58+
endif()

orc-rt/cmake/OrcRTTesting.cmake

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Keep track if we have all dependencies.
2+
set(ORC_RT_LLVM_TOOLS_AVAILABLE TRUE)
3+
4+
if (NOT DEFINED ORC_RT_LLVM_TOOLS_DIR AND DEFINED LLVM_BINARY_DIR)
5+
cmake_path(APPEND ORC_RT_LLVM_TOOLS_DIR "${LLVM_BINARY_DIR}" "bin")
6+
endif()
7+
8+
if (TARGET utils/llvm-lit/all)
9+
list(APPEND utils/llvm-lit/all)
10+
endif()
11+
12+
# Add dependence on FileCheck.
13+
if (TARGET FileCheck)
14+
list(APPEND ORC_RT_TEST_DEPS FileCheck)
15+
endif()
16+
17+
find_program(ORC_RT_FILECHECK_EXECUTABLE
18+
NAMES FileCheck
19+
PATHS ${ORC_RT_LLVM_TOOLS_DIR})
20+
if (NOT ORC_RT_FILECHECK_EXECUTABLE)
21+
message(STATUS "Cannot find FileCheck. Please put it in your PATH, set ORC_RT_FILECHECK_EXECUTABLE to its full path, or point ORC_RT_LLVM_TOOLS_DIR to its directory.")
22+
set(ORC_RT_LLVM_TOOLS_AVAILABLE FALSE)
23+
endif()
24+
25+
# Add dependence on not.
26+
if (TARGET not)
27+
list(APPEND ORC_RT_TEST_DEPS not)
28+
endif()
29+
30+
find_program(ORC_RT_NOT_EXECUTABLE
31+
NAMES not
32+
PATHS ${ORC_RT_LLVM_TOOLS_DIR})
33+
if (NOT ORC_RT_NOT_EXECUTABLE)
34+
message(STATUS "Cannot find 'not'. Please put it in your PATH, set ORC_RT_NOT_EXECUTABLE to its full path, or point ORC_RT_LLVM_TOOLS_DIR to its directory.")
35+
set(ORC_RT_LLVM_TOOLS_AVAILABLE FALSE)
36+
endif()

orc-rt/test/CMakeLists.txt

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,40 @@
1-
configure_lit_site_cfg(
2-
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
3-
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py
4-
MAIN_CONFIG
5-
${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py
6-
)
1+
include(OrcRTTesting)
72

8-
list(APPEND ORC_RT_TEST_DEPS
9-
FileCheck
10-
count
11-
not
12-
orc-executor
3+
if (ORC_RT_LLVM_TOOLS_AVAILABLE)
4+
configure_lit_site_cfg(
5+
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
6+
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py
7+
MAIN_CONFIG
8+
${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py
139
)
1410

15-
add_custom_target(orc-rt-test-depends DEPENDS ${ORC_RT_TEST_DEPS})
16-
set_target_properties(orc-rt-test-depends PROPERTIES FOLDER "orc-rt/Tests")
17-
18-
add_lit_testsuite(check-orc-rt "Running the ORCRT regression tests"
19-
${CMAKE_CURRENT_BINARY_DIR}
20-
DEPENDS ${ORC_RT_TEST_DEPS}
11+
list(APPEND ORC_RT_TEST_DEPS
12+
orc-executor
2113
)
2214

23-
add_lit_testsuites(ORC-RT ${CMAKE_CURRENT_SOURCE_DIR}
24-
DEPENDS ${ORC_RT_TEST_DEPS}
25-
)
15+
add_custom_target(orc-rt-test-depends DEPENDS ${ORC_RT_TEST_DEPS})
16+
set_target_properties(orc-rt-test-depends PROPERTIES FOLDER "orc-rt/tests")
17+
18+
add_lit_testsuite(check-orc-rt "Running the ORC-RT regression tests"
19+
${CMAKE_CURRENT_BINARY_DIR}
20+
DEPENDS ${ORC_RT_TEST_DEPS}
21+
)
22+
else()
23+
message(WARNING "ORC-RT testing tools missing (see cmake log for details). ORC-RT regression tests disabled.")
24+
endif()
2625

27-
# Add orc-rt unit tests
2826
configure_lit_site_cfg(
2927
${CMAKE_CURRENT_SOURCE_DIR}/unit/lit.site.cfg.py.in
30-
${CMAKE_CURRENT_BINARY_DIR}/unit/lit.site.cfg
28+
${CMAKE_CURRENT_BINARY_DIR}/unit/lit.site.cfg.py
3129
MAIN_CONFIG
32-
${CMAKE_CURRENT_SOURCE_DIR}/unit/lit.cfg.py)
30+
${CMAKE_CURRENT_SOURCE_DIR}/unit/lit.cfg.py
31+
)
32+
33+
# add_lit_testsuites(ORC-RT ${CMAKE_CURRENT_SOURCE_DIR}
34+
# DEPENDS ${ORC_RT_TEST_DEPS}
35+
# )
3336

34-
add_lit_testsuite(check-orcrt-unit "Running orc-rt unittest suites"
37+
add_lit_testsuite(check-orc-rt-unit "Running orc-rt unittest suites"
3538
${CMAKE_CURRENT_BINARY_DIR}/unit
3639
EXCLUDE_FROM_CHECK_ALL
3740
DEPENDS OrcRTUnitTests)

orc-rt/test/lit.cfg.py

Lines changed: 7 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,24 @@
11
# -*- Python -*-
22

33
import os
4-
import platform
5-
import re
6-
import subprocess
7-
import tempfile
84

95
import lit.formats
106
import lit.util
117

128
from lit.llvm import llvm_config
139
from lit.llvm.subst import ToolSubst
14-
from lit.llvm.subst import FindTool
1510

16-
17-
# name: The name of this test suite.
18-
config.name = "ORCRT"
19-
20-
# TODO: Consolidate the logic for turning on the internal shell by default for all LLVM test suites.
21-
# See https://github.com/llvm/llvm-project/issues/106636 for more details.
22-
#
23-
# We prefer the lit internal shell which provides a better user experience on failures
24-
# unless the user explicitly disables it with LIT_USE_INTERNAL_SHELL=0 env var.
25-
use_lit_shell = True
26-
lit_shell_env = os.environ.get("LIT_USE_INTERNAL_SHELL")
27-
if lit_shell_env:
28-
use_lit_shell = lit.util.pythonize_bool(lit_shell_env)
29-
30-
config.test_format = lit.formats.ShTest(execute_external=not use_lit_shell)
31-
32-
# suffixes: A list of file extensions to treat as test files.
11+
config.name = "ORC-RT"
12+
config.test_format = lit.formats.ShTest()
13+
config.test_source_root = os.path.dirname(__file__)
14+
config.test_exec_root = os.path.join(config.orc_rt_obj_root, "test")
3315
config.suffixes = [
34-
".ll",
35-
".test",
36-
".c",
16+
".test"
3717
]
38-
# test_source_root: The root path where tests are located.
39-
config.test_source_root = os.path.dirname(__file__)
4018

41-
# test_exec_root: The root path where tests should be run.
42-
config.test_exec_root = os.path.join(config.orcrt_obj_root, "test")
4319
llvm_config.with_environment(
4420
"PATH",
45-
os.path.join(config.orcrt_obj_root, "tools", "orc-executor"),
21+
os.path.join(config.orc_rt_obj_root, "tools", "orc-executor"),
4622
append_path=True)
47-
config.substitutions.append(("%PATH%", config.environment["PATH"]))
48-
# config.substitutions.append(("%shlibext", config.llvm_shlib_ext))
49-
config.substitutions.append(("%llvm_src_root", config.llvm_src_root))
50-
# config.substitutions.append(("%host_cxx", config.host_cxx))
51-
# config.substitutions.append(("%host_cc", config.host_cc))
52-
if config.llvm_rt_tools_dir:
53-
config.llvm_tools_dir = config.llvm_rt_tools_dir
54-
llvm_config.use_default_substitutions()
55-
5623

57-
# excludes: A list of directories to exclude from the testsuite. The 'Inputs'
58-
# subdirectories contain auxiliary inputs for various tests in their parent
59-
# directories.
60-
config.excludes = [
61-
"lit.cfg.py",
62-
"lit.site.cfg.py.in",
63-
]
24+
llvm_config.use_default_substitutions()

orc-rt/test/lit.site.cfg.py.in

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,13 @@ import sys
44

55
config.llvm_src_root = "@LLVM_SOURCE_DIR@"
66
config.llvm_obj_root = "@LLVM_BINARY_DIR@"
7-
config.orcrt_obj_root = "@ORCRT_BINARY_DIR@"
8-
config.llvm_rt_tools_dir = "@LLVM_RT_TOOLS_BINARY_DIR@"
9-
config.llvm_tools_dir = lit_config.substitute("@LLVM_TOOLS_DIR@")
10-
config.llvm_libs_dir = lit_config.substitute("@LLVM_LIBS_DIR@")
11-
config.llvm_shlib_dir = lit_config.substitute("@SHLIBDIR@")
12-
config.lit_tools_dir = "@LLVM_LIT_TOOLS_DIR@"
7+
config.orc_rt_obj_root = "@ORC_RT_BINARY_DIR@"
138
config.host_triple = "@LLVM_HOST_TRIPLE@"
149
config.target_triple = "@LLVM_TARGET_TRIPLE@"
15-
config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
16-
config.host_arch = "@HOST_ARCH@"
17-
config.python_executable = "@Python3_EXECUTABLE@"
18-
config.targets_to_build = "@ORCRT_TARGETS_TO_BUILD@"
10+
config.llvm_tools_dir = "@ORC_RT_LLVM_TOOLS_DIR@"
11+
1912

2013
import lit.llvm
2114
lit.llvm.initialize(lit_config, config)
2215
# Let the main config do the real work.
23-
lit_config.load_config(config, "@ORCRT_SOURCE_DIR@/test/lit.cfg.py")
16+
lit_config.load_config(config, "@ORC_RT_SOURCE_DIR@/test/lit.cfg.py")

orc-rt/test/unit/lit.cfg.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@
33
# Configuration file for the 'lit' test runner.
44

55
import os
6-
import subprocess
76

87
import lit.formats
8+
import lit.util
9+
10+
from lit.llvm import llvm_config
911

1012
# name: The name of this test suite.
11-
config.name = "ORCRT-Unit"
13+
config.name = "ORC-RT-Unit"
1214

1315
# suffixes: A list of file extensions to treat as test files.
1416
config.suffixes = []
1517

1618
# test_source_root: The root path where tests are located.
1719
# test_exec_root: The root path where tests should be run.
18-
config.test_exec_root = os.path.join(config.orcrt_obj_root, "unittests")
20+
config.test_exec_root = os.path.join(config.orc_rt_obj_root, "unittests")
1921
config.test_source_root = config.test_exec_root
2022

2123
# testFormat: The test format to use to interpret tests.
22-
config.test_format = lit.formats.GoogleTest(config.llvm_build_mode, "Tests")
24+
config.test_format = lit.formats.GoogleTest(config.llvm_build_mode, "Tests")

orc-rt/test/unit/lit.site.cfg.py.in

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
@LIT_SITE_CFG_IN_HEADER@
22

3+
import sys
4+
35
config.llvm_src_root = "@LLVM_SOURCE_DIR@"
46
config.llvm_obj_root = "@LLVM_BINARY_DIR@"
5-
config.llvm_tools_dir = lit_config.substitute("@LLVM_TOOLS_DIR@")
6-
config.llvm_libs_dir = lit_config.substitute("@LLVM_LIBS_DIR@")
7-
config.llvm_build_mode = lit_config.substitute("@LLVM_BUILD_MODE@")
8-
config.lit_tools_dir = "@LLVM_LIT_TOOLS_DIR@"
9-
config.llvm_obj_root = "@LLVM_BINARY_DIR@"
10-
config.orcrt_obj_root = "@ORCRT_BINARY_DIR@"
7+
config.orc_rt_obj_root = "@ORC_RT_BINARY_DIR@"
8+
config.host_triple = "@LLVM_HOST_TRIPLE@"
119
config.target_triple = "@LLVM_TARGET_TRIPLE@"
10+
config.llvm_tools_dir = "@ORC_RT_LLVM_TOOLS_DIR@"
11+
1212

1313
import lit.llvm
1414
lit.llvm.initialize(lit_config, config)
15-
1615
# Let the main config do the real work.
17-
lit_config.load_config(config, "@ORCRT_SOURCE_DIR@/test/unit/lit.cfg.py")
16+
lit_config.load_config(config, "@ORC_RT_SOURCE_DIR@/test/lit.cfg.py")

orc-rt/unittests/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
add_custom_target(OrcRTUnitTests)
2-
set_target_properties(OrcRTUnitTests PROPERTIES FOLDER "orcrt/Tests")
2+
set_target_properties(OrcRTUnitTests PROPERTIES FOLDER "orc-rt/Tests")
3+
4+
if (NOT TARGET llvm_gtest)
5+
message(WARNING "orc-rt unittests disabled due to GTest being unavailable; "
6+
"Try LLVM_INSTALL_GTEST=ON for the LLVM build")
7+
return ()
8+
endif ()
39

410
function(add_orc_rt_unittest test_dirname)
511
add_unittest(OrcRTUnitTests ${test_dirname} ${ARGN})

orc-rt/unittests/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33

44
TEST(TEST, emptyFuncs) {
5-
ASSERT_EQ(True, False);
5+
ASSERT_TRUE(true);
66
}

0 commit comments

Comments
 (0)