Running LIT based testcases outside of llvm source

Hello,

So far, I have been copying .ll lit bases test cases in some
/llvm-project/llvm/test/<directory>
and then running them with
/build-dir/bin/llvm-lit.

Now, I need to run these test cases without adding them to llvm source, using
/build-dir/bin/llvm-lit
or
/install-dir/bin/llvm-lit
So to create similar test suite environment outside of source, I followed:
<https://medium.com/@mshockwave/using-llvm-lit-out-of-tree-5cddada85a78>
with some relevant changes but I am stumbling on error:
AttributeError: 'TestingConfig' object has no attribute 'my_obj_root'

Any changes that I am missing here?

OR
Regardless of the above link. Is there a simpler way to do this where
I can run any IR based test cases outside of llvm source while
referring to the corresponding tool in /build-dir/bin/ or
/install-dir/bin/?

Thanks,
Tejas

Hi, I’m the author of that blog post.

Without knowing the details of your issue, my guess is that somehow LIT didn’t execute the correct config file.
Long story short, there are two LIT config files: The one you put in source directory (lit.cfg.py) and the other one (lit.site.cfg.py), which is generated from a template file (lit.site.cfg.py.in), in the build direcotry
The latter one is the config file LIT should execute first, because it’s actually a trampoline that sets up some environment – the my_obj_root is one of them – before executing the real config file, lit.cfg.py in the source directory.

To answer your section question, there is a simpler way to run LIT: Write a simple lit.cfg.py, put side by side with your test file, and launch LIT at the same directory, period. IIRC this is also the example I showed at the beginning of the blog post.
The problem is, if you have a separate build directory – just like LLVM or most of the CMake-based projects – you will have a hard time configuring the path to your program using this simple setup. The fancy trampoline trick adopted by LLVM is only designed to configure the paths to various tools – like clang and opt – used in the test file.

Hope that answer your question
-Min

Hi,

Hi, I'm the author of that blog post.

Great. That blog post is really helpful.

Without knowing the details of your issue, my guess is that somehow LIT didn't execute the correct config file.
Long story short, there are two LIT config files: The one you put in source directory (lit.cfg.py) and the other one (lit.site.cfg.py), which is generated from a template file (lit.site.cfg.py.in), in the build direcotry
The latter one is the config file LIT should execute first, because it's actually a trampoline that sets up some environment -- the my_obj_root is one of them -- before executing the real config file, lit.cfg.py in the source directory.

Let me explain. Consider the following directory structure (the ones
with -- prefix are subdirs to the upper one):

llvm-project
build-dir (llvm is built here)
install-dir (llvm is installed here)
test-suite
-- tests
---- filename.ll

Now, I want to run test cases (which uses opt, clang, etc) inside the
tests directory using llvm-lit from build-dir or install-dir. After
running llvm-lit on them, the tests should refer to build-dir/bin/ or
install-dir/bin/ binaries to run.
Can you suggest changes from the above blog post for lit.cfg.py,
lit.site.cfg.py.in because I am confused for which file should reside
in what directory in my particular case.

Thanks,
Tejas