Running llvm-lit on external project test file derived from standalone fails

Is it possible to use llvm-lit to test a single file from an external project (created from examples/standalone)?

For instance, this is possible:

/working_dir/builds/llvm-project/build/bin/llvm-lit /working_dir/llvm-project/mlir/test/Dialect/Linalg/tile-conv.mlir 
-- Testing: 1 tests, 1 workers --
PASS: MLIR :: Dialect/Linalg/tile-conv.mlir (1 of 1)

Testing Time: 0.03s
  Passed: 1

But calling it on an external file returns the following error in this line:

/working_dir/builds/llvm-project/build/bin/llvm-lit /working_dir/standalone/test/Conversion/TensorToLLVM/tensor-to-llvm.mlir
llvm-lit: /working_dir/llvm-project/llvm/utils/lit/lit/TestingConfig.py:140: fatal: unable to parse config file '/working_dir/standalone/test/lit.cfg.py', traceback: Traceback (most recent call last):
  File "/working_dir/llvm-project/llvm/utils/lit/lit/TestingConfig.py", line 129, in load_from_path
    exec(compile(data, path, 'exec'), cfg_globals, None)
  File "/working_dir/standalone/test/lit.cfg.py", line 21, in <module>
    config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
AttributeError: 'NoneType' object has no attribute 'use_lit_shell'

Note ninja check-standalone also works without problems.

Thank you in advance.

This was written some years ago, primarily for cmake-based projects but I hope it’s still helpful.

:headstone: Apologies for necropost. Ran into this same problem and came across this thread from my search engine. Figured I should leave a better answer for those who follow my same path.

The problem is due to test/lit.site.cfg.py.in which initializes LLVM’s config in lit with lit.llvm.initialize(lit_config, config) is not executed, as this is a template file which is built. lit picks up just lit.cfg.py and will miss the settings from the template.

To fix, use a path to your build directory. For a monolithic build, this would be lit build/tools/standalone-dialect/test, while in a component build, this is lit build/test. This works since the templated file will be rendered to the build directory.

3 Likes