From a52a4737f1dfc61a8464b5e74b008a750f5c975e Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Fri, 8 May 2020 12:31:06 +0200 Subject: [PATCH] Add support for using lit tests. --- .gitignore | 1 + .travis.yml | 7 +++++++ Project.toml | 5 ----- test/Project.toml | 6 ++++++ test/codegen/native.jl | 7 +++++++ test/lit.cfg.py | 39 +++++++++++++++++++++++++++++++++++ test/runtests.jl | 46 ++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 106 insertions(+), 5 deletions(-) create mode 100644 .gitignore create mode 100644 test/Project.toml create mode 100644 test/codegen/native.jl create mode 100644 test/lit.cfg.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..b9a48250 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +test/**/Output diff --git a/.travis.yml b/.travis.yml index 19d7b012..fd927905 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,10 @@ jobs: - os: osx julia: nightly +cache: + directories: + - /home/travis/.julia/ + notifications: email: false @@ -23,3 +27,6 @@ codecov: true branches: only: - master + +before_install: + - if [ "$TRAVIS_OS_NAME" = "windows" ]; then choco install python3 --params "PrependPath=1"; fi diff --git a/Project.toml b/Project.toml index 6b5e9aa9..97254a01 100644 --- a/Project.toml +++ b/Project.toml @@ -17,8 +17,3 @@ DataStructures = "0.15, 0.16, 0.17" LLVM = "1.4.0" TimerOutputs = "0.5" julia = "1.3" -[extras] -Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" - -[targets] -test = ["Test"] diff --git a/test/Project.toml b/test/Project.toml new file mode 100644 index 00000000..9d424d3a --- /dev/null +++ b/test/Project.toml @@ -0,0 +1,6 @@ +[deps] +InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" +LLVM = "929cbde3-209d-540e-8aea-75f648917ca0" +LLVM_jll = "86de99a1-58d6-5da7-8064-bd56ce2e322c" +Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/test/codegen/native.jl b/test/codegen/native.jl new file mode 100644 index 00000000..1379dc33 --- /dev/null +++ b/test/codegen/native.jl @@ -0,0 +1,7 @@ +# RUN: julia --startup-file=no -L ../definitions/native.jl %s | FileCheck %s + +valid_kernel() = return + +# CHECK-LABEL: define{{.*}} void @julia_valid_kernel +native_code_llvm(valid_kernel, Tuple{}; optimize=false, dump_module=true) + diff --git a/test/lit.cfg.py b/test/lit.cfg.py new file mode 100644 index 00000000..9a2f65d0 --- /dev/null +++ b/test/lit.cfg.py @@ -0,0 +1,39 @@ +import os +import sys +import re +import platform + +import lit.util +import lit.formats + +import lit.llvm + +config.llvm_tools_dir = os.environ.get('LLVM_TOOLS_DIR') +config.lit_tools_dir = '' # Intentionally empty +lit.llvm.initialize(lit_config, config) + +from lit.llvm import llvm_config + +config.name = 'GPUCompiler' +config.suffixes = ['.ll', '.jl'] +config.test_source_root = os.path.dirname(__file__) +execute_external = platform.system() != 'Windows' +config.test_format = lit.formats.ShTest(execute_external) +config.substitutions.append(('%shlibext', '.dylib' if platform.system() == 'Darwin' else '.dll' if + platform.system() == 'Windows' else '.so')) + +# Lit uses an empty environment so we copy over the settings from +# Pkg.test(), most importantly that's the `JULIA_LOAD_PATH`. +config.environment['JULIA_PROJECT'] = os.environ.get('JULIA_PROJECT') + +LOAD_PATH = os.environ.get('JULIA_LOAD_PATH') +DEPOT_PATH = os.environ.get('JULIA_DEPOT_PATH') + +if LOAD_PATH: + config.environment['JULIA_LOAD_PATH'] = LOAD_PATH + +if DEPOT_PATH: + config.environment['JULIA_DEPOT_PATH'] = DEPOT_PATH + +llvm_config.use_default_substitutions() + diff --git a/test/runtests.jl b/test/runtests.jl index 4c407c63..1fb84e7c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -22,3 +22,49 @@ end haskey(ENV, "CI") && GPUCompiler.timings() end + +using LLVM_jll +function lit(f; adjust_PATH=true, adjust_LIBPATH=true) + PATH_SEP = Sys.iswindows() ? ';' : ':' + env_mapping = Dict{String,String}() + PATH = string(LLVM_jll.PATH, PATH_SEP, Base.Sys.BINDIR) # To get the right julia + if adjust_PATH + if !isempty(get(ENV, "PATH", "")) + env_mapping["PATH"] = string(PATH, PATH_SEP, ENV["PATH"]) + else + env_mapping["PATH"] = PATH + end + end + LIBPATH=LLVM_jll.LIBPATH + LIBPATH_env=LLVM_jll.LIBPATH_env + if adjust_LIBPATH + if !isempty(get(ENV, LIBPATH_env, "")) + env_mapping[LIBPATH_env] = string(LIBPATH, PATH_SEP, ENV[LIBPATH_env]) + else + env_mapping[LIBPATH_env] = LIBPATH + end + end + if Sys.iswindows() + PYTHONPATH = joinpath(LLVM_jll.artifact_dir, "tools", "lit") + if haskey(ENV, "PYTHONPATH") + env_mapping["PYTHONPATH"] = string(PYTHONPATH, PATH_SEP, ENV["PYTHONPATH"]) + else + env_mapping["PYTHONPATH"] = PYTHONPATH + end + end + # set JULIA_PROJECT to the `test/Project.toml` + env_mapping["JULIA_PROJECT"] = Base.current_project() + env_mapping["LLVM_TOOLS_DIR"] = joinpath(LLVM_jll.artifact_dir, "tools") + lit_path = joinpath(LLVM_jll.artifact_dir, "tools", "lit", "lit.py") + withenv(env_mapping...) do + f(lit_path) + end +end + +lit() do lit_path + if Sys.iswindows() + run(`python $lit_path -va codegen`) + else + run(`$lit_path -va codegen`) + end +end