Skip to content

Commit ea1955d

Browse files
committed
Adding ways to find utils during a RT build
1 parent 91e73b1 commit ea1955d

File tree

10 files changed

+235
-3
lines changed

10 files changed

+235
-3
lines changed

orc-rt/CMakeLists.txt

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,17 @@
66

77
cmake_minimum_required(VERSION 3.20.0)
88

9+
option(LLVM_RT_INCLUDE_TESTS "Build orcrt tests." ${LLVM_INCLUDE_TESTS})
10+
11+
912
set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)
1013
include(${LLVM_COMMON_CMAKE_UTILS}/Modules/CMakePolicy.cmake
1114
NO_POLICY_SCOPE)
1215

16+
if (ORC_RT_INCLUDE_TESTS)
17+
set(LLVM_INCLUDE_UTILS YES)
18+
endif()
19+
1320
project(OrcRT LANGUAGES C CXX ASM)
1421

1522
include(GNUInstallDirs)
@@ -33,9 +40,57 @@ set(CMAKE_FOLDER "orc-rt")
3340
#===============================================================================
3441

3542
if (ORC_RT_INCLUDE_DOCS)
36-
add_subdirectory(docs)
43+
add_subdirectory(docs)
3744
endif()
3845

3946
add_subdirectory(include)
4047
add_subdirectory(lib)
4148
add_subdirectory(tools)
49+
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+
88+
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()

orc-rt/test/CMakeLists.txt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
)
7+
8+
list(APPEND ORC_RT_TEST_DEPS
9+
FileCheck
10+
count
11+
not
12+
orc-executor
13+
)
14+
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}
21+
)
22+
23+
add_lit_testsuites(ORC-RT ${CMAKE_CURRENT_SOURCE_DIR}
24+
DEPENDS ${ORC_RT_TEST_DEPS}
25+
)
26+
27+
# Add orc-rt unit tests
28+
configure_lit_site_cfg(
29+
${CMAKE_CURRENT_SOURCE_DIR}/unit/lit.site.cfg.py.in
30+
${CMAKE_CURRENT_BINARY_DIR}/unit/lit.site.cfg
31+
MAIN_CONFIG
32+
${CMAKE_CURRENT_SOURCE_DIR}/unit/lit.cfg.py)
33+
34+
add_lit_testsuite(check-orcrt-unit "Running orc-rt unittest suites"
35+
${CMAKE_CURRENT_BINARY_DIR}/unit
36+
EXCLUDE_FROM_CHECK_ALL
37+
DEPENDS OrcRTUnitTests)
38+

orc-rt/test/init.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
RUN: orc-executor %s %s

orc-rt/test/lit.cfg.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# -*- Python -*-
2+
3+
import os
4+
import platform
5+
import re
6+
import subprocess
7+
import tempfile
8+
9+
import lit.formats
10+
import lit.util
11+
12+
from lit.llvm import llvm_config
13+
from lit.llvm.subst import ToolSubst
14+
from lit.llvm.subst import FindTool
15+
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.
33+
config.suffixes = [
34+
".ll",
35+
".test",
36+
".c",
37+
]
38+
# test_source_root: The root path where tests are located.
39+
config.test_source_root = os.path.dirname(__file__)
40+
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")
43+
llvm_config.with_environment("PATH", os.path.join(config.orcrt_obj_root, "tools", "orc-executor"), append_path=True)
44+
config.substitutions.append(("%PATH%", config.environment["PATH"]))
45+
#config.substitutions.append(("%shlibext", config.llvm_shlib_ext))
46+
config.substitutions.append(("%llvm_src_root", config.llvm_src_root))
47+
#config.substitutions.append(("%host_cxx", config.host_cxx))
48+
#config.substitutions.append(("%host_cc", config.host_cc))
49+
if (config.llvm_rt_tools_dir):
50+
config.llvm_tools_dir = config.llvm_rt_tools_dir
51+
llvm_config.use_default_substitutions()
52+
53+
54+
# excludes: A list of directories to exclude from the testsuite. The 'Inputs'
55+
# subdirectories contain auxiliary inputs for various tests in their parent
56+
# directories.
57+
config.excludes = [
58+
"lit.cfg.py",
59+
"lit.site.cfg.py.in",
60+
]

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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.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@"
13+
config.host_triple = "@LLVM_HOST_TRIPLE@"
14+
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@"
19+
20+
import lit.llvm
21+
lit.llvm.initialize(lit_config, config)
22+
# Let the main config do the real work.
23+
lit_config.load_config(config, "@ORCRT_SOURCE_DIR@/test/lit.cfg.py")

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# -*- Python -*-
2+
3+
# Configuration file for the 'lit' test runner.
4+
5+
import os
6+
import subprocess
7+
8+
import lit.formats
9+
10+
# name: The name of this test suite.
11+
config.name = "ORCRT-Unit"
12+
13+
# suffixes: A list of file extensions to treat as test files.
14+
config.suffixes = []
15+
16+
# test_source_root: The root path where tests are located.
17+
# test_exec_root: The root path where tests should be run.
18+
config.test_exec_root = os.path.join(config.orcrt_obj_root, "unittests")
19+
config.test_source_root = config.test_exec_root
20+
21+
# testFormat: The test format to use to interpret tests.
22+
config.test_format = lit.formats.GoogleTest(config.llvm_build_mode, "Tests")

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@LIT_SITE_CFG_IN_HEADER@
2+
3+
config.llvm_src_root = "@LLVM_SOURCE_DIR@"
4+
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@"
11+
config.target_triple = "@LLVM_TARGET_TRIPLE@"
12+
13+
import lit.llvm
14+
lit.llvm.initialize(lit_config, config)
15+
16+
# Let the main config do the real work.
17+
lit_config.load_config(config, "@ORCRT_SOURCE_DIR@/test/unit/lit.cfg.py")

orc-rt/unittests/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
add_custom_target(OrcRTUnitTests)
2+
set_target_properties(OrcRTUnitTests PROPERTIES FOLDER "orcrt/Tests")
3+
4+
function(add_orc_rt_unittest test_dirname)
5+
add_unittest(OrcRTUnitTests ${test_dirname} ${ARGN})
6+
endfunction()
7+
8+
add_orc_rt_unittest(CoreTests
9+
init.cpp
10+
DISABLE_LLVM_LINK_LLVM_DYLIB
11+
)

orc-rt/unittests/init.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "gtest/gtest.h"
2+
3+
4+
TEST(TEST, emptyFuncs) {
5+
ASSERT_EQ(True, False);
6+
}

runtimes/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ if(LLVM_ENABLE_RUNTIMES STREQUAL "all" )
3232
endif()
3333
include(SortSubset)
3434
sort_subset("${LLVM_SUPPORTED_RUNTIMES}" "${LLVM_ENABLE_RUNTIMES}" LLVM_ENABLE_RUNTIMES)
35-
35+
set(LLVM_RT_TOOLS_BINARY_DIR ${LLVM_TOOLS_BINARY_DIR} CACHE STRING "runtime path to required test tools")
3636
foreach(proj ${LLVM_ENABLE_RUNTIMES})
3737
set(proj_dir "${CMAKE_CURRENT_SOURCE_DIR}/../${proj}")
3838
if(IS_DIRECTORY ${proj_dir} AND EXISTS ${proj_dir}/CMakeLists.txt)
@@ -237,7 +237,6 @@ foreach(entry ${runtimes})
237237
# will be included under here.
238238
set(HAVE_${canon_name} ON)
239239
endforeach()
240-
241240
if(LLVM_INCLUDE_TESTS)
242241
set(LIT_ARGS_DEFAULT "-sv --show-xfail --show-unsupported")
243242
if (MSVC OR XCODE)

0 commit comments

Comments
 (0)