Skip to content
This repository was archived by the owner on Jul 3, 2021. It is now read-only.

Commit 82465fc

Browse files
Add lit tests
1 parent 87cb540 commit 82465fc

File tree

5 files changed

+98
-1
lines changed

5 files changed

+98
-1
lines changed

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ if(LLVM_BUILD_MAIN_SRC_DIR AND EXISTS "${LLVM_BUILD_MAIN_SRC_DIR}" AND UNIX)
2525
)
2626
endif()
2727

28+
# Import extra CMake helpers from LLVM
29+
list(APPEND CMAKE_MODULE_PATH ${LLVM_DIR})
30+
include(AddLLVM)
31+
2832
if(NOT CMAKE_BUILD_TYPE)
2933
message(STATUS "No explicit CMAKE_BUILD_TYPE provided; JitFromScratch defaults to the build type of LLVM")
3034
set(CMAKE_BUILD_TYPE ${LLVM_BUILD_TYPE} CACHE STRING "" FORCE)
@@ -74,4 +78,4 @@ add_custom_target(run
7478
COMMENT "Running JitFromScratch"
7579
)
7680

77-
message("")
81+
add_subdirectory(test)

test/CMakeLists.txt

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Used in add_lit_target to find the llvm-lit driver
2+
set(LLVM_RUNTIME_OUTPUT_INTDIR ${LLVM_TOOLS_BINARY_DIR})
3+
4+
# Show test output for failures
5+
list(APPEND LLVM_LIT_ARGS -v)
6+
7+
# lit driver and config files are Python scripts
8+
set(Python_ADDITIONAL_VERSIONS 3.7 3.6 3.5 2.7)
9+
include(FindPythonInterp)
10+
11+
if(NOT PYTHONINTERP_FOUND OR ${PYTHON_VERSION_STRING} VERSION_LESS 2.7)
12+
string(CONCAT error
13+
"Python 2.7 or newer is required for tests. Please install "
14+
"Python or specify the PYTHON_EXECUTABLE CMake variable. "
15+
)
16+
endif()
17+
18+
if(NOT TARGET FileCheck)
19+
if(LLVM_BUILD_MAIN_SRC_DIR)
20+
string(CONCAT error ${error}
21+
"FileCheck is required for tests. Make sure the "
22+
"${LLVM_TOOLS_BINARY_DIR}/FileCheck executable was built. "
23+
"Make sure LLVM has LLVM_BUILD_UTILS=ON (default). "
24+
)
25+
else()
26+
string(CONCAT error ${error}
27+
"The installed LLVM does not provide the FileCheck executable. This is "
28+
"the default for distribution packages (the distributor can change that "
29+
"by passing LLVM_INSTALL_UTILS=ON). Without FileCheck lit tests "
30+
"cannot run. Build LLVM yourself from source and point JitFromScratch to "
31+
"the build-tree to enable tests. "
32+
)
33+
endif()
34+
endif()
35+
36+
if(error)
37+
message(WARNING "Failed to configure tests: ${error}")
38+
add_custom_target(check
39+
COMMAND ${CMAKE_COMMAND} -E echo
40+
COMMENT "Cannot run tests"
41+
)
42+
# We still want to build the executable.
43+
add_dependencies(check JitFromScratch)
44+
else()
45+
set(LLVM_DEFAULT_EXTERNAL_LIT ${LLVM_TOOLS_BINARY_DIR}/llvm-lit
46+
CACHE PATH "Path to llvm-lit")
47+
48+
configure_lit_site_cfg(
49+
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
50+
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py
51+
MAIN_CONFIG
52+
${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py
53+
)
54+
55+
add_lit_target(check "Running tests"
56+
${CMAKE_CURRENT_BINARY_DIR}
57+
DEPENDS JitFromScratch FileCheck
58+
)
59+
endif()
60+
61+
message("")

test/lit.cfg.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import os
2+
3+
import lit.util
4+
import lit.formats
5+
from lit.llvm import llvm_config
6+
7+
config.name = 'JitFromScratch'
8+
9+
config.test_format = lit.formats.ShTest()
10+
config.test_source_root = os.path.dirname(__file__)
11+
config.suffixes = ['.test']
12+
13+
# Add binary directories for JitFromScratch and FileCheck executables
14+
llvm_config.with_environment('PATH', config.jitfromscratch_build_dir, append_path=True)
15+
llvm_config.with_environment('PATH', config.llvm_tools_dir, append_path=True)

test/lit.site.cfg.py.in

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@LIT_SITE_CFG_IN_HEADER@
2+
3+
import sys
4+
5+
config.llvm_tools_dir = "@LLVM_TOOLS_DIR@"
6+
config.lit_tools_dir = "@LLVM_LIT_TOOLS_DIR@"
7+
config.python_executable = "@PYTHON_EXECUTABLE@"
8+
config.jitfromscratch_build_dir = "@CMAKE_BINARY_DIR@/@CMAKE_CFG_INTDIR@"
9+
10+
import lit.llvm
11+
lit.llvm.initialize(lit_config, config)
12+
13+
# Let the main config do the real work.
14+
lit_config.load_config(config, "@CMAKE_SOURCE_DIR@/test/lit.cfg.py")

test/stdout.test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Check that integer distances are printed as expected
2+
# RUN: JitFromScratch | FileCheck %s
3+
# CHECK: Integer Distances: 3, 0, 3

0 commit comments

Comments
 (0)