xref: /llvm-project/compiler-rt/test/orc/lit.cfg.py (revision f2d18a4d00c5f5dea436b4f7b62ec5c87b98eac2)
15e537ea1SLang Hames# -*- Python -*-
25e537ea1SLang Hames
35e537ea1SLang Hamesimport os
42e25926bSAlexander Richardsonimport subprocess
55e537ea1SLang Hames
65e537ea1SLang Hames# Setup config name.
7f98ee40fSTobias Hietaconfig.name = "ORC" + config.name_suffix
85e537ea1SLang Hames
95e537ea1SLang Hames# Setup source root.
105e537ea1SLang Hamesconfig.test_source_root = os.path.dirname(__file__)
115e537ea1SLang Hames
121169586dSLang Hames# Determine whether the test target is compatible with execution on the host.
131169586dSLang Hameshost_arch_compatible = config.target_arch == config.host_arch
141169586dSLang Hames
151169586dSLang Hamesif config.host_arch == "x86_64h" and config.target_arch == "x86_64":
161169586dSLang Hames    host_arch_compatible = True
177937fe1aSLang Hamesif host_arch_compatible:
187937fe1aSLang Hames    config.available_features.add("host-arch-compatible")
19*f2d18a4dSLang Hames
20*f2d18a4dSLang Hames# If the target OS hasn't been set then assume host.
21*f2d18a4dSLang Hamesif not config.target_os:
22*f2d18a4dSLang Hames    config.target_os = config.host_os
23*f2d18a4dSLang Hames
24f98ee40fSTobias Hietaconfig.test_target_is_host_executable = (
25f98ee40fSTobias Hieta    config.target_os == config.host_os and host_arch_compatible
26f98ee40fSTobias Hieta)
275e537ea1SLang Hames
285e537ea1SLang Hames# Assume that llvm-jitlink is in the config.llvm_tools_dir.
29f98ee40fSTobias Hietallvm_jitlink = os.path.join(config.llvm_tools_dir, "llvm-jitlink")
30f98ee40fSTobias Hietaorc_rt_executor_stem = os.path.join(
31f98ee40fSTobias Hieta    config.compiler_rt_obj_root, "lib/orc/tests/tools/orc-rt-executor"
32f98ee40fSTobias Hieta)
33f98ee40fSTobias Hietalli = os.path.join(config.llvm_tools_dir, "lli")
34f98ee40fSTobias Hietaif config.host_os == "Darwin":
35f98ee40fSTobias Hieta    orc_rt_path = "%s/liborc_rt_osx.a" % config.compiler_rt_libdir
36b749ef9eSLang Hameselse:
37f98ee40fSTobias Hieta    orc_rt_path = "%s/liborc_rt%s.a" % (config.compiler_rt_libdir, config.target_suffix)
385e537ea1SLang Hames
39981523b2SPeter S. Houselif config.libunwind_shared:
40f98ee40fSTobias Hieta    config.available_features.add("libunwind-available")
41f98ee40fSTobias Hieta    shared_libunwind_path = os.path.join(config.libunwind_install_dir, "libunwind.so")
42981523b2SPeter S. Housel    config.substitutions.append(("%shared_libunwind", shared_libunwind_path))
43981523b2SPeter S. Housel
441169586dSLang Hames
45f98ee40fSTobias Hietadef build_invocation(compile_flags):
46f98ee40fSTobias Hieta    return " " + " ".join([config.clang] + compile_flags) + " "
47f98ee40fSTobias Hieta
48f98ee40fSTobias Hieta
49f98ee40fSTobias Hietaconfig.substitutions.append(("%clang ", build_invocation([config.target_cflags])))
505e537ea1SLang Hamesconfig.substitutions.append(
51f98ee40fSTobias Hieta    ("%clangxx ", build_invocation(config.cxx_mode_flags + [config.target_cflags]))
52f98ee40fSTobias Hieta)
535e537ea1SLang Hamesconfig.substitutions.append(
54f98ee40fSTobias Hieta    ("%clang_cl ", build_invocation(["--driver-mode=cl"] + [config.target_cflags]))
55f98ee40fSTobias Hieta)
56f98ee40fSTobias Hietaif config.host_os == "Windows":
5773c40339Ssunho    config.substitutions.append(
58f98ee40fSTobias Hieta        (
59f98ee40fSTobias Hieta            "%llvm_jitlink",
60f98ee40fSTobias Hieta            (
61f98ee40fSTobias Hieta                llvm_jitlink
62f98ee40fSTobias Hieta                + " -orc-runtime="
63f98ee40fSTobias Hieta                + orc_rt_path
64f98ee40fSTobias Hieta                + " -no-process-syms=true -slab-allocate=64MB"
65f98ee40fSTobias Hieta            ),
66f98ee40fSTobias Hieta        )
67f98ee40fSTobias Hieta    )
689189a266SSunho Kimelse:
695e537ea1SLang Hames    config.substitutions.append(
70f98ee40fSTobias Hieta        ("%llvm_jitlink", (llvm_jitlink + " -orc-runtime=" + orc_rt_path))
71f98ee40fSTobias Hieta    )
721aa71f86SPeter S. Houselconfig.substitutions.append(
73f98ee40fSTobias Hieta    ("%orc_rt_executor", orc_rt_executor_stem + "-" + config.host_arch)
74f98ee40fSTobias Hieta)
751169586dSLang Hamesconfig.substitutions.append(
76f98ee40fSTobias Hieta    (
77f98ee40fSTobias Hieta        "%lli_orc_jitlink",
78f98ee40fSTobias Hieta        (lli + " -jit-kind=orc -jit-linker=jitlink -orc-runtime=" + orc_rt_path),
79f98ee40fSTobias Hieta    )
80f98ee40fSTobias Hieta)
817937fe1aSLang Hamesconfig.substitutions.append(("%ar", "ar"))
825e537ea1SLang Hames
835e537ea1SLang Hames# Default test suffixes.
847937fe1aSLang Hamesconfig.suffixes = [".c", ".cpp", ".m", ".S", ".ll", ".test"]
855e537ea1SLang Hames
86f9aef477SLang Hames# Exclude Inputs directories.
87f98ee40fSTobias Hietaconfig.excludes = ["Inputs"]
88f9aef477SLang Hames
89f98ee40fSTobias Hietaif config.host_os not in ["Darwin", "FreeBSD", "Linux", "Windows"]:
905e537ea1SLang Hames    config.unsupported = True
912e25926bSAlexander Richardson
922e25926bSAlexander Richardson# Ask llvm-config about assertion mode.
932e25926bSAlexander Richardsontry:
942e25926bSAlexander Richardson    llvm_config_result = subprocess.check_output(
952e25926bSAlexander Richardson        [os.path.join(config.llvm_tools_dir, "llvm-config"), "--assertion-mode"],
962e25926bSAlexander Richardson        env=config.environment,
972e25926bSAlexander Richardson    )
982e25926bSAlexander Richardson    if llvm_config_result.startswith(b"ON"):
992e25926bSAlexander Richardson        config.available_features.add("asserts")
1002e25926bSAlexander Richardsonexcept OSError as e:
1012e25926bSAlexander Richardson    lit_config.warning(f"Could not determine if LLVM was built with assertions: {e}")
102