Cannot run LLVM unit tests doe to python error in lit

Hello, LLVM community.

I've built a cross-toolchain on Windows and I'm now trying to run unit tests for the LLVM libraries.

I used Ninja as a build system and MSVC as host compiler without an issue, but when I try to run 'ninja check-llvm-unit', I get the following error: C:/Users/sergej/Developer/llvm-project/llvm\utils\lit\lit\ fatal: unable to parse config file 'C:\\Users\\sergej\\Developer\\llvm-project\\llvm\\test\\Unit\\', traceback: Traceback (most recent call last):
  File "C:/Users/sergej/Developer/llvm-project/llvm\utils\lit\lit\", line 89, in load_from_path
    exec(compile(data, path, 'exec'), cfg_globals, None)
  File "C:\Users\sergej\Developer\llvm-project\llvm\test\Unit\", line 24, in <module>
    config.test_exec_root = os.path.join(config.llvm_obj_root, 'unittests')
AttributeError: 'TestingConfig' object has no attribute 'llvm_obj_root'
FAILED: test/CMakeFiles/check-llvm-unit

From what I can see, the TestingConfig class (which can be found in llvm/utils/lit/lit/ doesn't have this 'llvm_obj_root' indeed. Also I can't spot any Python magic here like __getattr__. How is this supposed to work?

Reproducible with both Python 2 and 3.

Maybe anyone has an idea? I’d really appreciate any help

llvm_obj_root is supposed to be assigned in

config.llvm_obj_root = "@LLVM_BINARY_DIR@"

(which will `configure_file`ed by cmake). I can run ninja
check-llvm-unit on my Windows machine without problems. Maybe look for in your build dir


Thank you for pointing a direction, Michael.

This allowed me to investigate the issue, which was not in lit, but rather in CMake configuration.

The issue was that when was executed, 'config_map', which maps lit config files from source directory to build directory, was empty, because the template for,, contains @LLVM_LIT_CONFIG_MAP@, which was being expanded to an empty string.

Why was it expanded to an empty string?

Well, as I’ve said, I’m building a cross-toolchain, which means that first I build llvm & clang, and then using the just-built compiler compiler-rt and friends are built. All of this in a single Ninja invocation. This is achieved by setting the -DLLVM_ENABLE_RUNTIMES="compiler-rt;libunwind;libcxxabi;libcxx" flag.

It turns out that everything is OK at configure time for LLVM & clang, @LLVM_LIT_CONFIG_MAP@ is expanded correctly. But then, during the ninja invocation, after the compiler is built, a new CMake command is run _at build time_ to configure and build compiler-rt (namely builtins & runtimes) using the just-built compiler. This new CMake invocation calls ‘configure_file’ again, this time replacing @LLVM_LIT_CONFIG_MAP@ with an empty string, erasing the previous expansion.

I’ll see if I can fix this, but currently I guess a workaround would be to first build LLVM & clang with -DLLVM_ENABLE_RUNTIMES="", run the relevant tests, and only then build the runtimes.

Thank you for sharing what the problems was.


[1] xkcd: Wisdom of the Ancients