End-to-end tests of the ORC runtime. Run them with ninja check-orc-rt. For tests of individual APIs, write unit tests under test/unit instead.
Place a test by the question it asks, not by the kind of input file it uses:
jit-free-foundations/: Tests that don‘t compile, link, or run any JIT’d code, e.g. tests of ogre's command line, process info, logging, and connection lifecycle.languages/<language>/ (e.g. languages/c/): Tests that a source-language construct behaves correctly when JIT'd.object-formats/<format>/<arch>/ (e.g. object-formats/mach-o/arm64/): Tests that a specific object format feature (e.g. a relocation, section, or directive) is handled correctly. These are written in assembly.orc-rt-c/<header path> (e.g. orc-rt-c/bedrock/host/posix/): Tests that JIT'd code can use a C API that the runtime provides. Each test lives at the path of the header that declares the API under test, and is named after it (e.g. dlfcn-host.c tests orc-rt-c/bedrock/host/posix/dlfcn-host.h).The jit-free-foundations/ rule is enforced: the %{cc}, %{cxx}, %{mc}, and %{obj-jit} substitutions are unavailable there.
A typical test:
// Check that JIT'd code can load from static data defined in the same object. // // Stresses: fixups for code addressing data in the same object. // // RUN: %{cc} -O0 -c -o %t.O0.o %s // RUN: %{obj-jit} -show-jit-result %t.O0.o | FileCheck %s // RUN: %{cc} -O2 -c -o %t.O2.o %s // RUN: %{obj-jit} -show-jit-result %t.O2.o | FileCheck %s // CHECK: JIT result: 0 static int Data = 42; int main(void) { // Volatile load, to prevent constant propagation of the initializer. if (*(volatile int *)&Data != 42) return 1; return 0; }
Conventions:
JIT result: 2).orc-rt-c/ are the exception: they include the header that declares the API under test (using %{orc-rt-cflags}), along with any system headers it includes.For tests compiled from source:
-O0 and -O2, with RUN lines for each. Most JIT'd code is optimized, and optimization changes how constructs are lowered. If a construct can only be tested at one level, say which, and why.volatile or noinline, which may hide the optimized lowering we want to test. When a test needs a barrier, apply the weakest one to the construct under test only, and name the optimization it suppresses (e.g. // Volatile load, to prevent store-to-load forwarding.).%{cc} and %{cxx} may be user-supplied (see below). Say what a compiler may do, not what it will do, and use generic optimization names rather than those of a particular compiler's passes.Tests that need more than one source file (e.g. to link several objects) are .test files that hold their sources, split out with split-file:
# Check that JIT'd code can load from global data defined in another object.
#
# Stresses: fixups for code addressing data defined in another object, which
# the compiler usually addresses through the GOT.
RUN: rm -rf %t && split-file %s %t
RUN: %{cc} -O0 -c -o %t/def.O0.o %t/def.c
RUN: %{cc} -O0 -c -o %t/main.O0.o %t/main.c
RUN: %{obj-jit} -show-jit-result %t/main.O0.o %t/def.O0.o | FileCheck %s
RUN: %{cc} -O2 -c -o %t/def.O2.o %t/def.c
RUN: %{cc} -O2 -c -o %t/main.O2.o %t/main.c
RUN: %{obj-jit} -show-jit-result %t/main.O2.o %t/def.O2.o | FileCheck %s
CHECK: JIT result: 0
#--- def.c
int Data = 42;
#--- main.c
extern int Data;
int main(void) {
if (Data != 42)
return 1;
return 0;
}
%{cc}: Compiles C for the runtime's target.%{cxx}: Compiles C++ for the runtime's target.%{mc}: Assembles its input into an object file for the runtime‘s target, using llvm-mc. Unlike %{cc} and %{cxx}, this can’t be overridden, so object format tests always check the runtime against the same assembler.%{obj-jit}: Links and runs its inputs under ogre, using llvm-jitlink as the controller. Pass -show-jit-result to print JIT result: <value>.%{ogre}: Path to the ogre executable.%{orc-rt-cflags}: Header search paths for the runtime‘s headers, for tests that compile JIT’d code against the APIs the runtime provides.%{test-dylib}: Path to a minimal shared library (test/Inputs/orc-rt-test-dylib.c), for tests that load, search, and close a host library. Its functions return distinct values, so that a test can check that a lookup found the right one.Don‘t spell out a target triple or connection method in a test unless that’s what the test is about: the substitutions provide these, so that the same tests can be run with different compilers and targets. Flags that select a feature under test (e.g. -mattr=, -mcmodel=, -fPIC) are fine, but gate the test on the target architecture and CPU features they require.
%{cc} and %{cxx} accept clang-style options, and tests must restrict themselves to this subset: -c, -o, -I, -D, -O<n>, -g, -std=, -x, -fexceptions, and -fno-exceptions. If a test needs another option, add it to this list, so that anyone writing a wrapper for another compiler knows which options to support.
Directories and tests gate on lit features describing the build, rather than the host:
orc-rt-cc: %{cc} is usable.orc-rt-cxx: %{cxx} is usable.llvm-mc: %{mc} is usable.llvm-jitlink: %{obj-jit} is usable.target-arch=<arch>: The runtime's target architecture (arm64 and aarch64 are aliases).target-object-format=<coff|elf|mach-o>: The runtime's target object format.target-posix: The runtime was built with its shared POSIX host implementation, and provides the POSIX-only APIs.orc-rt-log-backend-<backend>, orc-rt-log-level-<level>: The runtime was built with the given logging backend / level.languages/c/ requires orc-rt-cc and llvm-jitlink, so tests there don't need to repeat those requirements. Likewise, object-formats/ requires llvm-mc and llvm-jitlink, and each <format>/<arch>/ subdirectory requires the matching target-object-format= and target-arch= features. orc-rt-c/ requires orc-rt-cc and llvm-jitlink, and subdirectories for system-specific APIs require the matching feature (e.g. target-posix for posix/).
By default %{cc} and %{cxx} are the clang and clang++ in the LLVM tools directory, i.e. bin/ in the LLVM build given by -DLLVM_BINARY_DIR (or -DORC_RT_LLVM_TOOLS_DIR). If no clang is found, the C tests are reported as unsupported.
To test the runtime against another compiler's output, pass:
llvm-lit --param orc-rt-cc=<cc> --param orc-rt-cxx=<cxx> \ <path-to-build>/orc-rt/test/regression
The compiler must accept the clang-style options above and must target the runtime‘s target without being told to. Write a wrapper script if your compiler needs different options. Treat results from other compilers as reports rather than expectations: don’t add XFAILs for them in-tree.
To print each test's result instead of a progress bar:
LIT_OPTS="--no-progress-bar --print-result-after=all" ninja check-orc-rt