LLVM Integrated Tester (lit)
lit (LLVM Integrated Tester) is a portable command-line tool for executing LLVM and Clang style test suites, summarizing their results, and providing indication of failures. It is designed to be lightweight and flexible, supporting parallel test execution and various test formats. The current version is 18.1.8 and is actively maintained as part of the LLVM project.
Warnings
- gotcha lit is primarily a command-line testing tool. While written in Python, its main usage involves running the `lit` executable and configuring test suites via `lit.cfg.py` or `lit.site.cfg.py` files, rather than through direct Python API imports for general application logic. The Python files define test execution logic, not library functions to be called.
- gotcha The `lit` command expects a `lit.cfg.py` or `lit.site.cfg.py` file to be present in the root of each test suite or discovered by searching upwards from the input path. Without these configuration files, `lit` cannot properly discover or execute tests.
- gotcha The `lit` tool, especially for certain test formats, often relies on external LLVM utilities like `FileCheck` and `not`. If these are not available in the system's PATH, or explicitly configured in `lit.cfg.py`, tests that use them will fail.
Install
-
pip install lit
Imports
- lit_config
This is a global object implicitly available within lit.cfg.py / lit.site.cfg.py files.
- config
This is a global object implicitly available within lit.cfg.py / lit.site.cfg.py files.
Quickstart
# 1. Create a test directory and a lit configuration file:
# my_project/
# ├── lit.cfg.py
# └── tests/
# └── my_test.txt
# --- lit.cfg.py ---
# This file is executed by lit to configure the test suite.
# Define standard test formats.
import lit.formats
config.name = 'MyProject'
config.test_format = lit.formats.ShTest(not_tool='/usr/bin/not')
config.suffixes = ['.txt']
# Add an optional path to tools if they are not in PATH
# config.substitutions = [('%my_tool', '/path/to/my_tool')]
# --- tests/my_test.txt ---
# RUN: echo "Hello, lit!" | FileCheck %s
# CHECK: Hello, lit!
# --- Run lit from the project root ---
# In your terminal:
# cd my_project
# lit tests/